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 EntityFallingSand extends Entity
007 {
008 public int blockID;
009 public int field_70285_b;
010
011 /** How long the block has been falling for. */
012 public int fallTime;
013 public boolean field_70284_d;
014
015 public EntityFallingSand(World par1World)
016 {
017 super(par1World);
018 this.fallTime = 0;
019 this.field_70284_d = true;
020 }
021
022 public EntityFallingSand(World par1World, double par2, double par4, double par6, int par8)
023 {
024 this(par1World, par2, par4, par6, par8, 0);
025 }
026
027 public EntityFallingSand(World par1World, double par2, double par4, double par6, int par8, int par9)
028 {
029 super(par1World);
030 this.fallTime = 0;
031 this.field_70284_d = true;
032 this.blockID = par8;
033 this.field_70285_b = par9;
034 this.preventEntitySpawning = true;
035 this.setSize(0.98F, 0.98F);
036 this.yOffset = this.height / 2.0F;
037 this.setPosition(par2, par4, par6);
038 this.motionX = 0.0D;
039 this.motionY = 0.0D;
040 this.motionZ = 0.0D;
041 this.prevPosX = par2;
042 this.prevPosY = par4;
043 this.prevPosZ = par6;
044 }
045
046 /**
047 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
048 * prevent them from trampling crops
049 */
050 protected boolean canTriggerWalking()
051 {
052 return false;
053 }
054
055 protected void entityInit() {}
056
057 /**
058 * Returns true if other Entities should be prevented from moving through this Entity.
059 */
060 public boolean canBeCollidedWith()
061 {
062 return !this.isDead;
063 }
064
065 /**
066 * Called to update the entity's position/logic.
067 */
068 public void onUpdate()
069 {
070 if (this.blockID == 0)
071 {
072 this.setDead();
073 }
074 else
075 {
076 this.prevPosX = this.posX;
077 this.prevPosY = this.posY;
078 this.prevPosZ = this.posZ;
079 ++this.fallTime;
080 this.motionY -= 0.03999999910593033D;
081 this.moveEntity(this.motionX, this.motionY, this.motionZ);
082 this.motionX *= 0.9800000190734863D;
083 this.motionY *= 0.9800000190734863D;
084 this.motionZ *= 0.9800000190734863D;
085
086 if (!this.worldObj.isRemote)
087 {
088 int var1 = MathHelper.floor_double(this.posX);
089 int var2 = MathHelper.floor_double(this.posY);
090 int var3 = MathHelper.floor_double(this.posZ);
091
092 if (this.fallTime == 1)
093 {
094 if (this.fallTime == 1 && this.worldObj.getBlockId(var1, var2, var3) == this.blockID)
095 {
096 this.worldObj.setBlockWithNotify(var1, var2, var3, 0);
097 }
098 else
099 {
100 this.setDead();
101 }
102 }
103
104 if (this.onGround)
105 {
106 this.motionX *= 0.699999988079071D;
107 this.motionZ *= 0.699999988079071D;
108 this.motionY *= -0.5D;
109
110 if (this.worldObj.getBlockId(var1, var2, var3) != Block.pistonMoving.blockID)
111 {
112 this.setDead();
113
114 if ((!this.worldObj.canPlaceEntityOnSide(this.blockID, var1, var2, var3, true, 1, (Entity)null) || BlockSand.canFallBelow(this.worldObj, var1, var2 - 1, var3) || !this.worldObj.setBlockAndMetadataWithNotify(var1, var2, var3, this.blockID, this.field_70285_b)) && !this.worldObj.isRemote && this.field_70284_d)
115 {
116 this.entityDropItem(new ItemStack(this.blockID, 1, this.field_70285_b), 0.0F);
117 }
118 }
119 }
120 else if (this.fallTime > 100 && !this.worldObj.isRemote && (var2 < 1 || var2 > 256) || this.fallTime > 600)
121 {
122 if (this.field_70284_d)
123 {
124 this.dropItem(this.blockID, 1);
125 }
126
127 this.setDead();
128 }
129 }
130 }
131 }
132
133 /**
134 * (abstract) Protected helper method to write subclass entity data to NBT.
135 */
136 protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
137 {
138 par1NBTTagCompound.setByte("Tile", (byte)this.blockID);
139 par1NBTTagCompound.setByte("Data", (byte)this.field_70285_b);
140 par1NBTTagCompound.setByte("Time", (byte)this.fallTime);
141 par1NBTTagCompound.setBoolean("DropItem", this.field_70284_d);
142 }
143
144 /**
145 * (abstract) Protected helper method to read subclass entity data from NBT.
146 */
147 protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
148 {
149 this.blockID = par1NBTTagCompound.getByte("Tile") & 255;
150 this.field_70285_b = par1NBTTagCompound.getByte("Data") & 255;
151 this.fallTime = par1NBTTagCompound.getByte("Time") & 255;
152
153 if (par1NBTTagCompound.hasKey("DropItem"))
154 {
155 this.field_70284_d = par1NBTTagCompound.getBoolean("DropItem");
156 }
157
158 if (this.blockID == 0)
159 {
160 this.blockID = Block.sand.blockID;
161 }
162 }
163
164 @SideOnly(Side.CLIENT)
165 public float getShadowSize()
166 {
167 return 0.0F;
168 }
169
170 @SideOnly(Side.CLIENT)
171 public World getWorld()
172 {
173 return this.worldObj;
174 }
175 }