001 package net.minecraft.src;
002
003 import java.util.List;
004 import java.util.Random;
005
006 public class BlockPressurePlate extends Block
007 {
008 /** The mob type that can trigger this pressure plate. */
009 private EnumMobType triggerMobType;
010
011 protected BlockPressurePlate(int par1, int par2, EnumMobType par3EnumMobType, Material par4Material)
012 {
013 super(par1, par2, par4Material);
014 this.triggerMobType = par3EnumMobType;
015 this.setCreativeTab(CreativeTabs.tabRedstone);
016 this.setTickRandomly(true);
017 float var5 = 0.0625F;
018 this.setBlockBounds(var5, 0.0F, var5, 1.0F - var5, 0.03125F, 1.0F - var5);
019 }
020
021 /**
022 * How many world ticks before ticking
023 */
024 public int tickRate()
025 {
026 return 20;
027 }
028
029 /**
030 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
031 * cleared to be reused)
032 */
033 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
034 {
035 return null;
036 }
037
038 /**
039 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
040 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
041 */
042 public boolean isOpaqueCube()
043 {
044 return false;
045 }
046
047 /**
048 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
049 */
050 public boolean renderAsNormalBlock()
051 {
052 return false;
053 }
054
055 public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
056 {
057 return true;
058 }
059
060 /**
061 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
062 */
063 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
064 {
065 return par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) || BlockFence.isIdAFence(par1World.getBlockId(par2, par3 - 1, par4));
066 }
067
068 /**
069 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
070 * their own) Args: x, y, z, neighbor blockID
071 */
072 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
073 {
074 boolean var6 = false;
075
076 if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && !BlockFence.isIdAFence(par1World.getBlockId(par2, par3 - 1, par4)))
077 {
078 var6 = true;
079 }
080
081 if (var6)
082 {
083 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
084 par1World.setBlockWithNotify(par2, par3, par4, 0);
085 }
086 }
087
088 /**
089 * Ticks the block if it's been scheduled
090 */
091 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
092 {
093 if (!par1World.isRemote)
094 {
095 if (par1World.getBlockMetadata(par2, par3, par4) != 0)
096 {
097 this.setStateIfMobInteractsWithPlate(par1World, par2, par3, par4);
098 }
099 }
100 }
101
102 /**
103 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
104 */
105 public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
106 {
107 if (!par1World.isRemote)
108 {
109 if (par1World.getBlockMetadata(par2, par3, par4) != 1)
110 {
111 this.setStateIfMobInteractsWithPlate(par1World, par2, par3, par4);
112 }
113 }
114 }
115
116 /**
117 * Checks if there are mobs on the plate. If a mob is on the plate and it is off, it turns it on, and vice versa.
118 */
119 private void setStateIfMobInteractsWithPlate(World par1World, int par2, int par3, int par4)
120 {
121 boolean var5 = par1World.getBlockMetadata(par2, par3, par4) == 1;
122 boolean var6 = false;
123 float var7 = 0.125F;
124 List var8 = null;
125
126 if (this.triggerMobType == EnumMobType.everything)
127 {
128 var8 = par1World.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var7), (double)((float)(par2 + 1) - var7), (double)par3 + 0.25D, (double)((float)(par4 + 1) - var7)));
129 }
130
131 if (this.triggerMobType == EnumMobType.mobs)
132 {
133 var8 = par1World.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var7), (double)((float)(par2 + 1) - var7), (double)par3 + 0.25D, (double)((float)(par4 + 1) - var7)));
134 }
135
136 if (this.triggerMobType == EnumMobType.players)
137 {
138 var8 = par1World.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var7), (double)((float)(par2 + 1) - var7), (double)par3 + 0.25D, (double)((float)(par4 + 1) - var7)));
139 }
140
141 if (!var8.isEmpty())
142 {
143 var6 = true;
144 }
145
146 if (var6 && !var5)
147 {
148 par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
149 par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
150 par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
151 par1World.markBlocksDirty(par2, par3, par4, par2, par3, par4);
152 par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.1D, (double)par4 + 0.5D, "random.click", 0.3F, 0.6F);
153 }
154
155 if (!var6 && var5)
156 {
157 par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
158 par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
159 par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
160 par1World.markBlocksDirty(par2, par3, par4, par2, par3, par4);
161 par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.1D, (double)par4 + 0.5D, "random.click", 0.3F, 0.5F);
162 }
163
164 if (var6)
165 {
166 par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
167 }
168 }
169
170 /**
171 * ejects contained items into the world, and notifies neighbours of an update, as appropriate
172 */
173 public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
174 {
175 if (par6 > 0)
176 {
177 par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
178 par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
179 }
180
181 super.breakBlock(par1World, par2, par3, par4, par5, par6);
182 }
183
184 /**
185 * Updates the blocks bounds based on its current state. Args: world, x, y, z
186 */
187 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
188 {
189 boolean var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 1;
190 float var6 = 0.0625F;
191
192 if (var5)
193 {
194 this.setBlockBounds(var6, 0.0F, var6, 1.0F - var6, 0.03125F, 1.0F - var6);
195 }
196 else
197 {
198 this.setBlockBounds(var6, 0.0F, var6, 1.0F - var6, 0.0625F, 1.0F - var6);
199 }
200 }
201
202 /**
203 * Is this block powering the block on the specified side
204 */
205 public boolean isPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
206 {
207 return par1IBlockAccess.getBlockMetadata(par2, par3, par4) > 0;
208 }
209
210 /**
211 * Is this block indirectly powering the block on the specified side
212 */
213 public boolean isIndirectlyPoweringTo(World par1World, int par2, int par3, int par4, int par5)
214 {
215 return par1World.getBlockMetadata(par2, par3, par4) == 0 ? false : par5 == 1;
216 }
217
218 /**
219 * Can this block provide power. Only wire currently seems to have this change based on its state.
220 */
221 public boolean canProvidePower()
222 {
223 return true;
224 }
225
226 /**
227 * Sets the block's bounds for rendering it as an item
228 */
229 public void setBlockBoundsForItemRender()
230 {
231 float var1 = 0.5F;
232 float var2 = 0.125F;
233 float var3 = 0.5F;
234 this.setBlockBounds(0.5F - var1, 0.5F - var2, 0.5F - var3, 0.5F + var1, 0.5F + var2, 0.5F + var3);
235 }
236
237 /**
238 * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
239 * and stop pistons
240 */
241 public int getMobilityFlag()
242 {
243 return 1;
244 }
245 }