From c8d9d9b252c6e63c0a2fbc06a9f35182b6d22865 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 24 Jul 2021 00:59:22 +0300 Subject: [PATCH] Wooden material rename, javadoc fix, recipe entries --- .../complexmaterials/ComplexMaterial.java | 58 ++- ...terial.java => WoodenComplexMaterial.java} | 339 ++++++++++-------- .../complexmaterials/entry/RecipeEntry.java | 19 + .../java/ru/bclib/recipes/GridRecipe.java | 8 +- src/main/java/ru/bclib/util/TriConsumer.java | 6 + 5 files changed, 270 insertions(+), 160 deletions(-) rename src/main/java/ru/bclib/complexmaterials/{WoodenMaterial.java => WoodenComplexMaterial.java} (58%) create mode 100644 src/main/java/ru/bclib/complexmaterials/entry/RecipeEntry.java create mode 100644 src/main/java/ru/bclib/util/TriConsumer.java diff --git a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java index 06afd420..9cfb2d2b 100644 --- a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java @@ -12,6 +12,7 @@ import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.Nullable; import ru.bclib.complexmaterials.entry.BlockEntry; import ru.bclib.complexmaterials.entry.ItemEntry; +import ru.bclib.complexmaterials.entry.RecipeEntry; import ru.bclib.config.PathConfig; import ru.bclib.registry.BlockRegistry; import ru.bclib.registry.ItemRegistry; @@ -21,12 +22,15 @@ import java.util.List; import java.util.Map; public abstract class ComplexMaterial { + private static final Map> RECIPE_ENTRIES = Maps.newHashMap(); private static final Map> BLOCK_ENTRIES = Maps.newHashMap(); private static final Map> ITEM_ENTRIES = Maps.newHashMap(); private static final List MATERIALS = Lists.newArrayList(); - + + private final List defaultRecipeEntries = Lists.newArrayList(); private final List defaultBlockEntries = Lists.newArrayList(); private final List defaultItemEntries = Lists.newArrayList(); + private final Map> blockTags = Maps.newHashMap(); private final Map> itemTags = Maps.newHashMap(); private final Map blocks = Maps.newHashMap(); @@ -64,8 +68,12 @@ public abstract class ComplexMaterial { Item item = entry.init(this, itemSettings, itemsRegistry); items.put(entry.getSuffix(), item); }); - - initRecipes(recipeConfig); + + initDefaultRecipes(); + getRecipeEntries().forEach(entry -> { + entry.init(this, recipeConfig); + }); + initFlammable(FlammableBlockRegistry.getDefaultInstance()); return this; } @@ -83,9 +91,9 @@ public abstract class ComplexMaterial { protected void initTags() {} /** - * Init custom recipes for this {@link ComplexMaterial}, not required. + * Init default recipes for this {@link ComplexMaterial}, not required. */ - protected void initRecipes(PathConfig recipeConfig) {} + protected void initDefaultRecipes() {} /** * Allows to add blocks into Fabric {@link FlammableBlockRegistry} for this {@link ComplexMaterial}, not required. @@ -181,6 +189,15 @@ public abstract class ComplexMaterial { } return result; } + + private Collection getRecipeEntries() { + List result = Lists.newArrayList(defaultRecipeEntries); + List entries = RECIPE_ENTRIES.get(this.getMaterialID()); + if (entries != null) { + result.addAll(entries); + } + return result; + } /** * Get base name of this {@link ComplexMaterial}. @@ -202,8 +219,8 @@ public abstract class ComplexMaterial { * 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 Fabric Documentation: Entrypoint */ public abstract ResourceLocation getMaterialID(); @@ -238,14 +255,22 @@ public abstract class ComplexMaterial { protected void addItemEntry(ItemEntry entry) { defaultItemEntries.add(entry); } + + /** + * Adds a default {@link RecipeEntry} to this {@link ComplexMaterial}. Used to initiate items later. + * @param entry {@link RecipeEntry} + */ + protected void addRecipeEntry(RecipeEntry entry) { + defaultRecipeEntries.add(entry); + } /** * Adds a custom {@link BlockEntry} for specified {@link ComplexMaterial} using its {@link ResourceLocation}. * Used to add custom entry for all instances of {@link ComplexMaterial}. * Should be called only using Fabric "preLaunch" entry point. - * @see Fabric Documentation: Entrypoint */ public static void addBlockEntry(ResourceLocation materialName, BlockEntry entry) { List entries = BLOCK_ENTRIES.get(materialName); @@ -260,9 +285,9 @@ public abstract class ComplexMaterial { * Adds a custom {@link ItemEntry} for specified {@link ComplexMaterial} using its {@link ResourceLocation}. * Used to add custom entry for all instances of {@link ComplexMaterial}. * Should be called only using Fabric "preLaunch" entry point. - * @see Fabric Documentation: Entrypoint */ public static void addItemEntry(ResourceLocation materialName, ItemEntry entry) { List entries = ITEM_ENTRIES.get(materialName); @@ -272,6 +297,23 @@ public abstract class ComplexMaterial { } entries.add(entry); } + + /** + * Adds a custom {@link RecipeEntry} for specified {@link ComplexMaterial} using its {@link ResourceLocation}. + * Used to add custom entry for all instances of {@link ComplexMaterial}. + * Should be called only using Fabric "preLaunch" entry point. + * @param materialName {@link ResourceLocation} id of {@link ComplexMaterial}; + * @param entry {@link RecipeEntry}. + * @see Fabric Documentation: Entrypoint + */ + public static void addRecipeEntry(ResourceLocation materialName, RecipeEntry entry) { + List entries = RECIPE_ENTRIES.get(materialName); + if (entries == null) { + entries = Lists.newArrayList(); + RECIPE_ENTRIES.put(materialName, entries); + } + entries.add(entry); + } /** * Get all instances of all materials. diff --git a/src/main/java/ru/bclib/complexmaterials/WoodenMaterial.java b/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java similarity index 58% rename from src/main/java/ru/bclib/complexmaterials/WoodenMaterial.java rename to src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java index 141e6e56..d51c8a3b 100644 --- a/src/main/java/ru/bclib/complexmaterials/WoodenMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java @@ -37,12 +37,13 @@ import ru.bclib.blocks.StripableBarkBlock; import ru.bclib.blocks.WoodenPressurePlateBlock; import ru.bclib.complexmaterials.entry.BlockEntry; import ru.bclib.complexmaterials.entry.ItemEntry; +import ru.bclib.complexmaterials.entry.RecipeEntry; import ru.bclib.config.PathConfig; import ru.bclib.recipes.GridRecipe; import java.util.List; -public class WoodenMaterial extends ComplexMaterial { +public class WoodenComplexMaterial extends ComplexMaterial { public static final ResourceLocation MATERIAL_ID = BCLib.makeID("wooden_material"); public static final String BLOCK_CRAFTING_TABLE = "crafting_table"; @@ -71,7 +72,7 @@ public class WoodenMaterial extends ComplexMaterial { public final MaterialColor planksColor; public final MaterialColor woodColor; - public WoodenMaterial(String modID, String baseName, MaterialColor woodColor, MaterialColor planksColor) { + public WoodenComplexMaterial(String modID, String baseName, MaterialColor woodColor, MaterialColor planksColor) { super(modID, baseName); this.planksColor = planksColor; this.woodColor = woodColor; @@ -193,154 +194,192 @@ public class WoodenMaterial extends ComplexMaterial { } @Override - public void initRecipes(PathConfig recipeConfig) { - Block log_stripped = getBlock(BLOCK_STRIPPED_LOG); - Block bark_stripped = getBlock(BLOCK_STRIPPED_BARK); - Block log = getBlock(BLOCK_LOG); - Block bark = getBlock(BLOCK_BARK); + public void initDefaultRecipes() { 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"); - Block trapdoor = getBlock("trapdoor"); - Block door = getBlock("door"); - Block craftingTable = getBlock("crafting_table"); - Block ladder = getBlock("ladder"); - Block sign = getBlock("sign"); - Block chest = getBlock("chest"); - Block barrel = getBlock("barrel"); - Block shelf = getBlock("bookshelf"); - Block composter = getBlock("composter"); - - GridRecipe.make(getModID(), getBaseName() + "_planks", planks) - .checkConfig(recipeConfig) - .setOutputCount(4) - .setList("#") - .addMaterial('#', log, bark, log_stripped, bark_stripped) - .setGroup("end_planks") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_stairs", stairs) - .checkConfig(recipeConfig) - .setOutputCount(4) - .setShape("# ", "## ", "###") - .addMaterial('#', planks) - .setGroup("end_planks_stairs") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_slab", slab) - .checkConfig(recipeConfig) - .setOutputCount(6) - .setShape("###") - .addMaterial('#', planks) - .setGroup("end_planks_slabs") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_fence", fence) - .checkConfig(recipeConfig) - .setOutputCount(3) - .setShape("#I#", "#I#") - .addMaterial('#', planks) - .addMaterial('I', Items.STICK) - .setGroup("end_planks_fences") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_gate", gate) - .checkConfig(recipeConfig) - .setShape("I#I", "I#I") - .addMaterial('#', planks) - .addMaterial('I', Items.STICK) - .setGroup("end_planks_gates") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_button", button) - .checkConfig(recipeConfig) - .setList("#") - .addMaterial('#', planks) - .setGroup("end_planks_buttons") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_pressure_plate", pressurePlate) - .checkConfig(recipeConfig) - .setShape("##") - .addMaterial('#', planks) - .setGroup("end_planks_plates") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_trapdoor", trapdoor) - .checkConfig(recipeConfig) - .setOutputCount(2) - .setShape("###", "###") - .addMaterial('#', planks) - .setGroup("end_trapdoors") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_door", door) - .checkConfig(recipeConfig) - .setOutputCount(3) - .setShape("##", "##", "##") - .addMaterial('#', planks) - .setGroup("end_doors") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_crafting_table", craftingTable) - .checkConfig(recipeConfig) - .setShape("##", "##") - .addMaterial('#', planks) - .setGroup("end_tables") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_ladder", ladder) - .checkConfig(recipeConfig) - .setOutputCount(3) - .setShape("I I", "I#I", "I I") - .addMaterial('#', planks) - .addMaterial('I', Items.STICK) - .setGroup("end_ladders") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_sign", sign) - .checkConfig(recipeConfig) - .setOutputCount(3) - .setShape("###", "###", " I ") - .addMaterial('#', planks) - .addMaterial('I', Items.STICK) - .setGroup("end_signs") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_chest", chest) - .checkConfig(recipeConfig) - .setShape("###", "# #", "###") - .addMaterial('#', planks) - .setGroup("end_chests") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_barrel", barrel) - .checkConfig(recipeConfig) - .setShape("#S#", "# #", "#S#") - .addMaterial('#', planks) - .addMaterial('S', slab) - .setGroup("end_barrels") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_bookshelf", shelf) - .checkConfig(recipeConfig) - .setShape("###", "PPP", "###") - .addMaterial('#', planks) - .addMaterial('P', Items.BOOK) - .setGroup("end_BLOCK_BOOKSHELVES") - .build(); - GridRecipe.make(getModID(), getBaseName() + "_bark", bark) - .checkConfig(recipeConfig) - .setShape("##", "##") - .addMaterial('#', log) - .setOutputCount(3) - .build(); - GridRecipe.make(getModID(), getBaseName() + "_log", log) - .checkConfig(recipeConfig) - .setShape("##", "##") - .addMaterial('#', bark) - .setOutputCount(3) - .build(); - GridRecipe.make(getModID(), getBaseName() + "_composter", composter) - .checkConfig(recipeConfig) - .setShape("# #", "# #", "###") - .addMaterial('#', slab) - .build(); - GridRecipe.make(getModID(), getBaseName() + "_shulker", Items.SHULKER_BOX) - .checkConfig(recipeConfig) - .setShape("S", "#", "S") - .addMaterial('S', Items.SHULKER_SHELL) - .addMaterial('#', chest) - .build(); + addRecipeEntry(new RecipeEntry("planks", (material, config, id) -> { + Block log_stripped = getBlock(BLOCK_STRIPPED_LOG); + Block bark_stripped = getBlock(BLOCK_STRIPPED_BARK); + Block log = getBlock(BLOCK_LOG); + Block bark = getBlock(BLOCK_BARK); + GridRecipe.make(id, planks) + .checkConfig(config) + .setOutputCount(4) + .setList("#") + .addMaterial('#', log, bark, log_stripped, bark_stripped) + .setGroup("end_planks") + .build(); + })); + addRecipeEntry(new RecipeEntry("stairs", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_STAIRS)) + .checkConfig(config) + .setOutputCount(4) + .setShape("# ", "## ", "###") + .addMaterial('#', planks) + .setGroup("end_planks_stairs") + .build(); + })); + addRecipeEntry(new RecipeEntry("slab", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_SLAB)) + .checkConfig(config) + .setOutputCount(6) + .setShape("###") + .addMaterial('#', planks) + .setGroup("end_planks_slabs") + .build(); + })); + addRecipeEntry(new RecipeEntry("fence", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_FENCE)) + .checkConfig(config) + .setOutputCount(3) + .setShape("#I#", "#I#") + .addMaterial('#', planks) + .addMaterial('I', Items.STICK) + .setGroup("end_planks_fences") + .build(); + })); + addRecipeEntry(new RecipeEntry("gate", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_GATE)) + .checkConfig(config) + .setShape("I#I", "I#I") + .addMaterial('#', planks) + .addMaterial('I', Items.STICK) + .setGroup("end_planks_gates") + .build(); + })); + addRecipeEntry(new RecipeEntry("button", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_BUTTON)) + .checkConfig(config) + .setList("#") + .addMaterial('#', planks) + .setGroup("end_planks_buttons") + .build(); + })); + addRecipeEntry(new RecipeEntry("pressure_plate", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_PRESSURE_PLATE)) + .checkConfig(config) + .setShape("##") + .addMaterial('#', planks) + .setGroup("end_planks_plates") + .build(); + })); + addRecipeEntry(new RecipeEntry("trapdoor", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_TRAPDOOR)) + .checkConfig(config) + .setOutputCount(2) + .setShape("###", "###") + .addMaterial('#', planks) + .setGroup("end_trapdoors") + .build(); + })); + addRecipeEntry(new RecipeEntry("door", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_DOOR)) + .checkConfig(config) + .setOutputCount(3) + .setShape("##", "##", "##") + .addMaterial('#', planks) + .setGroup("end_doors") + .build(); + })); + addRecipeEntry(new RecipeEntry("crafting_table", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_CRAFTING_TABLE)) + .checkConfig(config) + .setShape("##", "##") + .addMaterial('#', planks) + .setGroup("end_tables") + .build(); + })); + addRecipeEntry(new RecipeEntry("ladder", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_LADDER)) + .checkConfig(config) + .setOutputCount(3) + .setShape("I I", "I#I", "I I") + .addMaterial('#', planks) + .addMaterial('I', Items.STICK) + .setGroup("end_ladders") + .build(); + })); + addRecipeEntry(new RecipeEntry("sign", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_SIGN)) + .checkConfig(config) + .setOutputCount(3) + .setShape("###", "###", " I ") + .addMaterial('#', planks) + .addMaterial('I', Items.STICK) + .setGroup("end_signs") + .build(); + })); + addRecipeEntry(new RecipeEntry("chest", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_CHEST)) + .checkConfig(config) + .setShape("###", "# #", "###") + .addMaterial('#', planks) + .setGroup("end_chests") + .build(); + })); + addRecipeEntry(new RecipeEntry("barrel", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_BARREL)) + .checkConfig(config) + .setShape("#S#", "# #", "#S#") + .addMaterial('#', planks) + .addMaterial('S', getBlock(BLOCK_SLAB)) + .setGroup("end_barrels") + .build(); + })); + addRecipeEntry(new RecipeEntry("bookshelf", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_BOOKSHELF)) + .checkConfig(config) + .setShape("###", "PPP", "###") + .addMaterial('#', planks) + .addMaterial('P', Items.BOOK) + .setGroup("end_bookshelves") + .build(); + })); + addRecipeEntry(new RecipeEntry("bark", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_BARK)) + .checkConfig(config) + .setShape("##", "##") + .addMaterial('#', getBlock(BLOCK_LOG)) + .setOutputCount(3) + .build(); + })); + addRecipeEntry(new RecipeEntry("log", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_LOG)) + .checkConfig(config) + .setShape("##", "##") + .addMaterial('#', getBlock(BLOCK_BARK)) + .setOutputCount(3) + .build(); + })); + addRecipeEntry(new RecipeEntry("stripped_bark", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_STRIPPED_BARK)) + .checkConfig(config) + .setShape("##", "##") + .addMaterial('#', getBlock(BLOCK_STRIPPED_LOG)) + .setOutputCount(3) + .build(); + })); + addRecipeEntry(new RecipeEntry("stripped_log", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_STRIPPED_LOG)) + .checkConfig(config) + .setShape("##", "##") + .addMaterial('#', getBlock(BLOCK_STRIPPED_BARK)) + .setOutputCount(3) + .build(); + })); + addRecipeEntry(new RecipeEntry("composter", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_COMPOSTER)) + .checkConfig(config) + .setShape("# #", "# #", "###") + .addMaterial('#', getBlock(BLOCK_SLAB)) + .build(); + })); + addRecipeEntry(new RecipeEntry("shulker", (material, config, id) -> { + GridRecipe.make(id, getBlock(BLOCK_COMPOSTER)) + .checkConfig(config) + .setShape("S", "#", "S") + .addMaterial('S', Items.SHULKER_SHELL) + .addMaterial('#', getBlock(BLOCK_CHEST)) + .build(); + })); } } \ No newline at end of file diff --git a/src/main/java/ru/bclib/complexmaterials/entry/RecipeEntry.java b/src/main/java/ru/bclib/complexmaterials/entry/RecipeEntry.java new file mode 100644 index 00000000..d91a7ca8 --- /dev/null +++ b/src/main/java/ru/bclib/complexmaterials/entry/RecipeEntry.java @@ -0,0 +1,19 @@ +package ru.bclib.complexmaterials.entry; + +import net.minecraft.resources.ResourceLocation; +import ru.bclib.complexmaterials.ComplexMaterial; +import ru.bclib.config.PathConfig; +import ru.bclib.util.TriConsumer; + +public class RecipeEntry extends ComplexMaterialEntry { + final TriConsumer initFunction; + + public RecipeEntry(String suffix, TriConsumer initFunction) { + super(suffix); + this.initFunction = initFunction; + } + + public void init(ComplexMaterial material, PathConfig recipeConfig) { + initFunction.accept(material, recipeConfig, getLocation(material.getModID(), material.getBaseName())); + } +} diff --git a/src/main/java/ru/bclib/recipes/GridRecipe.java b/src/main/java/ru/bclib/recipes/GridRecipe.java index 655903bf..71a6bbc9 100644 --- a/src/main/java/ru/bclib/recipes/GridRecipe.java +++ b/src/main/java/ru/bclib/recipes/GridRecipe.java @@ -33,9 +33,13 @@ public class GridRecipe { private boolean exist = true; private GridRecipe() {} - + public static GridRecipe make(String modID, String name, ItemLike output) { - INSTANCE.id = new ResourceLocation(modID, name); + return make(new ResourceLocation(modID, name), output); + } + + public static GridRecipe make(ResourceLocation id, ItemLike output) { + INSTANCE.id = id; INSTANCE.output = output; INSTANCE.group = ""; diff --git a/src/main/java/ru/bclib/util/TriConsumer.java b/src/main/java/ru/bclib/util/TriConsumer.java new file mode 100644 index 00000000..6e5ac17c --- /dev/null +++ b/src/main/java/ru/bclib/util/TriConsumer.java @@ -0,0 +1,6 @@ +package ru.bclib.util; + +@FunctionalInterface +public interface TriConsumer { + void accept(A a, B b, C c); +}