Start migration
This commit is contained in:
parent
6630ce0cab
commit
47ed597358
491 changed files with 12045 additions and 11953 deletions
|
@ -6,17 +6,17 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemConvertible;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.interfaces.BetterEndRecipe;
|
||||
|
@ -25,38 +25,39 @@ import ru.betterend.rituals.InfusionRitual;
|
|||
import ru.betterend.util.ItemUtil;
|
||||
|
||||
public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
||||
|
||||
|
||||
public final static String GROUP = "infusion";
|
||||
public final static RecipeType<InfusionRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
||||
public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer());
|
||||
public final static Identifier ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
private final Identifier id;
|
||||
public final static ResourceLocation ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
private final ResourceLocation id;
|
||||
private Ingredient input;
|
||||
private ItemStack output;
|
||||
private int time = 1;
|
||||
private Ingredient[] catalysts = new Ingredient[8];
|
||||
private String group;
|
||||
|
||||
private InfusionRecipe(Identifier id) {
|
||||
|
||||
private InfusionRecipe(ResourceLocation id) {
|
||||
this(id, null, null);
|
||||
}
|
||||
|
||||
private InfusionRecipe(Identifier id, Ingredient input, ItemStack output) {
|
||||
|
||||
private InfusionRecipe(ResourceLocation id, Ingredient input, ItemStack output) {
|
||||
this.id = id;
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
Arrays.fill(catalysts, Ingredient.EMPTY);
|
||||
}
|
||||
|
||||
|
||||
public int getInfusionTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InfusionRitual inv, World world) {
|
||||
public boolean matches(InfusionRitual inv, Level world) {
|
||||
boolean valid = this.input.test(inv.getStack(0));
|
||||
if (!valid) return false;
|
||||
if (!valid)
|
||||
return false;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
valid &= this.catalysts[i].test(inv.getStack(i + 1));
|
||||
}
|
||||
|
@ -72,7 +73,7 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
public boolean fits(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DefaultedList<Ingredient> getPreviewInputs() {
|
||||
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
|
||||
|
@ -89,10 +90,10 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getGroup() {
|
||||
|
@ -108,79 +109,82 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
public RecipeType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
private static boolean exist;
|
||||
|
||||
|
||||
public static Builder create(String id) {
|
||||
return create(BetterEnd.makeID(id));
|
||||
}
|
||||
|
||||
public static Builder create(Identifier id) {
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.input = null;
|
||||
INSTANCE.output = null;
|
||||
INSTANCE.time = 1;
|
||||
exist = Configs.RECIPE_CONFIG.getBoolean("infusion", id.getPath(), true);
|
||||
|
||||
|
||||
Arrays.fill(INSTANCE.catalysts, Ingredient.EMPTY);
|
||||
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private Identifier id;
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient input;
|
||||
private ItemStack output;
|
||||
private String group;
|
||||
private int time = 1;
|
||||
private Ingredient[] catalysts = new Ingredient[8];
|
||||
|
||||
|
||||
private Builder() {
|
||||
Arrays.fill(catalysts, Ingredient.EMPTY);
|
||||
}
|
||||
|
||||
|
||||
public Builder setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(ItemConvertible input) {
|
||||
this.input = Ingredient.ofItems(input);
|
||||
this.input = Ingredient.of(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemConvertible output) {
|
||||
this.output = new ItemStack(output);
|
||||
this.output.setCount(1);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemStack output) {
|
||||
this.output = output;
|
||||
this.output.setCount(1);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setTime(int time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder addCatalyst(int slot, ItemConvertible... items) {
|
||||
if (slot > 7) return this;
|
||||
this.catalysts[slot] = Ingredient.ofItems(items);
|
||||
if (slot > 7)
|
||||
return this;
|
||||
this.catalysts[slot] = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void build() {
|
||||
if (exist) {
|
||||
if (input == null) {
|
||||
BetterEnd.LOGGER.warning("Input for Infusion recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
BetterEnd.LOGGER.warning("Input for Infusion recipe can't be 'null', recipe {} will be ignored!",
|
||||
id);
|
||||
return;
|
||||
}
|
||||
if (output == null) {
|
||||
BetterEnd.LOGGER.warning("Output for Infusion recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
BetterEnd.LOGGER.warning("Output for Infusion recipe can't be 'null', recipe {} will be ignored!",
|
||||
id);
|
||||
return;
|
||||
}
|
||||
InfusionRecipe recipe = new InfusionRecipe(id, input, output);
|
||||
|
@ -188,8 +192,10 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
recipe.time = time;
|
||||
int empty = 0;
|
||||
for (int i = 0; i < catalysts.length; i++) {
|
||||
if (catalysts[i].isEmpty()) empty++;
|
||||
else recipe.catalysts[i] = catalysts[i];
|
||||
if (catalysts[i].isEmpty())
|
||||
empty++;
|
||||
else
|
||||
recipe.catalysts[i] = catalysts[i];
|
||||
}
|
||||
if (empty == catalysts.length) {
|
||||
BetterEnd.LOGGER.warning("At least one catalyst must be non empty, recipe {} will be ignored!", id);
|
||||
|
@ -199,10 +205,10 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Serializer implements RecipeSerializer<InfusionRecipe> {
|
||||
@Override
|
||||
public InfusionRecipe read(Identifier id, JsonObject json) {
|
||||
public InfusionRecipe read(ResourceLocation id, JsonObject json) {
|
||||
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||
recipe.input = Ingredient.fromJson(json.get("input"));
|
||||
JsonObject result = JsonHelper.getObject(json, "result");
|
||||
|
@ -212,7 +218,7 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
}
|
||||
recipe.group = JsonHelper.getString(json, "group", GROUP);
|
||||
recipe.time = JsonHelper.getInt(json, "time", 1);
|
||||
|
||||
|
||||
JsonObject catalysts = JsonHelper.asObject(json, "catalysts");
|
||||
ItemStack catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "north", ""));
|
||||
recipe.catalysts[0] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
|
@ -230,12 +236,12 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
recipe.catalysts[6] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "north_west", ""));
|
||||
recipe.catalysts[7] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfusionRecipe read(Identifier id, PacketByteBuf buffer) {
|
||||
public InfusionRecipe read(ResourceLocation id, PacketByteBuf buffer) {
|
||||
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||
recipe.input = Ingredient.fromPacket(buffer);
|
||||
recipe.output = buffer.readItemStack();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue