From 6c70b68e6532658c378cd7623cb770983afbb2c2 Mon Sep 17 00:00:00 2001 From: Shnupbups <shnupbups@gmail.com> Date: Tue, 3 Jan 2023 00:03:40 +1100 Subject: [PATCH] Fixed blocks with vanilla loot tables making strict validation of datagen fail (#2816) * Fixed blocks with vanilla loot tables making strict validation of datagen fail Previously, blocks that used `.dropsLike(block)` in their block settings to use a vanilla block's loot table, or `.dropsNothing()` to use the `minecraft:empty` loot table, would cause strict validation in data generation to fail as the vanilla loot tables wouldn't be present in the mod's own block loot table generator. This fixes that by ensuring that the block's loot table ID has a namespace that matches the loot table generator before adding it to the missing IDs list. Two test blocks were added to the testmod, one which uses `.dropsLike(Blocks.STONE)` to use the same loot table as Stone, and one that uses `.dropsNothing()`. Previously, these would have caused strict validation to fail as the `minecraft:stone` and `minecraft:empty` loot tables aren't generated by the testmod's generator. Now they pass just fine. * Fixed blocks with vanilla loot tables making strict validation of datagen fail Previously, blocks that used `.dropsLike(block)` in their block settings to use a vanilla block's loot table, or `.dropsNothing()` to use the `minecraft:empty` loot table, would cause strict validation in data generation to fail as the vanilla loot tables wouldn't be present in the mod's own block loot table generator. This fixes that by ensuring that the block's loot table ID has a namespace that matches the loot table generator before adding it to the missing IDs list. Two test blocks were added to the testmod, one which uses `.dropsLike(Blocks.STONE)` to use the same loot table as Stone, and one that uses `.dropsNothing()`. Previously, these would have caused strict validation to fail as the `minecraft:stone` and `minecraft:empty` loot tables aren't generated by the testmod's generator. Now they pass just fine. --- .../v1/provider/FabricBlockLootTableProvider.java | 8 ++++++-- .../test/datagen/DataGeneratorTestContent.java | 15 ++++++++++----- .../test/datagen/DataGeneratorTestEntrypoint.java | 4 ++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java index df763ebed..08c3bc34f 100644 --- a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java +++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java @@ -90,8 +90,12 @@ public abstract class FabricBlockLootTableProvider extends BlockLootTableGenerat for (Identifier blockId : Registry.BLOCK.getIds()) { if (blockId.getNamespace().equals(dataGenerator.getModId())) { - if (!lootTables.containsKey(Registry.BLOCK.get(blockId).getLootTableId())) { - missing.add(blockId); + Identifier blockLootTableId = Registry.BLOCK.get(blockId).getLootTableId(); + + if (blockLootTableId.getNamespace().equals(dataGenerator.getModId())) { + if (!lootTables.containsKey(blockLootTableId)) { + missing.add(blockId); + } } } } diff --git a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java index f397f2b82..db7edbe16 100644 --- a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java +++ b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java @@ -20,6 +20,7 @@ import java.util.Objects; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; +import net.minecraft.block.Blocks; import net.minecraft.block.Material; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; @@ -38,19 +39,23 @@ public class DataGeneratorTestContent implements ModInitializer { public static Block SIMPLE_BLOCK; public static Block BLOCK_WITHOUT_ITEM; public static Block BLOCK_WITHOUT_LOOT_TABLE; + public static Block BLOCK_WITH_VANILLA_LOOT_TABLE; + public static Block BLOCK_THAT_DROPS_NOTHING; public static ItemGroup SIMPLE_ITEM_GROUP; @Override public void onInitialize() { SIMPLE_ITEM_GROUP = FabricItemGroupBuilder.build(new Identifier(MOD_ID, "default"), () -> new ItemStack(Items.BONE)); - SIMPLE_BLOCK = createBlock("simple_block", true); - BLOCK_WITHOUT_ITEM = createBlock("block_without_item", false); - BLOCK_WITHOUT_LOOT_TABLE = createBlock("block_without_loot_table", false); + SIMPLE_BLOCK = createBlock("simple_block", true, AbstractBlock.Settings.of(Material.STONE)); + BLOCK_WITHOUT_ITEM = createBlock("block_without_item", false, AbstractBlock.Settings.of(Material.STONE)); + BLOCK_WITHOUT_LOOT_TABLE = createBlock("block_without_loot_table", false, AbstractBlock.Settings.of(Material.STONE)); + BLOCK_WITH_VANILLA_LOOT_TABLE = createBlock("block_with_vanilla_loot_table", false, AbstractBlock.Settings.of(Material.STONE).dropsLike(Blocks.STONE)); + BLOCK_THAT_DROPS_NOTHING = createBlock("block_that_drops_nothing", false, AbstractBlock.Settings.of(Material.STONE).dropsNothing()); } - private static Block createBlock(String name, boolean hasItem) { + private static Block createBlock(String name, boolean hasItem, AbstractBlock.Settings settings) { Identifier identifier = new Identifier(MOD_ID, name); - Block block = Registry.register(Registry.BLOCK, identifier, new Block(AbstractBlock.Settings.of(Material.STONE))); + Block block = Registry.register(Registry.BLOCK, identifier, new Block(settings)); if (hasItem) { Registry.register(Registry.ITEM, identifier, new BlockItem(block, new Item.Settings().group(ItemGroup.MISC))); diff --git a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java index a5e501520..caeda19c7 100644 --- a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java +++ b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java @@ -16,8 +16,10 @@ package net.fabricmc.fabric.test.datagen; +import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.BLOCK_THAT_DROPS_NOTHING; import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.BLOCK_WITHOUT_ITEM; import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.BLOCK_WITHOUT_LOOT_TABLE; +import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.BLOCK_WITH_VANILLA_LOOT_TABLE; import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.MOD_ID; import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.SIMPLE_BLOCK; import static net.fabricmc.fabric.test.datagen.DataGeneratorTestContent.SIMPLE_ITEM_GROUP; @@ -189,6 +191,8 @@ public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint { blockStateModelGenerator.registerSimpleCubeAll(SIMPLE_BLOCK); blockStateModelGenerator.registerSimpleCubeAll(BLOCK_WITHOUT_ITEM); blockStateModelGenerator.registerSimpleCubeAll(BLOCK_WITHOUT_LOOT_TABLE); + blockStateModelGenerator.registerSimpleCubeAll(BLOCK_WITH_VANILLA_LOOT_TABLE); + blockStateModelGenerator.registerSimpleCubeAll(BLOCK_THAT_DROPS_NOTHING); } @Override