Replaced old SmithingTableRecipe
This commit is contained in:
parent
b0964cd30d
commit
355a563cb8
3 changed files with 46 additions and 136 deletions
|
@ -40,6 +40,7 @@ public abstract class AbstractSimpleRecipe<T extends AbstractSimpleRecipe, C ext
|
|||
|
||||
|
||||
protected T setInput(ItemLike in) {
|
||||
this.exist &= BCLRecipeManager.exists(in);
|
||||
this.input = Ingredient.of(in);
|
||||
unlockedBy(in);
|
||||
return (T) this;
|
||||
|
@ -83,6 +84,15 @@ public abstract class AbstractSimpleRecipe<T extends AbstractSimpleRecipe, C ext
|
|||
return;
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
BCLib.LOGGER.warning("Result 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;
|
||||
}
|
||||
|
||||
if (hasErrors()) return;
|
||||
|
||||
R recipe = buildRecipe();
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
|
||||
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;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.UpgradeRecipe;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class SmithingRecipe extends AbstractSimpleRecipe<SmithingRecipe, Container, UpgradeRecipe> {
|
||||
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<Item> in) {
|
||||
return super.setInput(in);
|
||||
}
|
||||
|
||||
public SmithingRecipe setAddon(ItemLike in) {
|
||||
this.addon = Ingredient.of(in);
|
||||
unlockedBy(in);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmithingRecipe setAddon(TagKey<Item> 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));
|
||||
}
|
||||
}
|
|
@ -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<SmithingTableRecipe, Container, UpgradeRecipe> {
|
||||
protected Ingredient addon;
|
||||
|
||||
private final static SmithingTableRecipe BUILDER = new SmithingTableRecipe();
|
||||
private final static RecipeType<UpgradeRecipe> 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<Item> 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<Item> 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;
|
||||
@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();
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setBase(TagKey<Item> 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<Item> tag) {
|
||||
unlockedBy(tag);
|
||||
this.addition = (Ingredient.of(tag));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (!exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue