001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 006 public class EntityItemFrame extends EntityHanging 007 { 008 /** Chance for this item frame's item to drop from the frame. */ 009 private float itemDropChance = 1.0F; 010 011 public EntityItemFrame(World par1World) 012 { 013 super(par1World); 014 } 015 016 public EntityItemFrame(World par1World, int par2, int par3, int par4, int par5) 017 { 018 super(par1World, par2, par3, par4, par5); 019 this.func_82328_a(par5); 020 } 021 022 protected void entityInit() 023 { 024 this.getDataWatcher().addObjectByDataType(2, 5); 025 this.getDataWatcher().addObject(3, Byte.valueOf((byte)0)); 026 } 027 028 public int func_82329_d() 029 { 030 return 9; 031 } 032 033 public int func_82330_g() 034 { 035 return 9; 036 } 037 038 @SideOnly(Side.CLIENT) 039 040 /** 041 * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge 042 * length * 64 * renderDistanceWeight Args: distance 043 */ 044 public boolean isInRangeToRenderDist(double par1) 045 { 046 double var3 = 16.0D; 047 var3 *= 64.0D * this.renderDistanceWeight; 048 return par1 < var3 * var3; 049 } 050 051 /** 052 * Drop the item currently on this item frame. 053 */ 054 public void dropItemStack() 055 { 056 this.entityDropItem(new ItemStack(Item.itemFrame), 0.0F); 057 058 if (this.func_82335_i() != null && this.rand.nextFloat() < this.itemDropChance) 059 { 060 this.func_82335_i().setItemFrame((EntityItemFrame)null); 061 this.entityDropItem(this.func_82335_i(), 0.0F); 062 } 063 } 064 065 public ItemStack func_82335_i() 066 { 067 return this.getDataWatcher().getWatchableObjectItemStack(2); 068 } 069 070 public void func_82334_a(ItemStack par1ItemStack) 071 { 072 par1ItemStack = par1ItemStack.copy(); 073 par1ItemStack.stackSize = 1; 074 par1ItemStack.setItemFrame(this); 075 this.getDataWatcher().updateObject(2, par1ItemStack); 076 this.getDataWatcher().func_82708_h(2); 077 } 078 079 /** 080 * Return the rotation of the item currently on this frame. 081 */ 082 public int getRotation() 083 { 084 return this.getDataWatcher().getWatchableObjectByte(3); 085 } 086 087 public void func_82336_g(int par1) 088 { 089 this.getDataWatcher().updateObject(3, Byte.valueOf((byte)(par1 % 4))); 090 } 091 092 /** 093 * (abstract) Protected helper method to write subclass entity data to NBT. 094 */ 095 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 096 { 097 if (this.func_82335_i() != null) 098 { 099 par1NBTTagCompound.setCompoundTag("Item", this.func_82335_i().writeToNBT(new NBTTagCompound())); 100 par1NBTTagCompound.setByte("ItemRotation", (byte)this.getRotation()); 101 par1NBTTagCompound.setFloat("ItemDropChance", this.itemDropChance); 102 } 103 104 super.writeEntityToNBT(par1NBTTagCompound); 105 } 106 107 /** 108 * (abstract) Protected helper method to read subclass entity data from NBT. 109 */ 110 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 111 { 112 NBTTagCompound var2 = par1NBTTagCompound.getCompoundTag("Item"); 113 114 if (var2 != null && !var2.hasNoTags()) 115 { 116 this.func_82334_a(ItemStack.loadItemStackFromNBT(var2)); 117 this.func_82336_g(par1NBTTagCompound.getByte("ItemRotation")); 118 119 if (par1NBTTagCompound.hasKey("ItemDropChance")) 120 { 121 this.itemDropChance = par1NBTTagCompound.getFloat("ItemDropChance"); 122 } 123 } 124 125 super.readEntityFromNBT(par1NBTTagCompound); 126 } 127 128 /** 129 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. 130 */ 131 public boolean interact(EntityPlayer par1EntityPlayer) 132 { 133 if (this.func_82335_i() == null) 134 { 135 ItemStack var2 = par1EntityPlayer.getHeldItem(); 136 137 if (var2 != null && !this.worldObj.isRemote) 138 { 139 this.func_82334_a(var2); 140 141 if (!par1EntityPlayer.capabilities.isCreativeMode && --var2.stackSize <= 0) 142 { 143 par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); 144 } 145 } 146 } 147 else if (!this.worldObj.isRemote) 148 { 149 this.func_82336_g(this.getRotation() + 1); 150 } 151 152 return true; 153 } 154 }