Java Code Examples for net.minecraft.nbt.NBTUtil#writeGameProfile()

The following examples show how to use net.minecraft.nbt.NBTUtil#writeGameProfile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public Collection<ItemStack> getDrops() {
    List<ItemStack> drops = new ArrayList<ItemStack>();

    net.minecraft.block.Block block = this.getNMSBlock();
    if (block != Blocks.AIR) {
        IBlockState data = getData0();
        // based on nms.Block.dropNaturally
        int count = block.quantityDroppedWithBonus(0, chunk.getHandle().getWorld().rand);
        for (int i = 0; i < count; ++i) {
            Item item = block.getItemDropped(data, chunk.getHandle().getWorld().rand, 0);
            if (item != Items.AIR) {
                // Skulls are special, their data is based on the tile entity
                if (Blocks.SKULL == block) {
                    net.minecraft.item.ItemStack nmsStack = new net.minecraft.item.ItemStack(item, 1, block.damageDropped(data));
                    TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().getWorld().getTileEntity(new BlockPos(x, y, z));

                    if (tileentityskull.getSkullType() == 3 && tileentityskull.getPlayerProfile() != null) {
                        nmsStack.setTagCompound(new NBTTagCompound());
                        NBTTagCompound nbttagcompound = new NBTTagCompound();

                        NBTUtil.writeGameProfile(nbttagcompound, tileentityskull.getPlayerProfile());
                        nmsStack.getTagCompound().setTag("SkullOwner", nbttagcompound);
                    }

                    drops.add(CraftItemStack.asBukkitCopy(nmsStack));
                    // We don't want to drop cocoa blocks, we want to drop cocoa beans.
                } else if (Blocks.COCOA == block) {
                    int age = (Integer) data.getValue(BlockCocoa.AGE);
                    int dropAmount = (age >= 2 ? 3 : 1);
                    for (int j = 0; j < dropAmount; ++j) {
                        drops.add(new ItemStack(Material.INK_SACK, 1, (short) 3));
                    }
                } else {
                    drops.add(new ItemStack(CraftMagicNumbers.getMaterial(item), 1, (short) block.damageDropped(data)));
                }
            }
        }
    }
    return drops;
}
 
Example 2
Source File: CraftMetaSkull.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
void serializeInternal(final Map<String, NBTBase> internalTags) {
    if (profile != null) {
        NBTTagCompound nbtData = new NBTTagCompound();
        NBTUtil.writeGameProfile(nbtData, profile);
        internalTags.put(SKULL_PROFILE.NBT, nbtData);
    }
}
 
Example 3
Source File: CraftMetaSkull.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);

    if (profile != null) {
        // Fill in textures
        profile = TileEntitySkull.updateGameprofile(profile);

        NBTTagCompound owner = new NBTTagCompound();
        NBTUtil.writeGameProfile(owner, profile);
        tag.setTag(SKULL_OWNER.NBT, owner);
    }
}