001 package net.minecraft.block; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.util.Random; 006 import net.minecraft.block.material.Material; 007 import net.minecraft.entity.item.EntityFallingSand; 008 import net.minecraft.entity.player.EntityPlayer; 009 import net.minecraft.world.IBlockAccess; 010 import net.minecraft.world.World; 011 012 public class BlockDragonEgg extends Block 013 { 014 public BlockDragonEgg(int par1, int par2) 015 { 016 super(par1, par2, Material.dragonEgg); 017 } 018 019 /** 020 * Called whenever the block is added into the world. Args: world, x, y, z 021 */ 022 public void onBlockAdded(World par1World, int par2, int par3, int par4) 023 { 024 par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate()); 025 } 026 027 /** 028 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 029 * their own) Args: x, y, z, neighbor blockID 030 */ 031 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 032 { 033 par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate()); 034 } 035 036 /** 037 * Ticks the block if it's been scheduled 038 */ 039 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 040 { 041 this.fallIfPossible(par1World, par2, par3, par4); 042 } 043 044 /** 045 * Checks if the dragon egg can fall down, and if so, makes it fall. 046 */ 047 private void fallIfPossible(World par1World, int par2, int par3, int par4) 048 { 049 if (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0) 050 { 051 byte var5 = 32; 052 053 if (!BlockSand.fallInstantly && par1World.checkChunksExist(par2 - var5, par3 - var5, par4 - var5, par2 + var5, par3 + var5, par4 + var5)) 054 { 055 EntityFallingSand var6 = new EntityFallingSand(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), this.blockID); 056 par1World.spawnEntityInWorld(var6); 057 } 058 else 059 { 060 par1World.setBlockWithNotify(par2, par3, par4, 0); 061 062 while (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0) 063 { 064 --par3; 065 } 066 067 if (par3 > 0) 068 { 069 par1World.setBlockWithNotify(par2, par3, par4, this.blockID); 070 } 071 } 072 } 073 } 074 075 /** 076 * Called upon block activation (right click on the block.) 077 */ 078 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 079 { 080 this.teleportNearby(par1World, par2, par3, par4); 081 return true; 082 } 083 084 /** 085 * Called when the block is clicked by a player. Args: x, y, z, entityPlayer 086 */ 087 public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) 088 { 089 this.teleportNearby(par1World, par2, par3, par4); 090 } 091 092 /** 093 * Teleports the dragon egg somewhere else in a 31x19x31 area centered on the egg. 094 */ 095 private void teleportNearby(World par1World, int par2, int par3, int par4) 096 { 097 if (par1World.getBlockId(par2, par3, par4) == this.blockID) 098 { 099 for (int var5 = 0; var5 < 1000; ++var5) 100 { 101 int var6 = par2 + par1World.rand.nextInt(16) - par1World.rand.nextInt(16); 102 int var7 = par3 + par1World.rand.nextInt(8) - par1World.rand.nextInt(8); 103 int var8 = par4 + par1World.rand.nextInt(16) - par1World.rand.nextInt(16); 104 105 if (par1World.getBlockId(var6, var7, var8) == 0) 106 { 107 if (!par1World.isRemote) 108 { 109 par1World.setBlockAndMetadataWithNotify(var6, var7, var8, this.blockID, par1World.getBlockMetadata(par2, par3, par4)); 110 par1World.setBlockWithNotify(par2, par3, par4, 0); 111 } 112 else 113 { 114 short var9 = 128; 115 116 for (int var10 = 0; var10 < var9; ++var10) 117 { 118 double var11 = par1World.rand.nextDouble(); 119 float var13 = (par1World.rand.nextFloat() - 0.5F) * 0.2F; 120 float var14 = (par1World.rand.nextFloat() - 0.5F) * 0.2F; 121 float var15 = (par1World.rand.nextFloat() - 0.5F) * 0.2F; 122 double var16 = (double)var6 + (double)(par2 - var6) * var11 + (par1World.rand.nextDouble() - 0.5D) * 1.0D + 0.5D; 123 double var18 = (double)var7 + (double)(par3 - var7) * var11 + par1World.rand.nextDouble() * 1.0D - 0.5D; 124 double var20 = (double)var8 + (double)(par4 - var8) * var11 + (par1World.rand.nextDouble() - 0.5D) * 1.0D + 0.5D; 125 par1World.spawnParticle("portal", var16, var18, var20, (double)var13, (double)var14, (double)var15); 126 } 127 } 128 129 return; 130 } 131 } 132 } 133 } 134 135 /** 136 * How many world ticks before ticking 137 */ 138 public int tickRate() 139 { 140 return 5; 141 } 142 143 /** 144 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 145 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 146 */ 147 public boolean isOpaqueCube() 148 { 149 return false; 150 } 151 152 /** 153 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 154 */ 155 public boolean renderAsNormalBlock() 156 { 157 return false; 158 } 159 160 @SideOnly(Side.CLIENT) 161 162 /** 163 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 164 * coordinates. Args: blockAccess, x, y, z, side 165 */ 166 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 167 { 168 return true; 169 } 170 171 /** 172 * The type of render function that is called for this block 173 */ 174 public int getRenderType() 175 { 176 return 27; 177 } 178 179 @SideOnly(Side.CLIENT) 180 181 /** 182 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 183 */ 184 public int idPicked(World par1World, int par2, int par3, int par4) 185 { 186 return 0; 187 } 188 }