[Change] Recipe Handling moved to Datagen
This commit is contained in:
parent
f60fcd02d5
commit
809bfddd32
28 changed files with 1279 additions and 1121 deletions
|
@ -1,14 +1,13 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.config.PathConfig;
|
||||
import org.betterx.bclib.interfaces.AlloyingRecipeWorkstation;
|
||||
import org.betterx.bclib.interfaces.UnknownReceipBookCategory;
|
||||
import org.betterx.bclib.util.ItemUtil;
|
||||
import org.betterx.bclib.util.RecipeHelper;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
@ -130,77 +129,29 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
|
|||
return AlloyingRecipeWorkstation.getWorkstationIcon();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
private static boolean exist;
|
||||
public static class Builder extends AbstractDoubleInputRecipeBuilder<Builder, AlloyingRecipe> {
|
||||
private Builder(ResourceLocation id, ItemLike output) {
|
||||
super(id, output);
|
||||
this.experience = 0.0F;
|
||||
this.smeltTime = 350;
|
||||
}
|
||||
|
||||
static Builder create(ResourceLocation id, ItemLike output) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.group = String.format("%s_%s", GROUP, id);
|
||||
INSTANCE.primaryInput = null;
|
||||
INSTANCE.secondaryInput = null;
|
||||
INSTANCE.output = output;
|
||||
INSTANCE.experience = 0.0F;
|
||||
INSTANCE.smeltTime = 350;
|
||||
INSTANCE.count = 1;
|
||||
INSTANCE.alright = RecipeHelper.exists(output);
|
||||
exist = true;
|
||||
|
||||
return INSTANCE;
|
||||
return new Builder(id, output);
|
||||
}
|
||||
|
||||
private int count = 1;
|
||||
private ResourceLocation id;
|
||||
private Ingredient primaryInput;
|
||||
private Ingredient secondaryInput;
|
||||
private ItemLike output;
|
||||
private String group;
|
||||
private float experience;
|
||||
private int smeltTime;
|
||||
private boolean alright = true;
|
||||
|
||||
protected Builder() {
|
||||
}
|
||||
|
||||
public Builder checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean("alloying", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
return super.setOutputCount(count);
|
||||
}
|
||||
|
||||
public Builder setPrimaryInput(ItemLike... inputs) {
|
||||
for (ItemLike item : inputs) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
}
|
||||
this.primaryInput = Ingredient.of(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSecondaryInput(ItemLike... inputs) {
|
||||
for (ItemLike item : inputs) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
}
|
||||
this.secondaryInput = Ingredient.of(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPrimaryInput(TagKey<Item> input) {
|
||||
this.primaryInput = Ingredient.of(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSecondaryInput(TagKey<Item> input) {
|
||||
this.secondaryInput = Ingredient.of(input);
|
||||
return this;
|
||||
@Override
|
||||
public Builder setOutputTag(CompoundTag tag) {
|
||||
return super.setOutputTag(tag);
|
||||
}
|
||||
|
||||
public Builder setInput(ItemLike primaryInput, ItemLike secondaryInput) {
|
||||
|
@ -225,46 +176,34 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
|
|||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (exist) {
|
||||
if (primaryInput == null) {
|
||||
BCLib.LOGGER.warning(
|
||||
"Primary input for Alloying recipe can't be 'null', recipe {} will be ignored!",
|
||||
id
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (secondaryInput == null) {
|
||||
BCLib.LOGGER.warning(
|
||||
"Secondary input for Alloying can't be 'null', recipe {} will be ignored!",
|
||||
id
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (output == null) {
|
||||
BCLib.LOGGER.warning("Output for Alloying can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (BCLRecipeManager.getRecipe(TYPE, id) != null) {
|
||||
BCLib.LOGGER.warning("Can't add Alloying recipe! Id {} already exists!", id);
|
||||
return;
|
||||
}
|
||||
if (!alright) {
|
||||
BCLib.LOGGER.debug("Can't add Alloying recipe {}! Ingeredient or output not exists.", id);
|
||||
return;
|
||||
}
|
||||
BCLRecipeManager.addRecipe(
|
||||
TYPE,
|
||||
new AlloyingRecipe(
|
||||
id,
|
||||
group,
|
||||
primaryInput,
|
||||
secondaryInput,
|
||||
new ItemStack(output, count),
|
||||
experience,
|
||||
smeltTime
|
||||
)
|
||||
);
|
||||
@Override
|
||||
public Builder setGroup(String group) {
|
||||
return super.setGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkRecipe() {
|
||||
if (smeltTime < 0) {
|
||||
BCLib.LOGGER.warning("Semelt-time for recipe {} most be positive!", id);
|
||||
return false;
|
||||
}
|
||||
return super.checkRecipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecipeSerializer<AlloyingRecipe> getSerializer() {
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serializeRecipeData(JsonObject root) {
|
||||
super.serializeRecipeData(root);
|
||||
|
||||
if (experience != 0) {
|
||||
root.addProperty("experience", experience);
|
||||
}
|
||||
if (experience != 350) {
|
||||
root.addProperty("smelttime", smeltTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -275,9 +214,11 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
|
|||
JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
|
||||
Ingredient primaryInput = Ingredient.fromJson(ingredients.get(0));
|
||||
Ingredient secondaryInput = Ingredient.fromJson(ingredients.get(1));
|
||||
|
||||
String group = GsonHelper.getAsString(json, "group", "");
|
||||
|
||||
JsonObject result = GsonHelper.getAsJsonObject(json, "result");
|
||||
ItemStack output = ItemUtil.fromJsonRecipe(result);
|
||||
ItemStack output = ItemUtil.fromJsonRecipeWithNBT(result);
|
||||
if (output == null) {
|
||||
throw new IllegalStateException("Output item does not exists!");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue