Skip to content

refactor Drums,#55

Draft
Spicierspace153 wants to merge 21 commits intomasterfrom
kath/fix-drums
Draft

refactor Drums,#55
Spicierspace153 wants to merge 21 commits intomasterfrom
kath/fix-drums

Conversation

@Spicierspace153
Copy link
Collaborator

Drums w/ buckets now work as intended in every single way

Copy link
Member

@chrombread chrombread left a comment

Choose a reason for hiding this comment

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

quick suggestion

@danyadev
Copy link
Member

danyadev commented Nov 8, 2025

Love the IFluidContainerItem support, but... I tried to fill a drum while holding a stack of Certus Quartz Tanks with 16000L water and they all just gone

tank.-.drum.mp4

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

#56

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

#57

@github-actions
Copy link
Contributor

#99

Copy link
Contributor

@SuperSoupr SuperSoupr left a comment

Choose a reason for hiding this comment

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

Mostly nits but some fixes needed as well, otherwise LGTM 👍

@github-actions
Copy link
Contributor

#102

FourIsTheNumber pushed a commit that referenced this pull request Dec 15, 2025
Co-authored-by: GitHub GTNH Actions <>
Comment on lines 8 to 14
public class DrumConfig {

@Config.DefaultBoolean(true)
@Config.Comment("Change it to MB vs L's")
public static boolean unitToDisplay;

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't think of this before but can you add a config for the size of the regular and bedrockium drums?

@github-actions
Copy link
Contributor

#103

Comment on lines +74 to +78
player.addChatComponentMessage(
new ChatComponentTranslation(
"%s %s",
NumberFormat.DEFAULT.format(drumTank.getFluidAmount()),
DrumConfig.unitToDisplay ? "mB" : "L"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ChatComponentTranslation? you aren't giving it a translation key...
either make it a translation key or replace with ChatComponentText

also the formatter puts a q after the number if it's 0 for some reaons
Image

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how to fix this, but there is a desync between the client and server here. The client doesn't get told how full the drum is when it's loaded. Not sure of how impactful this is but the onBlockActivated logic is wrong on the client because of it

@GTNewHorizons GTNewHorizons deleted a comment from SuperSoupr Dec 15, 2025
@@ -51,50 +55,205 @@ public boolean hasTileEntity(int metadata) {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX,
Copy link

Choose a reason for hiding this comment

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

This method is HUGE and should be divided into smaller parts.
Here is how I would refactor the current code to improve readability (logic kept the same):

@Override
public boolean onBlockActivated(
    World world, int x, int y, int z,
    EntityPlayer player, int side,
    float hitX, float hitY, float hitZ
) {
    TileEntity te = world.getTileEntity(x, y, z);
    if (!(te instanceof TileEntityDrum drum)) {
        return false;
    }

    FluidTank tank = drum.tank;
    FluidStack fluid = tank.getFluid();
    ItemStack held = player.inventory.getCurrentItem();

    if (held == null) {
        return handleEmptyHand(world, player, tank);
    }

    Item item = held.getItem();

    return fluid == null
        ? handleEmptyDrum(world, x, y, z, player, tank, held, item)
        : handleFilledDrum(world, x, y, z, player, tank, fluid, held, item);
}

private boolean handleEmptyHand(World world, EntityPlayer player, FluidTank tank) {
    if (world.isRemote) {
        return false;
    }

    player.addChatComponentMessage(
        new ChatComponentTranslation(
            "%s %s",
            NumberFormat.DEFAULT.format(tank.getFluidAmount()),
            DrumConfig.unitToDisplay ? "mB" : "L"
        )
    );
    return true;
}

private boolean handleEmptyDrum(
    World world, int x, int y, int z,
    EntityPlayer player,
    FluidTank tank,
    ItemStack stack,
    Item item
) {
    if (item instanceof IFluidContainerItem container) {
        return fillDrumFromContainer(world, x, y, z, player, tank, stack, container);
    }

    if (item instanceof ItemBucket) {
        return fillDrumFromBucket(world, x, y, z, player, tank, stack);
    }

    return true;
}

private boolean fillDrumFromContainer(
    World world, int x, int y, int z,
    EntityPlayer player,
    FluidTank tank,
    ItemStack stack,
    IFluidContainerItem container
) {
    FluidStack fluid = container.getFluid(stack);
    if (fluid == null) {
        return true;
    }

    int fillAmount = Math.min(tank.getCapacity(), fluid.amount);
    FluidStack toFill = fluid.copy();
    toFill.amount = fillAmount;

    int filled = tank.fill(toFill, true);
    container.drain(stack, filled, true);

    if (!world.isRemote) {
        player.addChatComponentMessage(
            new ChatComponentTranslation(
                "message.drum.filled",
                filled,
                fluid.getLocalizedName()
            )
        );
    }

    world.markBlockForUpdate(x, y, z);
    return true;
}

private boolean fillDrumFromBucket(
    World world, int x, int y, int z,
    EntityPlayer player,
    FluidTank tank,
    ItemStack stack
) {
    FluidStack bucketFluid = FluidContainerRegistry.getFluidForFilledItem(stack);
    if (bucketFluid == null) {
        return false;
    }

    int filled = tank.fill(bucketFluid.copy(), true);
    if (filled <= 0) {
        return false;
    }

    if (!world.isRemote) {
        consumeItemStack(player, stack, new ItemStack(Items.bucket));
        player.addChatComponentMessage(
            new ChatComponentTranslation(
                "message.drum.filled",
                filled,
                bucketFluid.getLocalizedName()
            )
        );
    }

    world.markBlockForUpdate(x, y, z);
    return true;
}

private boolean handleFilledDrum(
    World world, int x, int y, int z,
    EntityPlayer player,
    FluidTank tank,
    FluidStack fluid,
    ItemStack stack,
    Item item
) {
    if (item instanceof IFluidContainerItem container) {
        return drainDrumIntoContainer(world, x, y, z, player, tank, fluid, stack, container);
    }

    if (item instanceof ItemBucket) {
        return handleBucketDrain(world, x, y, z, player, tank, fluid, stack);
    }

    return true;
}

return true;
}

private static void consumeItemStack(EntityPlayer player, ItemStack hand, ItemStack result) {
Copy link

Choose a reason for hiding this comment

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

nesting could be reduced here

private static void consumeItemStack(
    EntityPlayer player,
    ItemStack hand,
    ItemStack result
) {
    InventoryPlayer inv = player.inventory;

    if (hand.stackSize == 1) {
        inv.setInventorySlotContents(inv.currentItem, result);
        finalizeInventoryChange(player);
        return;
    }

    hand.stackSize--;

    if (!inv.addItemStackToInventory(result)) {
        player.dropPlayerItemWithRandomChoice(result, false);
    }

    finalizeInventoryChange(player);
}

private static void finalizeInventoryChange(EntityPlayer player) {
    player.inventoryContainer.detectAndSendChanges();
    player.inventory.markDirty();
}

@FourIsTheNumber FourIsTheNumber marked this pull request as draft February 15, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments