Fixed an edge case when working with varbits that encapsulate the 31st bit of a varp

Fixed health check of whiteberry bush
This commit is contained in:
Ceikry 2023-06-16 07:04:20 +00:00 committed by Ryan
parent d04302c99f
commit aab37414c3
2 changed files with 4 additions and 4 deletions

View file

@ -1012,7 +1012,7 @@ fun getVarp (player: Player, varpIndex: Int) : Int {
fun getVarbit (player: Player, def: VarbitDefinition) : Int {
val mask = def.mask
val current = getVarp (player, def.varpId)
return (current and mask) shr def.startBit
return (current shr def.startBit) and mask
}
fun getVarbit (player: Player, varbitId: Int) : Int {
@ -1030,8 +1030,8 @@ fun setVarp (player: Player, varpIndex: Int, value: Int, save: Boolean = false)
@JvmOverloads
fun setVarbit (player: Player, def: VarbitDefinition, value: Int, save: Boolean = false) {
val mask = def.mask
val current = getVarp (player, def.varpId) and mask.inv()
val newValue = (value shl def.startBit) and mask
val current = getVarp (player, def.varpId) and (mask shl def.startBit).inv()
val newValue = (value and mask) shl def.startBit
setVarp (player, def.varpId, current or newValue, save)
}

View file

@ -162,7 +162,7 @@ public final class VarbitDefinition {
public int getMask() {
int mask = 0;
for (int i = startBit; i <= endBit; i++)
mask |= (1 << i);
mask |= (1 << (i - startBit));
return mask;
}