CC: Tweaked

CC: Tweaked

65M Downloads

CC: Tweaked 1.18.2 does not seem to take into account NBT Long arrays.

masecla22 opened this issue ยท 1 comments

commented

Minecraft Version

1.18.2

Version

1.101.0

Details

Hello!

I was playing on my modpack, (Stoneblock 3), and happened upon a bug.

When using Advanced Peripherals, alongside the ME Bridge and Applied Energistics 2 mod, I saw that the amts NBT tag appears to get dropped when using the getItems function on the ME Bridge as a peripheral.

I have tracked the issue down, and have gone through the source for both CC: Tweaked, AE2 and Advanced Peripherals, and have narrowed it down to the following function:

https://github.com/IntelligenceModding/AdvancedPeripherals/blob/a8d481af49ca6d0f1a7b740e894fce9511858fdd/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java#L135-L149

This seems to make use of the function NBTUtil.toLua, which, as far as I can tell is sourced from CC: Tweaked.

I am unsure whether CC: Tweaked further sources it upstream from CC, however, with IntelliJ, I was able to find this implementation of the function being used:

    public static Object toLua( Tag tag )
    {
        if( tag == null ) return null;

        byte typeID = tag.getId();
        switch( typeID )
        {
            case Tag.TAG_BYTE:
            case Tag.TAG_SHORT:
            case Tag.TAG_INT:
            case Tag.TAG_LONG:
                return ((NumericTag) tag).getAsLong();
            case Tag.TAG_FLOAT:
            case Tag.TAG_DOUBLE:
                return ((NumericTag) tag).getAsDouble();
            case Tag.TAG_STRING: // String
                return tag.getAsString();
            case Tag.TAG_COMPOUND: // Compound
            {
                CompoundTag compound = (CompoundTag) tag;
                Map<String, Object> map = new HashMap<>( compound.size() );
                for( String key : compound.getAllKeys() )
                {
                    Object value = toLua( compound.get( key ) );
                    if( value != null ) map.put( key, value );
                }
                return map;
            }
            case Tag.TAG_LIST:
            {
                ListTag list = (ListTag) tag;
                Map<Integer, Object> map = new HashMap<>( list.size() );
                for( int i = 0; i < list.size(); i++ ) map.put( i, toLua( list.get( i ) ) );
                return map;
            }
            case Tag.TAG_BYTE_ARRAY:
            {
                byte[] array = ((ByteArrayTag) tag).getAsByteArray();
                Map<Integer, Byte> map = new HashMap<>( array.length );
                for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] );
                return map;
            }
            case Tag.TAG_INT_ARRAY:
            {
                int[] array = ((IntArrayTag) tag).getAsIntArray();
                Map<Integer, Integer> map = new HashMap<>( array.length );
                for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] );
                return map;
            }

            default:
                return null;
        }
    }

Which, after some debugging landed me with this in my logs:

 {id:"ae2:item_storage_cell_256k",tag:{amts:[L;1L],ic:1L,keys:[{"#c":"ae2:i",id:"ae2:cyan_smart_dense_cable"}]}}
Tag Type ID: 10
Tag Type ID: 8
Tag Type ID: 10
Tag Type ID: 4
Tag Type ID: 9
Tag Type ID: 10
Tag Type ID: 8
Tag Type ID: 8
Tag Type ID: 12
Unsupported NBT tag: 12

Looking in the Tag class, I can see that NBT Tag 12 corresponds to TAG_LONG_ARRAY = 12;, and with that it makes quite a bit of sense why it's getting dropped.

That being said, I've gone ahead and have Advanced Peripherals as well, in this way:

    public static Object toLua(Tag tag) {
        if (tag == null) return null;

        byte typeID = tag.getId();
        switch (typeID) {
            case Tag.TAG_BYTE:
            case Tag.TAG_SHORT:
            case Tag.TAG_INT:
            case Tag.TAG_LONG:
                return ((NumericTag) tag).getAsLong();
            case Tag.TAG_FLOAT:
            case Tag.TAG_DOUBLE:
                return ((NumericTag) tag).getAsDouble();
            case Tag.TAG_STRING: // String
                return tag.getAsString();
            case Tag.TAG_COMPOUND: // Compound
            {
                CompoundTag compound = (CompoundTag) tag;
                Map<String, Object> map = new HashMap<>(compound.size());
                for (String key : compound.getAllKeys()) {
                    Object value = toLua(compound.get(key));
                    if (value != null) map.put(key, value);
                }
                return map;
            }
            case Tag.TAG_LIST: {
                ListTag list = (ListTag) tag;
                Map<Integer, Object> map = new HashMap<>(list.size());
                for (int i = 0; i < list.size(); i++) map.put(i, toLua(list.get(i)));
                return map;
            }
            case Tag.TAG_BYTE_ARRAY: {
                byte[] array = ((ByteArrayTag) tag).getAsByteArray();
                Map<Integer, Byte> map = new HashMap<>(array.length);
                for (int i = 0; i < array.length; i++) map.put(i + 1, array[i]);
                return map;
            }
            case Tag.TAG_INT_ARRAY: {
                int[] array = ((IntArrayTag) tag).getAsIntArray();
                Map<Integer, Integer> map = new HashMap<>(array.length);
                for (int i = 0; i < array.length; i++) map.put(i + 1, array[i]);
                return map;
            }
            case Tag.TAG_LONG_ARRAY: {
                long[] array = ((LongArrayTag) tag).getAsLongArray();
                Map<Integer, Long> map = new HashMap<>(array.length);
                for (int i = 0; i < array.length; i++) map.put(i + 1, array[i]);
                return map;
            }
            default: 
                return null;
        }
    }

I renamed this function to patchedToLua, and have simply been playing with the patched version of the mod.

I am unsure whether you guys take contributions / PRs for older versions, I apologize for wasting your time if not ๐Ÿ˜… , that being said, my investigations show that this is patched in the latest version in 1.21 (likely due to the whole switch to data components).

I have also made an issue about this within Advanced Peripherals, hopefully something comes of this!

commented

Thanks for the report! This has been fixed on 1.20.1 and later (in 94ad6da), but as you say, not on older versions!

I am unsure whether you guys take contributions / PRs for older versions,

I'm afraid generally not, no. In theory publishing an old version should be easy, but in practice something always ends up breaking (bitrot is real :/), so I generally try to do it for critical/high-impact bugs.