Scarpet Language broke Attribute's UUIDs
IceWolf23 opened this issue ยท 7 comments
Scarpet Language broke the item's AttributeModifiers UUID
If you get a item_tuple by inventory_get(); and try to enter the nbt to 'AttributeModifiers': it return null, so we have to do a parse_nbt before that, the parse_nbt turn the UUID from [I; 1234, 1234, 1234, 1234] to [1234, 1234, 1234, 1234] (it remove the I; part and broke the UUID) being the UUID a non-json syntax value, it's no way to define it correctly.
I propose to add a method like gen_uuid(); which will randomly generate a correct UUID value which can be used to replace the one previously broken by parse_nbt();
or fix the parse_nbt() "bug" which violates the UUID
i did not get what you want.
do you want to get the UUID of it?
you can use this:
/script run inventory_get(p,1):2:'AttributeModifiers[]':0:'UUID'
to get its uuid as a NBT Value.
if you want to use the 4 long int values in scarpet,
you can use parse_nbt or something like
/script run inventory_get(p,1):2:'AttributeModifiers[]':0:'UUID[]'
but as you have already find, it will change those nbt longs ints to scarpet number. which is difficult to change it back.
so do not use it unless necessary. i dont know what are you doing. maybe i could know some better solution if you tell me more about what are you doing.
if you want to create NBT IntArray,
use /script run nbt(str('[I;%s,%s,%s,%s]',[1,2,3,4]))
in a word, parse nbt does make irreversible information loss during conversion
do not use it. use some other ways.
in a word, parse nbt does make irreversible information loss during conversion do not use it. use some other ways.
My goal is to modify the value of an item's AttributeModifier
Assuming the nbt of the item is {AttributeModifiers:[{AttributeName:"generic.attack_damage",Name:"generic.attack_damage",Amount:1,Operation:0,UUID:[I;894611322,-359773006,-1643033169 ,-427522960]}]}
to be able to modify it what I'm doing is;
Get the item_tuple
to get the nbt
from
Attempting to reach item_tuple:2:'AttributeModifiers':0:'Amount'
(but it returns null
once it passes 'AttributeModifiers'
, so I'm forced to do a parse_nbt();
)
replace the value of 'Amount'
with the desired value
Do an inventory_set()
to the player who replaces the item by modifying the nbt by setting the new 'Amount'
value
I have just a question...
why print(item_tuple:2:'AttributeModifiers[]':0:'UUID');
actually return the UUID's value
but print(item_tuple:2:'AttributeModifiers':0:'UUID');
return Null
?
I have just a question...
why
print(item_tuple:2:'AttributeModifiers[]':0:'UUID');
actually return the UUID's valuebut
print(item_tuple:2:'AttributeModifiers':0:'UUID');
returnNull
?
u should keep in mind that those values has type.
item_tuple:2:'AttributeModifiers'
returns a NBT List Value,
but,
item_tuple:2:'AttributeModifiers[]'
returns a scarpet list. (it is to qurey the nbt value with the nbt path 'AttributeModifiers[]' , which returns all elements it get and make them into a list)
those object looks the same (both is warped in [] ), but nbt_list:0 will be view as nbtlist:'0', in which '0' is a nbtpath.
ofc it will return nothing but null. while scarpet_list:0 will just view 0 as the index and get it.
about your question, you should keep the datatype in nbt as much as you can.
for example:
a=inventory_get(p,1):2; //a is a nbt tag.
a:'AttributeModifiers[0].Amount'=nbt(30+'d'); //i know it is ugly, but to auto-convert a scarpet number in to nbt number is not relyable. you have to use this way to ensure the result nbt is double.
a //is changed.
it seems that scarpet`s NBT support is difficult to use. i did not say it is not use able, but it sure needs a lot of more things to do. Just read the answers to the questions above carefully, and you can see multiple pain points.
such as now parse_nbt
makes irreversible information loss during conversion. number type and number array type is lost. but UUID has to be a INT ARRAY.
and something like a:'Amount'=nbt(30+'d');
/ nbt(str('[I;%s,%s,%s,%s]',[1,2,3,4]))
above is really ugly and slow. it is really hard to create number nbt in certain number type.
I'm hoping someone can come up with a more fundamental solution.
=========
and i love wolves and cool ice XD
furry?