protected void register(List<Entry<Consumer<NBTCompound>>> list, Material banner, int color) { for (BlockData blockdata : MaterialAPI.getBlockDataList(banner)) { list.add(new ArrayMap.Entry<>(MaterialAPI.getBlockDataNetworkId(blockdata), nbt -> nbt.setTag("Base", new NBTInt(color)))); } } @Override
public TileEntity(TileEntityType type, Position position, NBTCompound nbt) { this.type = type; this.position = position; this.nbt = nbt; this.nbt.setTag("id", new NBTString(type.getRegistryId())); this.nbt.setTag("x", new NBTInt(position.getX())); this.nbt.setTag("y", new NBTInt(position.getY())); this.nbt.setTag("z", new NBTInt(position.getZ())); }
@Override public TileEntity apply(Position position) { NBTCompound tag = new NBTCompound(); tag.setTag("color", new NBTInt(color)); return new TileEntity(TileEntityType.BED, position, tag); }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { tag = new NBTCompound(); itemstack.setNBT(tag); } tag.setTag("Damage", new NBTInt(itemstack.getLegacyData())); return itemstack; }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { tag = new NBTCompound(); itemstack.setNBT(tag); } tag.setTag("map", new NBTInt(itemstack.getLegacyData())); return itemstack; }
registerType(NBTType.BYTE, 1, stream -> new NBTByte(stream.readByte()), (stream, tag) -> stream.writeByte(tag.getAsByte())); registerType(NBTType.SHORT, 2, stream -> new NBTShort(stream.readShort()), (stream, tag) -> stream.writeShort(tag.getAsShort())); registerType(NBTType.INT, 3, stream -> new NBTInt(stream.readInt()), (stream, tag) -> stream.writeInt(tag.getAsInt())); registerType(NBTType.LONG, 4, stream -> new NBTLong(stream.readLong()), (stream, tag) -> stream.writeLong(tag.getAsLong())); registerType(NBTType.FLOAT, 5, stream -> new NBTFloat(stream.readFloat()), (stream, tag) -> stream.writeFloat(tag.getAsFloat()));
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testList() { NBTList<NBTInt> list = new NBTList<>(NBTType.INT); list.addTag(new NBTInt(30)); list.addTag(new NBTInt(30)); Assertions.assertTrue(list.getTagsType() == NBTType.INT); Assertions.assertTrue(list.size() == 2); Assertions.assertThrows(IllegalArgumentException.class, () -> ((NBTList) list).addTag(new NBTShort((short) 0))); }
@Test public void testEq() { Assertions.assertEquals(new NBTByte((byte) 5), new NBTByte((byte) 5)); Assertions.assertEquals(new NBTShort((short) 5), new NBTShort((short) 5)); Assertions.assertEquals(new NBTInt(5), new NBTInt(5)); Assertions.assertEquals(new NBTLong(5), new NBTLong(5)); Assertions.assertEquals(new NBTFloat(5), new NBTFloat(5)); Assertions.assertEquals(new NBTDouble(5), new NBTDouble(5)); Assertions.assertEquals(new NBTString("5"), new NBTString("5")); }
@Test public void testCompound() { String testtagname = "test"; NBTCompound compound = new NBTCompound(); compound.setTag(testtagname, new NBTShort((short) 20)); String testlisttagname = "testlist"; NBTList<NBTInt> list = new NBTList<>(NBTType.INT); list.addTag(new NBTInt(30)); compound.setTag(testlisttagname, list); Assertions.assertNotNull(compound.getTag(testtagname)); Assertions.assertNotNull(compound.getTagOfType(testtagname, NBTType.SHORT)); Assertions.assertNull(compound.getTagOfType(testtagname, NBTType.INT)); Assertions.assertNotNull(compound.getNumberTag(testtagname)); Assertions.assertNotNull(compound.getTag(testlisttagname)); Assertions.assertNotNull(compound.getTagOfType(testlisttagname, NBTType.LIST)); Assertions.assertNull(compound.getTagOfType(testlisttagname, NBTType.DOUBLE)); Assertions.assertNotNull(compound.getTagListOfType(testlisttagname, NBTType.INT)); Assertions.assertNull(compound.getTagListOfType(testlisttagname, NBTType.SHORT)); Assertions.assertNotNull(compound.getNumberTagList(testlisttagname)); }