Start migration
This commit is contained in:
parent
6630ce0cab
commit
47ed597358
491 changed files with 12045 additions and 11953 deletions
|
@ -6,19 +6,19 @@ import com.google.gson.JsonObject;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.Item;
|
||||
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.tag.Tag;
|
||||
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.tags.Tag;
|
||||
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;
|
||||
|
@ -28,22 +28,23 @@ import ru.betterend.util.ItemUtil;
|
|||
import ru.betterend.util.RecipeHelper;
|
||||
|
||||
public class AlloyingRecipe implements Recipe<Inventory>, 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 Identifier ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
public final static ResourceLocation ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
protected final RecipeType<?> type;
|
||||
protected final Identifier id;
|
||||
protected final ResourceLocation id;
|
||||
protected final Ingredient primaryInput;
|
||||
protected final Ingredient secondaryInput;
|
||||
protected final ItemStack output;
|
||||
protected final String group;
|
||||
protected final float experience;
|
||||
protected final int smeltTime;
|
||||
|
||||
public AlloyingRecipe(Identifier 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;
|
||||
|
@ -53,11 +54,11 @@ 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;
|
||||
}
|
||||
|
@ -67,14 +68,14 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
|
||||
defaultedList.add(primaryInput);
|
||||
defaultedList.add(secondaryInput);
|
||||
|
||||
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Inventory inv, World 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(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));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +94,7 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
@ -106,23 +107,23 @@ 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() {
|
||||
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(Identifier id) {
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.group = String.format("%s_%s", GROUP, id);
|
||||
INSTANCE.primaryInput = null;
|
||||
|
@ -131,15 +132,15 @@ 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 Identifier id;
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient primaryInput;
|
||||
private Ingredient secondaryInput;
|
||||
private ItemStack output;
|
||||
|
@ -147,79 +148,82 @@ 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(ItemConvertible... inputs) {
|
||||
for (ItemConvertible item : inputs) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
}
|
||||
this.primaryInput = Ingredient.ofItems(inputs);
|
||||
this.primaryInput = Ingredient.of(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setSecondaryInput(ItemConvertible... inputs) {
|
||||
for (ItemConvertible item : inputs) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
}
|
||||
this.secondaryInput = Ingredient.ofItems(inputs);
|
||||
this.secondaryInput = Ingredient.of(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setPrimaryInput(Tag<Item> input) {
|
||||
this.primaryInput = Ingredient.fromTag(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setSecondaryInput(Tag<Item> input) {
|
||||
this.secondaryInput = Ingredient.fromTag(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(ItemConvertible primaryInput, ItemConvertible 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(ItemConvertible 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;
|
||||
}
|
||||
|
@ -231,14 +235,15 @@ 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(Identifier id, JsonObject json) {
|
||||
public AlloyingRecipe read(ResourceLocation id, JsonObject json) {
|
||||
JsonArray ingredients = JsonHelper.getArray(json, "ingredients");
|
||||
Ingredient primaryInput = Ingredient.fromJson(ingredients.get(0));
|
||||
Ingredient secondaryInput = Ingredient.fromJson(ingredients.get(1));
|
||||
|
@ -250,19 +255,19 @@ public class AlloyingRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
}
|
||||
float experience = JsonHelper.getFloat(json, "experience", 0.0F);
|
||||
int smeltTime = JsonHelper.getInt(json, "smelttime", 350);
|
||||
|
||||
|
||||
return new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlloyingRecipe read(Identifier id, PacketByteBuf packetBuffer) {
|
||||
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();
|
||||
float experience = packetBuffer.readFloat();
|
||||
int smeltTime = packetBuffer.readVarInt();
|
||||
|
||||
|
||||
return new AlloyingRecipe(id, group, primary, secondary, output, experience, smeltTime);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,22 +6,22 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemConvertible;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ToolItem;
|
||||
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.tag.Tag;
|
||||
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.tags.Tag;
|
||||
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;
|
||||
|
@ -31,21 +31,22 @@ import ru.betterend.util.ItemUtil;
|
|||
import ru.betterend.util.RecipeHelper;
|
||||
|
||||
public class AnvilRecipe implements Recipe<Inventory>, 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 Identifier ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
private final Identifier id;
|
||||
public final static ResourceLocation ID = BetterEnd.makeID(GROUP);
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final Ingredient input;
|
||||
private final ItemStack output;
|
||||
private final int damage;
|
||||
private final int toolLevel;
|
||||
private final int anvilLevel;
|
||||
private final int inputCount;
|
||||
|
||||
public AnvilRecipe(Identifier 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;
|
||||
|
@ -64,34 +65,35 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
public ItemStack getOutput() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(Inventory craftingInventory, World world) {
|
||||
public boolean matches(Inventory craftingInventory, Level world) {
|
||||
return this.matches(craftingInventory);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack craft(Inventory craftingInventory) {
|
||||
return this.output.copy();
|
||||
}
|
||||
|
||||
|
||||
public ItemStack craft(Inventory craftingInventory, PlayerEntity player) {
|
||||
if (!player.isCreative()) {
|
||||
if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY;
|
||||
if (!checkHammerDurability(craftingInventory, player))
|
||||
return ItemStack.EMPTY;
|
||||
ItemStack hammer = craftingInventory.getStack(1);
|
||||
hammer.damage(this.damage, player, entity ->
|
||||
entity.sendEquipmentBreakStatus(null));
|
||||
hammer.damage(this.damage, player, entity -> entity.sendEquipmentBreakStatus(null));
|
||||
}
|
||||
return this.craft(craftingInventory);
|
||||
}
|
||||
|
||||
public boolean checkHammerDurability(Inventory craftingInventory, PlayerEntity player) {
|
||||
if (player.isCreative()) return true;
|
||||
if (player.isCreative())
|
||||
return true;
|
||||
ItemStack hammer = craftingInventory.getStack(1);
|
||||
int damage = hammer.getDamage() + this.damage;
|
||||
return damage < hammer.getMaxDamage();
|
||||
}
|
||||
|
||||
|
||||
public boolean matches(Inventory craftingInventory) {
|
||||
ItemStack hammer = craftingInventory.getStack(1);
|
||||
if (hammer.isEmpty() || !EndTags.HAMMERS.contains(hammer.getItem())) {
|
||||
|
@ -99,12 +101,11 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
}
|
||||
ItemStack material = craftingInventory.getStack(0);
|
||||
int materialCount = material.getCount();
|
||||
int level = ((ToolItem) hammer.getItem()).getMaterial().getMiningLevel();
|
||||
return this.input.test(craftingInventory.getStack(0)) &&
|
||||
materialCount >= this.inputCount &&
|
||||
level >= this.toolLevel;
|
||||
int level = ((ToolItem) hammer.getItem()).getTier().getLevel();
|
||||
return this.input.test(craftingInventory.getStack(0)) && materialCount >= this.inputCount
|
||||
&& level >= this.toolLevel;
|
||||
}
|
||||
|
||||
|
||||
public int getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
|
@ -120,10 +121,10 @@ 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 ->
|
||||
((ToolItem) hammer).getMaterial().getMiningLevel() >= toolLevel).map(ItemStack::new)));
|
||||
defaultedList.add(Ingredient.ofStacks(EndTags.HAMMERS.values().stream()
|
||||
.filter(hammer -> ((ToolItem) hammer).getTier().getLevel() >= toolLevel).map(ItemStack::new)));
|
||||
defaultedList.add(input);
|
||||
|
||||
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
|
@ -134,7 +135,7 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
@ -142,7 +143,7 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
public RecipeType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isIgnoredInRecipeBook() {
|
||||
return true;
|
||||
|
@ -150,10 +151,13 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
|
||||
@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
|
||||
|
@ -168,12 +172,12 @@ 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(Identifier id) {
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.input = null;
|
||||
INSTANCE.output = null;
|
||||
|
@ -182,11 +186,11 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
INSTANCE.anvilLevel = 1;
|
||||
INSTANCE.damage = 1;
|
||||
INSTANCE.alright = true;
|
||||
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private Identifier id;
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient input;
|
||||
private ItemStack output;
|
||||
private int inputCount = 1;
|
||||
|
@ -194,20 +198,21 @@ 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(ItemConvertible... inputItems) {
|
||||
this.alright &= RecipeHelper.exists(inputItems);
|
||||
this.setInput(Ingredient.ofItems(inputItems));
|
||||
this.setInput(Ingredient.of(inputItems));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(Tag<Item> inputTag) {
|
||||
this.setInput(Ingredient.fromTag(inputTag));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setInput(Ingredient ingredient) {
|
||||
this.input = ingredient;
|
||||
return this;
|
||||
|
@ -217,17 +222,17 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
this.inputCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemConvertible output) {
|
||||
return this.setOutput(output, 1);
|
||||
}
|
||||
|
||||
|
||||
public Builder setOutput(ItemConvertible 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;
|
||||
|
@ -237,19 +242,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;
|
||||
}
|
||||
|
@ -261,14 +266,15 @@ 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(Identifier id, JsonObject json) {
|
||||
public AnvilRecipe read(ResourceLocation id, JsonObject json) {
|
||||
Ingredient input = Ingredient.fromJson(json.get("input"));
|
||||
JsonObject result = JsonHelper.getObject(json, "result");
|
||||
ItemStack output = ItemUtil.fromJsonRecipe(result);
|
||||
|
@ -279,19 +285,19 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
int toolLevel = JsonHelper.getInt(json, "toolLevel", 1);
|
||||
int anvilLevel = JsonHelper.getInt(json, "anvilLevel", 1);
|
||||
int damage = JsonHelper.getInt(json, "damage", 1);
|
||||
|
||||
|
||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnvilRecipe read(Identifier id, PacketByteBuf packetBuffer) {
|
||||
public AnvilRecipe read(ResourceLocation id, PacketByteBuf packetBuffer) {
|
||||
Ingredient input = Ingredient.fromPacket(packetBuffer);
|
||||
ItemStack output = packetBuffer.readItemStack();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package ru.betterend.recipe.builders;
|
||||
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.BlastingRecipe;
|
||||
import net.minecraft.recipe.CampfireCookingRecipe;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.recipe.SmeltingRecipe;
|
||||
import net.minecraft.recipe.SmokingRecipe;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.item.ItemConvertible;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.BlastingRecipe;
|
||||
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
|
||||
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 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 ItemConvertible input;
|
||||
private ItemConvertible output;
|
||||
private boolean exist;
|
||||
|
@ -25,9 +25,10 @@ public class FurnaceRecipe {
|
|||
private int count;
|
||||
private int time;
|
||||
private float xp;
|
||||
|
||||
private FurnaceRecipe() {}
|
||||
|
||||
|
||||
private FurnaceRecipe() {
|
||||
}
|
||||
|
||||
public static FurnaceRecipe make(String name, ItemConvertible input, ItemConvertible output) {
|
||||
INSTANCE.name = name;
|
||||
INSTANCE.group = "";
|
||||
|
@ -36,64 +37,68 @@ 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) {
|
||||
Identifier id = BetterEnd.makeID(name);
|
||||
SmeltingRecipe recipe = new SmeltingRecipe(id, group, Ingredient.ofItems(input), new ItemStack(output, count), xp, time);
|
||||
ResourceLocation id = BetterEnd.makeID(name);
|
||||
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.ofItems(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.ofItems(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.ofItems(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ import java.util.Map;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemConvertible;
|
||||
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 ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
|
@ -23,10 +23,10 @@ import ru.betterend.util.RecipeHelper;
|
|||
|
||||
public class GridRecipe {
|
||||
private static final GridRecipe INSTANCE = new GridRecipe();
|
||||
|
||||
|
||||
private String name;
|
||||
private ItemConvertible output;
|
||||
|
||||
|
||||
private String group;
|
||||
private RecipeType<?> type;
|
||||
private boolean shaped;
|
||||
|
@ -34,22 +34,23 @@ 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, ItemConvertible 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;
|
||||
}
|
||||
|
||||
|
@ -57,65 +58,66 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemStack... value) {
|
||||
return addMaterial(key, Ingredient.ofStacks(Arrays.stream(value)));
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemConvertible... values) {
|
||||
for (ItemConvertible item: values) {
|
||||
for (ItemConvertible item : values) {
|
||||
exist &= RecipeHelper.exists(item);
|
||||
}
|
||||
return addMaterial(key, Ingredient.ofItems(values));
|
||||
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);
|
||||
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);
|
||||
Identifier id = BetterEnd.makeID(name);
|
||||
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);
|
||||
|
||||
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,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();
|
||||
|
|
|
@ -1,88 +1,91 @@
|
|||
package ru.betterend.recipe.builders;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.recipe.SmithingRecipe;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemConvertible;
|
||||
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 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;
|
||||
|
||||
|
||||
public static SmithingTableRecipe create(String name) {
|
||||
return create(BetterEnd.makeID(name));
|
||||
}
|
||||
|
||||
public static SmithingTableRecipe create(Identifier id) {
|
||||
|
||||
public static SmithingTableRecipe create(ResourceLocation id) {
|
||||
BUILDER.id = id;
|
||||
BUILDER.base = null;
|
||||
BUILDER.addition = null;
|
||||
BUILDER.result = null;
|
||||
BUILDER.alright = true;
|
||||
|
||||
|
||||
return BUILDER;
|
||||
}
|
||||
|
||||
private Identifier id;
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient base;
|
||||
private Ingredient addition;
|
||||
private ItemStack result;
|
||||
private boolean alright;
|
||||
|
||||
private SmithingTableRecipe() {}
|
||||
|
||||
|
||||
private SmithingTableRecipe() {
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setResult(ItemConvertible item) {
|
||||
return this.setResult(item, 1);
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setResult(ItemConvertible item, int count) {
|
||||
this.alright &= RecipeHelper.exists(item);
|
||||
this.result = new ItemStack(item, count);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setBase(ItemConvertible... items) {
|
||||
this.alright &= RecipeHelper.exists(items);
|
||||
this.base = Ingredient.ofItems(items);
|
||||
this.base = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setBase(Tag<Item> tag) {
|
||||
this.base = (Ingredient.fromTag(tag));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setAddition(ItemConvertible... items) {
|
||||
this.alright &= RecipeHelper.exists(items);
|
||||
this.addition = Ingredient.ofItems(items);
|
||||
this.addition = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SmithingTableRecipe setAddition(Tag<Item> tag) {
|
||||
this.addition = (Ingredient.fromTag(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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue