diff --git a/src/main/java/dev/falseresync/wizcraft/common/block/EnergizedWorktableBlock.java b/src/main/java/dev/falseresync/wizcraft/common/block/EnergizedWorktableBlock.java index d996644..a5fa083 100644 --- a/src/main/java/dev/falseresync/wizcraft/common/block/EnergizedWorktableBlock.java +++ b/src/main/java/dev/falseresync/wizcraft/common/block/EnergizedWorktableBlock.java @@ -13,10 +13,12 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.block.entity.CampfireBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; +import net.minecraft.util.ItemScatterer; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -74,6 +76,17 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt return super.onUse(state, world, pos, player, hand, hit); } + @Override + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + if (!state.isOf(newState.getBlock())) { + if (world.getBlockEntity(pos) instanceof EnergizedWorktableBlockEntity worktable) { + ItemScatterer.spawn(world, pos, worktable.getInventory()); + } + + super.onStateReplaced(state, world, pos, newState, moved); + } + } + @Override public Identifier getId() { return ID; diff --git a/src/main/java/dev/falseresync/wizcraft/common/block/LensingPedestalBlock.java b/src/main/java/dev/falseresync/wizcraft/common/block/LensingPedestalBlock.java index ec7f056..fb90f9a 100644 --- a/src/main/java/dev/falseresync/wizcraft/common/block/LensingPedestalBlock.java +++ b/src/main/java/dev/falseresync/wizcraft/common/block/LensingPedestalBlock.java @@ -2,6 +2,7 @@ import com.mojang.serialization.MapCodec; import dev.falseresync.wizcraft.common.Wizcraft; +import dev.falseresync.wizcraft.common.block.entity.EnergizedWorktableBlockEntity; import dev.falseresync.wizcraft.common.block.entity.LensingPedestalBlockEntity; import dev.falseresync.wizcraft.api.HasId; import dev.falseresync.wizcraft.common.WizUtil; @@ -14,6 +15,7 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; +import net.minecraft.util.ItemScatterer; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; @@ -67,6 +69,17 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt return super.onUse(state, world, pos, player, hand, hit); } + @Override + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + if (!state.isOf(newState.getBlock())) { + if (world.getBlockEntity(pos) instanceof LensingPedestalBlockEntity pedestal) { + ItemScatterer.spawn(world, pos, pedestal.getInventory()); + } + + super.onStateReplaced(state, world, pos, newState, moved); + } + } + @Override public Identifier getId() { return ID; diff --git a/src/main/java/dev/falseresync/wizcraft/common/block/WizBlocks.java b/src/main/java/dev/falseresync/wizcraft/common/block/WizBlocks.java index b75eb4a..25e56e7 100644 --- a/src/main/java/dev/falseresync/wizcraft/common/block/WizBlocks.java +++ b/src/main/java/dev/falseresync/wizcraft/common/block/WizBlocks.java @@ -19,7 +19,7 @@ public class WizBlocks { static { LENS = r("lens", new Block(FabricBlockSettings.copyOf(Blocks.GLASS).luminance(1))); - ENERGIZED_WORKTABLE = r(new EnergizedWorktableBlock(FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE))); + ENERGIZED_WORKTABLE = r(new EnergizedWorktableBlock(FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE).requiresTool())); LENSING_PEDESTAL = r(new LensingPedestalBlock(FabricBlockSettings.copyOf(Blocks.BRICK_WALL))); } diff --git a/src/main/java/dev/falseresync/wizcraft/common/block/entity/EnergizedWorktableBlockEntity.java b/src/main/java/dev/falseresync/wizcraft/common/block/entity/EnergizedWorktableBlockEntity.java index fdf1562..46bc092 100644 --- a/src/main/java/dev/falseresync/wizcraft/common/block/entity/EnergizedWorktableBlockEntity.java +++ b/src/main/java/dev/falseresync/wizcraft/common/block/entity/EnergizedWorktableBlockEntity.java @@ -133,6 +133,10 @@ public NbtCompound toInitialChunkDataNbt() { return createNbt(); } + public SimpleInventory getInventory() { + return inventory; + } + public InventoryStorage getStorage() { return storage; } diff --git a/src/main/java/dev/falseresync/wizcraft/common/block/entity/LensingPedestalBlockEntity.java b/src/main/java/dev/falseresync/wizcraft/common/block/entity/LensingPedestalBlockEntity.java index 27a0f80..74b2eb9 100644 --- a/src/main/java/dev/falseresync/wizcraft/common/block/entity/LensingPedestalBlockEntity.java +++ b/src/main/java/dev/falseresync/wizcraft/common/block/entity/LensingPedestalBlockEntity.java @@ -63,6 +63,10 @@ public NbtCompound toInitialChunkDataNbt() { return createNbt(); } + public SimpleInventory getInventory() { + return inventory; + } + public InventoryStorage getStorage() { return storage; } diff --git a/src/main/java/dev/falseresync/wizcraft/datagen/WizBlockLootTableProvider.java b/src/main/java/dev/falseresync/wizcraft/datagen/WizBlockLootTableProvider.java new file mode 100644 index 0000000..71b0d56 --- /dev/null +++ b/src/main/java/dev/falseresync/wizcraft/datagen/WizBlockLootTableProvider.java @@ -0,0 +1,18 @@ +package dev.falseresync.wizcraft.datagen; + +import dev.falseresync.wizcraft.common.block.WizBlocks; +import dev.falseresync.wizcraft.common.item.WizItems; +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; + +public class WizBlockLootTableProvider extends FabricBlockLootTableProvider { + protected WizBlockLootTableProvider(FabricDataOutput dataOutput) { + super(dataOutput); + } + + @Override + public void generate() { + addDrop(WizBlocks.ENERGIZED_WORKTABLE, drops(WizItems.ENERGIZED_WORKTABLE)); + addDrop(WizBlocks.LENSING_PEDESTAL, drops(WizItems.LENSING_PEDESTAL)); + } +} diff --git a/src/main/java/dev/falseresync/wizcraft/datagen/WizBlockTagProvider.java b/src/main/java/dev/falseresync/wizcraft/datagen/WizBlockTagProvider.java new file mode 100644 index 0000000..e081a77 --- /dev/null +++ b/src/main/java/dev/falseresync/wizcraft/datagen/WizBlockTagProvider.java @@ -0,0 +1,24 @@ +package dev.falseresync.wizcraft.datagen; + +import dev.falseresync.wizcraft.common.block.WizBlocks; +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.tag.BlockTags; + +import java.util.concurrent.CompletableFuture; + +public class WizBlockTagProvider extends FabricTagProvider.BlockTagProvider { + public WizBlockTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, registriesFuture); + } + + @Override + protected void configure(RegistryWrapper.WrapperLookup arg) { + getOrCreateTagBuilder(BlockTags.AXE_MINEABLE) + .add(WizBlocks.ENERGIZED_WORKTABLE); + getOrCreateTagBuilder(BlockTags.PICKAXE_MINEABLE) + .add(WizBlocks.ENERGIZED_WORKTABLE) + .add(WizBlocks.LENSING_PEDESTAL); + } +} diff --git a/src/main/java/dev/falseresync/wizcraft/datagen/WizcraftDatagen.java b/src/main/java/dev/falseresync/wizcraft/datagen/WizcraftDatagen.java index 71c77c8..b25c543 100644 --- a/src/main/java/dev/falseresync/wizcraft/datagen/WizcraftDatagen.java +++ b/src/main/java/dev/falseresync/wizcraft/datagen/WizcraftDatagen.java @@ -9,5 +9,7 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { var pack = fabricDataGenerator.createPack(); pack.addProvider(WizModelProvider::new); pack.addProvider(WizRecipeProvider::new); + pack.addProvider(WizBlockLootTableProvider::new); + pack.addProvider(WizBlockTagProvider::new); } }