AztechMC / Modern-Industrialization

Modern industrial mod for Minecraft.
https://www.curseforge.com/minecraft/mc-mods/modern-industrialization
MIT License
155 stars 86 forks source link

Steam Drill rarely saves invalid nbt #825

Closed Swedz closed 3 months ago

Swedz commented 3 months ago

I had someone report a really odd bug with EI's chainsaw, and I believe its an issue with MI's drill as well. It's possible for the value of the water component in the steam tool to get set to 0 (see here), and the data component only allows 1 or higher (see here, POSITIVE_INT only allows 1 or higher). When this happens, the world becomes "corrupted" where it can't load anymore. This could be fixed by making the water component use NON_NEGATIVE_INT for its codec instead.

That, or you could do something like:

int water = stack.get(MIComponents.WATER);
if(water > 0)
{
    stack.set(MIComponents.WATER, water);
}
else
{
    stack.remove(MIComponents.WATER);
}

instead of using the stack.update(...) call. This is the solution I'm going with for EI's chainsaw just so I can push a fix out for it right now.

Technici4n commented 3 months ago

This is actually not a problem for MI because the steam drill has a default value of 0 for its WATER component. So that value will never get serialized. :smile:

See https://github.com/AztechMC/Modern-Industrialization/blob/32fa676c6ff88377974d10af5a5493c40db0b319/src/main/java/aztech/modern_industrialization/items/SteamDrillItem.java#L120