diff --git a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java index f67ef314..06afd420 100644 --- a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.world.item.Item; @@ -40,6 +41,13 @@ public abstract class ComplexMaterial { MATERIALS.add(this); } + /** + * Initialize and registers all content inside material, return material itself. + * @param blocksRegistry {@link BlockRegistry} instance to add blocks in; + * @param itemsRegistry {@link ItemRegistry} instance to add items in; + * @param recipeConfig {@link PathConfig} for recipes check. + * @return {@link ComplexMaterial}. + */ public ComplexMaterial init(BlockRegistry blocksRegistry, ItemRegistry itemsRegistry, PathConfig recipeConfig) { initTags(); @@ -58,48 +66,100 @@ public abstract class ComplexMaterial { }); initRecipes(recipeConfig); - initFlammable(); + initFlammable(FlammableBlockRegistry.getDefaultInstance()); return this; } + /** + * Init default content for {@link ComplexMaterial} - blocks and items. + * @param blockSettings {@link FabricBlockSettings} default block settings for this material; + * @param itemSettings {@link FabricItemSettings} default item settings for this material. + */ protected abstract void initDefault(FabricBlockSettings blockSettings, FabricItemSettings itemSettings); + /** + * Init custom tags for this {@link ComplexMaterial}, not required. + */ protected void initTags() {} + /** + * Init custom recipes for this {@link ComplexMaterial}, not required. + */ protected void initRecipes(PathConfig recipeConfig) {} - protected void initFlammable() {} + /** + * Allows to add blocks into Fabric {@link FlammableBlockRegistry} for this {@link ComplexMaterial}, not required. + */ + protected void initFlammable(FlammableBlockRegistry registry) {} + /** + * Adds custom block tag for this {@link ComplexMaterial}, tag can be created with {@link ru.bclib.api.TagAPI} or you can use one of already created tags. + * @param tag {@link Tag.Named} for {@link Block} + */ protected void addBlockTag(Tag.Named tag) { - blockTags.put(tag.getName().getPath(), tag); + String key = tag.getName().getPath().replace(getBaseName() + "_", ""); + blockTags.put(key, tag); } + /** + * Adds custom iten tag for this {@link ComplexMaterial}, tag can be created with {@link ru.bclib.api.TagAPI} or you can use one of already created tags. + * @param tag {@link Tag.Named} for {@link Item} + */ protected void addItemTag(Tag.Named tag) { - itemTags.put(tag.getName().getPath(), tag); + String key = tag.getName().getPath().replace(getBaseName() + "_", ""); + itemTags.put(key, tag); } + /** + * Get custom {@link Block} {@link Tag.Named} from this {@link ComplexMaterial}. + * @param key {@link String} tag name (path of its {@link ResourceLocation}), for inner tags created inside material its tag suffix. + * @return {@link Tag.Named} for {@link Block} or {@code null} if nothing is stored. + */ @Nullable public Tag.Named getBlockTag(String key) { return blockTags.get(key); } + /** + * Get custom {@link Item} {@link Tag.Named} from this {@link ComplexMaterial}. + * @param key {@link String} tag name (path of its {@link ResourceLocation}), for inner tags created inside material its tag suffix. + * @return {@link Tag.Named} for {@link Item} or {@code null} if nothing is stored. + */ @Nullable public Tag.Named getItemTag(String key) { return itemTags.get(key); } + /** + * Get initiated {@link Block} from this {@link ComplexMaterial}. + * @param key {@link String} block name suffix (example: "mod:custom_log" will have a "log" suffix if "custom" is a base name of this material) + * @return {@link Block} or {@code null} if nothing is stored. + */ @Nullable public Block getBlock(String key) { return blocks.get(key); } + /** + * Get initiated {@link Item} from this {@link ComplexMaterial}. + * @param key {@link String} block name suffix (example: "mod:custom_apple" will have a "apple" suffix if "custom" is a base name of this material) + * @return {@link Item} or {@code null} if nothing is stored. + */ @Nullable public Item getItem(String key) { return items.get(key); } + /** + * Get default block settings for this material. + * @return {@link FabricBlockSettings} + */ protected abstract FabricBlockSettings getBlockSettings(); + /** + * Get default item settings for this material. + * @return {@link FabricItemSettings} + */ protected FabricItemSettings getItemSettings(ItemRegistry registry) { return registry.makeItemSettings(); } @@ -122,24 +182,71 @@ public abstract class ComplexMaterial { return result; } + /** + * Get base name of this {@link ComplexMaterial}. + * @return {@link String} name + */ public String getBaseName() { return baseName; } + /** + * Get mod ID for this {@link ComplexMaterial}. + * @return {@link String} mod ID. + */ public String getModID() { return modID; } + /** + * Get a unique {@link ResourceLocation} for each material class. + * For example WoodenComplexMaterial will have a "bclib:Wooden_Complex_Material" {@link ResourceLocation}. + * This is used to add custom entries before mods init using Fabric "preLaunch" entry point. + * @see tagBlockLog = getBlockTag(getBaseName() + "_logs"); - Tag.Named tagItemLog = getItemTag(getBaseName() + "_logs"); + Tag.Named tagBlockLog = getBlockTag(TAG_LOGS); + Tag.Named tagItemLog = getItemTag(TAG_LOGS); addBlockEntry( - new BlockEntry("stripped_log", (complexMaterial, settings) -> { + new BlockEntry(BLOCK_STRIPPED_LOG, (complexMaterial, settings) -> { return new BaseRotatedPillarBlock(settings); }) .setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog) .setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog) ); addBlockEntry( - new BlockEntry("stripped_bark", (complexMaterial, settings) -> { + new BlockEntry(BLOCK_STRIPPED_BARK, (complexMaterial, settings) -> { return new BaseBarkBlock(settings); }) .setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog) @@ -90,109 +114,94 @@ public class WoodenMaterial extends ComplexMaterial { ); addBlockEntry( - new BlockEntry("log", (complexMaterial, settings) -> { + new BlockEntry(BLOCK_LOG, (complexMaterial, settings) -> { return new BaseStripableLogBlock(woodColor, getBlock("stripped_log")); }) .setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog) .setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog) ); addBlockEntry( - new BlockEntry("bark", (complexMaterial, settings) -> { + new BlockEntry(BLOCK_BARK, (complexMaterial, settings) -> { return new StripableBarkBlock(woodColor, getBlock("stripped_bark")); }) .setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog) .setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog) ); - addBlockEntry(new BlockEntry("planks", (complexMaterial, settings) -> { + addBlockEntry(new BlockEntry(BLOCK_PLANKS, (complexMaterial, settings) -> { return new BaseBlock(settings); }).setBlockTags(BlockTags.PLANKS).setItemTags(ItemTags.PLANKS)); - addBlockEntry(new BlockEntry("stairs", (complexMaterial, settings) -> { - return new BaseStairsBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_STAIRS, (complexMaterial, settings) -> { + return new BaseStairsBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.WOODEN_STAIRS, BlockTags.STAIRS).setItemTags(ItemTags.WOODEN_STAIRS, ItemTags.STAIRS)); - addBlockEntry(new BlockEntry("slab", (complexMaterial, settings) -> { - return new BaseSlabBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_SLAB, (complexMaterial, settings) -> { + return new BaseSlabBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.WOODEN_SLABS, BlockTags.SLABS).setItemTags(ItemTags.WOODEN_SLABS, ItemTags.SLABS)); - addBlockEntry(new BlockEntry("fence", (complexMaterial, settings) -> { - return new BaseFenceBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_FENCE, (complexMaterial, settings) -> { + return new BaseFenceBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.FENCES, BlockTags.WOODEN_FENCES).setItemTags(ItemTags.FENCES, ItemTags.WOODEN_FENCES)); - addBlockEntry(new BlockEntry("gate", (complexMaterial, settings) -> { - return new BaseGateBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_GATE, (complexMaterial, settings) -> { + return new BaseGateBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.FENCE_GATES)); - addBlockEntry(new BlockEntry("button", (complexMaterial, settings) -> { - return new BaseWoodenButtonBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_BUTTON, (complexMaterial, settings) -> { + return new BaseWoodenButtonBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.BUTTONS, BlockTags.WOODEN_BUTTONS).setItemTags(ItemTags.BUTTONS, ItemTags.WOODEN_BUTTONS)); - addBlockEntry(new BlockEntry("plate", (complexMaterial, settings) -> { - return new WoodenPressurePlateBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_PRESSURE_PLATE, (complexMaterial, settings) -> { + return new WoodenPressurePlateBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.PRESSURE_PLATES, BlockTags.WOODEN_PRESSURE_PLATES).setItemTags(ItemTags.WOODEN_PRESSURE_PLATES)); - addBlockEntry(new BlockEntry("trapdoor", (complexMaterial, settings) -> { - return new BaseTrapdoorBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_TRAPDOOR, (complexMaterial, settings) -> { + return new BaseTrapdoorBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.TRAPDOORS, BlockTags.WOODEN_TRAPDOORS).setItemTags(ItemTags.TRAPDOORS, ItemTags.WOODEN_TRAPDOORS)); - addBlockEntry(new BlockEntry("door", (complexMaterial, settings) -> { - return new BaseDoorBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_DOOR, (complexMaterial, settings) -> { + return new BaseDoorBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.DOORS, BlockTags.WOODEN_DOORS).setItemTags(ItemTags.DOORS, ItemTags.WOODEN_DOORS)); - addBlockEntry(new BlockEntry("crafting_table", (complexMaterial, settings) -> { - return new BaseCraftingTableBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_CRAFTING_TABLE, (complexMaterial, settings) -> { + return new BaseCraftingTableBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(TagAPI.BLOCK_WORKBENCHES).setItemTags(TagAPI.ITEM_WORKBENCHES)); - addBlockEntry(new BlockEntry("ladder", (complexMaterial, settings) -> { - return new BaseLadderBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_LADDER, (complexMaterial, settings) -> { + return new BaseLadderBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.CLIMBABLE)); - addBlockEntry(new BlockEntry("sign", (complexMaterial, settings) -> { - return new BaseSignBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_SIGN, (complexMaterial, settings) -> { + return new BaseSignBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(BlockTags.SIGNS).setItemTags(ItemTags.SIGNS)); - addBlockEntry(new BlockEntry("chest", (complexMaterial, settings) -> { - return new BaseChestBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_CHEST, (complexMaterial, settings) -> { + return new BaseChestBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(TagAPI.BLOCK_CHEST).setItemTags(TagAPI.ITEM_CHEST)); - addBlockEntry(new BlockEntry("barrel", (complexMaterial, settings) -> { - return new BaseBarrelBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_BARREL, (complexMaterial, settings) -> { + return new BaseBarrelBlock(getBlock(BLOCK_PLANKS)); })); - addBlockEntry(new BlockEntry("bookshelf", (complexMaterial, settings) -> { - return new BaseBookshelfBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_BOOKSHELF, (complexMaterial, settings) -> { + return new BaseBookshelfBlock(getBlock(BLOCK_PLANKS)); }).setBlockTags(TagAPI.BLOCK_BOOKSHELVES)); - addBlockEntry(new BlockEntry("composter", (complexMaterial, settings) -> { - return new BaseComposterBlock(getBlock("planks")); + addBlockEntry(new BlockEntry(BLOCK_COMPOSTER, (complexMaterial, settings) -> { + return new BaseComposterBlock(getBlock(BLOCK_PLANKS)); })); } - protected void initFlammable() { - FlammableBlockRegistry.getDefaultInstance().add(getBlock("log"), 5, 5); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("bark"), 5, 5); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("stripped_log"), 5, 5); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("stripped_bark"), 5, 5); + @Override + protected void initFlammable(FlammableBlockRegistry registry) { + getBlocks().forEach(block -> { + registry.add(block, 5, 20); + }); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("planks"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("stairs"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("slab"), 5, 20); - - FlammableBlockRegistry.getDefaultInstance().add(getBlock("fence"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("gate"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("button"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("plate"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("trapdoor"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("door"), 5, 20); - - FlammableBlockRegistry.getDefaultInstance().add(getBlock("crafting_table"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("ladder"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("sign"), 5, 20); - - FlammableBlockRegistry.getDefaultInstance().add(getBlock("chest"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("barrel"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("bookshelf"), 5, 20); - FlammableBlockRegistry.getDefaultInstance().add(getBlock("composter"), 5, 20); + registry.add(getBlock(BLOCK_LOG), 5, 5); + registry.add(getBlock(BLOCK_BARK), 5, 5); + registry.add(getBlock(BLOCK_STRIPPED_LOG), 5, 5); + registry.add(getBlock(BLOCK_STRIPPED_BARK), 5, 5); } @Override public void initRecipes(PathConfig recipeConfig) { - Block log_stripped = getBlock("stripped_log"); - Block bark_stripped = getBlock("stripped_bark"); - Block log = getBlock("log"); - Block bark = getBlock("bark"); - Block planks = getBlock("planks"); - Block stairs = getBlock("stairs"); - Block slab = getBlock("slab"); - Block fence = getBlock("fence"); + Block log_stripped = getBlock(BLOCK_STRIPPED_LOG); + Block bark_stripped = getBlock(BLOCK_STRIPPED_BARK); + Block log = getBlock(BLOCK_LOG); + Block bark = getBlock(BLOCK_BARK); + Block planks = getBlock(BLOCK_PLANKS); + Block stairs = getBlock(BLOCK_STAIRS); + Block slab = getBlock(BLOCK_SLAB); + Block fence = getBlock(BLOCK_FENCE); Block gate = getBlock("gate"); Block button = getBlock("button"); Block pressurePlate = getBlock("plate"); diff --git a/src/main/java/ru/bclib/recipes/GridRecipe.java b/src/main/java/ru/bclib/recipes/GridRecipe.java index cc902a35..655903bf 100644 --- a/src/main/java/ru/bclib/recipes/GridRecipe.java +++ b/src/main/java/ru/bclib/recipes/GridRecipe.java @@ -45,7 +45,7 @@ public class GridRecipe { INSTANCE.materialKeys.clear(); INSTANCE.count = 1; - INSTANCE.exist = BCLRecipeManager.exists(output); + INSTANCE.exist = output != null && BCLRecipeManager.exists(output); return INSTANCE; }