mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-23 21:40:02 -04:00
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.
This commit is contained in:
parent
0690875101
commit
6c70b68e65
3 changed files with 20 additions and 7 deletions
fabric-data-generation-api-v1/src
main/java/net/fabricmc/fabric/api/datagen/v1/provider
testmod/java/net/fabricmc/fabric/test/datagen
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue