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