Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
made certain tiles save recipes to nbt using the toJson methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Sep 1, 2024
1 parent f5c5d41 commit 3fa639a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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;
import muramasa.antimatter.capability.machine.MachineRecipeHandler;
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;
Expand Down Expand Up @@ -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")));
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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;
import muramasa.antimatter.capability.machine.MachineRecipeHandler;
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;
import muramasa.gregtech.GTIRef;
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;
Expand Down Expand Up @@ -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")));
}
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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")));
}
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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")));
}
}
});
}

Expand Down

0 comments on commit 3fa639a

Please sign in to comment.