[Feature] BCLRecipeBuilder

This commit is contained in:
Frank 2022-08-02 11:52:46 +02:00
parent 355a563cb8
commit 80a4ff8319
12 changed files with 308 additions and 280 deletions

View file

@ -4,7 +4,7 @@ import org.betterx.bclib.BCLib;
import org.betterx.bclib.blocks.*; import org.betterx.bclib.blocks.*;
import org.betterx.bclib.complexmaterials.entry.BlockEntry; import org.betterx.bclib.complexmaterials.entry.BlockEntry;
import org.betterx.bclib.complexmaterials.entry.RecipeEntry; import org.betterx.bclib.complexmaterials.entry.RecipeEntry;
import org.betterx.bclib.recipes.GridRecipe; import org.betterx.bclib.recipes.BCLRecipeBuilder;
import org.betterx.worlds.together.tag.v3.CommonBlockTags; import org.betterx.worlds.together.tag.v3.CommonBlockTags;
import org.betterx.worlds.together.tag.v3.CommonItemTags; import org.betterx.worlds.together.tag.v3.CommonItemTags;
import org.betterx.worlds.together.tag.v3.CommonPoiTags; import org.betterx.worlds.together.tag.v3.CommonPoiTags;
@ -257,177 +257,177 @@ public class WoodenComplexMaterial extends ComplexMaterial {
Block bark_stripped = getBlock(BLOCK_STRIPPED_BARK); Block bark_stripped = getBlock(BLOCK_STRIPPED_BARK);
Block log = getBlock(BLOCK_LOG); Block log = getBlock(BLOCK_LOG);
Block bark = getBlock(BLOCK_BARK); Block bark = getBlock(BLOCK_BARK);
GridRecipe.make(id, planks) BCLRecipeBuilder.crafting(id, planks)
.checkConfig(config) .checkConfig(config)
.setOutputCount(4) .setOutputCount(4)
.setList("#") .setList("#")
.addMaterial('#', log, bark, log_stripped, bark_stripped) .addMaterial('#', log, bark, log_stripped, bark_stripped)
.setGroup(receipGroupPrefix + "_planks") .setGroup(receipGroupPrefix + "_planks")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("stairs", (material, config, id) -> { addRecipeEntry(new RecipeEntry("stairs", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_STAIRS)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_STAIRS))
.checkConfig(config) .checkConfig(config)
.setOutputCount(4) .setOutputCount(4)
.setShape("# ", "## ", "###") .setShape("# ", "## ", "###")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_stairs") .setGroup(receipGroupPrefix + "_planks_stairs")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("slab", (material, config, id) -> { addRecipeEntry(new RecipeEntry("slab", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_SLAB)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_SLAB))
.checkConfig(config) .checkConfig(config)
.setOutputCount(6) .setOutputCount(6)
.setShape("###") .setShape("###")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_slabs") .setGroup(receipGroupPrefix + "_planks_slabs")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("fence", (material, config, id) -> { addRecipeEntry(new RecipeEntry("fence", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_FENCE)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_FENCE))
.checkConfig(config) .checkConfig(config)
.setOutputCount(3) .setOutputCount(3)
.setShape("#I#", "#I#") .setShape("#I#", "#I#")
.addMaterial('#', planks) .addMaterial('#', planks)
.addMaterial('I', Items.STICK) .addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_planks_fences") .setGroup(receipGroupPrefix + "_planks_fences")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("gate", (material, config, id) -> { addRecipeEntry(new RecipeEntry("gate", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_GATE)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_GATE))
.checkConfig(config) .checkConfig(config)
.setShape("I#I", "I#I") .setShape("I#I", "I#I")
.addMaterial('#', planks) .addMaterial('#', planks)
.addMaterial('I', Items.STICK) .addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_planks_gates") .setGroup(receipGroupPrefix + "_planks_gates")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("button", (material, config, id) -> { addRecipeEntry(new RecipeEntry("button", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BUTTON)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_BUTTON))
.checkConfig(config) .checkConfig(config)
.setList("#") .setList("#")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_buttons") .setGroup(receipGroupPrefix + "_planks_buttons")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("pressure_plate", (material, config, id) -> { addRecipeEntry(new RecipeEntry("pressure_plate", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_PRESSURE_PLATE)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_PRESSURE_PLATE))
.checkConfig(config) .checkConfig(config)
.setShape("##") .setShape("##")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_plates") .setGroup(receipGroupPrefix + "_planks_plates")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("trapdoor", (material, config, id) -> { addRecipeEntry(new RecipeEntry("trapdoor", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_TRAPDOOR)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_TRAPDOOR))
.checkConfig(config) .checkConfig(config)
.setOutputCount(2) .setOutputCount(2)
.setShape("###", "###") .setShape("###", "###")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_trapdoors") .setGroup(receipGroupPrefix + "_trapdoors")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("door", (material, config, id) -> { addRecipeEntry(new RecipeEntry("door", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_DOOR)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_DOOR))
.checkConfig(config) .checkConfig(config)
.setOutputCount(3) .setOutputCount(3)
.setShape("##", "##", "##") .setShape("##", "##", "##")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_doors") .setGroup(receipGroupPrefix + "_doors")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("crafting_table", (material, config, id) -> { addRecipeEntry(new RecipeEntry("crafting_table", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_CRAFTING_TABLE)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_CRAFTING_TABLE))
.checkConfig(config) .checkConfig(config)
.setShape("##", "##") .setShape("##", "##")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_tables") .setGroup(receipGroupPrefix + "_tables")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("ladder", (material, config, id) -> { addRecipeEntry(new RecipeEntry("ladder", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_LADDER)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_LADDER))
.checkConfig(config) .checkConfig(config)
.setOutputCount(3) .setOutputCount(3)
.setShape("I I", "I#I", "I I") .setShape("I I", "I#I", "I I")
.addMaterial('#', planks) .addMaterial('#', planks)
.addMaterial('I', Items.STICK) .addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_ladders") .setGroup(receipGroupPrefix + "_ladders")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("sign", (material, config, id) -> { addRecipeEntry(new RecipeEntry("sign", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_SIGN)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_SIGN))
.checkConfig(config) .checkConfig(config)
.setOutputCount(3) .setOutputCount(3)
.setShape("###", "###", " I ") .setShape("###", "###", " I ")
.addMaterial('#', planks) .addMaterial('#', planks)
.addMaterial('I', Items.STICK) .addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_signs") .setGroup(receipGroupPrefix + "_signs")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("chest", (material, config, id) -> { addRecipeEntry(new RecipeEntry("chest", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_CHEST)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_CHEST))
.checkConfig(config) .checkConfig(config)
.setShape("###", "# #", "###") .setShape("###", "# #", "###")
.addMaterial('#', planks) .addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_chests") .setGroup(receipGroupPrefix + "_chests")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("barrel", (material, config, id) -> { addRecipeEntry(new RecipeEntry("barrel", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BARREL)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_BARREL))
.checkConfig(config) .checkConfig(config)
.setShape("#S#", "# #", "#S#") .setShape("#S#", "# #", "#S#")
.addMaterial('#', planks) .addMaterial('#', planks)
.addMaterial('S', getBlock(BLOCK_SLAB)) .addMaterial('S', getBlock(BLOCK_SLAB))
.setGroup(receipGroupPrefix + "_barrels") .setGroup(receipGroupPrefix + "_barrels")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("bookshelf", (material, config, id) -> { addRecipeEntry(new RecipeEntry("bookshelf", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BOOKSHELF)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_BOOKSHELF))
.checkConfig(config) .checkConfig(config)
.setShape("###", "PPP", "###") .setShape("###", "PPP", "###")
.addMaterial('#', planks) .addMaterial('#', planks)
.addMaterial('P', Items.BOOK) .addMaterial('P', Items.BOOK)
.setGroup(receipGroupPrefix + "_bookshelves") .setGroup(receipGroupPrefix + "_bookshelves")
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("bark", (material, config, id) -> { addRecipeEntry(new RecipeEntry("bark", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BARK)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_BARK))
.checkConfig(config) .checkConfig(config)
.setShape("##", "##") .setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_LOG)) .addMaterial('#', getBlock(BLOCK_LOG))
.setOutputCount(3) .setOutputCount(3)
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("log", (material, config, id) -> { addRecipeEntry(new RecipeEntry("log", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_LOG)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_LOG))
.checkConfig(config) .checkConfig(config)
.setShape("##", "##") .setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_BARK)) .addMaterial('#', getBlock(BLOCK_BARK))
.setOutputCount(3) .setOutputCount(3)
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("stripped_bark", (material, config, id) -> { addRecipeEntry(new RecipeEntry("stripped_bark", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_STRIPPED_BARK)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_STRIPPED_BARK))
.checkConfig(config) .checkConfig(config)
.setShape("##", "##") .setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_STRIPPED_LOG)) .addMaterial('#', getBlock(BLOCK_STRIPPED_LOG))
.setOutputCount(3) .setOutputCount(3)
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("stripped_log", (material, config, id) -> { addRecipeEntry(new RecipeEntry("stripped_log", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_STRIPPED_LOG)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_STRIPPED_LOG))
.checkConfig(config) .checkConfig(config)
.setShape("##", "##") .setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_STRIPPED_BARK)) .addMaterial('#', getBlock(BLOCK_STRIPPED_BARK))
.setOutputCount(3) .setOutputCount(3)
.build(); .build();
})); }));
addRecipeEntry(new RecipeEntry("composter", (material, config, id) -> { addRecipeEntry(new RecipeEntry("composter", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_COMPOSTER)) BCLRecipeBuilder.crafting(id, getBlock(BLOCK_COMPOSTER))
.checkConfig(config) .checkConfig(config)
.setShape("# #", "# #", "###") .setShape("# #", "# #", "###")
.addMaterial('#', getBlock(BLOCK_SLAB)) .addMaterial('#', getBlock(BLOCK_SLAB))
.build(); .build();
})); }));
} }
} }

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.items.complex; package org.betterx.bclib.items.complex;
import org.betterx.bclib.items.BaseArmorItem; import org.betterx.bclib.items.BaseArmorItem;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import org.betterx.bclib.recipes.GridRecipe; import org.betterx.bclib.recipes.GridRecipe;
import org.betterx.bclib.registry.ItemRegistry; import org.betterx.bclib.registry.ItemRegistry;
@ -34,9 +35,8 @@ public class EquipmentDescription<I extends Item> {
if (repairItems == null || repairItems.length == 0) return; if (repairItems == null || repairItems.length == 0) return;
final ItemLike ingot = repairItems[0].getItem(); final ItemLike ingot = repairItems[0].getItem();
var builder = GridRecipe var builder = BCLRecipeBuilder.crafting(id, tool)
.make(id, tool) .addMaterial('#', ingot);
.addMaterial('#', ingot);
if (buildRecipe(tool, stick, builder)) return; if (buildRecipe(tool, stick, builder)) return;
builder builder

View file

@ -133,27 +133,26 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
private final static Builder INSTANCE = new Builder(); private final static Builder INSTANCE = new Builder();
private static boolean exist; private static boolean exist;
protected static Builder create(ResourceLocation id, PathConfig config) { static Builder create(ResourceLocation id, ItemLike output) {
INSTANCE.id = id; INSTANCE.id = id;
INSTANCE.group = String.format("%s_%s", GROUP, id); INSTANCE.group = String.format("%s_%s", GROUP, id);
INSTANCE.primaryInput = null; INSTANCE.primaryInput = null;
INSTANCE.secondaryInput = null; INSTANCE.secondaryInput = null;
INSTANCE.output = null; INSTANCE.output = output;
INSTANCE.experience = 0.0F; INSTANCE.experience = 0.0F;
INSTANCE.smeltTime = 350; INSTANCE.smeltTime = 350;
exist = config.getBoolean("alloying", id.getPath(), true); INSTANCE.count = 1;
INSTANCE.alright = RecipeHelper.exists(output);
exist = true;
return INSTANCE; return INSTANCE;
} }
protected static Builder create(String modID, String id, PathConfig config) { private int count = 1;
return create(new ResourceLocation(modID, id), config);
}
private ResourceLocation id; private ResourceLocation id;
private Ingredient primaryInput; private Ingredient primaryInput;
private Ingredient secondaryInput; private Ingredient secondaryInput;
private ItemStack output; private ItemLike output;
private String group; private String group;
private float experience; private float experience;
private int smeltTime; private int smeltTime;
@ -162,11 +161,21 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
protected Builder() { protected Builder() {
} }
public Builder checkConfig(PathConfig config) {
exist &= config.getBoolean("alloying", id.getPath(), true);
return this;
}
public Builder setGroup(String group) { public Builder setGroup(String group) {
this.group = group; this.group = group;
return this; return this;
} }
public Builder setOutputCount(int count) {
this.count = count;
return this;
}
public Builder setPrimaryInput(ItemLike... inputs) { public Builder setPrimaryInput(ItemLike... inputs) {
for (ItemLike item : inputs) { for (ItemLike item : inputs) {
this.alright &= RecipeHelper.exists(item); this.alright &= RecipeHelper.exists(item);
@ -205,13 +214,7 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
return this; return this;
} }
public Builder setOutput(ItemLike output, int amount) { public Builder setExperience(float amount) {
this.alright &= RecipeHelper.exists(output);
this.output = new ItemStack(output, amount);
return this;
}
public Builder setExpiriense(float amount) {
this.experience = amount; this.experience = amount;
return this; return this;
} }
@ -251,7 +254,15 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
} }
BCLRecipeManager.addRecipe( BCLRecipeManager.addRecipe(
TYPE, TYPE,
new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime) new AlloyingRecipe(
id,
group,
primaryInput,
secondaryInput,
new ItemStack(output, count),
experience,
smeltTime
)
); );
} }
} }

View file

@ -79,11 +79,11 @@ public class AnvilRecipe implements Recipe<Container>, UnknownReceipBookCategory
this.damage = damage; this.damage = damage;
} }
public static Builder create(String id) { static Builder create(String id) {
return create(BCLib.makeID(id)); return create(BCLib.makeID(id));
} }
public static Builder create(ResourceLocation id) { static Builder create(ResourceLocation id) {
Builder.INSTANCE.id = id; Builder.INSTANCE.id = id;
Builder.INSTANCE.input = null; Builder.INSTANCE.input = null;
Builder.INSTANCE.output = null; Builder.INSTANCE.output = null;

View file

@ -0,0 +1,36 @@
package org.betterx.bclib.recipes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ItemLike;
public class BCLRecipeBuilder {
public static AlloyingRecipe.Builder alloying(ResourceLocation id, ItemLike output) {
return AlloyingRecipe.Builder.create(id, output);
}
public static AnvilRecipe.Builder anvil(ResourceLocation id) {
return AnvilRecipe.create(id);
}
public static BlastFurnaceRecipe blasting(ResourceLocation id, ItemLike output) {
return BlastFurnaceRecipe.make(id, output);
}
public static GridRecipe crafting(ResourceLocation id, ItemLike output) {
return BCLRecipeBuilder.crafting(
id, output);
}
public static FurnaceRecipe smelting(ResourceLocation id, ItemLike output) {
return FurnaceRecipe.make(id, output);
}
public static SmithingTableRecipe smithing(ResourceLocation id, ItemLike output) {
return SmithingTableRecipe.make(id, output);
}
public static StoneCutterRecipe stonecutting(ResourceLocation id, ItemLike output) {
return StoneCutterRecipe.make(id, output);
}
}

View file

@ -12,11 +12,11 @@ public class BlastFurnaceRecipe extends CookingRecipe<BlastFurnaceRecipe, Contai
super(id, RecipeType.BLASTING, output); super(id, RecipeType.BLASTING, output);
} }
public static BlastFurnaceRecipe make(String modID, String name, ItemLike output) { static BlastFurnaceRecipe make(String modID, String name, ItemLike output) {
return make(new ResourceLocation(modID, name), output); return make(new ResourceLocation(modID, name), output);
} }
public static BlastFurnaceRecipe make(ResourceLocation id, ItemLike output) { static BlastFurnaceRecipe make(ResourceLocation id, ItemLike output) {
BlastFurnaceRecipe res = new BlastFurnaceRecipe(id, output); BlastFurnaceRecipe res = new BlastFurnaceRecipe(id, output);
res.createAdvancement(id, false); res.createAdvancement(id, false);
return res; return res;

View file

@ -10,72 +10,72 @@ import net.minecraft.world.level.block.Blocks;
public class CraftingRecipes { public class CraftingRecipes {
public static void init() { public static void init() {
GridRecipe.make(BCLib.MOD_ID, "tag_smith_table", Blocks.SMITHING_TABLE) BCLRecipeBuilder.crafting(BCLib.makeID("tag_smith_table"), Blocks.SMITHING_TABLE)
.setShape("II", "##", "##") .setShape("II", "##", "##")
.addMaterial('#', ItemTags.PLANKS) .addMaterial('#', ItemTags.PLANKS)
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_cauldron", Blocks.CAULDRON) BCLRecipeBuilder.crafting(BCLib.makeID("tag_cauldron"), Blocks.CAULDRON)
.setShape("I I", "I I", "III") .setShape("I I", "I I", "III")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER) BCLRecipeBuilder.crafting(BCLib.makeID("tag_hopper"), Blocks.HOPPER)
.setShape("I I", "ICI", " I ") .setShape("I I", "ICI", " I ")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.addMaterial('C', CommonItemTags.CHEST) .addMaterial('C', CommonItemTags.CHEST)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_piston", Blocks.PISTON) BCLRecipeBuilder.crafting(BCLib.makeID("tag_piston"), Blocks.PISTON)
.setShape("WWW", "CIC", "CDC") .setShape("WWW", "CIC", "CDC")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.addMaterial('D', Items.REDSTONE) .addMaterial('D', Items.REDSTONE)
.addMaterial('C', Items.COBBLESTONE) .addMaterial('C', Items.COBBLESTONE)
.addMaterial('W', ItemTags.PLANKS) .addMaterial('W', ItemTags.PLANKS)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_rail", Blocks.RAIL) BCLRecipeBuilder.crafting(BCLib.makeID("tag_rail"), Blocks.RAIL)
.setOutputCount(16) .setOutputCount(16)
.setShape("I I", "ISI", "I I") .setShape("I I", "ISI", "I I")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.addMaterial('S', Items.STICK) .addMaterial('S', Items.STICK)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_stonecutter", Blocks.STONECUTTER) BCLRecipeBuilder.crafting(BCLib.makeID("tag_stonecutter"), Blocks.STONECUTTER)
.setShape(" I ", "SSS") .setShape(" I ", "SSS")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.addMaterial('S', Items.STONE) .addMaterial('S', Items.STONE)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_compass", Items.COMPASS) BCLRecipeBuilder.crafting(BCLib.makeID("tag_compass"), Items.COMPASS)
.setShape(" I ", "IDI", " I ") .setShape(" I ", "IDI", " I ")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.addMaterial('D', Items.REDSTONE) .addMaterial('D', Items.REDSTONE)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_bucket", Items.BUCKET) BCLRecipeBuilder.crafting(BCLib.makeID("tag_bucket"), Items.BUCKET)
.setShape("I I", " I ") .setShape("I I", " I ")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART) BCLRecipeBuilder.crafting(BCLib.makeID("tag_minecart"), Items.MINECART)
.setShape("I I", "III") .setShape("I I", "III")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD) BCLRecipeBuilder.crafting(BCLib.makeID("tag_shield"), Items.SHIELD)
.setShape("WIW", "WWW", " W ") .setShape("WIW", "WWW", " W ")
.addMaterial('I', CommonItemTags.IRON_INGOTS) .addMaterial('I', CommonItemTags.IRON_INGOTS)
.addMaterial('W', ItemTags.PLANKS) .addMaterial('W', ItemTags.PLANKS)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX) BCLRecipeBuilder.crafting(BCLib.makeID("tag_shulker_box"), Blocks.SHULKER_BOX)
.setShape("S", "C", "S") .setShape("S", "C", "S")
.addMaterial('S', Items.SHULKER_SHELL) .addMaterial('S', Items.SHULKER_SHELL)
.addMaterial('C', CommonItemTags.CHEST) .addMaterial('C', CommonItemTags.CHEST)
.checkConfig(Configs.RECIPE_CONFIG) .checkConfig(Configs.RECIPE_CONFIG)
.build(); .build();
} }
} }

View file

@ -3,6 +3,8 @@ package org.betterx.bclib.recipes;
import org.betterx.bclib.config.PathConfig; import org.betterx.bclib.config.PathConfig;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.*; import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
@ -11,7 +13,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
private static final FurnaceRecipe INSTANCE = new FurnaceRecipe(); private static final FurnaceRecipe INSTANCE = new FurnaceRecipe();
private ResourceLocation id; private ResourceLocation id;
private ItemLike input; private Ingredient input;
private ItemLike output; private ItemLike output;
private boolean exist; private boolean exist;
private String group; private String group;
@ -22,20 +24,33 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
private FurnaceRecipe() { private FurnaceRecipe() {
} }
public static FurnaceRecipe make(String modID, String name, ItemLike input, ItemLike output) { static FurnaceRecipe make(ResourceLocation id, ItemLike output) {
INSTANCE.id = new ResourceLocation(modID, name); INSTANCE.id = id;
INSTANCE.group = ""; INSTANCE.group = "";
INSTANCE.input = input; INSTANCE.input = null;
INSTANCE.output = output; INSTANCE.output = output;
INSTANCE.count = 1; INSTANCE.count = 1;
INSTANCE.time = 200; INSTANCE.time = 200;
INSTANCE.xp = 0; INSTANCE.xp = 0;
INSTANCE.exist = BCLRecipeManager.exists(output) && BCLRecipeManager.exists(input); INSTANCE.exist = BCLRecipeManager.exists(output);
INSTANCE.createAdvancement(INSTANCE.id, false); INSTANCE.createAdvancement(INSTANCE.id, false);
INSTANCE.unlockedBy(input);
return INSTANCE; return INSTANCE;
} }
public FurnaceRecipe setInput(ItemLike input) {
exist &= BCLRecipeManager.exists(input);
this.input = Ingredient.of(input);
unlockedBy(input);
return this;
}
public FurnaceRecipe setInput(TagKey<Item> tag) {
this.input = Ingredient.of(tag);
unlockedBy(tag);
return this;
}
public FurnaceRecipe checkConfig(PathConfig config) { public FurnaceRecipe checkConfig(PathConfig config) {
exist &= config.getBoolean("furnace", id.getPath(), true); exist &= config.getBoolean("furnace", id.getPath(), true);
return this; return this;
@ -51,12 +66,12 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
return this; return this;
} }
public FurnaceRecipe setXP(float xp) { public FurnaceRecipe setExperience(float xp) {
this.xp = xp; this.xp = xp;
return this; return this;
} }
public FurnaceRecipe setCookTime(int time) { public FurnaceRecipe setCookingTime(int time) {
this.time = time; this.time = time;
return this; return this;
} }
@ -81,7 +96,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
SmeltingRecipe recipe = new SmeltingRecipe( SmeltingRecipe recipe = new SmeltingRecipe(
new ResourceLocation(id + "_smelting"), new ResourceLocation(id + "_smelting"),
group, group,
Ingredient.of(input), input,
new ItemStack(output, count), new ItemStack(output, count),
xp, xp,
time time
@ -93,11 +108,12 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
BlastingRecipe recipe2 = new BlastingRecipe( BlastingRecipe recipe2 = new BlastingRecipe(
new ResourceLocation(id + "_blasting"), new ResourceLocation(id + "_blasting"),
group, group,
Ingredient.of(input), input,
new ItemStack(output, count), new ItemStack(output, count),
xp, xp,
time / 2 time / 2
); );
BCLRecipeManager.addRecipe(RecipeType.BLASTING, recipe2); BCLRecipeManager.addRecipe(RecipeType.BLASTING, recipe2);
} }
@ -105,7 +121,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe( CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(
new ResourceLocation(id + "_campfire"), new ResourceLocation(id + "_campfire"),
group, group,
Ingredient.of(input), input,
new ItemStack(output, count), new ItemStack(output, count),
xp, xp,
time * 3 time * 3
@ -118,7 +134,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
SmokingRecipe recipe2 = new SmokingRecipe( SmokingRecipe recipe2 = new SmokingRecipe(
new ResourceLocation(id + "_smoker"), new ResourceLocation(id + "_smoker"),
group, group,
Ingredient.of(input), input,
new ItemStack(output, count), new ItemStack(output, count),
xp, xp,
time / 2 time / 2

View file

@ -34,11 +34,14 @@ public class GridRecipe extends AbstractAdvancementRecipe {
private GridRecipe() { private GridRecipe() {
} }
public static GridRecipe make(String modID, String name, ItemLike output) { /**
return make(new ResourceLocation(modID, name), output); * Please use {@link BCLRecipeBuilder#crafting(ResourceLocation, ItemLike)} instead
} *
* @param id
public static GridRecipe make(ResourceLocation id, ItemLike output) { * @param output
* @return
*/
static GridRecipe make(ResourceLocation id, ItemLike output) {
INSTANCE.id = id; INSTANCE.id = id;
INSTANCE.output = output; INSTANCE.output = output;

View file

@ -1,31 +0,0 @@
package org.betterx.bclib.recipes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SmeltingRecipe;
import net.minecraft.world.level.ItemLike;
public class SmelterRecipe extends CookingRecipe<SmelterRecipe, Container, SmeltingRecipe> {
SmelterRecipe(
ResourceLocation id, ItemLike output
) {
super(id, RecipeType.SMELTING, output);
}
public static SmelterRecipe make(String modID, String name, ItemLike output) {
return make(new ResourceLocation(modID, name), output);
}
public static SmelterRecipe make(ResourceLocation id, ItemLike output) {
SmelterRecipe res = new SmelterRecipe(id, output);
res.createAdvancement(id, false);
return res;
}
@Override
protected SmeltingRecipe buildRecipe() {
return new SmeltingRecipe(id, group, input, new ItemStack(output, count), experience, cookingTime);
}
}

View file

@ -19,11 +19,8 @@ public class SmithingTableRecipe extends AbstractSimpleRecipe<SmithingTableRecip
super(id, RecipeType.SMITHING, output); super(id, RecipeType.SMITHING, output);
} }
public static SmithingTableRecipe make(String modID, String name, ItemLike output) {
return make(new ResourceLocation(modID, name), output);
}
public static SmithingTableRecipe make(ResourceLocation id, ItemLike output) { static SmithingTableRecipe make(ResourceLocation id, ItemLike output) {
SmithingTableRecipe res = new SmithingTableRecipe(id, output); SmithingTableRecipe res = new SmithingTableRecipe(id, output);
res.createAdvancement(id, false); res.createAdvancement(id, false);
return res; return res;

View file

@ -14,11 +14,7 @@ public class StoneCutterRecipe extends AbstractSimpleRecipe<StoneCutterRecipe, C
super(id, RecipeType.STONECUTTING, "stonecutting", output); super(id, RecipeType.STONECUTTING, "stonecutting", output);
} }
public static StoneCutterRecipe make(String modID, String name, ItemLike output) { static StoneCutterRecipe make(ResourceLocation id, ItemLike output) {
return make(new ResourceLocation(modID, name), output);
}
public static StoneCutterRecipe make(ResourceLocation id, ItemLike output) {
StoneCutterRecipe res = new StoneCutterRecipe(id, output); StoneCutterRecipe res = new StoneCutterRecipe(id, output);
res.createAdvancement(id, false); res.createAdvancement(id, false);
return res; return res;