From 355a563cb8efeab053b899e646e6ac241ab78c22 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 2 Aug 2022 11:14:27 +0200 Subject: [PATCH] Replaced old SmithingTableRecipe --- .../bclib/recipes/AbstractSimpleRecipe.java | 10 ++ .../betterx/bclib/recipes/SmithingRecipe.java | 56 --------- .../bclib/recipes/SmithingTableRecipe.java | 116 ++++++------------ 3 files changed, 46 insertions(+), 136 deletions(-) delete mode 100644 src/main/java/org/betterx/bclib/recipes/SmithingRecipe.java diff --git a/src/main/java/org/betterx/bclib/recipes/AbstractSimpleRecipe.java b/src/main/java/org/betterx/bclib/recipes/AbstractSimpleRecipe.java index 4e41506a..09158850 100644 --- a/src/main/java/org/betterx/bclib/recipes/AbstractSimpleRecipe.java +++ b/src/main/java/org/betterx/bclib/recipes/AbstractSimpleRecipe.java @@ -40,6 +40,7 @@ public abstract class AbstractSimpleRecipe { - protected Ingredient addon; - - protected SmithingRecipe(ResourceLocation id, ItemLike output) { - super(id, RecipeType.SMITHING, output); - } - - - public SmithingRecipe setBase(ItemLike in) { - return super.setInput(in); - } - - public SmithingRecipe setBase(TagKey in) { - return super.setInput(in); - } - - public SmithingRecipe setAddon(ItemLike in) { - this.addon = Ingredient.of(in); - unlockedBy(in); - return this; - } - - public SmithingRecipe setAddon(TagKey in) { - this.addon = Ingredient.of(in); - unlockedBy(in); - return this; - } - - @Override - protected boolean hasErrors() { - if (addon == null || addon.isEmpty()) { - BCLib.LOGGER.warning("Unable to build Recipe " + id + ": No Addon Ingredient"); - return true; - } - return super.hasErrors(); - } - - @Override - protected UpgradeRecipe buildRecipe() { - return new UpgradeRecipe(id, input, addon, new ItemStack(output, count)); - } -} diff --git a/src/main/java/org/betterx/bclib/recipes/SmithingTableRecipe.java b/src/main/java/org/betterx/bclib/recipes/SmithingTableRecipe.java index 425916f8..e81bbe23 100644 --- a/src/main/java/org/betterx/bclib/recipes/SmithingTableRecipe.java +++ b/src/main/java/org/betterx/bclib/recipes/SmithingTableRecipe.java @@ -1,10 +1,10 @@ package org.betterx.bclib.recipes; import org.betterx.bclib.BCLib; -import org.betterx.bclib.config.PathConfig; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; +import net.minecraft.world.Container; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -12,99 +12,55 @@ import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.UpgradeRecipe; import net.minecraft.world.level.ItemLike; -public class SmithingTableRecipe extends AbstractAdvancementRecipe { +public class SmithingTableRecipe extends AbstractSimpleRecipe { + protected Ingredient addon; - private final static SmithingTableRecipe BUILDER = new SmithingTableRecipe(); - private final static RecipeType TYPE = RecipeType.SMITHING; - - public static SmithingTableRecipe create(String modID, String name) { - return create(new ResourceLocation(modID, name)); + protected SmithingTableRecipe(ResourceLocation id, ItemLike output) { + super(id, RecipeType.SMITHING, output); } - public static SmithingTableRecipe create(ResourceLocation id) { - BUILDER.id = id; - BUILDER.base = null; - BUILDER.addition = null; - BUILDER.result = null; - BUILDER.exist = true; - BUILDER.createAdvancement(id, false); - return BUILDER; + public static SmithingTableRecipe make(String modID, String name, ItemLike output) { + return make(new ResourceLocation(modID, name), output); } - private ResourceLocation id; - private Ingredient base; - private Ingredient addition; - private ItemStack result; - private boolean exist; - - private SmithingTableRecipe() { + public static SmithingTableRecipe make(ResourceLocation id, ItemLike output) { + SmithingTableRecipe res = new SmithingTableRecipe(id, output); + res.createAdvancement(id, false); + return res; } - public SmithingTableRecipe checkConfig(PathConfig config) { - exist &= config.getBoolean("smithing", id.getPath(), true); + public SmithingTableRecipe setBase(ItemLike in) { + return super.setInput(in); + } + + public SmithingTableRecipe setBase(TagKey in) { + return super.setInput(in); + } + + public SmithingTableRecipe setAddon(ItemLike in) { + this.exist &= BCLRecipeManager.exists(in); + this.addon = Ingredient.of(in); + unlockedBy(in); return this; } - public SmithingTableRecipe setResult(ItemLike item) { - return this.setResult(item, 1); - } - - public SmithingTableRecipe setResult(ItemLike item, int count) { - this.exist &= BCLRecipeManager.exists(item); - this.result = new ItemStack(item, count); + public SmithingTableRecipe setAddon(TagKey in) { + this.addon = Ingredient.of(in); + unlockedBy(in); return this; } - public SmithingTableRecipe setBase(ItemLike... items) { - unlockedBy(items); - this.exist &= BCLRecipeManager.exists(items); - this.base = Ingredient.of(items); - return this; - } - - public SmithingTableRecipe setBase(TagKey tag) { - unlockedBy(tag); - this.base = (Ingredient.of(tag)); - return this; - } - - public SmithingTableRecipe setAddition(ItemLike... items) { - unlockedBy(items); - this.exist &= BCLRecipeManager.exists(items); - this.addition = Ingredient.of(items); - return this; - } - - public SmithingTableRecipe setAddition(TagKey tag) { - unlockedBy(tag); - this.addition = (Ingredient.of(tag)); - return this; - } - - public void build() { - if (!exist) { - return; + @Override + protected boolean hasErrors() { + if (addon == null || addon.isEmpty()) { + BCLib.LOGGER.warning("Unable to build Recipe " + id + ": No Addon Ingredient"); + return true; } + return super.hasErrors(); + } - if (base == null) { - BCLib.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); - return; - } - if (addition == null) { - BCLib.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); - return; - } - if (result == null) { - BCLib.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id); - return; - } - if (BCLRecipeManager.getRecipe(TYPE, id) != null) { - BCLib.LOGGER.warning("Can't add Smithing recipe! Id {} already exists!", id); - return; - } - - UpgradeRecipe recipe = new UpgradeRecipe(id, base, addition, result); - BCLRecipeManager.addRecipe(TYPE, recipe); - registerAdvancement(recipe); + @Override + protected UpgradeRecipe buildRecipe() { + return new UpgradeRecipe(id, input, addon, new ItemStack(output, count)); } }