Skip to content

Commit

Permalink
Fix Legacy Filter NBT Reading (GregTechCEu#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored Aug 11, 2024
1 parent 7ca48a9 commit 9fde08c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/main/java/gregtech/common/covers/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,12 @@ public void readFromNBT(@NotNull NBTTagCompound tagCompound) {
this.distributionMode = DistributionMode.VALUES[tagCompound.getInteger("DistributionMode")];
this.isWorkingAllowed = tagCompound.getBoolean("WorkingAllowed");
this.manualImportExportMode = ManualImportExportMode.VALUES[tagCompound.getInteger("ManualImportExportMode")];
this.itemFilterContainer.deserializeNBT(tagCompound.getCompoundTag("Filter"));
this.itemFilterContainer.handleLegacyNBT(tagCompound.getCompoundTag("Filter"));
var filterTag = tagCompound.getCompoundTag("Filter");
if (filterTag.hasKey("IsBlacklist")) {
this.itemFilterContainer.handleLegacyNBT(filterTag);
} else {
this.itemFilterContainer.deserializeNBT(filterTag);
}
}

@Override
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/gregtech/common/covers/CoverFluidFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,13 @@ public void writeToNBT(@NotNull NBTTagCompound tagCompound) {
public void readFromNBT(@NotNull NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
this.filterMode = FluidFilterMode.values()[tagCompound.getInteger("FilterMode")];
var filterTag = tagCompound.getCompoundTag("Filter");
if (!filterTag.hasKey("FilterInventory")) {
if (tagCompound.hasKey("IsBlacklist")) {
this.fluidFilterContainer.setFilterStack(getDefinition().getDropItemStack());
this.fluidFilterContainer.handleLegacyNBT(tagCompound);
this.fluidFilterContainer.setBlacklistFilter(tagCompound.getBoolean("IsBlacklist"));
} else {
this.fluidFilterContainer.deserializeNBT(filterTag);
this.fluidFilterContainer.deserializeNBT(tagCompound.getCompoundTag("Filter"));
}

this.fluidFilterContainer.handleLegacyNBT(tagCompound);
}

private class FluidHandlerFiltered extends FluidHandlerDelegate {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtech/common/covers/CoverItemFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ public void writeToNBT(@NotNull NBTTagCompound tagCompound) {
public void readFromNBT(@NotNull NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
this.filterMode = ItemFilterMode.VALUES[tagCompound.getInteger("FilterMode")];
var filterTag = tagCompound.getCompoundTag("Filter");
if (!filterTag.hasKey("FilterInventory")) {
if (tagCompound.hasKey("IsBlacklist")) {
this.itemFilterContainer.setFilterStack(getDefinition().getDropItemStack());
this.itemFilterContainer.handleLegacyNBT(tagCompound);
this.itemFilterContainer.setBlacklistFilter(tagCompound.getBoolean("IsBlacklist"));
} else {
this.itemFilterContainer.deserializeNBT(filterTag);
this.itemFilterContainer.deserializeNBT(tagCompound.getCompoundTag("Filter"));
}
this.itemFilterContainer.handleLegacyNBT(tagCompound);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/gregtech/common/covers/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,11 @@ public void readFromNBT(@NotNull NBTTagCompound tagCompound) {
this.isWorkingAllowed = tagCompound.getBoolean("WorkingAllowed");
this.manualImportExportMode = ManualImportExportMode.VALUES[tagCompound.getInteger("ManualImportExportMode")];
this.bucketMode = BucketMode.VALUES[tagCompound.getInteger("BucketMode")];
this.fluidFilterContainer.deserializeNBT(tagCompound.getCompoundTag("Filter"));
this.fluidFilterContainer.handleLegacyNBT(tagCompound);
var filterTag = tagCompound.getCompoundTag("Filter");
if (filterTag.hasKey("IsBlacklist"))
this.fluidFilterContainer.handleLegacyNBT(filterTag);
else
this.fluidFilterContainer.deserializeNBT(filterTag);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public void setTransferSize(int transferSize) {
public NBTTagCompound serializeNBT() {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setTag("FilterInventory", super.serializeNBT());
// tagCompound.setInteger("MaxStackSize", getMaxTransferSize());
tagCompound.setInteger("TransferStackSize", getTransferSize());
return tagCompound;
}
Expand All @@ -201,9 +200,15 @@ public void deserializeNBT(NBTTagCompound nbt) {
}

public void handleLegacyNBT(NBTTagCompound nbt) {
if (hasFilter()) {
getFilter().getFilterReader().handleLegacyNBT(nbt);
// for filters as covers, the stack is set manually, and "FilterInventory" doesn't exist to be deserialized
// also, ItemStackHandler's deserialization doesn't use setStackInSlot, so I have to do that manually here
if (nbt.hasKey("FilterInventory")) {
super.deserializeNBT(nbt.getCompoundTag("FilterInventory"));
setFilter(BaseFilter.getFilterFromStack(getFilterStack()));
}

if (hasFilter())
getFilter().getFilterReader().handleLegacyNBT(nbt);
}

/** Uses Cleanroom MUI */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void setStackInSlot(int slot, ItemStack stack) {
}
NBTTagList list = getInventoryNbt();
list.set(slot, stack.isEmpty() ? new NBTTagCompound() : stack.serializeNBT());
markDirty();
}
}

Expand Down

0 comments on commit 9fde08c

Please sign in to comment.