Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Legacy Filter NBT Reading #2570

Merged
merged 6 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this converting the legacy tag into the new format? If so, should IsBlacklist be removed from the tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, since "IsBlacklist" is written to a different place in the tag, this should only run once. i could remove the tag, but i don't see how that's useful.

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")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"FilterInventory" only exists when the cover used a FilterContainer (pumps, conveyors, etc). Filters as a cover only used the FilterWrapper, which does not have "FilterInventory" written to the tag. with the filter rework, "FilterInventory" is always written.

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