001 package net.minecraft.entity.item;
002
003 import cpw.mods.fml.relauncher.Side;
004 import cpw.mods.fml.relauncher.SideOnly;
005 import net.minecraft.block.Block;
006 import net.minecraft.entity.Entity;
007 import net.minecraft.nbt.NBTTagCompound;
008 import net.minecraft.util.DamageSource;
009 import net.minecraft.util.MathHelper;
010 import net.minecraft.world.World;
011
012 public class EntityEnderCrystal extends Entity
013 {
014 /** Used to create the rotation animation when rendering the crystal. */
015 public int innerRotation;
016 public int health;
017
018 public EntityEnderCrystal(World par1World)
019 {
020 super(par1World);
021 this.innerRotation = 0;
022 this.preventEntitySpawning = true;
023 this.setSize(2.0F, 2.0F);
024 this.yOffset = this.height / 2.0F;
025 this.health = 5;
026 this.innerRotation = this.rand.nextInt(100000);
027 }
028
029 @SideOnly(Side.CLIENT)
030 public EntityEnderCrystal(World par1World, double par2, double par4, double par6)
031 {
032 this(par1World);
033 this.setPosition(par2, par4, par6);
034 }
035
036 /**
037 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
038 * prevent them from trampling crops
039 */
040 protected boolean canTriggerWalking()
041 {
042 return false;
043 }
044
045 protected void entityInit()
046 {
047 this.dataWatcher.addObject(8, Integer.valueOf(this.health));
048 }
049
050 /**
051 * Called to update the entity's position/logic.
052 */
053 public void onUpdate()
054 {
055 this.prevPosX = this.posX;
056 this.prevPosY = this.posY;
057 this.prevPosZ = this.posZ;
058 ++this.innerRotation;
059 this.dataWatcher.updateObject(8, Integer.valueOf(this.health));
060 int var1 = MathHelper.floor_double(this.posX);
061 int var2 = MathHelper.floor_double(this.posY);
062 int var3 = MathHelper.floor_double(this.posZ);
063
064 if (this.worldObj.getBlockId(var1, var2, var3) != Block.fire.blockID)
065 {
066 this.worldObj.setBlockWithNotify(var1, var2, var3, Block.fire.blockID);
067 }
068 }
069
070 /**
071 * (abstract) Protected helper method to write subclass entity data to NBT.
072 */
073 protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
074
075 /**
076 * (abstract) Protected helper method to read subclass entity data from NBT.
077 */
078 protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
079
080 @SideOnly(Side.CLIENT)
081 public float getShadowSize()
082 {
083 return 0.0F;
084 }
085
086 /**
087 * Returns true if other Entities should be prevented from moving through this Entity.
088 */
089 public boolean canBeCollidedWith()
090 {
091 return true;
092 }
093
094 /**
095 * Called when the entity is attacked.
096 */
097 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
098 {
099 if (this.isEntityInvulnerable())
100 {
101 return false;
102 }
103 else
104 {
105 if (!this.isDead && !this.worldObj.isRemote)
106 {
107 this.health = 0;
108
109 if (this.health <= 0)
110 {
111 this.setDead();
112
113 if (!this.worldObj.isRemote)
114 {
115 this.worldObj.createExplosion((Entity)null, this.posX, this.posY, this.posZ, 6.0F, true);
116 }
117 }
118 }
119
120 return true;
121 }
122 }
123 }