[Feature] Builder for Blasting, Smelting and Smithing Recipes
This commit is contained in:
parent
cb4c8c4db3
commit
b0964cd30d
6 changed files with 258 additions and 52 deletions
|
@ -0,0 +1,92 @@
|
|||
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.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public abstract class AbstractSimpleRecipe<T extends AbstractSimpleRecipe, C extends Container, R extends Recipe<C>> extends AbstractAdvancementRecipe {
|
||||
public final ResourceLocation id;
|
||||
protected String group;
|
||||
protected Ingredient input;
|
||||
protected ItemLike output;
|
||||
protected final String category;
|
||||
protected final RecipeType<R> type;
|
||||
protected int count;
|
||||
protected boolean exist;
|
||||
|
||||
|
||||
protected AbstractSimpleRecipe(ResourceLocation id, RecipeType<R> type, ItemLike output) {
|
||||
this(id, type, type.toString(), output);
|
||||
}
|
||||
|
||||
protected AbstractSimpleRecipe(ResourceLocation id, RecipeType<R> type, String category, ItemLike output) {
|
||||
this.id = id;
|
||||
this.group = "";
|
||||
this.exist = true;
|
||||
this.count = 1;
|
||||
this.output = output;
|
||||
|
||||
this.category = category;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
protected T setInput(ItemLike in) {
|
||||
this.input = Ingredient.of(in);
|
||||
unlockedBy(in);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
protected T setInput(TagKey<Item> in) {
|
||||
this.input = Ingredient.of(in);
|
||||
unlockedBy(in);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setGroup(String group) {
|
||||
this.group = group;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean(category, id.getPath(), true);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
protected abstract R buildRecipe();
|
||||
|
||||
protected boolean hasErrors() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void build() {
|
||||
if (!exist) {
|
||||
BCLib.LOGGER.warning("Unable to build Recipe " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
BCLib.LOGGER.warning("Unable to build Recipe " + id + ": No Input Material");
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasErrors()) return;
|
||||
|
||||
R recipe = buildRecipe();
|
||||
BCLRecipeManager.addRecipe(type, recipe);
|
||||
registerAdvancement(recipe);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
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.BlastingRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class BlastFurnaceRecipe extends CookingRecipe<BlastFurnaceRecipe, Container, BlastingRecipe> {
|
||||
BlastFurnaceRecipe(ResourceLocation id, ItemLike output) {
|
||||
super(id, RecipeType.BLASTING, output);
|
||||
}
|
||||
|
||||
public static BlastFurnaceRecipe make(String modID, String name, ItemLike output) {
|
||||
return make(new ResourceLocation(modID, name), output);
|
||||
}
|
||||
|
||||
public static BlastFurnaceRecipe make(ResourceLocation id, ItemLike output) {
|
||||
BlastFurnaceRecipe res = new BlastFurnaceRecipe(id, output);
|
||||
res.createAdvancement(id, false);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlastingRecipe buildRecipe() {
|
||||
return new BlastingRecipe(id, group, input, new ItemStack(output, count), experience, cookingTime);
|
||||
}
|
||||
}
|
42
src/main/java/org/betterx/bclib/recipes/CookingRecipe.java
Normal file
42
src/main/java/org/betterx/bclib/recipes/CookingRecipe.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
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.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public abstract class CookingRecipe<T extends AbstractSimpleRecipe, C extends Container, R extends Recipe<C>> extends AbstractSimpleRecipe<T, C, R> {
|
||||
protected float experience;
|
||||
protected int cookingTime;
|
||||
|
||||
CookingRecipe(ResourceLocation id, RecipeType<R> type, ItemLike output) {
|
||||
this(id, type, type.toString(), output);
|
||||
}
|
||||
|
||||
CookingRecipe(ResourceLocation id, RecipeType<R> type, String category, ItemLike output) {
|
||||
super(id, type, category, output);
|
||||
cookingTime = 1000;
|
||||
experience = 0;
|
||||
}
|
||||
|
||||
public T setInput(ItemLike in) {
|
||||
return super.setInput(in);
|
||||
}
|
||||
|
||||
public T setInput(TagKey<Item> in) {
|
||||
return super.setInput(in);
|
||||
}
|
||||
|
||||
public T setExperience(float xp) {
|
||||
experience = xp;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setCookingTime(int time) {
|
||||
cookingTime = time;
|
||||
return (T) this;
|
||||
}
|
||||
}
|
31
src/main/java/org/betterx/bclib/recipes/SmelterRecipe.java
Normal file
31
src/main/java/org/betterx/bclib/recipes/SmelterRecipe.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
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);
|
||||
}
|
||||
}
|
56
src/main/java/org/betterx/bclib/recipes/SmithingRecipe.java
Normal file
56
src/main/java/org/betterx/bclib/recipes/SmithingRecipe.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
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,32 +1,17 @@
|
|||
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;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.StonecutterRecipe;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class StoneCutterRecipe extends AbstractAdvancementRecipe {
|
||||
private final ResourceLocation id;
|
||||
String group;
|
||||
Ingredient input;
|
||||
ItemLike output;
|
||||
int count;
|
||||
boolean exist;
|
||||
|
||||
|
||||
public class StoneCutterRecipe extends AbstractSimpleRecipe<StoneCutterRecipe, Container, StonecutterRecipe> {
|
||||
StoneCutterRecipe(ResourceLocation id, ItemLike output) {
|
||||
this.id = id;
|
||||
this.group = "";
|
||||
this.exist = true;
|
||||
this.count = 1;
|
||||
this.output = output;
|
||||
super(id, RecipeType.STONECUTTING, "stonecutting", output);
|
||||
}
|
||||
|
||||
public static StoneCutterRecipe make(String modID, String name, ItemLike output) {
|
||||
|
@ -40,44 +25,15 @@ public class StoneCutterRecipe extends AbstractAdvancementRecipe {
|
|||
}
|
||||
|
||||
public StoneCutterRecipe setInput(ItemLike in) {
|
||||
this.input = Ingredient.of(in);
|
||||
unlockedBy(in);
|
||||
return this;
|
||||
return super.setInput(in);
|
||||
}
|
||||
|
||||
public StoneCutterRecipe setInput(TagKey<Item> in) {
|
||||
this.input = Ingredient.of(in);
|
||||
unlockedBy(in);
|
||||
return this;
|
||||
return super.setInput(in);
|
||||
}
|
||||
|
||||
public StoneCutterRecipe setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StoneCutterRecipe setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StoneCutterRecipe checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean("stonecutting", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (!exist) {
|
||||
BCLib.LOGGER.warning("Unable to build Recipe " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
BCLib.LOGGER.warning("Unable to build Recipe " + id + ": Empty Material List");
|
||||
return;
|
||||
}
|
||||
StonecutterRecipe recipe = new StonecutterRecipe(id, group, input, new ItemStack(output, count));
|
||||
BCLRecipeManager.addRecipe(RecipeType.STONECUTTING, recipe);
|
||||
registerAdvancement(recipe);
|
||||
@Override
|
||||
protected StonecutterRecipe buildRecipe() {
|
||||
return new StonecutterRecipe(id, group, input, new ItemStack(output, count));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue