Skip to content

Conversation

@MCTian-mi
Copy link
Contributor

@MCTian-mi MCTian-mi commented Nov 23, 2025

What

The implementation of GTFluidHandlerItemStack clears the entire tag compound when fluids are drained:

private void removeTagWhenEmpty(boolean doDrain) {
if (doDrain && this.getFluid() == null) {
this.container.setTagCompound(null);
}
}

This causes other NBT datas to be purged together, e.g. the lockedFluid for quantum tanks. (btw the locked fluid don't work for item stacks)

Implementation Details

The removeTagWhenEmpty method is removed completely, since Forge handles fluid nbt clearing itself alr in FluidHandlerItemStack#setContainerToEmpty:

/**
 * Override this method for special handling.
 * Can be used to swap out or destroy the container.
 */
protected void setContainerToEmpty() {
    container.getTagCompound().removeTag(FLUID_NBT_KEY);
}

This clears only the NBT tag about the fluid contained within. An extra check was added to remove the NBT when empty:

@Override
protected void setContainerToEmpty() {
    super.setContainerToEmpty();
    var tag = container.getTagCompound();
    if (tag != null && tag.isEmpty()) {
        container.setTagCompound(null);
    }
}

@MCTian-mi MCTian-mi requested a review from a team as a code owner November 23, 2025 07:07
@MCTian-mi MCTian-mi force-pushed the GTFluidHandlerIS-nbt-clearing branch from 5a5c9fa to c5edec4 Compare November 23, 2025 08:16
@MCTian-mi MCTian-mi force-pushed the GTFluidHandlerIS-nbt-clearing branch from c5edec4 to ac63075 Compare November 23, 2025 09:46
@Zorbatron Zorbatron added the type: refactor Suggestion to refactor a section of code label Nov 23, 2025
@MCTian-mi MCTian-mi force-pushed the GTFluidHandlerIS-nbt-clearing branch from accfbfa to ac63075 Compare November 24, 2025 03:29
@ALongStringOfNumbers ALongStringOfNumbers merged commit 3aa6f76 into GregTechCEu:master Dec 1, 2025
6 of 7 checks passed
@MCTian-mi MCTian-mi deleted the GTFluidHandlerIS-nbt-clearing branch December 2, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: refactor Suggestion to refactor a section of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants