baritone icon indicating copy to clipboard operation
baritone copied to clipboard

Calculate item hash only if needed

Open ZacSharp opened this issue 9 months ago • 0 comments

Fixes a stackoverflow with SilentGear. The problem is that SilentGear has a complicated parts system and to get the damage value of an ItemStack it first constructs the relevant PartInstance, which involves defensively copying the ItemStack before storing it in the new PartInstance. Copying an ItemStack of course triggers our hash calculation in the constructor run for the copy, we query the damage value of the new stack, and the cycle repeats.

With this change we only calculate the hash once we actually need it (and if the hash happens to be 0 we do so every time it is needed). An alternative would be to try copying the hash from the old stack to the new one, though given the Mixin hackery this would require I'm not sure whether that would actually be better. (Need to redirect the relevant constructor call and probably also need a ThreadLocal to pass the hash)

Fixes #4538 Fixes #4863

ZacSharp avatar Mar 25 '25 00:03 ZacSharp