diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java new file mode 100644 index 0000000..2e67ece --- /dev/null +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java @@ -0,0 +1,107 @@ +package de.jottyfan.minecraft.quickiefabric.blocks; + +import java.util.HashSet; +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.util.math.BlockPos; +import net.minecraft.world.World; + +/** + * + * @author jotty + * + */ +public class BlockLavahoarder extends Block { + + public BlockLavahoarder() { + super(FabricBlockSettings.of(Material.STONE).hardness(2.5f)); + } + + 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; + 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)); + } + } + } +} 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 4c4e228..3e445ad 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/QuickieBlocks.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/QuickieBlocks.java @@ -1,4 +1,5 @@ package de.jottyfan.minecraft.quickiefabric.blocks; + /** * * @author jotty @@ -11,4 +12,5 @@ public class QuickieBlocks { public static final BlockOreSandSalpeter ORE_SAND_SALPETER = new BlockOreSandSalpeter(); public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor(); public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter(); + public static final BlockLavahoarder LAVAHOARDER = new BlockLavahoarder(); } 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 5fa1ac4..cde4d4c 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java @@ -56,6 +56,7 @@ public class RegistryManager { stacks.add(new ItemStack(QuickieBlocks.ORE_SAND_SALPETER)); stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR)); stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER)); + stacks.add(new ItemStack(QuickieBlocks.LAVAHOARDER)); }).build(); private static final void registerBlock(Block block, String name) { @@ -75,6 +76,7 @@ public class RegistryManager { registerBlock(QuickieBlocks.ORE_SAND_SALPETER, "oresandsalpeter"); registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor"); registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter"); + registerBlock(QuickieBlocks.LAVAHOARDER, "lavahoarder"); } public static final void registerItems() { diff --git a/src/main/resources/assets/quickiefabric/blockstates/lavahoarder.json b/src/main/resources/assets/quickiefabric/blockstates/lavahoarder.json new file mode 100644 index 0000000..eb1b9df --- /dev/null +++ b/src/main/resources/assets/quickiefabric/blockstates/lavahoarder.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "quickiefabric:block/lavahoarder" + } + } +} diff --git a/src/main/resources/assets/quickiefabric/models/block/lavahoarder.json b/src/main/resources/assets/quickiefabric/models/block/lavahoarder.json new file mode 100644 index 0000000..4ca8667 --- /dev/null +++ b/src/main/resources/assets/quickiefabric/models/block/lavahoarder.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "quickiefabric:block/lavahoarder" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickiefabric/models/item/lavahoarder.json b/src/main/resources/assets/quickiefabric/models/item/lavahoarder.json new file mode 100644 index 0000000..83a2809 --- /dev/null +++ b/src/main/resources/assets/quickiefabric/models/item/lavahoarder.json @@ -0,0 +1,10 @@ +{ + "parent": "quickiefabric:block/lavahoarder", + "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/lavahoarder.png b/src/main/resources/assets/quickiefabric/textures/block/lavahoarder.png new file mode 100644 index 0000000..7ae48cb Binary files /dev/null and b/src/main/resources/assets/quickiefabric/textures/block/lavahoarder.png differ diff --git a/src/main/resources/data/quickiefabric/recipes/lavahoarder.json b/src/main/resources/data/quickiefabric/recipes/lavahoarder.json new file mode 100644 index 0000000..37072a8 --- /dev/null +++ b/src/main/resources/data/quickiefabric/recipes/lavahoarder.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ooo", + "oso", + "ooo" + ], + "key": { + "o": { + "item": "minecraft:obsidian" + }, + "s": { + "item": "quickiefabric:speedpowder" + } + }, + "result": { + "item": "quickiefabric:lavahoarder", + "count": 1 + } +} \ No newline at end of file