Search in sources :

Example 16 with CommonTagCompound

use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.

the class ItemUtil method clearLoreNames.

/**
 * Removes all lores from an item that are set, if they are set
 *
 * @param itemStack
 */
public static void clearLoreNames(org.bukkit.inventory.ItemStack itemStack) {
    CommonTagCompound meta = ItemUtil.getMetaTag(itemStack, false);
    if (meta == null)
        return;
    CommonTagCompound display = meta.get("display", CommonTagCompound.class);
    if (display == null)
        return;
    display.remove("Lore");
}
Also used : CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound)

Example 17 with CommonTagCompound

use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.

the class CommonMapController method handleItemSync.

/**
 * Adjusts the internal remapping from UUID to Map Id taking into account the new item
 * being synchronized to the player. If the item is that of a virtual map, the map Id
 * of the item is updated. NBT data that should not be synchronized is dropped.
 *
 * @param item
 * @param tileX the X-coordinate of the tile in which the item is displayed
 * @param tileY the Y-coordinate of the tile in which the item is displayed
 * @return True if the item was changed and needs to be updated in the packet
 */
public ItemStack handleItemSync(ItemStack item, int tileX, int tileY) {
    if (!CommonMapUUIDStore.isMap(item)) {
        return null;
    }
    // When a map UUID is specified, use that to dynamically allocate a map Id to use
    CommonTagCompound tag = ItemUtil.getMetaTag(item, false);
    if (tag != null) {
        UUID mapUUID = tag.getUUID("mapDisplay");
        if (mapUUID != null) {
            item = trimExtraData(item);
            int id = getMapId(new MapUUID(mapUUID, tileX, tileY));
            CommonMapUUIDStore.setItemMapId(item, id);
            return item;
        }
    }
    // Static map Id MUST be enforced
    int mapId = CommonMapUUIDStore.getItemMapId(item);
    if (mapId != -1) {
        storeStaticMapId(mapId);
    }
    return null;
}
Also used : CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) MapUUID(com.bergerkiller.bukkit.common.map.util.MapUUID) UUID(java.util.UUID) MapUUID(com.bergerkiller.bukkit.common.map.util.MapUUID)

Example 18 with CommonTagCompound

use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.

the class ChunkBlockStateChangeConverter method convertInput.

@Override
public BlockStateChange convertInput(Object value) {
    final ClientboundLevelChunkPacketDataHandle.BlockEntityDataHandle handle;
    handle = ClientboundLevelChunkPacketDataHandle.BlockEntityDataHandle.createHandle(value);
    // Deferred readout of metadata for performance, as we're using reflection
    IntVector3 position = handle.getPosition(this.chunkX, this.chunkZ);
    BlockStateType type = handle.getType();
    CommonTagCompound initialMetadata = handle.getTag();
    if (initialMetadata != null) {
        // Constant value
        return BlockStateChange.deferred(position, type, LogicUtil.constantSupplier(initialMetadata), () -> true);
    } else {
        // Initialize when first called
        final DeferredSupplier<CommonTagCompound> metadataSupplier = DeferredSupplier.of(() -> {
            CommonTagCompound metadata = new CommonTagCompound();
            handle.setTag(metadata);
            return metadata;
        });
        return BlockStateChange.deferred(position, type, metadataSupplier, metadataSupplier::isInitialized);
    }
}
Also used : BlockStateType(com.bergerkiller.bukkit.common.resources.BlockStateType) CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) ClientboundLevelChunkPacketDataHandle(com.bergerkiller.generated.net.minecraft.network.protocol.game.ClientboundLevelChunkPacketDataHandle) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 19 with CommonTagCompound

use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.

the class NBTTest method testNBTCompoundWithList.

@Test
public void testNBTCompoundWithList() {
    CommonTagCompound compound = new CommonTagCompound();
    CommonTagList list = compound.createList("key");
    list.addValue("Value1");
    list.addValue("Value2");
    assertEquals(2, list.size());
    assertEquals("Value1", list.getValue(0));
    assertEquals("Value2", list.getValue(1));
    list = compound.get("key", CommonTagList.class);
    assertNotNull(list);
    assertEquals(2, list.size());
    assertEquals("Value1", list.getValue(0));
    assertEquals("Value2", list.getValue(1));
}
Also used : CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) CommonTagList(com.bergerkiller.bukkit.common.nbt.CommonTagList) Test(org.junit.Test)

Example 20 with CommonTagCompound

use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.

the class NBTTest method testNBTCompoundGetPut.

@Test
public void testNBTCompoundGetPut() {
    CommonTagCompound compound = new CommonTagCompound();
    testGetPutRemove(compound, "integerType", 12);
    testGetPutRemove(compound, "longType", 15L);
    testGetPutRemove(compound, "doubleType", 12D);
    testGetPutRemove(compound, "floatType", 12F);
    testGetPutRemove(compound, "byteType", (byte) 12);
    testGetPutRemove(compound, "stringType", "hello, world!");
    testGetPutRemove(compound, "blockPos", new BlockLocation("World2", 4, 6, 8));
    testGetPutRemove(compound, "intVector3Pos", new IntVector3(20, 44, 66));
    testGetPutRemove(compound, "random", UUID.randomUUID());
    testGetPutRemove(compound, "face", BlockFace.EAST);
    testGetPutRemove(compound, "perm", PermissionDefault.OP);
    testGetPutRemove(compound, "boolT", Boolean.TRUE);
    testGetPutRemove(compound, "boolF", Boolean.FALSE);
}
Also used : CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) Test(org.junit.Test)

Aggregations

CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)22 ItemStack (org.bukkit.inventory.ItemStack)4 Test (org.junit.Test)4 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 MapUUID (com.bergerkiller.bukkit.common.map.util.MapUUID)2 PacketPlayOutTileEntityDataHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutTileEntityDataHandle)2 UUID (java.util.UUID)2 MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)1 MapSession (com.bergerkiller.bukkit.common.map.MapSession)1 CommonTagList (com.bergerkiller.bukkit.common.nbt.CommonTagList)1 BlockStateType (com.bergerkiller.bukkit.common.resources.BlockStateType)1 BlockRenderOptions (com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions)1 BlockStateChange (com.bergerkiller.bukkit.common.wrappers.BlockStateChange)1 ChatText (com.bergerkiller.bukkit.common.wrappers.ChatText)1 ItemRenderOptions (com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions)1 ClientboundLevelChunkPacketDataHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.ClientboundLevelChunkPacketDataHandle)1 PacketPlayOutMapChunkHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutMapChunkHandle)1 PacketPlayOutUpdateSignHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutUpdateSignHandle)1 File (java.io.File)1 HashSet (java.util.HashSet)1