ryyanmapes / minecart-mod

An open-source Minecraft mod for 1.16.5 adding new options for rail networks.
https://www.curseforge.com/minecraft/mc-mods/more-minecarts
Other
14 stars 15 forks source link

Loading furnace minecart with fuel causes integer overflow in fuel counter #79

Closed PORTB closed 1 year ago

PORTB commented 2 years ago

Having a furnace minecart on some sort of loop that has a minecart loader filled with fuel will eventually make the minecart's fuel counter overflow and become negative. While this normally will 'fix' itself when the counter underflows again, it causes issues with create contraptions. This is what I used to trigger the bug image

The fuel counter overflowed after the minecart was reloaded. The fuel level has to be low enough to refuel but high enough to overflow so it took a few minutes. I used the /data command to show the fuel level of the minecart

Version: moreminecarts-1.5.3

ryyanmapes commented 2 years ago

Wow, an overflow bug in the wild? I'll look into this!

PORTB commented 2 years ago

Change

if (minecart.fuel + 3600 <= 32000) {

    for (ItemStack stack : items) {
        if (Ingredient.of(new ItemLike[]{Items.COAL, Items.CHARCOAL}).test(stack) && !(leave_one_in_stack && stack.getCount() == 1)) {
            stack.shrink(1);
            minecart.fuel += 3600;
            changed = true;

        }
    }
}

to something like

for(int stackIndex = 0; (minecart.fuel + 3600 <= 32000) && (stackIndex < items.size()); stackIndex++)
{
    ItemStack stack = items.get(stackIndex);

    if (Ingredient.of(new ItemLike[]{Items.COAL, Items.CHARCOAL}).test(stack) && !(leave_one_in_stack && stack.getCount() == 1)) {
        stack.shrink(1);
        minecart.fuel += 3600;
        changed = true;
    }
}

And similar for the locking rail loop above it. I didn't see your reply until just now

ryyanmapes commented 1 year ago

Sorry for the long response time. This has been fixed and included in the new version. Thank you so much for your help!