Skip to content

Commit 9d7ad32

Browse files
committed
Fix null object values not being skipped to NBT, Closes #22
1 parent 8a0c3e2 commit 9d7ad32

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorNbt.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ public ValueTypeNbt.ValueNbt translateFromGraal(Context context, Value value, IE
122122
// In all other cases, assume we have a compound tag
123123
CompoundTag tag = new CompoundTag();
124124
for (String memberKey : value.getMemberKeys()) {
125-
IValue subValue = ValueTranslators.REGISTRY.translateFromGraal(context, value.getMember(memberKey), exceptionFactory);
126-
tag.put(memberKey, ValueTranslators.REGISTRY.translateToNbt(context, subValue, exceptionFactory));
125+
Value memberValue = value.getMember(memberKey);
126+
if (!memberValue.isNull()) {
127+
IValue subValue = ValueTranslators.REGISTRY.translateFromGraal(context, memberValue, exceptionFactory);
128+
tag.put(memberKey, ValueTranslators.REGISTRY.translateToNbt(context, subValue, exceptionFactory));
129+
}
127130
}
128131
return ValueTypeNbt.ValueNbt.of(tag);
129132
}

src/test/java/org/cyclops/integratedscripting/evaluate/translation/ValueTranslatorsJavaScriptTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ public void testNbtCompound() throws EvaluationException {
352352
assertThat(listValue.getArrayElement(2), equalTo(CTX.asValue(3)));
353353
}
354354

355+
@Test
356+
public void testNbtCompoundWithNullAndUndefined() throws EvaluationException {
357+
CompoundTag compoundTag = new CompoundTag();
358+
compoundTag.put("a", StringTag.valueOf("bla"));
359+
assertThat(ValueTranslators.REGISTRY.translateFromGraal(CTX, getJsValue("exports = { 'a': 'bla', 'b': null, 'c': undefined }"), EF), equalTo(ValueTypeNbt.ValueNbt.of(compoundTag)));
360+
}
361+
355362
@Test
356363
public void testNbtCompoundBidirectional() throws EvaluationException {
357364
CompoundTag compoundTag = new CompoundTag();

0 commit comments

Comments
 (0)