Wooden material rename, javadoc fix, recipe entries

This commit is contained in:
paulevsGitch 2021-07-24 00:59:22 +03:00
parent 4df19c2193
commit c8d9d9b252
5 changed files with 270 additions and 160 deletions

View file

@ -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<ResourceLocation, List<RecipeEntry>> RECIPE_ENTRIES = Maps.newHashMap();
private static final Map<ResourceLocation, List<BlockEntry>> BLOCK_ENTRIES = Maps.newHashMap();
private static final Map<ResourceLocation, List<ItemEntry>> ITEM_ENTRIES = Maps.newHashMap();
private static final List<ComplexMaterial> MATERIALS = Lists.newArrayList();
private final List<RecipeEntry> defaultRecipeEntries = Lists.newArrayList();
private final List<BlockEntry> defaultBlockEntries = Lists.newArrayList();
private final List<ItemEntry> defaultItemEntries = Lists.newArrayList();
private final Map<String, Tag.Named<Block>> blockTags = Maps.newHashMap();
private final Map<String, Tag.Named<Item>> itemTags = Maps.newHashMap();
private final Map<String, Block> blocks = Maps.newHashMap();
@ -65,7 +69,11 @@ public abstract class ComplexMaterial {
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.
@ -182,6 +190,15 @@ public abstract class ComplexMaterial {
return result;
}
private Collection<RecipeEntry> getRecipeEntries() {
List<RecipeEntry> result = Lists.newArrayList(defaultRecipeEntries);
List<RecipeEntry> entries = RECIPE_ENTRIES.get(this.getMaterialID());
if (entries != null) {
result.addAll(entries);
}
return result;
}
/**
* Get base name of this {@link ComplexMaterial}.
* @return {@link String} name
@ -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 <a href="https://fabricmc.net/wiki/documentation:entrypoint>Fabric Documentation: Entrypoint</a>
* @return {@link ResourceLocation} for this material
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public abstract ResourceLocation getMaterialID();
@ -239,13 +256,21 @@ public abstract class ComplexMaterial {
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 <a href="https://fabricmc.net/wiki/documentation:entrypoint>Fabric Documentation: Entrypoint</a>
* @param materialName {@link ResourceLocation} id of {@link ComplexMaterial};
* @param entry {@link BlockEntry}.
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public static void addBlockEntry(ResourceLocation materialName, BlockEntry entry) {
List<BlockEntry> 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 <a href="https://fabricmc.net/wiki/documentation:entrypoint>Fabric Documentation: Entrypoint</a>
* @param materialName {@link ResourceLocation} id of {@link ComplexMaterial};
* @param entry {@link ItemEntry}.
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public static void addItemEntry(ResourceLocation materialName, ItemEntry entry) {
List<ItemEntry> entries = ITEM_ENTRIES.get(materialName);
@ -273,6 +298,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 <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public static void addRecipeEntry(ResourceLocation materialName, RecipeEntry entry) {
List<RecipeEntry> 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.
* @return {@link Collection} of {@link ComplexMaterial}.

View file

@ -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) {
public void initDefaultRecipes() {
Block planks = getBlock(BLOCK_PLANKS);
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);
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)
GridRecipe.make(id, planks)
.checkConfig(config)
.setOutputCount(4)
.setList("#")
.addMaterial('#', log, bark, log_stripped, bark_stripped)
.setGroup("end_planks")
.build();
GridRecipe.make(getModID(), getBaseName() + "_stairs", stairs)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_slab", slab)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_fence", fence)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_gate", gate)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_button", button)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("button", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BUTTON))
.checkConfig(config)
.setList("#")
.addMaterial('#', planks)
.setGroup("end_planks_buttons")
.build();
GridRecipe.make(getModID(), getBaseName() + "_pressure_plate", pressurePlate)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_trapdoor", trapdoor)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("trapdoor", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_TRAPDOOR))
.checkConfig(config)
.setOutputCount(2)
.setShape("###", "###")
.addMaterial('#', planks)
.setGroup("end_trapdoors")
.build();
GridRecipe.make(getModID(), getBaseName() + "_door", door)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("door", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_DOOR))
.checkConfig(config)
.setOutputCount(3)
.setShape("##", "##", "##")
.addMaterial('#', planks)
.setGroup("end_doors")
.build();
GridRecipe.make(getModID(), getBaseName() + "_crafting_table", craftingTable)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("crafting_table", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_CRAFTING_TABLE))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', planks)
.setGroup("end_tables")
.build();
GridRecipe.make(getModID(), getBaseName() + "_ladder", ladder)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_sign", sign)
.checkConfig(recipeConfig)
}));
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();
GridRecipe.make(getModID(), getBaseName() + "_chest", chest)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("chest", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_CHEST))
.checkConfig(config)
.setShape("###", "# #", "###")
.addMaterial('#', planks)
.setGroup("end_chests")
.build();
GridRecipe.make(getModID(), getBaseName() + "_barrel", barrel)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("barrel", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BARREL))
.checkConfig(config)
.setShape("#S#", "# #", "#S#")
.addMaterial('#', planks)
.addMaterial('S', slab)
.addMaterial('S', getBlock(BLOCK_SLAB))
.setGroup("end_barrels")
.build();
GridRecipe.make(getModID(), getBaseName() + "_bookshelf", shelf)
.checkConfig(recipeConfig)
}));
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_BLOCK_BOOKSHELVES")
.setGroup("end_bookshelves")
.build();
GridRecipe.make(getModID(), getBaseName() + "_bark", bark)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("bark", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BARK))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', log)
.addMaterial('#', getBlock(BLOCK_LOG))
.setOutputCount(3)
.build();
GridRecipe.make(getModID(), getBaseName() + "_log", log)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("log", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_LOG))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', bark)
.addMaterial('#', getBlock(BLOCK_BARK))
.setOutputCount(3)
.build();
GridRecipe.make(getModID(), getBaseName() + "_composter", composter)
.checkConfig(recipeConfig)
}));
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('#', slab)
.addMaterial('#', getBlock(BLOCK_SLAB))
.build();
GridRecipe.make(getModID(), getBaseName() + "_shulker", Items.SHULKER_BOX)
.checkConfig(recipeConfig)
}));
addRecipeEntry(new RecipeEntry("shulker", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_COMPOSTER))
.checkConfig(config)
.setShape("S", "#", "S")
.addMaterial('S', Items.SHULKER_SHELL)
.addMaterial('#', chest)
.addMaterial('#', getBlock(BLOCK_CHEST))
.build();
}));
}
}

View file

@ -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<ComplexMaterial, PathConfig, ResourceLocation> initFunction;
public RecipeEntry(String suffix, TriConsumer<ComplexMaterial, PathConfig, ResourceLocation> initFunction) {
super(suffix);
this.initFunction = initFunction;
}
public void init(ComplexMaterial material, PathConfig recipeConfig) {
initFunction.accept(material, recipeConfig, getLocation(material.getModID(), material.getBaseName()));
}
}

View file

@ -35,7 +35,11 @@ public class GridRecipe {
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 = "";

View file

@ -0,0 +1,6 @@
package ru.bclib.util;
@FunctionalInterface
public interface TriConsumer<A, B, C> {
void accept(A a, B b, C c);
}