Continue mapping migration
This commit is contained in:
parent
99ade39404
commit
f03fd03bd0
499 changed files with 12567 additions and 12723 deletions
|
@ -5,19 +5,19 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
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.tags.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
|
@ -27,13 +27,13 @@ import ru.betterend.registry.EndBlocks;
|
|||
import ru.betterend.util.ItemUtil;
|
||||
import ru.betterend.util.RecipeHelper;
|
||||
|
||||
public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
||||
|
||||
public class AlloyingRecipe implements Recipe<Container>, BetterEndRecipe {
|
||||
|
||||
public final static String GROUP = "alloying";
|
||||
public final static RecipeType<AlloyingRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
||||
public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer());
|
||||
public final static ResourceLocation ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
|
||||
protected final RecipeType<?> type;
|
||||
protected final ResourceLocation id;
|
||||
protected final Ingredient primaryInput;
|
||||
|
@ -42,9 +42,8 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
protected final String group;
|
||||
protected final float experience;
|
||||
protected final int smeltTime;
|
||||
|
||||
public AlloyingRecipe(ResourceLocation id, String group, Ingredient primaryInput, Ingredient secondaryInput,
|
||||
ItemStack output, float experience, int smeltTime) {
|
||||
|
||||
public AlloyingRecipe(ResourceLocation id, String group, Ingredient primaryInput, Ingredient secondaryInput, ItemStack output, float experience, int smeltTime) {
|
||||
this.group = group;
|
||||
this.id = id;
|
||||
this.primaryInput = primaryInput;
|
||||
|
@ -54,42 +53,42 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
this.smeltTime = smeltTime;
|
||||
this.type = TYPE;
|
||||
}
|
||||
|
||||
|
||||
public float getExperience() {
|
||||
return this.experience;
|
||||
}
|
||||
|
||||
|
||||
public int getSmeltTime() {
|
||||
return this.smeltTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultedList<Ingredient> getPreviewInputs() {
|
||||
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
||||
defaultedList.add(primaryInput);
|
||||
defaultedList.add(secondaryInput);
|
||||
|
||||
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Inventory inv, Level world) {
|
||||
return this.primaryInput.test(inv.getStack(0)) && this.secondaryInput.test(inv.getStack(1))
|
||||
|| this.primaryInput.test(inv.getStack(1)) && this.secondaryInput.test(inv.getStack(0));
|
||||
public boolean matches(Container inv, Level world) {
|
||||
return this.primaryInput.test(inv.getItem(0)) && this.secondaryInput.test(inv.getItem(1)) ||
|
||||
this.primaryInput.test(inv.getItem(1)) && this.secondaryInput.test(inv.getItem(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(Inventory inv) {
|
||||
public ItemStack assemble(Container inv) {
|
||||
return this.output.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fits(int width, int height) {
|
||||
public boolean canCraftInDimensions(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
public ItemStack getResultItem() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
|
@ -107,22 +106,22 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
public RecipeType<?> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public ItemStack getRecipeKindIcon() {
|
||||
public ItemStack getToastSymbol() {
|
||||
return new ItemStack(EndBlocks.END_STONE_SMELTER);
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
private static boolean exist;
|
||||
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.group = String.format("%s_%s", GROUP, id);
|
||||
|
@ -132,14 +131,14 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
INSTANCE.experience = 0.0F;
|
||||
INSTANCE.smeltTime = 350;
|
||||
exist = Configs.RECIPE_CONFIG.getBoolean("alloying", id.getPath(), true);
|
||||
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public static Builder create(String id) {
|
||||
return create(BetterEnd.makeID(id));
|
||||
}
|
||||
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient primaryInput;
|
||||
private Ingredient secondaryInput;
|
||||
|
@ -148,15 +147,14 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
private float experience;
|
||||
private int smeltTime;
|
||||
private boolean alright = true;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
|
||||
private Builder() {}
|
||||
|
||||
public Builder setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setPrimaryInput(ItemLike... inputs) {
|
||||
for (ItemLike item : inputs) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
|
@ -164,7 +162,7 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
this.primaryInput = Ingredient.of(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setSecondaryInput(ItemLike... inputs) {
|
||||
for (ItemLike item : inputs) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
|
@ -172,58 +170,56 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
this.secondaryInput = Ingredient.of(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setPrimaryInput(Tag<Item> input) {
|
||||
this.primaryInput = Ingredient.fromTag(input);
|
||||
this.primaryInput = Ingredient.of(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setSecondaryInput(Tag<Item> input) {
|
||||
this.secondaryInput = Ingredient.fromTag(input);
|
||||
this.secondaryInput = Ingredient.of(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(ItemLike primaryInput, ItemLike secondaryInput) {
|
||||
this.setPrimaryInput(primaryInput);
|
||||
this.setSecondaryInput(secondaryInput);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(Tag<Item> primaryInput, Tag<Item> secondaryInput) {
|
||||
this.setPrimaryInput(primaryInput);
|
||||
this.setSecondaryInput(secondaryInput);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemLike output, int amount) {
|
||||
this.alright &= RecipeHelper.exists(output);
|
||||
this.output = new ItemStack(output, amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setExpiriense(float amount) {
|
||||
this.experience = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setSmeltTime(int time) {
|
||||
this.smeltTime = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void build() {
|
||||
if (exist) {
|
||||
if (primaryInput == null) {
|
||||
BetterEnd.LOGGER.warning(
|
||||
"Primary input for Alloying recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
BetterEnd.LOGGER.warning("Primary input for Alloying recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (secondaryInput == null) {
|
||||
BetterEnd.LOGGER.warning("Secondary input for Alloying can't be 'null', recipe {} will be ignored!",
|
||||
id);
|
||||
if(secondaryInput == null) {
|
||||
BetterEnd.LOGGER.warning("Secondary input for Alloying can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (output == null) {
|
||||
if(output == null) {
|
||||
BetterEnd.LOGGER.warning("Output for Alloying can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
|
@ -235,48 +231,47 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
BetterEnd.LOGGER.debug("Can't add Alloying recipe {}! Ingeredient or output not exists.", id);
|
||||
return;
|
||||
}
|
||||
EndRecipeManager.addRecipe(TYPE,
|
||||
new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime));
|
||||
EndRecipeManager.addRecipe(TYPE, new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Serializer implements RecipeSerializer<AlloyingRecipe> {
|
||||
@Override
|
||||
public AlloyingRecipe read(ResourceLocation id, JsonObject json) {
|
||||
JsonArray ingredients = JsonHelper.getArray(json, "ingredients");
|
||||
public AlloyingRecipe fromJson(ResourceLocation id, JsonObject json) {
|
||||
JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
|
||||
Ingredient primaryInput = Ingredient.fromJson(ingredients.get(0));
|
||||
Ingredient secondaryInput = Ingredient.fromJson(ingredients.get(1));
|
||||
String group = JsonHelper.getString(json, "group", "");
|
||||
JsonObject result = JsonHelper.getObject(json, "result");
|
||||
String group = GsonHelper.getAsString(json, "group", "");
|
||||
JsonObject result = GsonHelper.getAsJsonObject(json, "result");
|
||||
ItemStack output = ItemUtil.fromJsonRecipe(result);
|
||||
if (output == null) {
|
||||
throw new IllegalStateException("Output item does not exists!");
|
||||
}
|
||||
float experience = JsonHelper.getFloat(json, "experience", 0.0F);
|
||||
int smeltTime = JsonHelper.getInt(json, "smelttime", 350);
|
||||
|
||||
float experience = GsonHelper.getAsFloat(json, "experience", 0.0F);
|
||||
int smeltTime = GsonHelper.getAsInt(json, "smelttime", 350);
|
||||
|
||||
return new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlloyingRecipe read(ResourceLocation id, PacketByteBuf packetBuffer) {
|
||||
String group = packetBuffer.readString(32767);
|
||||
Ingredient primary = Ingredient.fromPacket(packetBuffer);
|
||||
Ingredient secondary = Ingredient.fromPacket(packetBuffer);
|
||||
ItemStack output = packetBuffer.readItemStack();
|
||||
public AlloyingRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf packetBuffer) {
|
||||
String group = packetBuffer.readUtf(32767);
|
||||
Ingredient primary = Ingredient.fromNetwork(packetBuffer);
|
||||
Ingredient secondary = Ingredient.fromNetwork(packetBuffer);
|
||||
ItemStack output = packetBuffer.readItem();
|
||||
float experience = packetBuffer.readFloat();
|
||||
int smeltTime = packetBuffer.readVarInt();
|
||||
|
||||
|
||||
return new AlloyingRecipe(id, group, primary, secondary, output, experience, smeltTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf packetBuffer, AlloyingRecipe recipe) {
|
||||
packetBuffer.writeString(recipe.group);
|
||||
recipe.primaryInput.write(packetBuffer);
|
||||
recipe.secondaryInput.write(packetBuffer);
|
||||
packetBuffer.writeItemStack(recipe.output);
|
||||
public void toNetwork(FriendlyByteBuf packetBuffer, AlloyingRecipe recipe) {
|
||||
packetBuffer.writeUtf(recipe.group);
|
||||
recipe.primaryInput.toNetwork(packetBuffer);
|
||||
recipe.secondaryInput.toNetwork(packetBuffer);
|
||||
packetBuffer.writeItem(recipe.output);
|
||||
packetBuffer.writeFloat(recipe.experience);
|
||||
packetBuffer.writeVarInt(recipe.smeltTime);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,22 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TieredItem;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
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.tags.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
|
@ -30,13 +31,13 @@ import ru.betterend.registry.EndTags;
|
|||
import ru.betterend.util.ItemUtil;
|
||||
import ru.betterend.util.RecipeHelper;
|
||||
|
||||
public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
||||
|
||||
public class AnvilRecipe implements Recipe<Container>, BetterEndRecipe {
|
||||
|
||||
public final static String GROUP = "smithing";
|
||||
public final static RecipeType<AnvilRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
||||
public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer());
|
||||
public final static ResourceLocation ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final Ingredient input;
|
||||
private final ItemStack output;
|
||||
|
@ -44,9 +45,8 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
private final int toolLevel;
|
||||
private final int anvilLevel;
|
||||
private final int inputCount;
|
||||
|
||||
public AnvilRecipe(ResourceLocation identifier, Ingredient input, ItemStack output, int inputCount, int toolLevel,
|
||||
int anvilLevel, int damage) {
|
||||
|
||||
public AnvilRecipe(ResourceLocation identifier, Ingredient input, ItemStack output, int inputCount, int toolLevel, int anvilLevel, int damage) {
|
||||
this.id = identifier;
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
|
@ -62,50 +62,50 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
public ItemStack getResultItem() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(Inventory craftingInventory, Level world) {
|
||||
public boolean matches(Container craftingInventory, Level world) {
|
||||
return this.matches(craftingInventory);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack craft(Inventory craftingInventory) {
|
||||
public ItemStack assemble(Container craftingInventory) {
|
||||
return this.output.copy();
|
||||
}
|
||||
|
||||
public ItemStack craft(Inventory craftingInventory, Player player) {
|
||||
|
||||
public ItemStack craft(Container craftingInventory, Player player) {
|
||||
if (!player.isCreative()) {
|
||||
if (!checkHammerDurability(craftingInventory, player))
|
||||
return ItemStack.EMPTY;
|
||||
ItemStack hammer = craftingInventory.getStack(1);
|
||||
hammer.damage(this.damage, player, entity -> entity.sendEquipmentBreakStatus(null));
|
||||
if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY;
|
||||
ItemStack hammer = craftingInventory.getItem(1);
|
||||
hammer.hurtAndBreak(this.damage, player, entity ->
|
||||
entity.broadcastBreakEvent((InteractionHand) null));
|
||||
}
|
||||
return this.craft(craftingInventory);
|
||||
return this.assemble(craftingInventory);
|
||||
}
|
||||
|
||||
public boolean checkHammerDurability(Inventory craftingInventory, Player player) {
|
||||
if (player.isCreative())
|
||||
return true;
|
||||
ItemStack hammer = craftingInventory.getStack(1);
|
||||
int damage = hammer.getDamage() + this.damage;
|
||||
public boolean checkHammerDurability(Container craftingInventory, Player player) {
|
||||
if (player.isCreative()) return true;
|
||||
ItemStack hammer = craftingInventory.getItem(1);
|
||||
int damage = hammer.getDamageValue() + this.damage;
|
||||
return damage < hammer.getMaxDamage();
|
||||
}
|
||||
|
||||
public boolean matches(Inventory craftingInventory) {
|
||||
ItemStack hammer = craftingInventory.getStack(1);
|
||||
|
||||
public boolean matches(Container craftingInventory) {
|
||||
ItemStack hammer = craftingInventory.getItem(1);
|
||||
if (hammer.isEmpty() || !EndTags.HAMMERS.contains(hammer.getItem())) {
|
||||
return false;
|
||||
}
|
||||
ItemStack material = craftingInventory.getStack(0);
|
||||
ItemStack material = craftingInventory.getItem(0);
|
||||
int materialCount = material.getCount();
|
||||
int level = ((TieredItem) hammer.getItem()).getTier().getLevel();
|
||||
return this.input.test(craftingInventory.getStack(0)) && materialCount >= this.inputCount
|
||||
&& level >= this.toolLevel;
|
||||
return this.input.test(craftingInventory.getItem(0)) &&
|
||||
materialCount >= this.inputCount &&
|
||||
level >= this.toolLevel;
|
||||
}
|
||||
|
||||
|
||||
public int getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
|
@ -119,18 +119,18 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DefaultedList<Ingredient> getPreviewInputs() {
|
||||
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
|
||||
defaultedList.add(Ingredient.ofStacks(EndTags.HAMMERS.values().stream()
|
||||
.filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel).map(ItemStack::new)));
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
||||
defaultedList.add(Ingredient.of(EndTags.HAMMERS.getValues().stream().filter(hammer ->
|
||||
((TieredItem) hammer).getTier().getLevel() >= toolLevel).map(ItemStack::new)));
|
||||
defaultedList.add(input);
|
||||
|
||||
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean fits(int width, int height) {
|
||||
public boolean canCraftInDimensions(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -143,21 +143,18 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
public RecipeType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isIgnoredInRecipeBook() {
|
||||
public boolean isSpecial() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AnvilRecipe that = (AnvilRecipe) o;
|
||||
return damage == that.damage && toolLevel == that.toolLevel && id.equals(that.id) && input.equals(that.input)
|
||||
&& output.equals(that.output);
|
||||
return damage == that.damage && toolLevel == that.toolLevel && id.equals(that.id) && input.equals(that.input) && output.equals(that.output);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,11 +169,11 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
|
||||
|
||||
public static Builder create(String id) {
|
||||
return create(BetterEnd.makeID(id));
|
||||
}
|
||||
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.input = null;
|
||||
|
@ -186,10 +183,10 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
INSTANCE.anvilLevel = 1;
|
||||
INSTANCE.damage = 1;
|
||||
INSTANCE.alright = true;
|
||||
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient input;
|
||||
private ItemStack output;
|
||||
|
@ -198,21 +195,20 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
private int anvilLevel = 1;
|
||||
private int damage = 1;
|
||||
private boolean alright;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
|
||||
private Builder() {}
|
||||
|
||||
public Builder setInput(ItemLike... inputItems) {
|
||||
this.alright &= RecipeHelper.exists(inputItems);
|
||||
this.setInput(Ingredient.of(inputItems));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(Tag<Item> inputTag) {
|
||||
this.setInput(Ingredient.fromTag(inputTag));
|
||||
this.setInput(Ingredient.of(inputTag));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(Ingredient ingredient) {
|
||||
this.input = ingredient;
|
||||
return this;
|
||||
|
@ -222,17 +218,17 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
this.inputCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemLike output) {
|
||||
return this.setOutput(output, 1);
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemLike output, int amount) {
|
||||
this.alright &= RecipeHelper.exists(output);
|
||||
this.output = new ItemStack(output, amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setToolLevel(int level) {
|
||||
this.toolLevel = level;
|
||||
return this;
|
||||
|
@ -242,19 +238,19 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
this.anvilLevel = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void build() {
|
||||
if (Configs.RECIPE_CONFIG.getBoolean("anvil", id.getPath(), true)) {
|
||||
if (input == null) {
|
||||
BetterEnd.LOGGER.warning("Input for Anvil recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (output == null) {
|
||||
if(output == null) {
|
||||
BetterEnd.LOGGER.warning("Output for Anvil recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
|
@ -266,45 +262,44 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
BetterEnd.LOGGER.debug("Can't add Anvil recipe {}! Ingeredient or output not exists.", id);
|
||||
return;
|
||||
}
|
||||
EndRecipeManager.addRecipe(TYPE,
|
||||
new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage));
|
||||
EndRecipeManager.addRecipe(TYPE, new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Serializer implements RecipeSerializer<AnvilRecipe> {
|
||||
@Override
|
||||
public AnvilRecipe read(ResourceLocation id, JsonObject json) {
|
||||
public AnvilRecipe fromJson(ResourceLocation id, JsonObject json) {
|
||||
Ingredient input = Ingredient.fromJson(json.get("input"));
|
||||
JsonObject result = JsonHelper.getObject(json, "result");
|
||||
JsonObject result = GsonHelper.getAsJsonObject(json, "result");
|
||||
ItemStack output = ItemUtil.fromJsonRecipe(result);
|
||||
if (output == null) {
|
||||
throw new IllegalStateException("Output item does not exists!");
|
||||
}
|
||||
int inputCount = JsonHelper.getInt(json, "inputCount", 1);
|
||||
int toolLevel = JsonHelper.getInt(json, "toolLevel", 1);
|
||||
int anvilLevel = JsonHelper.getInt(json, "anvilLevel", 1);
|
||||
int damage = JsonHelper.getInt(json, "damage", 1);
|
||||
|
||||
int inputCount = GsonHelper.getAsInt(json, "inputCount", 1);
|
||||
int toolLevel = GsonHelper.getAsInt(json, "toolLevel", 1);
|
||||
int anvilLevel = GsonHelper.getAsInt(json, "anvilLevel", 1);
|
||||
int damage = GsonHelper.getAsInt(json, "damage", 1);
|
||||
|
||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnvilRecipe read(ResourceLocation id, PacketByteBuf packetBuffer) {
|
||||
Ingredient input = Ingredient.fromPacket(packetBuffer);
|
||||
ItemStack output = packetBuffer.readItemStack();
|
||||
public AnvilRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf packetBuffer) {
|
||||
Ingredient input = Ingredient.fromNetwork(packetBuffer);
|
||||
ItemStack output = packetBuffer.readItem();
|
||||
int inputCount = packetBuffer.readVarInt();
|
||||
int toolLevel = packetBuffer.readVarInt();
|
||||
int anvilLevel = packetBuffer.readVarInt();
|
||||
int damage = packetBuffer.readVarInt();
|
||||
|
||||
|
||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf packetBuffer, AnvilRecipe recipe) {
|
||||
recipe.input.write(packetBuffer);
|
||||
packetBuffer.writeItemStack(recipe.output);
|
||||
public void toNetwork(FriendlyByteBuf packetBuffer, AnvilRecipe recipe) {
|
||||
recipe.input.toNetwork(packetBuffer);
|
||||
packetBuffer.writeItem(recipe.output);
|
||||
packetBuffer.writeVarInt(recipe.inputCount);
|
||||
packetBuffer.writeVarInt(recipe.toolLevel);
|
||||
packetBuffer.writeVarInt(recipe.anvilLevel);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ru.betterend.recipe.builders;
|
||||
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.BlastingRecipe;
|
||||
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
|
||||
|
@ -8,7 +8,7 @@ import net.minecraft.world.item.crafting.Ingredient;
|
|||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.SmeltingRecipe;
|
||||
import net.minecraft.world.item.crafting.SmokingRecipe;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
|
@ -16,7 +16,7 @@ import ru.betterend.util.RecipeHelper;
|
|||
|
||||
public class FurnaceRecipe {
|
||||
private static final FurnaceRecipe INSTANCE = new FurnaceRecipe();
|
||||
|
||||
|
||||
private ItemLike input;
|
||||
private ItemLike output;
|
||||
private boolean exist;
|
||||
|
@ -25,10 +25,9 @@ public class FurnaceRecipe {
|
|||
private int count;
|
||||
private int time;
|
||||
private float xp;
|
||||
|
||||
private FurnaceRecipe() {
|
||||
}
|
||||
|
||||
|
||||
private FurnaceRecipe() {}
|
||||
|
||||
public static FurnaceRecipe make(String name, ItemLike input, ItemLike output) {
|
||||
INSTANCE.name = name;
|
||||
INSTANCE.group = "";
|
||||
|
@ -37,68 +36,64 @@ public class FurnaceRecipe {
|
|||
INSTANCE.count = 1;
|
||||
INSTANCE.time = 200;
|
||||
INSTANCE.xp = 0;
|
||||
INSTANCE.exist = Configs.RECIPE_CONFIG.getBoolean("furnace", name, true) && RecipeHelper.exists(output)
|
||||
&& RecipeHelper.exists(input);
|
||||
INSTANCE.exist = Configs.RECIPE_CONFIG.getBoolean("furnace", name, true) && RecipeHelper.exists(output) && RecipeHelper.exists(input);
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public FurnaceRecipe setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FurnaceRecipe setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FurnaceRecipe setXP(float xp) {
|
||||
this.xp = xp;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FurnaceRecipe setCookTime(int time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void build() {
|
||||
build(false, false, false);
|
||||
}
|
||||
|
||||
|
||||
public void buildWithBlasting() {
|
||||
build(true, false, false);
|
||||
}
|
||||
|
||||
|
||||
public void buildFoodlike() {
|
||||
build(false, true, true);
|
||||
}
|
||||
|
||||
|
||||
public void build(boolean blasting, boolean campfire, boolean smoker) {
|
||||
if (exist) {
|
||||
ResourceLocation id = BetterEnd.makeID(name);
|
||||
SmeltingRecipe recipe = new SmeltingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count),
|
||||
xp, time);
|
||||
SmeltingRecipe recipe = new SmeltingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time);
|
||||
EndRecipeManager.addRecipe(RecipeType.SMELTING, recipe);
|
||||
|
||||
|
||||
if (blasting) {
|
||||
BlastingRecipe recipe2 = new BlastingRecipe(id, group, Ingredient.of(input),
|
||||
new ItemStack(output, count), xp, time / 2);
|
||||
BlastingRecipe recipe2 = new BlastingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time / 2);
|
||||
EndRecipeManager.addRecipe(RecipeType.BLASTING, recipe2);
|
||||
}
|
||||
|
||||
|
||||
if (campfire) {
|
||||
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(id, group, Ingredient.of(input),
|
||||
new ItemStack(output, count), xp, time * 3);
|
||||
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time * 3);
|
||||
EndRecipeManager.addRecipe(RecipeType.CAMPFIRE_COOKING, recipe2);
|
||||
}
|
||||
|
||||
|
||||
if (smoker) {
|
||||
SmokingRecipe recipe2 = new SmokingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count),
|
||||
xp, time / 2);
|
||||
SmokingRecipe recipe2 = new SmokingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time / 2);
|
||||
EndRecipeManager.addRecipe(RecipeType.SMOKING, recipe2);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
BetterEnd.LOGGER.debug("Furnace recipe {} couldn't be added", name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,20 +2,18 @@ package ru.betterend.recipe.builders;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.world.item.crafting.ShapelessRecipe;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import com.google.common.collect.Maps;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
|
@ -23,10 +21,10 @@ import ru.betterend.util.RecipeHelper;
|
|||
|
||||
public class GridRecipe {
|
||||
private static final GridRecipe INSTANCE = new GridRecipe();
|
||||
|
||||
|
||||
private String name;
|
||||
private ItemLike output;
|
||||
|
||||
|
||||
private String group;
|
||||
private RecipeType<?> type;
|
||||
private boolean shaped;
|
||||
|
@ -34,23 +32,22 @@ public class GridRecipe {
|
|||
private Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
||||
private int count;
|
||||
private boolean exist = true;
|
||||
|
||||
private GridRecipe() {
|
||||
}
|
||||
|
||||
|
||||
private GridRecipe() {}
|
||||
|
||||
public static GridRecipe make(String name, ItemLike output) {
|
||||
INSTANCE.name = name;
|
||||
INSTANCE.output = output;
|
||||
|
||||
|
||||
INSTANCE.group = "";
|
||||
INSTANCE.type = RecipeType.CRAFTING;
|
||||
INSTANCE.shaped = true;
|
||||
INSTANCE.shape = new String[] { "#" };
|
||||
INSTANCE.shape = new String[] {"#"};
|
||||
INSTANCE.materialKeys.clear();
|
||||
INSTANCE.count = 1;
|
||||
|
||||
|
||||
INSTANCE.exist = Configs.RECIPE_CONFIG.getBoolean("grid", name, true) && RecipeHelper.exists(output);
|
||||
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -58,66 +55,65 @@ public class GridRecipe {
|
|||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe setShape(String... shape) {
|
||||
this.shape = shape;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe setList(String shape) {
|
||||
this.shape = new String[] { shape };
|
||||
this.shaped = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe addMaterial(char key, Tag<Item> value) {
|
||||
return addMaterial(key, Ingredient.fromTag(value));
|
||||
return addMaterial(key, Ingredient.of(value));
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemStack... value) {
|
||||
return addMaterial(key, Ingredient.ofStacks(Arrays.stream(value)));
|
||||
return addMaterial(key, Ingredient.of(Arrays.stream(value)));
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemLike... values) {
|
||||
for (ItemLike item : values) {
|
||||
for (ItemLike item: values) {
|
||||
exist &= RecipeHelper.exists(item);
|
||||
}
|
||||
return addMaterial(key, Ingredient.of(values));
|
||||
}
|
||||
|
||||
|
||||
private GridRecipe addMaterial(char key, Ingredient value) {
|
||||
materialKeys.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
private DefaultedList<Ingredient> getMaterials(int width, int height) {
|
||||
DefaultedList<Ingredient> materials = DefaultedList.ofSize(width * height, Ingredient.EMPTY);
|
||||
|
||||
private NonNullList<Ingredient> getMaterials(int width, int height) {
|
||||
NonNullList<Ingredient> materials = NonNullList.withSize(width * height, Ingredient.EMPTY);
|
||||
int pos = 0;
|
||||
for (String line : shape) {
|
||||
for (String line: shape) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
char c = line.charAt(i);
|
||||
Ingredient material = materialKeys.get(c);
|
||||
materials.set(pos++, material == null ? Ingredient.EMPTY : material);
|
||||
materials.set(pos ++, material == null ? Ingredient.EMPTY : material);
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
|
||||
public void build() {
|
||||
if (exist) {
|
||||
int height = shape.length;
|
||||
int width = shape[0].length();
|
||||
ItemStack result = new ItemStack(output, count);
|
||||
ResourceLocation id = BetterEnd.makeID(name);
|
||||
DefaultedList<Ingredient> materials = this.getMaterials(width, height);
|
||||
|
||||
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result)
|
||||
: new ShapelessRecipe(id, group, result, materials);
|
||||
NonNullList<Ingredient> materials = this.getMaterials(width, height);
|
||||
|
||||
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
|
||||
EndRecipeManager.addRecipe(type, recipe);
|
||||
} else {
|
||||
BetterEnd.LOGGER.debug("Recipe {} couldn't be added", name);
|
||||
|
|
|
@ -6,16 +6,16 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
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.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
|
@ -25,67 +25,65 @@ 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 ResourceLocation ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final Ingredient[] catalysts;
|
||||
private Ingredient input;
|
||||
private ItemStack output;
|
||||
private int time = 1;
|
||||
private Ingredient[] catalysts = new Ingredient[8];
|
||||
private String group;
|
||||
|
||||
|
||||
private InfusionRecipe(ResourceLocation id) {
|
||||
this(id, null, null);
|
||||
}
|
||||
|
||||
|
||||
private InfusionRecipe(ResourceLocation id, Ingredient input, ItemStack output) {
|
||||
this.id = id;
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.catalysts = new Ingredient[8];
|
||||
Arrays.fill(catalysts, Ingredient.EMPTY);
|
||||
}
|
||||
|
||||
|
||||
public int getInfusionTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InfusionRitual inv, Level world) {
|
||||
boolean valid = this.input.test(inv.getStack(0));
|
||||
if (!valid)
|
||||
return false;
|
||||
boolean valid = this.input.test(inv.getItem(0));
|
||||
if (!valid) return false;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
valid &= this.catalysts[i].test(inv.getStack(i + 1));
|
||||
valid &= this.catalysts[i].test(inv.getItem(i + 1));
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(InfusionRitual ritual) {
|
||||
public ItemStack assemble(InfusionRitual ritual) {
|
||||
return this.output.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fits(int width, int height) {
|
||||
public boolean canCraftInDimensions(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DefaultedList<Ingredient> getPreviewInputs() {
|
||||
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
||||
defaultedList.add(input);
|
||||
for (Ingredient catalyst : catalysts) {
|
||||
defaultedList.add(catalyst);
|
||||
}
|
||||
defaultedList.addAll(Arrays.asList(catalysts));
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
public ItemStack getResultItem() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
|
@ -93,7 +91,7 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getGroup() {
|
||||
|
@ -109,82 +107,79 @@ 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(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 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(ItemLike input) {
|
||||
this.input = Ingredient.of(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemLike 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, ItemLike... items) {
|
||||
if (slot > 7)
|
||||
return this;
|
||||
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);
|
||||
|
@ -192,10 +187,8 @@ 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);
|
||||
|
@ -205,62 +198,62 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Serializer implements RecipeSerializer<InfusionRecipe> {
|
||||
@Override
|
||||
public InfusionRecipe read(ResourceLocation id, JsonObject json) {
|
||||
public InfusionRecipe fromJson(ResourceLocation id, JsonObject json) {
|
||||
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||
recipe.input = Ingredient.fromJson(json.get("input"));
|
||||
JsonObject result = JsonHelper.getObject(json, "result");
|
||||
JsonObject result = GsonHelper.getAsJsonObject(json, "result");
|
||||
recipe.output = ItemUtil.fromJsonRecipe(result);
|
||||
if (recipe.output == null) {
|
||||
throw new IllegalStateException("Output item does not exists!");
|
||||
}
|
||||
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 }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "north_east", ""));
|
||||
recipe.catalysts[1] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "east", ""));
|
||||
recipe.catalysts[2] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "south_east", ""));
|
||||
recipe.catalysts[3] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "south", ""));
|
||||
recipe.catalysts[4] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "south_west", ""));
|
||||
recipe.catalysts[5] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "west", ""));
|
||||
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 }));
|
||||
|
||||
recipe.group = GsonHelper.getAsString(json, "group", GROUP);
|
||||
recipe.time = GsonHelper.getAsInt(json, "time", 1);
|
||||
|
||||
JsonObject catalysts = GsonHelper.convertToJsonObject(json, "catalysts");
|
||||
ItemStack catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "north", ""));
|
||||
recipe.catalysts[0] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "north_east", ""));
|
||||
recipe.catalysts[1] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "east", ""));
|
||||
recipe.catalysts[2] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "south_east", ""));
|
||||
recipe.catalysts[3] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "south", ""));
|
||||
recipe.catalysts[4] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "south_west", ""));
|
||||
recipe.catalysts[5] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "west", ""));
|
||||
recipe.catalysts[6] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "north_west", ""));
|
||||
recipe.catalysts[7] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst }));
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfusionRecipe read(ResourceLocation id, PacketByteBuf buffer) {
|
||||
public InfusionRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
|
||||
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||
recipe.input = Ingredient.fromPacket(buffer);
|
||||
recipe.output = buffer.readItemStack();
|
||||
recipe.group = buffer.readString();
|
||||
recipe.input = Ingredient.fromNetwork(buffer);
|
||||
recipe.output = buffer.readItem();
|
||||
recipe.group = buffer.readUtf();
|
||||
recipe.time = buffer.readVarInt();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
recipe.catalysts[i] = Ingredient.fromPacket(buffer);
|
||||
recipe.catalysts[i] = Ingredient.fromNetwork(buffer);
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf buffer, InfusionRecipe recipe) {
|
||||
recipe.input.write(buffer);
|
||||
buffer.writeItemStack(recipe.output);
|
||||
buffer.writeString(recipe.group);
|
||||
public void toNetwork(FriendlyByteBuf buffer, InfusionRecipe recipe) {
|
||||
recipe.input.toNetwork(buffer);
|
||||
buffer.writeItem(recipe.output);
|
||||
buffer.writeUtf(recipe.group);
|
||||
buffer.writeVarInt(recipe.time);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
recipe.catalysts[i].write(buffer);
|
||||
recipe.catalysts[i].toNetwork(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,91 +1,88 @@
|
|||
package ru.betterend.recipe.builders;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
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.SmithingRecipe;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.UpgradeRecipe;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
import ru.betterend.util.RecipeHelper;
|
||||
|
||||
public class SmithingTableRecipe {
|
||||
|
||||
|
||||
private final static SmithingTableRecipe BUILDER = new SmithingTableRecipe();
|
||||
private final static RecipeType<SmithingRecipe> TYPE = RecipeType.SMITHING;
|
||||
|
||||
private final static RecipeType<UpgradeRecipe> TYPE = RecipeType.SMITHING;
|
||||
|
||||
public static SmithingTableRecipe create(String name) {
|
||||
return create(BetterEnd.makeID(name));
|
||||
}
|
||||
|
||||
|
||||
public static SmithingTableRecipe create(ResourceLocation id) {
|
||||
BUILDER.id = id;
|
||||
BUILDER.base = null;
|
||||
BUILDER.addition = null;
|
||||
BUILDER.result = null;
|
||||
BUILDER.alright = true;
|
||||
|
||||
|
||||
return BUILDER;
|
||||
}
|
||||
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient base;
|
||||
private Ingredient addition;
|
||||
private ItemStack result;
|
||||
private boolean alright;
|
||||
|
||||
private SmithingTableRecipe() {
|
||||
}
|
||||
|
||||
|
||||
private SmithingTableRecipe() {}
|
||||
|
||||
public SmithingTableRecipe setResult(ItemLike item) {
|
||||
return this.setResult(item, 1);
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setResult(ItemLike item, int count) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
this.result = new ItemStack(item, count);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setBase(ItemLike... items) {
|
||||
this.alright &= RecipeHelper.exists(items);
|
||||
this.base = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setBase(Tag<Item> tag) {
|
||||
this.base = (Ingredient.fromTag(tag));
|
||||
this.base = (Ingredient.of(tag));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setAddition(ItemLike... items) {
|
||||
this.alright &= RecipeHelper.exists(items);
|
||||
this.addition = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setAddition(Tag<Item> tag) {
|
||||
this.addition = (Ingredient.fromTag(tag));
|
||||
this.addition = (Ingredient.of(tag));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void build() {
|
||||
if (Configs.RECIPE_CONFIG.getBoolean("smithing", id.getPath(), true)) {
|
||||
if (base == null) {
|
||||
BetterEnd.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!",
|
||||
id);
|
||||
BetterEnd.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (addition == null) {
|
||||
BetterEnd.LOGGER
|
||||
.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
BetterEnd.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (result == null) {
|
||||
if(result == null) {
|
||||
BetterEnd.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
|
@ -97,7 +94,7 @@ public class SmithingTableRecipe {
|
|||
BetterEnd.LOGGER.debug("Can't add Smithing recipe {}! Ingeredients or output not exists.", id);
|
||||
return;
|
||||
}
|
||||
EndRecipeManager.addRecipe(TYPE, new SmithingRecipe(id, base, addition, result));
|
||||
EndRecipeManager.addRecipe(TYPE, new UpgradeRecipe(id, base, addition, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue