|
1 | 1 | package org.cyclops.integrateddynamics.core.evaluate.variable; |
2 | 2 |
|
3 | 3 | import com.google.common.collect.Lists; |
| 4 | +import net.minecraft.nbt.ByteArrayTag; |
4 | 5 | import net.minecraft.nbt.CompoundTag; |
| 6 | +import net.minecraft.nbt.IntArrayTag; |
| 7 | +import net.minecraft.nbt.LongArrayTag; |
5 | 8 | import org.cyclops.cyclopscore.helper.CyclopsCoreInstance; |
6 | 9 | import org.cyclops.integrateddynamics.ModBaseMocked; |
7 | 10 | import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeListProxy; |
@@ -63,6 +66,81 @@ public void testMaterialized() throws IValueTypeListProxyFactoryTypeRegistry.Ser |
63 | 66 | )); |
64 | 67 | } |
65 | 68 |
|
| 69 | + @Test |
| 70 | + public void testMaterializedIntegerListFromIntArrayTag() throws IValueTypeListProxyFactoryTypeRegistry.SerializationException { |
| 71 | + // Simulate codec round-trip: ListTag<IntTag> -> IntArrayTag (as done by Minecraft's NbtOps) |
| 72 | + ValueTypeListProxyMaterialized<?, ?> proxy = new ValueTypeListProxyMaterialized<>( |
| 73 | + ValueTypes.INTEGER, |
| 74 | + Lists.newArrayList(ValueTypeInteger.ValueInteger.of(42)) |
| 75 | + ); |
| 76 | + CompoundTag tag = serialize(o -> { |
| 77 | + try { |
| 78 | + ValueTypeListProxyFactories.REGISTRY.serialize(o, proxy); |
| 79 | + } catch (IValueTypeListProxyFactoryTypeRegistry.SerializationException e) { |
| 80 | + throw new RuntimeException(e); |
| 81 | + } |
| 82 | + }, ValueDeseralizationContextMocked.get().holderLookupProvider()); |
| 83 | + tag.put("values", new IntArrayTag(new int[]{42})); |
| 84 | + IValueTypeListProxy<?, ?> proxyNew = deserialize(tag, valueInput -> { |
| 85 | + try { |
| 86 | + return ValueTypeListProxyFactories.REGISTRY.deserialize(valueInput); |
| 87 | + } catch (IValueTypeListProxyFactoryTypeRegistry.SerializationException e) { |
| 88 | + throw new RuntimeException(e); |
| 89 | + } |
| 90 | + }, ValueDeseralizationContextMocked.get().holderLookupProvider()); |
| 91 | + assertThat(proxyNew, equalTo(proxy)); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testMaterializedLongListFromLongArrayTag() throws IValueTypeListProxyFactoryTypeRegistry.SerializationException { |
| 96 | + // Simulate codec round-trip: ListTag<LongTag> -> LongArrayTag (as done by Minecraft's NbtOps) |
| 97 | + ValueTypeListProxyMaterialized<?, ?> proxy = new ValueTypeListProxyMaterialized<>( |
| 98 | + ValueTypes.LONG, |
| 99 | + Lists.newArrayList(ValueTypeLong.ValueLong.of(123L)) |
| 100 | + ); |
| 101 | + CompoundTag tag = serialize(o -> { |
| 102 | + try { |
| 103 | + ValueTypeListProxyFactories.REGISTRY.serialize(o, proxy); |
| 104 | + } catch (IValueTypeListProxyFactoryTypeRegistry.SerializationException e) { |
| 105 | + throw new RuntimeException(e); |
| 106 | + } |
| 107 | + }, ValueDeseralizationContextMocked.get().holderLookupProvider()); |
| 108 | + tag.put("values", new LongArrayTag(new long[]{123L})); |
| 109 | + IValueTypeListProxy<?, ?> proxyNew = deserialize(tag, valueInput -> { |
| 110 | + try { |
| 111 | + return ValueTypeListProxyFactories.REGISTRY.deserialize(valueInput); |
| 112 | + } catch (IValueTypeListProxyFactoryTypeRegistry.SerializationException e) { |
| 113 | + throw new RuntimeException(e); |
| 114 | + } |
| 115 | + }, ValueDeseralizationContextMocked.get().holderLookupProvider()); |
| 116 | + assertThat(proxyNew, equalTo(proxy)); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void testMaterializedBooleanListFromByteArrayTag() throws IValueTypeListProxyFactoryTypeRegistry.SerializationException { |
| 121 | + // Simulate codec round-trip: ListTag<ByteTag> -> ByteArrayTag (as done by Minecraft's NbtOps) |
| 122 | + ValueTypeListProxyMaterialized<?, ?> proxy = new ValueTypeListProxyMaterialized<>( |
| 123 | + ValueTypes.BOOLEAN, |
| 124 | + Lists.newArrayList(ValueTypeBoolean.ValueBoolean.of(true)) |
| 125 | + ); |
| 126 | + CompoundTag tag = serialize(o -> { |
| 127 | + try { |
| 128 | + ValueTypeListProxyFactories.REGISTRY.serialize(o, proxy); |
| 129 | + } catch (IValueTypeListProxyFactoryTypeRegistry.SerializationException e) { |
| 130 | + throw new RuntimeException(e); |
| 131 | + } |
| 132 | + }, ValueDeseralizationContextMocked.get().holderLookupProvider()); |
| 133 | + tag.put("values", new ByteArrayTag(new byte[]{(byte) 1})); |
| 134 | + IValueTypeListProxy<?, ?> proxyNew = deserialize(tag, valueInput -> { |
| 135 | + try { |
| 136 | + return ValueTypeListProxyFactories.REGISTRY.deserialize(valueInput); |
| 137 | + } catch (IValueTypeListProxyFactoryTypeRegistry.SerializationException e) { |
| 138 | + throw new RuntimeException(e); |
| 139 | + } |
| 140 | + }, ValueDeseralizationContextMocked.get().holderLookupProvider()); |
| 141 | + assertThat(proxyNew, equalTo(proxy)); |
| 142 | + } |
| 143 | + |
66 | 144 | @Test |
67 | 145 | public void testNbtKeys() throws IValueTypeListProxyFactoryTypeRegistry.SerializationException { |
68 | 146 | testFactoryType(new ValueTypeListProxyNbtKeys( |
|
0 commit comments