diff --git a/src/generated/resources/data/occultism/loot_tables/blocks/stable_wormhole.json b/src/generated/resources/data/occultism/loot_tables/blocks/stable_wormhole.json index 053cdf6c7..4f572422b 100644 --- a/src/generated/resources/data/occultism/loot_tables/blocks/stable_wormhole.json +++ b/src/generated/resources/data/occultism/loot_tables/blocks/stable_wormhole.json @@ -3,7 +3,50 @@ "pools": [ { "bonus_rolls": 0.0, - "entries": [], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_nbt", + "ops": [ + { + "op": "replace", + "source": "linkedStorageControllerPosition", + "target": "BlockEntityTag.linkedStorageControllerPosition" + }, + { + "op": "replace", + "source": "sortDirection", + "target": "BlockEntityTag.sortDirection" + }, + { + "op": "replace", + "source": "sortType", + "target": "BlockEntityTag.sortType" + }, + { + "op": "replace", + "source": "matrix", + "target": "BlockEntityTag.matrix" + }, + { + "op": "replace", + "source": "orderStack", + "target": "BlockEntityTag.orderStack" + } + ], + "source": "block_entity" + } + ], + "name": "occultism:stable_wormhole" + } + ], "rolls": 1.0 } ], diff --git a/src/generated/resources/data/occultism/loot_tables/blocks/storage_controller.json b/src/generated/resources/data/occultism/loot_tables/blocks/storage_controller.json index 0fe26da76..a363bc138 100644 --- a/src/generated/resources/data/occultism/loot_tables/blocks/storage_controller.json +++ b/src/generated/resources/data/occultism/loot_tables/blocks/storage_controller.json @@ -3,7 +3,55 @@ "pools": [ { "bonus_rolls": 0.0, - "entries": [], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_nbt", + "ops": [ + { + "op": "replace", + "source": "items", + "target": "BlockEntityTag.items" + }, + { + "op": "replace", + "source": "sortDirection", + "target": "BlockEntityTag.sortDirection" + }, + { + "op": "replace", + "source": "sortType", + "target": "BlockEntityTag.sortType" + }, + { + "op": "replace", + "source": "maxSlots", + "target": "BlockEntityTag.maxSlots" + }, + { + "op": "replace", + "source": "matrix", + "target": "BlockEntityTag.matrix" + }, + { + "op": "replace", + "source": "orderStack", + "target": "BlockEntityTag.orderStack" + } + ], + "source": "block_entity" + } + ], + "name": "occultism:storage_controller" + } + ], "rolls": 1.0 } ], diff --git a/src/main/java/com/klikli_dev/occultism/common/block/storage/StableWormholeBlock.java b/src/main/java/com/klikli_dev/occultism/common/block/storage/StableWormholeBlock.java index 08362b02c..b4506b7bd 100644 --- a/src/main/java/com/klikli_dev/occultism/common/block/storage/StableWormholeBlock.java +++ b/src/main/java/com/klikli_dev/occultism/common/block/storage/StableWormholeBlock.java @@ -218,7 +218,6 @@ public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState n } } } - BlockEntityUtil.onBlockChangeDropWithNbt(this, state, worldIn, pos, newState); super.onRemove(state, worldIn, pos, newState, isMoving); } diff --git a/src/main/java/com/klikli_dev/occultism/common/block/storage/StorageControllerBlock.java b/src/main/java/com/klikli_dev/occultism/common/block/storage/StorageControllerBlock.java index 9e3647576..39edd19be 100644 --- a/src/main/java/com/klikli_dev/occultism/common/block/storage/StorageControllerBlock.java +++ b/src/main/java/com/klikli_dev/occultism/common/block/storage/StorageControllerBlock.java @@ -72,13 +72,6 @@ public boolean isPathfindable(BlockState pState, BlockGetter pLevel, BlockPos pP return super.isPathfindable(pState, pLevel, pPos, pType); } - @Override - @SuppressWarnings("deprecation") - public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - BlockEntityUtil.onBlockChangeDropWithNbt(this, state, worldIn, pos, newState); - super.onRemove(state, worldIn, pos, newState, isMoving); - } - @Override @SuppressWarnings("deprecation") public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, diff --git a/src/main/java/com/klikli_dev/occultism/datagen/loot/OccultismBlockLoot.java b/src/main/java/com/klikli_dev/occultism/datagen/loot/OccultismBlockLoot.java index 57db00b09..8de35643c 100644 --- a/src/main/java/com/klikli_dev/occultism/datagen/loot/OccultismBlockLoot.java +++ b/src/main/java/com/klikli_dev/occultism/datagen/loot/OccultismBlockLoot.java @@ -5,6 +5,8 @@ import com.klikli_dev.occultism.common.block.otherworld.IOtherworldBlock; import com.klikli_dev.occultism.registry.OccultismBlocks; import com.klikli_dev.occultism.registry.OccultismItems; +import com.klikli_dev.theurgy.registry.BlockRegistry; +import com.mojang.datafixers.util.Pair; import net.minecraft.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.loot.BlockLootSubProvider; @@ -19,14 +21,17 @@ import net.minecraft.world.level.storage.loot.LootPool; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction; import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction; import net.minecraft.world.level.storage.loot.predicates.BonusLevelTableCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; +import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator; import net.neoforged.neoforge.registries.DeferredHolder; +import java.util.Arrays; import java.util.Set; import java.util.function.BiConsumer; @@ -81,6 +86,24 @@ else if (settings.lootTableType == OccultismBlocks.LootTableType.OTHERWORLD_BLOC this.add(OccultismBlocks.SILVER_ORE.get(), this.createOreDrop(OccultismBlocks.SILVER_ORE.get(), OccultismItems.RAW_SILVER.get())); this.add(OccultismBlocks.SILVER_ORE_DEEPSLATE.get(), this.createOreDrop(OccultismBlocks.SILVER_ORE_DEEPSLATE.get(), OccultismItems.RAW_SILVER.get())); this.add(OccultismBlocks.IESNIUM_ORE.get(), this.createOreDrop(OccultismBlocks.IESNIUM_ORE.get(), OccultismItems.RAW_IESNIUM.get())); + + this.dropSelfWithNbt(OccultismBlocks.STORAGE_CONTROLLER.get(), + "items", + "sortDirection", + "sortType", + "maxSlots", + "matrix", + "orderStack" + ); + + + this.dropSelfWithNbt(OccultismBlocks.STABLE_WORMHOLE.get(), + "linkedStorageControllerPosition", + "sortDirection", + "sortType", + "matrix", + "orderStack" + ); } protected void registerOtherworldBlockTable(Block block) { @@ -135,4 +158,36 @@ protected LootTable.Builder createOtherworldLeavesDrops(Block leavesBlock, Block public void registerDropNothingLootTable(Block block) { this.add(block, LootTable.lootTable().withPool(LootPool.lootPool())); } + + @SuppressWarnings("unchecked") + protected final void dropSelfWithNbt(Block pBlock, String... sourcePaths) { + this.dropSelfWithNbt(pBlock, Arrays.stream(sourcePaths).map(s -> Pair.of(s, "BlockEntityTag." + s)).toArray(Pair[]::new)); + } + + @SafeVarargs + protected final void dropSelfWithNbt(Block pBlock, Pair... sourceTargetPathPairs) { + this.add(pBlock, this.createSelfWithNbtDrop(pBlock, this.copyData(sourceTargetPathPairs))); + } + + protected LootTable.Builder createSelfWithNbtDrop(Block pBlock, CopyNbtFunction.Builder data) { + return LootTable.lootTable() + .withPool( + this.applyExplosionCondition(pBlock, + LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add( + LootItem.lootTableItem(pBlock) + .apply( + data + ) + ) + ) + ); + } + + protected CopyNbtFunction.Builder copyData(Pair... sourceTargetPathPairs) { + var builder = CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY); + for (var pair : sourceTargetPathPairs) { + builder.copy(pair.getFirst(), pair.getSecond()); + } + return builder; + } } diff --git a/src/main/java/com/klikli_dev/occultism/registry/OccultismBlocks.java b/src/main/java/com/klikli_dev/occultism/registry/OccultismBlocks.java index c8db13a94..877b4696b 100644 --- a/src/main/java/com/klikli_dev/occultism/registry/OccultismBlocks.java +++ b/src/main/java/com/klikli_dev/occultism/registry/OccultismBlocks.java @@ -185,7 +185,8 @@ public void tick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSou Block.Properties.of() .mapColor(MapColor.STONE) .sound(SoundType.STONE) - .strength(5f, 100).noOcclusion()), false, LootTableType.EMPTY); + .strength(5f, 100).noOcclusion()), false, LootTableType.CUSTOM); + public static final DeferredBlock STORAGE_STABILIZER_TIER1 = register( "storage_stabilizer_tier1", () -> new StorageStabilizerBlock( Block.Properties.of() @@ -216,7 +217,7 @@ public void tick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSou Block.Properties.of() .mapColor(MapColor.STONE) .sound(SoundType.STONE).noCollission() - .strength(2f, 2).noOcclusion()), false, LootTableType.EMPTY); + .strength(2f, 2).noOcclusion()), false, LootTableType.CUSTOM); public static final DeferredBlock DIMENSIONAL_MINESHAFT = register("dimensional_mineshaft", () -> new DimensionalMineshaftBlock(