Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with NBT.from_tag_list on maped NBT list with empty object #1315

Closed
met4000 opened this issue Nov 7, 2023 · 1 comment
Closed

Error with NBT.from_tag_list on maped NBT list with empty object #1315

met4000 opened this issue Nov 7, 2023 · 1 comment
Labels

Comments

@met4000
Copy link
Contributor

met4000 commented Nov 7, 2023

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

@rubensworks rubensworks added the bug label Nov 7, 2023
@rubensworks
Copy link
Member

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

2 participants