nbtlib icon indicating copy to clipboard operation
nbtlib copied to clipboard

nbtlib.Long can not set 64bytes value

Open xkcb1 opened this issue 2 years ago • 1 comments

a Long use 64 bytes cannot run ,error is "btlib.tag.OutOfRange: Long(14757395258967641292) is out of range"

xkcb1 avatar Aug 11 '23 08:08 xkcb1

A Long tag is a signed 64bit integer. The maximum allowed value is 9223372036854775807. Your value would fit in an unsigned 64bit integer. nbtlib has a from_unsigned helper for encoding unsigned integers into signed NBT tags

from nbtlib import Long
print(Long.from_unsigned(14757395258967641292))
Long(-3689348814741910324)

You do the opposite with as_unsigned

from nbtlib import Long
print(Long(-3689348814741910324).as_unsigned)
14757395258967641292

vberlier avatar Aug 11 '23 16:08 vberlier