diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockEmptyLavahoarder.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockEmptyLavahoarder.java new file mode 100644 index 0000000..cbffe64 --- /dev/null +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockEmptyLavahoarder.java @@ -0,0 +1,118 @@ +package de.jottyfan.minecraft.quickiefabric.blocks; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import de.jottyfan.minecraft.quickiefabric.items.QuickieItems; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.Material; +import net.minecraft.entity.ExperienceOrbEntity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.loot.context.LootContext.Builder; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +/** + * + * @author jotty + * + */ +public class BlockEmptyLavahoarder extends Block { + + public BlockEmptyLavahoarder() { + super(FabricBlockSettings.of(Material.STONE).hardness(2.5f)); + } + + @Override + public List getDroppedStacks(BlockState state, Builder builder) { + List list = new ArrayList<>(); + list.add(new ItemStack(QuickieBlocks.EMPTYLAVAHOARDER)); + 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 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 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()); + } + Random random = new Random(); + if (amount > 0) { + world.setBlockState(pos, QuickieBlocks.LAVAHOARDER.getDefaultState()); + int count = 0; + for (int i = 0; i < amount; i++) { + if (random.nextFloat() < 0.0125) { + count++; + } + } + BlockPos up = pos.up(); + if (count > 0) { + world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(QuickieItems.SULPHOR, count))); + world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count)))); + world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count)))); + world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(count)))); + world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.IRON_NUGGET, new Random().nextInt(count)))); + world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(count)))); + world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count)); + } + } + } +} diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java index a244c0a..4d45c7b 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java @@ -1,23 +1,21 @@ package de.jottyfan.minecraft.quickiefabric.blocks; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Random; -import java.util.Set; import de.jottyfan.minecraft.quickiefabric.items.QuickieItems; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; import net.minecraft.block.Material; -import net.minecraft.entity.ExperienceOrbEntity; import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.loot.context.LootContext.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; @@ -39,79 +37,20 @@ public class BlockLavahoarder extends Block { 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 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 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()); - } - Random random = new Random(); - if (amount > 0) { - int count = 0; - for (int i = 0; i < amount; i++) { - if (random.nextFloat() < 0.0125) { - count++; - } - } - BlockPos up = pos.up(); - if (count > 0) { - world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(QuickieItems.SULPHOR, count))); - world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count)))); - world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count)))); - world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(count)))); - world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.IRON_NUGGET, new Random().nextInt(count)))); - world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(count)))); - world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count)); + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, + BlockHitResult hit) { + if (!world.isClient) { + 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); + player.setStackInHand(hand, emptyBucketStack); + world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack)); + world.setBlockState(pos, QuickieBlocks.EMPTYLAVAHOARDER.getDefaultState()); } } + return ActionResult.SUCCESS; // forbid to empty the just filled lava bucket } } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/QuickieBlocks.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/QuickieBlocks.java index 09f1b2d..951c0ef 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/QuickieBlocks.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/QuickieBlocks.java @@ -13,6 +13,7 @@ public class QuickieBlocks { public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor(); public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter(); public static final BlockLavahoarder LAVAHOARDER = new BlockLavahoarder(); + public static final BlockEmptyLavahoarder EMPTYLAVAHOARDER = new BlockEmptyLavahoarder(); public static final BlockItemhoarder ITEMHOARDER = new BlockItemhoarder(); public static final BlockMonsterhoarder MONSTERHOARDER = new BlockMonsterhoarder(); public static final BlockKelpstack KELPSTACK = new BlockKelpstack(); diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java index a16d613..3dbec65 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java @@ -121,6 +121,7 @@ public class RegistryManager { stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR)); stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER)); stacks.add(new ItemStack(QuickieBlocks.LAVAHOARDER)); + stacks.add(new ItemStack(QuickieBlocks.EMPTYLAVAHOARDER)); stacks.add(new ItemStack(QuickieBlocks.ITEMHOARDER)); stacks.add(new ItemStack(QuickieBlocks.MONSTERHOARDER)); stacks.add(new ItemStack(QuickieBlocks.KELPSTACK)); @@ -154,6 +155,7 @@ public class RegistryManager { registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor"); registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter"); registerBlock(QuickieBlocks.LAVAHOARDER, "lavahoarder"); + registerBlock(QuickieBlocks.EMPTYLAVAHOARDER, "emptylavahoarder"); registerBlock(QuickieBlocks.ITEMHOARDER, "itemhoarder"); registerBlock(QuickieBlocks.MONSTERHOARDER, "monsterhoarder"); registerBlock(QuickieBlocks.KELPSTACK, "kelpstack"); diff --git a/src/main/resources/assets/quickiefabric/blockstates/emptylavahoarder.json b/src/main/resources/assets/quickiefabric/blockstates/emptylavahoarder.json new file mode 100644 index 0000000..f0a5607 --- /dev/null +++ b/src/main/resources/assets/quickiefabric/blockstates/emptylavahoarder.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "quickiefabric:block/emptylavahoarder" + } + } +} diff --git a/src/main/resources/assets/quickiefabric/lang/de_de.json b/src/main/resources/assets/quickiefabric/lang/de_de.json index 0ab5b94..8476693 100644 --- a/src/main/resources/assets/quickiefabric/lang/de_de.json +++ b/src/main/resources/assets/quickiefabric/lang/de_de.json @@ -43,7 +43,8 @@ "block.quickiefabric.moveup": "Höhenpositionsaddierer", "block.quickiefabric.movedown": "Höhenpositionssubtrahierer", "block.quickiefabric.menu": "Bauplanwerkbank", - "block.quickiefabric.lavahoarder": "Lavasauger", + "block.quickiefabric.lavahoarder": "voller Lavasauger", + "block.quickiefabric.emptylavahoarder": "Lavasauger", "block.quickiefabric.itemhoarder": "Itemsauger", "block.quickiefabric.monsterhoarder": "Monstersauger", "block.quickiefabric.kelpstack": "Seegrassbündel", diff --git a/src/main/resources/assets/quickiefabric/lang/en_us.json b/src/main/resources/assets/quickiefabric/lang/en_us.json index f59bfd7..ffa7106 100644 --- a/src/main/resources/assets/quickiefabric/lang/en_us.json +++ b/src/main/resources/assets/quickiefabric/lang/en_us.json @@ -43,7 +43,8 @@ "block.quickiefabric.moveup": "height position adder", "block.quickiefabric.movedown": "height position substractor", "block.quickiefabric.menu": "building plan crafting table", - "block.quickiefabric.lavahoarder": "lava hoarder", + "block.quickiefabric.lavahoarder": "filled lava hoarder", + "block.quickiefabric.emptylavahoarder": "lava hoarder", "block.quickiefabric.itemhoarder": "item hoarder", "block.quickiefabric.monsterhoarder": "monster hoarder", "block.quickiefabric.kelpstack": "kelp bundle", diff --git a/src/main/resources/assets/quickiefabric/models/block/emptylavahoarder.json b/src/main/resources/assets/quickiefabric/models/block/emptylavahoarder.json new file mode 100644 index 0000000..66413f6 --- /dev/null +++ b/src/main/resources/assets/quickiefabric/models/block/emptylavahoarder.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "quickiefabric:block/emptylavahoarder" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickiefabric/models/item/emptylavahoarder.json b/src/main/resources/assets/quickiefabric/models/item/emptylavahoarder.json new file mode 100644 index 0000000..282da31 --- /dev/null +++ b/src/main/resources/assets/quickiefabric/models/item/emptylavahoarder.json @@ -0,0 +1,10 @@ +{ + "parent": "quickiefabric:block/emptylavahoarder", + "display": { + "thirdperson": { + "rotation": [ 10, -45, 170 ], + "translation": [ 0, 1.5, -2.75 ], + "scale": [ 0.375, 0.375, 0.375 ] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickiefabric/textures/block/emptylavahoarder.png b/src/main/resources/assets/quickiefabric/textures/block/emptylavahoarder.png new file mode 100644 index 0000000..8e0bed9 Binary files /dev/null and b/src/main/resources/assets/quickiefabric/textures/block/emptylavahoarder.png differ