Skip to content

Commit

Permalink
Error handling for old LDLib tags
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg committed Sep 24, 2024
1 parent 8db3256 commit 201cbe9
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gregtechceu.gtceu.syncdata;

import com.gregtechceu.gtceu.GTCEu;

import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl;
import com.lowdragmc.lowdraglib.syncdata.payload.ObjectTypedPayload;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -29,6 +32,14 @@ public Tag serializeNBT() {

@Override
public void deserializeNBT(Tag tag) {
payload = FluidStack.loadFluidStackFromNBT((CompoundTag) tag);
try {
payload = FluidStack.loadFluidStackFromNBT((CompoundTag) tag);
} catch (ClassCastException exception) {
// LDLib FluidStack stores amount as Long tag, which will throw an error
// Loads from tag using LDLib FluidStack, then converts it to a Forge FluidStack
GTCEu.LOGGER.warn("Old FluidStack Tag Detected");
var stack = com.lowdragmc.lowdraglib.side.fluid.FluidStack.loadFromTag((CompoundTag) tag);
payload = FluidHelperImpl.toFluidStack(stack);
}
}
}

0 comments on commit 201cbe9

Please sign in to comment.