Smelter recipe serialization fix
This commit is contained in:
parent
193717bf34
commit
74c6c14b2a
4 changed files with 168 additions and 44 deletions
Binary file not shown.
|
@ -1,18 +1,24 @@
|
||||||
package ru.betterend.recipe;
|
package ru.betterend.recipe;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemConvertible;
|
import net.minecraft.item.ItemConvertible;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.recipe.Ingredient;
|
import net.minecraft.recipe.Ingredient;
|
||||||
import net.minecraft.recipe.Recipe;
|
import net.minecraft.recipe.Recipe;
|
||||||
import net.minecraft.recipe.RecipeSerializer;
|
import net.minecraft.recipe.RecipeSerializer;
|
||||||
import net.minecraft.recipe.RecipeType;
|
import net.minecraft.recipe.RecipeType;
|
||||||
import net.minecraft.tag.Tag;
|
import net.minecraft.tag.Tag;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.JsonHelper;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
|
@ -21,7 +27,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
||||||
|
|
||||||
public final static String GROUP = "alloying";
|
public final static String GROUP = "alloying";
|
||||||
public final static RecipeType<AlloyingRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
public final static RecipeType<AlloyingRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
||||||
public final static AlloyingRecipeSerializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new AlloyingRecipeSerializer());
|
public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer());
|
||||||
|
|
||||||
protected final RecipeType<?> type;
|
protected final RecipeType<?> type;
|
||||||
protected final Identifier id;
|
protected final Identifier id;
|
||||||
|
@ -202,4 +208,45 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
||||||
EndRecipeManager.addRecipe(AlloyingRecipe.TYPE, new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime));
|
EndRecipeManager.addRecipe(AlloyingRecipe.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) {
|
||||||
|
JsonArray ingredients = JsonHelper.getArray(json, "ingredients");
|
||||||
|
Ingredient primaryInput = Ingredient.fromJson(ingredients.get(0));
|
||||||
|
Ingredient secondaryInput = Ingredient.fromJson(ingredients.get(1));
|
||||||
|
String resultStr = JsonHelper.getString(json, "result");
|
||||||
|
String group = JsonHelper.getString(json, "group", "");
|
||||||
|
Identifier resultId = new Identifier(resultStr);
|
||||||
|
ItemStack output = new ItemStack(Registry.ITEM.getOrEmpty(resultId).orElseThrow(() -> {
|
||||||
|
return new IllegalStateException("Item: " + resultStr + " does not exists!");
|
||||||
|
}));
|
||||||
|
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) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(PacketByteBuf packetBuffer, AlloyingRecipe recipe) {
|
||||||
|
packetBuffer.writeString(recipe.group);
|
||||||
|
recipe.primaryInput.write(packetBuffer);
|
||||||
|
recipe.secondaryInput.write(packetBuffer);
|
||||||
|
packetBuffer.writeItemStack(recipe.output);
|
||||||
|
packetBuffer.writeFloat(recipe.experience);
|
||||||
|
packetBuffer.writeVarInt(recipe.smeltTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
package ru.betterend.recipe;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.recipe.Ingredient;
|
|
||||||
import net.minecraft.recipe.RecipeSerializer;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.JsonHelper;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
|
|
||||||
public class AlloyingRecipeSerializer implements RecipeSerializer<AlloyingRecipe> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AlloyingRecipe read(Identifier id, JsonObject json) {
|
|
||||||
JsonArray ingredients = JsonHelper.getArray(json, "ingredients");
|
|
||||||
Ingredient primaryInput = Ingredient.fromJson(ingredients.get(0));
|
|
||||||
Ingredient secondaryInput = Ingredient.fromJson(ingredients.get(1));
|
|
||||||
String resultStr = JsonHelper.getString(json, "result");
|
|
||||||
String group = JsonHelper.getString(json, "group", "");
|
|
||||||
Identifier resultId = new Identifier(resultStr);
|
|
||||||
ItemStack output = new ItemStack(Registry.ITEM.getOrEmpty(resultId).orElseThrow(() -> {
|
|
||||||
return new IllegalStateException("Item: " + resultStr + " does not exists!");
|
|
||||||
}));
|
|
||||||
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) {
|
|
||||||
Identifier recipeId = packetBuffer.readIdentifier();
|
|
||||||
return EndRecipeManager.getRecipe(AlloyingRecipe.TYPE, recipeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(PacketByteBuf packetBuffer, AlloyingRecipe recipe) {
|
|
||||||
packetBuffer.writeIdentifier(recipe.id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,9 +5,39 @@ import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
|
import ru.betterend.registry.ItemRegistry;
|
||||||
|
|
||||||
public class CraftingRecipes {
|
public class CraftingRecipes {
|
||||||
|
private static String[] helmet_recipe = new String[] {
|
||||||
|
"III", "I I"
|
||||||
|
};
|
||||||
|
private static String[] chestplate_recipe = new String[] {
|
||||||
|
"I I", "III", "III"
|
||||||
|
};
|
||||||
|
private static String[] leggings_recipe = new String[] {
|
||||||
|
"III", "I I", "I I"
|
||||||
|
};
|
||||||
|
private static String[] boots_recipe = new String[] {
|
||||||
|
"I I", "I I"
|
||||||
|
};
|
||||||
|
private static String[] shovel_recipe = new String[] {
|
||||||
|
"I", "#", "#"
|
||||||
|
};
|
||||||
|
private static String[] sword_recipe = new String[] {
|
||||||
|
"I", "I", "#"
|
||||||
|
};
|
||||||
|
private static String[] pickaxe_recipe = new String[] {
|
||||||
|
"III", " # ", " # "
|
||||||
|
};
|
||||||
|
private static String[] axe_recipe = new String[] {
|
||||||
|
"II", "#I", "# "
|
||||||
|
};
|
||||||
|
private static String[] hoe_recipe = new String[] {
|
||||||
|
"II", "# ", "# "
|
||||||
|
};
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
if (blockExists(BlockRegistry.ENDER_BLOCK)) {
|
if (blockExists(BlockRegistry.ENDER_BLOCK)) {
|
||||||
RecipeBuilder.make("ender_pearl_to_block", BlockRegistry.ENDER_BLOCK)
|
RecipeBuilder.make("ender_pearl_to_block", BlockRegistry.ENDER_BLOCK)
|
||||||
|
@ -28,6 +58,96 @@ public class CraftingRecipes {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (itemExists(ItemRegistry.TERMINITE_INGOT)) {
|
||||||
|
registerHelmet("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HELMET);
|
||||||
|
registerChestplate("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_CHESTPLATE);
|
||||||
|
registerLeggings("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_LEGGINGS);
|
||||||
|
registerBoots("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_BOOTS);
|
||||||
|
registerShovel("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SHOVEL);
|
||||||
|
registerSword("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SWORD);
|
||||||
|
registerPickaxe("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_PICKAXE);
|
||||||
|
registerAxe("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_AXE);
|
||||||
|
registerHoe("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HOE);
|
||||||
|
}
|
||||||
|
if (itemExists(ItemRegistry.AETERNIUM_INGOT)) {
|
||||||
|
registerHelmet("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HELMET);
|
||||||
|
registerChestplate("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_CHESTPLATE);
|
||||||
|
registerLeggings("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_LEGGINGS);
|
||||||
|
registerBoots("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_BOOTS);
|
||||||
|
registerShovel("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SHOVEL);
|
||||||
|
registerSword("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SWORD);
|
||||||
|
registerPickaxe("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_PICKAXE);
|
||||||
|
registerAxe("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_AXE);
|
||||||
|
registerHoe("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HOE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerHelmet(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_helmet", result)
|
||||||
|
.setShape(helmet_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerChestplate(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_chestplate", result)
|
||||||
|
.setShape(chestplate_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerLeggings(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_leggings", result)
|
||||||
|
.setShape(leggings_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerBoots(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_boots", result)
|
||||||
|
.setShape(boots_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerShovel(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_shovel", result)
|
||||||
|
.setShape(shovel_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.addMaterial('#', Items.STICK)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerSword(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_sword", result)
|
||||||
|
.setShape(sword_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.addMaterial('#', Items.STICK)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerPickaxe(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_pickaxe", result)
|
||||||
|
.setShape(pickaxe_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.addMaterial('#', Items.STICK)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerAxe(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_axe", result)
|
||||||
|
.setShape(axe_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.addMaterial('#', Items.STICK)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerHoe(String name, Item material, Item result) {
|
||||||
|
RecipeBuilder.make(name + "_hoe", result)
|
||||||
|
.setShape(hoe_recipe)
|
||||||
|
.addMaterial('I', material)
|
||||||
|
.addMaterial('#', Items.STICK)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean itemExists(Item item) {
|
protected static boolean itemExists(Item item) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue