@Override public void writeToNBT(final NBTTagCompound tag) { super.writeToNBT(tag); final NBTTagCompound inventoriesTag = new NBTTagCompound(); final NBTTagCompound ownerTag = new NBTTagCompound(); for (final Entry<String, Map<Integer, ItemStack>> inventoryEntry : this.inventories.entrySet()) { final NBTTagList inventoryTag = new NBTTagList(); for (final Entry<Integer, ItemStack> slotEntry : inventoryEntry.getValue().entrySet()) { final NBTTagCompound slotTag = new NBTTagCompound(); slotEntry.getValue().writeToNBT(slotTag); slotTag.setByte("slot", slotEntry.getKey().byteValue()); inventoryTag.appendTag(slotTag); } inventoriesTag.setTag(inventoryEntry.getKey(), inventoryTag); } NBTUtil.writeGameProfile(ownerTag, this.owner); tag.setLong("age", this.age); tag.setTag("inventories", inventoriesTag); tag.setTag("owner", ownerTag); }
/** Called when an ItemStack with NBT data is read to potentially that ItemStack's NBT data */ public boolean updateItemStackNBT(NBTTagCompound nbt) { super.updateItemStackNBT(nbt); if (nbt.hasKey("SkullOwner", 8) && nbt.getString("SkullOwner").length() > 0) { GameProfile gameprofile = new GameProfile((UUID) null, nbt.getString("SkullOwner")); gameprofile = TileEntitySkull.updateGameprofile(gameprofile); nbt.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile)); return true; } else { return false; } }
public void renderByItem(ItemStack p_179022_1_) { if (p_179022_1_.getItem() == Items.banner) { this.banner.setItemValues(p_179022_1_); TileEntityRendererDispatcher.instance.renderTileEntityAt(this.banner, 0.0D, 0.0D, 0.0D, 0.0F); } else if (p_179022_1_.getItem() == Items.skull) { GameProfile gameprofile = null; if (p_179022_1_.hasTagCompound()) { NBTTagCompound nbttagcompound = p_179022_1_.getTagCompound(); if (nbttagcompound.hasKey("SkullOwner", 10)) { gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner")); } else if (nbttagcompound.hasKey("SkullOwner", 8) && nbttagcompound.getString("SkullOwner").length() > 0) { gameprofile = new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner")); gameprofile = TileEntitySkull.updateGameprofile(gameprofile); nbttagcompound.removeTag("SkullOwner"); nbttagcompound.setTag( "SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile)); } } if (TileEntitySkullRenderer.instance != null) { GlStateManager.pushMatrix(); GlStateManager.translate(-0.5F, 0.0F, -0.5F); GlStateManager.scale(2.0F, 2.0F, 2.0F); GlStateManager.disableCull(); TileEntitySkullRenderer.instance.renderSkull( 0.0F, 0.0F, 0.0F, EnumFacing.UP, 0.0F, p_179022_1_.getMetadata(), gameprofile, -1); GlStateManager.enableCull(); GlStateManager.popMatrix(); } } else { Block block = Block.getBlockFromItem(p_179022_1_.getItem()); if (block == Blocks.ender_chest) { TileEntityRendererDispatcher.instance.renderTileEntityAt( this.field_147716_d, 0.0D, 0.0D, 0.0D, 0.0F); } else if (block == Blocks.trapped_chest) { TileEntityRendererDispatcher.instance.renderTileEntityAt( this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F); } else { TileEntityRendererDispatcher.instance.renderTileEntityAt( this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F); } } }