What should i do if i want to read and change entity_identifiers.dat

i have tried to use NBTIO.read() but it doesnt work

Hello,

Sorry for the late reply, I was taking some time off in December.

Why would you need to modify that resource?

We extract that file from the connection between a bedrock client (usually Windows 10 Edition) and BDS.

TL;DR

Read: (CompoundTag) NBTIO.readTag(stream, ByteOrder.LITTLE_ENDIAN, true);
Write: NBTIO.write(tags, ByteOrder.LITTLE_ENDIAN, true);

It is used in PowerNukkit directly in the AvailableEntityIdentifiersPacket:

We get the content using ProxyPass:

Here is how you could read it directly from the file:

public class EntityIdentifiersDumper {
    public static void main(String[] args)  {
        CompoundTag tags;
        try (InputStream stream = Server.class.getClassLoader().getResourceAsStream("entity_identifiers.dat")) {
            if (stream == null) {
                throw new AssertionError("Unable to locate entity_identifiers.dat");
            }

            tags = (CompoundTag) NBTIO.readTag(stream, ByteOrder.LITTLE_ENDIAN, true);
        } catch (IOException e) {
            throw new AssertionError(e);
        }
        System.out.println(tags);
    }
}

And how you could use the cache from the packet:

public class EntityIdentifiersDumper {
    public static void main(String[] args) {
        CompoundTag tags;
        try (InputStream stream = new ByteArrayInputStream(new AvailableEntityIdentifiersPacket().tag)) {
            tags = (CompoundTag) NBTIO.readTag(stream, ByteOrder.LITTLE_ENDIAN, true);
        } catch (IOException e) {
            throw new AssertionError(e);
        }
        System.out.println(tags);
    }
}

To write in the same format:

NBTIO.write(tags, ByteOrder.LITTLE_ENDIAN, true)

Example output:

CompoundTag '' (1 entries) {
	'idlist' : ListTag 'idlist' (111 entries of type TAG_Compound) {
		CompoundTag '' (6 entries) {
			'hasspawnegg' : ByteTag hasspawnegg (data: 0x01),
			'experimental' : ByteTag experimental (data: 0x00),
			'summonable' : ByteTag summonable (data: 0x00),
			'id' : StringTag id (data: minecraft:villager_v2),
			'bid' : StringTag bid (data: ),
			'rid' : IntTag rid(data: 115)
		},
		CompoundTag '' (6 entries) {
			'hasspawnegg' : ByteTag hasspawnegg (data: 0x01),
			'experimental' : ByteTag experimental (data: 0x00),
			'summonable' : ByteTag summonable (data: 0x01),
			'id' : StringTag id (data: minecraft:cat),
			'bid' : StringTag bid (data: ),
			'rid' : IntTag rid(data: 75)
		},
		CompoundTag '' (6 entries) {
			'hasspawnegg' : ByteTag hasspawnegg (data: 0x01),
			'experimental' : ByteTag experimental (data: 0x00),
			'summonable' : ByteTag summonable (data: 0x01),
			'id' : StringTag id (data: minecraft:turtle),
			'bid' : StringTag bid (data: ),
			'rid' : IntTag rid(data: 74)
		},
1 Like

thanks. i’m going to create a server like Decimation in JE so i need to register entities. you really helps me a lot.