001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.util.ArrayList; 006 import java.util.Iterator; 007 import java.util.List; 008 009 public class EntityPainting extends Entity 010 { 011 private int tickCounter1; 012 013 /** the direction the painting faces */ 014 public int direction; 015 public int xPosition; 016 public int yPosition; 017 public int zPosition; 018 public EnumArt art; 019 020 public EntityPainting(World par1World) 021 { 022 super(par1World); 023 this.tickCounter1 = 0; 024 this.direction = 0; 025 this.yOffset = 0.0F; 026 this.setSize(0.5F, 0.5F); 027 } 028 029 public EntityPainting(World par1World, int par2, int par3, int par4, int par5) 030 { 031 this(par1World); 032 this.xPosition = par2; 033 this.yPosition = par3; 034 this.zPosition = par4; 035 ArrayList var6 = new ArrayList(); 036 EnumArt[] var7 = EnumArt.values(); 037 int var8 = var7.length; 038 039 for (int var9 = 0; var9 < var8; ++var9) 040 { 041 EnumArt var10 = var7[var9]; 042 this.art = var10; 043 this.setDirection(par5); 044 045 if (this.onValidSurface()) 046 { 047 var6.add(var10); 048 } 049 } 050 051 if (!var6.isEmpty()) 052 { 053 this.art = (EnumArt)var6.get(this.rand.nextInt(var6.size())); 054 } 055 056 this.setDirection(par5); 057 } 058 059 @SideOnly(Side.CLIENT) 060 public EntityPainting(World par1World, int par2, int par3, int par4, int par5, String par6Str) 061 { 062 this(par1World); 063 this.xPosition = par2; 064 this.yPosition = par3; 065 this.zPosition = par4; 066 EnumArt[] var7 = EnumArt.values(); 067 int var8 = var7.length; 068 069 for (int var9 = 0; var9 < var8; ++var9) 070 { 071 EnumArt var10 = var7[var9]; 072 073 if (var10.title.equals(par6Str)) 074 { 075 this.art = var10; 076 break; 077 } 078 } 079 080 this.setDirection(par5); 081 } 082 083 protected void entityInit() {} 084 085 /** 086 * Sets the direction the painting faces. 087 */ 088 public void setDirection(int par1) 089 { 090 this.direction = par1; 091 this.prevRotationYaw = this.rotationYaw = (float)(par1 * 90); 092 float var2 = (float)this.art.sizeX; 093 float var3 = (float)this.art.sizeY; 094 float var4 = (float)this.art.sizeX; 095 096 if (par1 != 0 && par1 != 2) 097 { 098 var2 = 0.5F; 099 } 100 else 101 { 102 var4 = 0.5F; 103 } 104 105 var2 /= 32.0F; 106 var3 /= 32.0F; 107 var4 /= 32.0F; 108 float var5 = (float)this.xPosition + 0.5F; 109 float var6 = (float)this.yPosition + 0.5F; 110 float var7 = (float)this.zPosition + 0.5F; 111 float var8 = 0.5625F; 112 113 if (par1 == 0) 114 { 115 var7 -= var8; 116 } 117 118 if (par1 == 1) 119 { 120 var5 -= var8; 121 } 122 123 if (par1 == 2) 124 { 125 var7 += var8; 126 } 127 128 if (par1 == 3) 129 { 130 var5 += var8; 131 } 132 133 if (par1 == 0) 134 { 135 var5 -= this.func_70517_b(this.art.sizeX); 136 } 137 138 if (par1 == 1) 139 { 140 var7 += this.func_70517_b(this.art.sizeX); 141 } 142 143 if (par1 == 2) 144 { 145 var5 += this.func_70517_b(this.art.sizeX); 146 } 147 148 if (par1 == 3) 149 { 150 var7 -= this.func_70517_b(this.art.sizeX); 151 } 152 153 var6 += this.func_70517_b(this.art.sizeY); 154 this.setPosition((double)var5, (double)var6, (double)var7); 155 float var9 = -0.00625F; 156 this.boundingBox.setBounds((double)(var5 - var2 - var9), (double)(var6 - var3 - var9), (double)(var7 - var4 - var9), (double)(var5 + var2 + var9), (double)(var6 + var3 + var9), (double)(var7 + var4 + var9)); 157 } 158 159 private float func_70517_b(int par1) 160 { 161 return par1 == 32 ? 0.5F : (par1 == 64 ? 0.5F : 0.0F); 162 } 163 164 /** 165 * Called to update the entity's position/logic. 166 */ 167 public void onUpdate() 168 { 169 if (this.tickCounter1++ == 100 && !this.worldObj.isRemote) 170 { 171 this.tickCounter1 = 0; 172 173 if (!this.isDead && !this.onValidSurface()) 174 { 175 this.setDead(); 176 this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Item.painting))); 177 } 178 } 179 } 180 181 /** 182 * checks to make sure painting can be placed there 183 */ 184 public boolean onValidSurface() 185 { 186 if (!this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty()) 187 { 188 return false; 189 } 190 else 191 { 192 int var1 = this.art.sizeX / 16; 193 int var2 = this.art.sizeY / 16; 194 int var3 = this.xPosition; 195 int var4 = this.yPosition; 196 int var5 = this.zPosition; 197 198 if (this.direction == 0) 199 { 200 var3 = MathHelper.floor_double(this.posX - (double)((float)this.art.sizeX / 32.0F)); 201 } 202 203 if (this.direction == 1) 204 { 205 var5 = MathHelper.floor_double(this.posZ - (double)((float)this.art.sizeX / 32.0F)); 206 } 207 208 if (this.direction == 2) 209 { 210 var3 = MathHelper.floor_double(this.posX - (double)((float)this.art.sizeX / 32.0F)); 211 } 212 213 if (this.direction == 3) 214 { 215 var5 = MathHelper.floor_double(this.posZ - (double)((float)this.art.sizeX / 32.0F)); 216 } 217 218 var4 = MathHelper.floor_double(this.posY - (double)((float)this.art.sizeY / 32.0F)); 219 220 for (int var6 = 0; var6 < var1; ++var6) 221 { 222 for (int var7 = 0; var7 < var2; ++var7) 223 { 224 Material var8; 225 226 if (this.direction != 0 && this.direction != 2) 227 { 228 var8 = this.worldObj.getBlockMaterial(this.xPosition, var4 + var7, var5 + var6); 229 } 230 else 231 { 232 var8 = this.worldObj.getBlockMaterial(var3 + var6, var4 + var7, this.zPosition); 233 } 234 235 if (!var8.isSolid()) 236 { 237 return false; 238 } 239 } 240 } 241 242 List var9 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox); 243 Iterator var10 = var9.iterator(); 244 Entity var11; 245 246 do 247 { 248 if (!var10.hasNext()) 249 { 250 return true; 251 } 252 253 var11 = (Entity)var10.next(); 254 } 255 while (!(var11 instanceof EntityPainting)); 256 257 return false; 258 } 259 } 260 261 /** 262 * Returns true if other Entities should be prevented from moving through this Entity. 263 */ 264 public boolean canBeCollidedWith() 265 { 266 return true; 267 } 268 269 /** 270 * Called when the entity is attacked. 271 */ 272 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) 273 { 274 if (!this.isDead && !this.worldObj.isRemote) 275 { 276 this.setDead(); 277 this.setBeenAttacked(); 278 EntityPlayer var3 = null; 279 280 if (par1DamageSource.getEntity() instanceof EntityPlayer) 281 { 282 var3 = (EntityPlayer)par1DamageSource.getEntity(); 283 } 284 285 if (var3 != null && var3.capabilities.isCreativeMode) 286 { 287 return true; 288 } 289 290 this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Item.painting))); 291 } 292 293 return true; 294 } 295 296 /** 297 * (abstract) Protected helper method to write subclass entity data to NBT. 298 */ 299 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 300 { 301 par1NBTTagCompound.setByte("Dir", (byte)this.direction); 302 par1NBTTagCompound.setString("Motive", this.art.title); 303 par1NBTTagCompound.setInteger("TileX", this.xPosition); 304 par1NBTTagCompound.setInteger("TileY", this.yPosition); 305 par1NBTTagCompound.setInteger("TileZ", this.zPosition); 306 } 307 308 /** 309 * (abstract) Protected helper method to read subclass entity data from NBT. 310 */ 311 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 312 { 313 this.direction = par1NBTTagCompound.getByte("Dir"); 314 this.xPosition = par1NBTTagCompound.getInteger("TileX"); 315 this.yPosition = par1NBTTagCompound.getInteger("TileY"); 316 this.zPosition = par1NBTTagCompound.getInteger("TileZ"); 317 String var2 = par1NBTTagCompound.getString("Motive"); 318 EnumArt[] var3 = EnumArt.values(); 319 int var4 = var3.length; 320 321 for (int var5 = 0; var5 < var4; ++var5) 322 { 323 EnumArt var6 = var3[var5]; 324 325 if (var6.title.equals(var2)) 326 { 327 this.art = var6; 328 } 329 } 330 331 if (this.art == null) 332 { 333 this.art = EnumArt.Kebab; 334 } 335 336 this.setDirection(this.direction); 337 } 338 339 /** 340 * Tries to moves the entity by the passed in displacement. Args: x, y, z 341 */ 342 public void moveEntity(double par1, double par3, double par5) 343 { 344 if (!this.worldObj.isRemote && !this.isDead && par1 * par1 + par3 * par3 + par5 * par5 > 0.0D) 345 { 346 this.setDead(); 347 this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Item.painting))); 348 } 349 } 350 351 /** 352 * Adds to the current velocity of the entity. Args: x, y, z 353 */ 354 public void addVelocity(double par1, double par3, double par5) 355 { 356 if (!this.worldObj.isRemote && !this.isDead && par1 * par1 + par3 * par3 + par5 * par5 > 0.0D) 357 { 358 this.setDead(); 359 this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Item.painting))); 360 } 361 } 362 }