Skip to content

Commit 941137c

Browse files
committed
save transporter stacks size-agnostically
1 parent 854168a commit 941137c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/api/java/mekanism/api/SerializationConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private SerializationConstants() {
3535
public static final String INGREDIENT = "ingredient";
3636
public static final String INGREDIENTS = "ingredients";
3737
public static final String ITEM = "item";
38+
public static final String ITEM_OVERSIZED = "item_oversized";
3839
public static final String GAS = "gas";
3940
public static final String INFUSE_TYPE = "infuse_type";
4041
public static final String PIGMENT = "pigment";

src/main/java/mekanism/common/content/transporter/TransporterStack.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Set;
1010
import java.util.function.IntFunction;
1111
import mekanism.api.SerializationConstants;
12+
import mekanism.api.SerializerHelper;
1213
import mekanism.api.text.EnumColor;
1314
import mekanism.common.content.network.transmitter.LogisticalTransporterBase;
1415
import mekanism.common.content.transporter.TransporterPathfinder.Destination;
@@ -106,7 +107,7 @@ public void writeToUpdateTag(HolderLookup.Provider provider, LogisticalTransport
106107
updateTag.putLong(SerializationConstants.PREVIOUS, prev);
107108
}
108109
if (!itemStack.isEmpty()) {
109-
itemStack.save(provider, updateTag);
110+
updateTag.put(SerializationConstants.ITEM, SerializerHelper.saveOversized(provider, itemStack));
110111
}
111112
}
112113

@@ -124,7 +125,10 @@ public void readFromUpdateTag(HolderLookup.Provider provider, CompoundTag update
124125
NBTUtils.setLongIfPresent(updateTag, SerializationConstants.PREVIOUS, coord -> clientPrev = coord);
125126
NBTUtils.setBlockPosIfPresent(updateTag, SerializationConstants.PREVIOUS, coord -> clientPrev = coord.asLong());
126127

127-
itemStack = ItemStack.parseOptional(provider, updateTag);
128+
Tag itemTag = updateTag.get(SerializationConstants.ITEM);
129+
if (itemTag != null) {
130+
itemStack = SerializerHelper.parseOversized(provider, itemTag).orElse(ItemStack.EMPTY);
131+
}
128132
}
129133

130134
public void write(HolderLookup.Provider provider, CompoundTag nbtTags) {
@@ -145,7 +149,7 @@ public void write(HolderLookup.Provider provider, CompoundTag nbtTags) {
145149
NBTUtils.writeEnum(nbtTags, SerializationConstants.PATH_TYPE, pathType);
146150
}
147151
if (!itemStack.isEmpty()) {
148-
nbtTags.put(SerializationConstants.ITEM, itemStack.save(provider));
152+
nbtTags.put(SerializationConstants.ITEM_OVERSIZED, SerializerHelper.saveOversized(provider, itemStack));
149153
}
150154
}
151155

@@ -156,7 +160,9 @@ public void read(HolderLookup.Provider provider, CompoundTag nbtTags) {
156160
NBTUtils.setEnumIfPresent(nbtTags, SerializationConstants.IDLE_DIR, Direction::from3DDataValue, dir -> idleDir = dir);
157161
NBTUtils.setBlockPosIfPresent(nbtTags, SerializationConstants.HOME_LOCATION, coord -> homeLocation = coord);
158162
NBTUtils.setEnumIfPresent(nbtTags, SerializationConstants.PATH_TYPE, Path.BY_ID, type -> pathType = type);
159-
if (nbtTags.contains(SerializationConstants.ITEM, Tag.TAG_COMPOUND)) {
163+
if (nbtTags.contains(SerializationConstants.ITEM_OVERSIZED)) {
164+
itemStack = SerializerHelper.parseOversized(provider, nbtTags.get(SerializationConstants.ITEM_OVERSIZED)).orElse(ItemStack.EMPTY);
165+
} else if (nbtTags.contains(SerializationConstants.ITEM, Tag.TAG_COMPOUND)) {//TODO - 1.22: Remove this legacy way of loading data
160166
itemStack = ItemStack.parseOptional(provider, nbtTags.getCompound(SerializationConstants.ITEM));
161167
} else {//TODO - 1.22: Remove this legacy way of loading data
162168
itemStack = ItemStack.parseOptional(provider, nbtTags);

0 commit comments

Comments
 (0)