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) {
|
protected T setInput(ItemLike in) {
|
||||||
|
this.exist &= BCLRecipeManager.exists(in);
|
||||||
this.input = Ingredient.of(in);
|
this.input = Ingredient.of(in);
|
||||||
unlockedBy(in);
|
unlockedBy(in);
|
||||||
return (T) this;
|
return (T) this;
|
||||||
|
@ -83,6 +84,15 @@ public abstract class AbstractSimpleRecipe<T extends AbstractSimpleRecipe, C ext
|
||||||
return;
|
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;
|
if (hasErrors()) return;
|
||||||
|
|
||||||
R recipe = buildRecipe();
|
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;
|
package org.betterx.bclib.recipes;
|
||||||
|
|
||||||
import org.betterx.bclib.BCLib;
|
import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.config.PathConfig;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
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.item.crafting.UpgradeRecipe;
|
||||||
import net.minecraft.world.level.ItemLike;
|
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();
|
protected SmithingTableRecipe(ResourceLocation id, ItemLike output) {
|
||||||
private final static RecipeType<UpgradeRecipe> TYPE = RecipeType.SMITHING;
|
super(id, RecipeType.SMITHING, output);
|
||||||
|
|
||||||
public static SmithingTableRecipe create(String modID, String name) {
|
|
||||||
return create(new ResourceLocation(modID, name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SmithingTableRecipe create(ResourceLocation id) {
|
public static SmithingTableRecipe make(String modID, String name, ItemLike output) {
|
||||||
BUILDER.id = id;
|
return make(new ResourceLocation(modID, name), output);
|
||||||
BUILDER.base = null;
|
|
||||||
BUILDER.addition = null;
|
|
||||||
BUILDER.result = null;
|
|
||||||
BUILDER.exist = true;
|
|
||||||
BUILDER.createAdvancement(id, false);
|
|
||||||
return BUILDER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResourceLocation id;
|
public static SmithingTableRecipe make(ResourceLocation id, ItemLike output) {
|
||||||
private Ingredient base;
|
SmithingTableRecipe res = new SmithingTableRecipe(id, output);
|
||||||
private Ingredient addition;
|
res.createAdvancement(id, false);
|
||||||
private ItemStack result;
|
return res;
|
||||||
private boolean exist;
|
|
||||||
|
|
||||||
private SmithingTableRecipe() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SmithingTableRecipe checkConfig(PathConfig config) {
|
public SmithingTableRecipe setBase(ItemLike in) {
|
||||||
exist &= config.getBoolean("smithing", id.getPath(), true);
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SmithingTableRecipe setResult(ItemLike item) {
|
public SmithingTableRecipe setAddon(TagKey<Item> in) {
|
||||||
return this.setResult(item, 1);
|
this.addon = Ingredient.of(in);
|
||||||
}
|
unlockedBy(in);
|
||||||
|
|
||||||
public SmithingTableRecipe setResult(ItemLike item, int count) {
|
|
||||||
this.exist &= BCLRecipeManager.exists(item);
|
|
||||||
this.result = new ItemStack(item, count);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SmithingTableRecipe setBase(ItemLike... items) {
|
@Override
|
||||||
unlockedBy(items);
|
protected boolean hasErrors() {
|
||||||
this.exist &= BCLRecipeManager.exists(items);
|
if (addon == null || addon.isEmpty()) {
|
||||||
this.base = Ingredient.of(items);
|
BCLib.LOGGER.warning("Unable to build Recipe " + id + ": No Addon Ingredient");
|
||||||
return this;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
return super.hasErrors();
|
||||||
|
}
|
||||||
|
|
||||||
if (base == null) {
|
@Override
|
||||||
BCLib.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
protected UpgradeRecipe buildRecipe() {
|
||||||
return;
|
return new UpgradeRecipe(id, input, addon, new ItemStack(output, count));
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue