From 3fa639a21587f0c194b76a2cdabddae90437e730 Mon Sep 17 00:00:00 2001 From: trinsdar <30245301+Trinsdar@users.noreply.github.com> Date: Sun, 1 Sep 2024 11:07:18 -0400 Subject: [PATCH] made certain tiles save recipes to nbt using the toJson methods --- AntimatterAPI | 2 +- .../single/BlockEntityAssembler.java | 28 +++++++++++++++++++ .../blockentity/single/BlockEntityBath.java | 28 +++++++++++++++++++ .../single/BlockEntityPrinter.java | 25 +++++++++++++++++ .../single/BlockEntityScanner.java | 27 ++++++++++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) diff --git a/AntimatterAPI b/AntimatterAPI index 6673bab16..8db460bc0 160000 --- a/AntimatterAPI +++ b/AntimatterAPI @@ -1 +1 @@ -Subproject commit 6673bab16ed204424e22a74a4f890be92a6e1448 +Subproject commit 8db460bc01400a584d5a1b5c8c6660e5f048464c diff --git a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityAssembler.java b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityAssembler.java index 2108a76d1..a4505aeee 100644 --- a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityAssembler.java +++ b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityAssembler.java @@ -1,5 +1,7 @@ package muramasa.gregtech.blockentity.single; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import earth.terrarium.botarium.common.fluid.base.FluidHolder; import earth.terrarium.botarium.common.fluid.utils.FluidHooks; import muramasa.antimatter.blockentity.BlockEntityMachine; @@ -7,9 +9,12 @@ import muramasa.antimatter.machine.types.Machine; import muramasa.antimatter.recipe.IRecipe; import muramasa.antimatter.recipe.ingredient.RecipeIngredient; +import muramasa.antimatter.recipe.serializer.AntimatterRecipeSerializer; import muramasa.gregtech.data.GregTechItems; import muramasa.gregtech.data.RecipeMaps; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.state.BlockState; @@ -53,6 +58,29 @@ public IRecipe findRecipe() { public boolean accepts(ItemStack stack) { return super.accepts(stack) || stack.getItem() == GregTechItems.PrintedPages; } + + @Override + public CompoundTag serialize() { + CompoundTag nbt = super.serialize(); + if (activeRecipe != null) { + nbt.putString("activeRecipe", activeRecipe.toJson().toString()); + } + if (lastRecipe != null) { + nbt.putString("lastRecipe", lastRecipe.toJson().toString()); + } + return nbt; + } + + @Override + public void deserialize(CompoundTag nbt) { + super.deserialize(nbt); + if (nbt.contains("activeRecipe")) { + activeRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("AR")), (JsonObject) JsonParser.parseString(nbt.getString("activeRecipe"))); + } + if (nbt.contains("lastRecipe")) { + lastRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("LR")), (JsonObject) JsonParser.parseString(nbt.getString("lastRecipe"))); + } + } }); } } diff --git a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityBath.java b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityBath.java index d00205ce7..433c15c73 100644 --- a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityBath.java +++ b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityBath.java @@ -1,5 +1,8 @@ package muramasa.gregtech.blockentity.single; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import earth.terrarium.botarium.common.fluid.base.FluidHolder; import earth.terrarium.botarium.common.fluid.utils.FluidHooks; import muramasa.antimatter.blockentity.BlockEntityMachine; @@ -7,6 +10,7 @@ import muramasa.antimatter.machine.types.Machine; import muramasa.antimatter.recipe.IRecipe; import muramasa.antimatter.recipe.ingredient.RecipeIngredient; +import muramasa.antimatter.recipe.serializer.AntimatterRecipeSerializer; import muramasa.antimatter.util.AntimatterPlatformUtils; import muramasa.antimatter.util.TagUtils; import muramasa.antimatter.util.Utils; @@ -14,6 +18,7 @@ import muramasa.gregtech.data.GregTechItems; import muramasa.gregtech.data.RecipeMaps; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; @@ -63,6 +68,29 @@ public boolean accepts(ItemStack stack) { ResourceLocation id = AntimatterPlatformUtils.getIdFromItem(stack.getItem()); return super.accepts(stack) || (id.getPath().contains("shulker_box") && id.getNamespace().equals("minecraft")); } + + @Override + public CompoundTag serialize() { + CompoundTag nbt = super.serialize(); + if (activeRecipe != null) { + nbt.putString("activeRecipe", activeRecipe.toJson().toString()); + } + if (lastRecipe != null) { + nbt.putString("lastRecipe", lastRecipe.toJson().toString()); + } + return nbt; + } + + @Override + public void deserialize(CompoundTag nbt) { + super.deserialize(nbt); + if (nbt.contains("activeRecipe")) { + activeRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("AR")), (JsonObject) JsonParser.parseString(nbt.getString("activeRecipe"))); + } + if (nbt.contains("lastRecipe")) { + lastRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("LR")), (JsonObject) JsonParser.parseString(nbt.getString("lastRecipe"))); + } + } }); } diff --git a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityPrinter.java b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityPrinter.java index 1faa44cd9..879ae5fb0 100644 --- a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityPrinter.java +++ b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityPrinter.java @@ -1,5 +1,7 @@ package muramasa.gregtech.blockentity.single; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import earth.terrarium.botarium.common.fluid.base.FluidHolder; import earth.terrarium.botarium.common.fluid.utils.FluidHooks; import muramasa.antimatter.blockentity.BlockEntityMachine; @@ -12,6 +14,7 @@ import muramasa.antimatter.material.Material; import muramasa.antimatter.recipe.IRecipe; import muramasa.antimatter.recipe.ingredient.RecipeIngredient; +import muramasa.antimatter.recipe.serializer.AntimatterRecipeSerializer; import muramasa.antimatter.util.AntimatterPlatformUtils; import muramasa.antimatter.util.Utils; import muramasa.gregtech.data.GregTechItems; @@ -124,6 +127,28 @@ public void onMachineEvent(IMachineEvent event, Object... data) { } super.onMachineEvent(event, data); } + @Override + public CompoundTag serialize() { + CompoundTag nbt = super.serialize(); + if (activeRecipe != null) { + nbt.putString("activeRecipe", activeRecipe.toJson().toString()); + } + if (lastRecipe != null) { + nbt.putString("lastRecipe", lastRecipe.toJson().toString()); + } + return nbt; + } + + @Override + public void deserialize(CompoundTag nbt) { + super.deserialize(nbt); + if (nbt.contains("activeRecipe")) { + activeRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("AR")), (JsonObject) JsonParser.parseString(nbt.getString("activeRecipe"))); + } + if (nbt.contains("lastRecipe")) { + lastRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("LR")), (JsonObject) JsonParser.parseString(nbt.getString("lastRecipe"))); + } + } }); } diff --git a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityScanner.java b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityScanner.java index ec9f2effb..c981a6334 100644 --- a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityScanner.java +++ b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityScanner.java @@ -1,5 +1,7 @@ package muramasa.gregtech.blockentity.single; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import io.github.gregtechintergalactical.gtcore.data.GTCoreItems; import muramasa.antimatter.blockentity.BlockEntityMachine; import muramasa.antimatter.capability.IFilterableHandler; @@ -9,10 +11,12 @@ import muramasa.antimatter.machine.types.Machine; import muramasa.antimatter.recipe.IRecipe; import muramasa.antimatter.recipe.ingredient.RecipeIngredient; +import muramasa.antimatter.recipe.serializer.AntimatterRecipeSerializer; import muramasa.gregtech.data.GregTechItems; import muramasa.gregtech.data.RecipeMaps; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.state.BlockState; @@ -52,6 +56,29 @@ public IRecipe findRecipe() { public boolean accepts(ItemStack stack) { return super.accepts(stack) || stack.getItem() == GregTechItems.DataStick || stack.getItem() == Items.WRITTEN_BOOK; } + + @Override + public CompoundTag serialize() { + CompoundTag nbt = super.serialize(); + if (activeRecipe != null) { + nbt.putString("activeRecipe", activeRecipe.toJson().toString()); + } + if (lastRecipe != null) { + nbt.putString("lastRecipe", lastRecipe.toJson().toString()); + } + return nbt; + } + + @Override + public void deserialize(CompoundTag nbt) { + super.deserialize(nbt); + if (nbt.contains("activeRecipe")) { + activeRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("AR")), (JsonObject) JsonParser.parseString(nbt.getString("activeRecipe"))); + } + if (nbt.contains("lastRecipe")) { + lastRecipe = AntimatterRecipeSerializer.INSTANCE.fromJson(new ResourceLocation(nbt.getString("LR")), (JsonObject) JsonParser.parseString(nbt.getString("lastRecipe"))); + } + } }); }