Integrated Dynamics

Integrated Dynamics

63M Downloads

Error with `NBT.from_tag_list` on `map`ed NBT list with empty object

met4000 opened this issue ยท 1 comments

commented

Issue type:

  • ๐Ÿ› Bug

Short description:

maping a list of items with itemNBT yields a list of NBT, with items that have no NBT having empty NBT (rather than an empty NBT object like {}).
This conversation is trying to provide the item NBT of an inventory to CC via a compat mod, and is trying to make an NBT list as the final output rather than a list of NBT.
Empty NBT elements seem to be removed when using NBT.from_tag_list (unknown if this is intended - expected behaviour would have been to have the empty NBT elements be present in the NBT list as well), which would be an issue as the entry for that item would then be missing from the CC side, so an operator that yields an empty NBT object for items that don't have NBT was made and used.
However, this new list of NBT causes NBT.from_tag_list to error.

Steps to reproduce the problem:

(see the expected behaviour section for a potentially simpler setup to reproduce the same error - they seem like they're caused by the same bug but I'm not sure so this reproduction section uses these steps because they were the original bug report)

  1. make a list of items, some with NBT and some without (e.g. book and quill vs blank variable card)
  2. map using itemNBT and then use NBT.from_tag_list on the list - should output and NBT list (see the top 2 display panels of the image below)
  3. map using the itemNBTorEmptyObject operator defined below and then use NBT.from_tag_list on the list - results in an error (see the bottom right 2 display panels of the image below, and the error message)
-- from the 'operators' tab
itemNBT
notNull
choice

emptyNBTObject :: NBT
emptyNBTObject = "{}"

temp1 = pipe(notNull, choice)
temp2 = pipe2(itemNBT, itemNBT, temp1)
temp3 = flip(temp2)

itemNBTorEmptyChoice = apply(temp3, emptyNBTObject)

image

image

Expected behaviour:

Step 3 does not error.

Note that using NBT.from_tag_list on the manually defined list of NBT [{}] produces the NBT list [{}] as expected, rather than an error.
However, making an Any list, appending "{}" :: NBT to it (giving [{}] like before, but with an Any list rather than an NBT list), and then using NBT.from_tag_list on it results in the same error as before instead of [{}] as expected.

image

Having a look at the source code, it seems like in

public static ListTag getListNbtTag(ValueTypeList.ValueList<?, ?> value, Component operatorName) {
ListTag list = new ListTag();
for (IValue valueNbt : value.getRawValue()) {
if (value.getRawValue().getValueType() != ValueTypes.NBT) {
MutableComponent error = Component.translatable(
L10NValues.OPERATOR_ERROR_WRONGTYPE,
operatorName,
Component.translatable(value.getType().getTranslationKey()),
1,
Component.translatable(ValueTypes.NBT.getTranslationKey()));
Helpers.sneakyThrow(new EvaluationException(error));
}
((ValueTypeNbt.ValueNbt) valueNbt).getRawValue().ifPresent(list::add);
}
return list;
}
on L160 (and L164) it's using value (which seems like it would be the list's value itself) rather than ever using valueNbt (which seems like it would be the value of a given element in the list) - I'm unsure if that's intended but it might be a cause of this behaviour.


Versions:

image

Log file:

N/A

commented

Thanks for reporting!