added lava hoarder
This commit is contained in:
parent
5f068b5cdb
commit
80e979d059
@ -0,0 +1,85 @@
|
||||
package de.jottyfan.quickiemod.blockentity;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
|
||||
import de.jottyfan.quickiemod.init.RegistryManager;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class EmptyLavaHoarderBlockEntity extends BlockEntity {
|
||||
|
||||
public EmptyLavaHoarderBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(RegistryManager.EMPTYLAVAHOARDER, pos, state);
|
||||
}
|
||||
|
||||
public static final void spawnRandomItems(World world, BlockPos pos, Integer count) {
|
||||
Integer which = new Random().nextInt(10);
|
||||
if (which < 1) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count + 2))));
|
||||
} else if (which < 2) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count + 1))));
|
||||
} else if (which < 3) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.RAW_GOLD, new Random().nextInt(count))));
|
||||
} else if (which < 4) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.RAW_IRON, new Random().nextInt(count + 1))));
|
||||
} else if (which < 5) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.RAW_COPPER, new Random().nextInt(count + 2))));
|
||||
} else if (which < 6) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.OBSIDIAN)));
|
||||
} else if (which < 7) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LAPIS_LAZULI)));
|
||||
} else if (which < 8) {
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(QuickieItems.SULPHOR.getItem())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sucks the lava that touches the block
|
||||
*
|
||||
* @param world the world
|
||||
* @param pos the pos
|
||||
* @return true if lava was found
|
||||
*/
|
||||
private boolean suckLava(World world, BlockPos pos) {
|
||||
if (world == null) {
|
||||
return false;
|
||||
} else if (Blocks.LAVA.equals(world.getBlockState(pos).getBlock())) {
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
BlockPos up = pos.up();
|
||||
Random random = new Random();
|
||||
if (random.nextFloat() > 0.9f) {
|
||||
spawnRandomItems(world, up, 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
|
||||
if (be instanceof EmptyLavaHoarderBlockEntity) {
|
||||
EmptyLavaHoarderBlockEntity elhbe = (EmptyLavaHoarderBlockEntity) be;
|
||||
boolean found = elhbe.suckLava(world, pos.north());
|
||||
found = found || elhbe.suckLava(world, pos.south());
|
||||
found = found || elhbe.suckLava(world, pos.east());
|
||||
found = found || elhbe.suckLava(world, pos.west());
|
||||
found = found || elhbe.suckLava(world, pos.up());
|
||||
found = found || elhbe.suckLava(world, pos.down());
|
||||
if (found) {
|
||||
world.setBlockState(pos, QuickieBlocks.LAVAHOARDER.getBlock().getDefaultState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package de.jottyfan.quickiemod.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import de.jottyfan.quickiemod.blockentity.EmptyLavaHoarderBlockEntity;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider {
|
||||
|
||||
public BlockEmptyLavahoarder() {
|
||||
super(AbstractBlock.Settings.create().hardness(2.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
|
||||
return new EmptyLavaHoarderBlockEntity(pos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
|
||||
return (world1, pos, state1, be) -> EmptyLavaHoarderBlockEntity.tick(world1, pos, state1, be);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(QuickieBlocks.EMPTYLAVAHOARDER.getBlock()));
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final String stringOf(BlockPos pos) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(pos.getX()).append(":");
|
||||
buf.append(pos.getY()).append(":");
|
||||
buf.append(pos.getZ());
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static final BlockPos blockPosOf(String s) {
|
||||
if (s.contains(":")) {
|
||||
String[] parts = s.split(":");
|
||||
if (parts.length > 2) {
|
||||
Integer x = Integer.valueOf(parts[0]);
|
||||
Integer y = Integer.valueOf(parts[1]);
|
||||
Integer z = Integer.valueOf(parts[2]);
|
||||
return new BlockPos(x, y, z);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void findAllAttachedLavaBlocks(Set<String> list, BlockPos pos, World world, Integer counter) {
|
||||
if (counter < 1) {
|
||||
return;
|
||||
} else if (Blocks.LAVA.equals(world.getBlockState(pos).getBlock())) {
|
||||
String p = stringOf(pos);
|
||||
if (!list.contains(p)) {
|
||||
list.add(p);
|
||||
findAllAttachedLavaBlocks(list, pos.up(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.down(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.north(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.south(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.east(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.west(), world, counter - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
Set<String> positions = new HashSet<>();
|
||||
Integer counter = 8; // TODO: make it level up - able
|
||||
findAllAttachedLavaBlocks(positions, pos.up(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.down(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.north(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.south(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.east(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.west(), world, counter);
|
||||
Integer amount = positions.size();
|
||||
for (String p : positions) {
|
||||
world.setBlockState(blockPosOf(p), Blocks.AIR.getDefaultState());
|
||||
}
|
||||
if (amount > 0) {
|
||||
world.setBlockState(pos, QuickieBlocks.LAVAHOARDER.getBlock().getDefaultState());
|
||||
int count = 0;
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (random.nextFloat() < 0.0125) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
BlockPos up = pos.up();
|
||||
if (count > 0) {
|
||||
EmptyLavaHoarderBlockEntity.spawnRandomItems(world, up, count);
|
||||
world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package de.jottyfan.quickiemod.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blockentity.EmptyLavaHoarderBlockEntity;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockLavahoarder extends Block implements BlockEntityProvider {
|
||||
|
||||
public BlockLavahoarder() {
|
||||
super(AbstractBlock.Settings.create().hardness(2.5f).luminance(state -> 15));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
|
||||
return new EmptyLavaHoarderBlockEntity(pos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
|
||||
BlockEntityType<T> type) {
|
||||
return (world1, pos, state1, be) -> EmptyLavaHoarderBlockEntity.tick(world1, pos, state1, be);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(QuickieBlocks.LAVAHOARDER.getBlock()));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||
if (!world.isClient) {
|
||||
Hand hand = player.getActiveHand();
|
||||
ItemStack handStack = player.getStackInHand(hand);
|
||||
if (handStack != null && Items.BUCKET.equals(handStack.getItem())) {
|
||||
Integer amount = handStack.getCount();
|
||||
ItemStack lavaBucketStack = new ItemStack(Items.LAVA_BUCKET, 1);
|
||||
ItemStack emptyBucketStack = new ItemStack(Items.BUCKET, amount - 1);
|
||||
if (emptyBucketStack.getCount() < 1) {
|
||||
player.setStackInHand(hand, lavaBucketStack);
|
||||
} else {
|
||||
player.setStackInHand(hand, emptyBucketStack);
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack));
|
||||
}
|
||||
EmptyLavaHoarderBlockEntity.spawnRandomItems(world, pos, 2);
|
||||
world.setBlockState(pos, QuickieBlocks.EMPTYLAVAHOARDER.getBlock().getDefaultState());
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS; // forbid to empty the just filled lava bucket
|
||||
}
|
||||
}
|
@ -9,6 +9,8 @@ import net.minecraft.block.Block;
|
||||
*/
|
||||
public enum QuickieBlocks {
|
||||
// @formatter:off
|
||||
LAVAHOARDER(new BlockLavahoarder(), "lavahoarder", false),
|
||||
EMPTYLAVAHOARDER(new BlockEmptyLavahoarder(), "emptylavahoarder"),
|
||||
KELPSTACK(new BlockKelpstack(), "kelpstack"),
|
||||
COTTONPLANT(new BlockCottonplant(), "cottonplant", false),
|
||||
CANOLAPLANT(new BlockCanolaplant(), "canolaplant", false),
|
||||
|
@ -0,0 +1,22 @@
|
||||
package de.jottyfan.quickiemod.init;
|
||||
|
||||
import de.jottyfan.quickiemod.QuickieMod;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockEntityIdentity {
|
||||
public static final Identifier ITEMHOARDER = new Identifier(QuickieMod.MODID, "itemhoarderblockentity");
|
||||
public static final Identifier BLOCKSPREADER = new Identifier(QuickieMod.MODID, "blockspreaderblockentity");
|
||||
public static final Identifier BLOCKSTACKERUP = new Identifier(QuickieMod.MODID, "blockstackerblockentity");
|
||||
public static final Identifier MONSTERHOARDER = new Identifier(QuickieMod.MODID, "monsterhoarderblockentity");
|
||||
public static final Identifier EMPTYLAVALHOARDER = new Identifier(QuickieMod.MODID, "emptylavahoarderblockentity");
|
||||
public static final Identifier DRILL_DOWN = new Identifier(QuickieMod.MODID, "drillblockdownblockentity");
|
||||
public static final Identifier DRILL_EAST = new Identifier(QuickieMod.MODID, "drillblockeastblockentity");
|
||||
public static final Identifier DRILL_SOUTH = new Identifier(QuickieMod.MODID, "drillblocksouthblockentity");
|
||||
public static final Identifier DRILL_WEST = new Identifier(QuickieMod.MODID, "drillblockwestblockentity");
|
||||
public static final Identifier DRILL_NORTH = new Identifier(QuickieMod.MODID, "drillblocknorthblockentity");
|
||||
}
|
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.jottyfan.quickiemod.QuickieMod;
|
||||
import de.jottyfan.quickiemod.blockentity.EmptyLavaHoarderBlockEntity;
|
||||
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||
@ -12,6 +13,7 @@ import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||
import net.fabricmc.fabric.api.registry.FuelRegistry;
|
||||
import net.minecraft.block.ComposterBlock;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item.Settings;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -30,6 +32,8 @@ import net.minecraft.util.Identifier;
|
||||
public class RegistryManager {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(QuickieMod.MODID);
|
||||
|
||||
public static final BlockEntityType<EmptyLavaHoarderBlockEntity> EMPTYLAVAHOARDER = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.EMPTYLAVALHOARDER, BlockEntityType.Builder.create(EmptyLavaHoarderBlockEntity::new, QuickieBlocks.EMPTYLAVAHOARDER.getBlock(), QuickieBlocks.LAVAHOARDER.getBlock()).build(null));
|
||||
|
||||
public static final void registerItemGroup() {
|
||||
Registry.register(Registries.ITEM_GROUP, RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(QuickieMod.MODID, "itemgroups")),
|
||||
FabricItemGroup.builder().icon(() -> new ItemStack(QuickieItems.ROTTEN_FLESH_STRIPES.getItem())).displayName(Text.literal(QuickieMod.MODID))
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "quickiemod:block/emptylavahoarder"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "quickiemod:block/lavahoarder"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "quickiemod:block/emptylavahoarder"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "quickiemod:block/lavahoarder"
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"parent": "quickiemod:block/emptylavahoarder",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"parent": "quickiemod:block/lavahoarder",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 542 B |
Binary file not shown.
After Width: | Height: | Size: 709 B |
@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"ooo",
|
||||
"obo",
|
||||
"ooo"
|
||||
],
|
||||
"key": {
|
||||
"o": {
|
||||
"item": "minecraft:obsidian"
|
||||
},
|
||||
"b": {
|
||||
"item": "minecraft:bucket"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:emptylavahoarder",
|
||||
"count": 1
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user