001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import net.minecraft.block.material.Material; 006import net.minecraft.client.renderer.texture.IconRegister; 007import net.minecraft.creativetab.CreativeTabs; 008import net.minecraft.entity.EntityLiving; 009import net.minecraft.entity.monster.EntityIronGolem; 010import net.minecraft.entity.monster.EntitySnowman; 011import net.minecraft.item.ItemStack; 012import net.minecraft.util.Icon; 013import net.minecraft.util.MathHelper; 014import net.minecraft.world.World; 015 016public class BlockPumpkin extends BlockDirectional 017{ 018 /** Boolean used to seperate different states of blocks */ 019 private boolean blockType; 020 @SideOnly(Side.CLIENT) 021 private Icon field_94474_b; 022 @SideOnly(Side.CLIENT) 023 private Icon field_94475_c; 024 025 protected BlockPumpkin(int par1, boolean par2) 026 { 027 super(par1, Material.pumpkin); 028 this.setTickRandomly(true); 029 this.blockType = par2; 030 this.setCreativeTab(CreativeTabs.tabBlock); 031 } 032 033 @SideOnly(Side.CLIENT) 034 035 /** 036 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 037 */ 038 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 039 { 040 return par1 == 1 ? this.field_94474_b : (par1 == 0 ? this.field_94474_b : (par2 == 2 && par1 == 2 ? this.field_94475_c : (par2 == 3 && par1 == 5 ? this.field_94475_c : (par2 == 0 && par1 == 3 ? this.field_94475_c : (par2 == 1 && par1 == 4 ? this.field_94475_c : this.blockIcon))))); 041 } 042 043 /** 044 * Called whenever the block is added into the world. Args: world, x, y, z 045 */ 046 public void onBlockAdded(World par1World, int par2, int par3, int par4) 047 { 048 super.onBlockAdded(par1World, par2, par3, par4); 049 050 if (par1World.getBlockId(par2, par3 - 1, par4) == Block.blockSnow.blockID && par1World.getBlockId(par2, par3 - 2, par4) == Block.blockSnow.blockID) 051 { 052 if (!par1World.isRemote) 053 { 054 par1World.setBlock(par2, par3, par4, 0, 0, 2); 055 par1World.setBlock(par2, par3 - 1, par4, 0, 0, 2); 056 par1World.setBlock(par2, par3 - 2, par4, 0, 0, 2); 057 EntitySnowman entitysnowman = new EntitySnowman(par1World); 058 entitysnowman.setLocationAndAngles((double)par2 + 0.5D, (double)par3 - 1.95D, (double)par4 + 0.5D, 0.0F, 0.0F); 059 par1World.spawnEntityInWorld(entitysnowman); 060 par1World.notifyBlockChange(par2, par3, par4, 0); 061 par1World.notifyBlockChange(par2, par3 - 1, par4, 0); 062 par1World.notifyBlockChange(par2, par3 - 2, par4, 0); 063 } 064 065 for (int l = 0; l < 120; ++l) 066 { 067 par1World.spawnParticle("snowshovel", (double)par2 + par1World.rand.nextDouble(), (double)(par3 - 2) + par1World.rand.nextDouble() * 2.5D, (double)par4 + par1World.rand.nextDouble(), 0.0D, 0.0D, 0.0D); 068 } 069 } 070 else if (par1World.getBlockId(par2, par3 - 1, par4) == Block.blockSteel.blockID && par1World.getBlockId(par2, par3 - 2, par4) == Block.blockSteel.blockID) 071 { 072 boolean flag = par1World.getBlockId(par2 - 1, par3 - 1, par4) == Block.blockSteel.blockID && par1World.getBlockId(par2 + 1, par3 - 1, par4) == Block.blockSteel.blockID; 073 boolean flag1 = par1World.getBlockId(par2, par3 - 1, par4 - 1) == Block.blockSteel.blockID && par1World.getBlockId(par2, par3 - 1, par4 + 1) == Block.blockSteel.blockID; 074 075 if (flag || flag1) 076 { 077 par1World.setBlock(par2, par3, par4, 0, 0, 2); 078 par1World.setBlock(par2, par3 - 1, par4, 0, 0, 2); 079 par1World.setBlock(par2, par3 - 2, par4, 0, 0, 2); 080 081 if (flag) 082 { 083 par1World.setBlock(par2 - 1, par3 - 1, par4, 0, 0, 2); 084 par1World.setBlock(par2 + 1, par3 - 1, par4, 0, 0, 2); 085 } 086 else 087 { 088 par1World.setBlock(par2, par3 - 1, par4 - 1, 0, 0, 2); 089 par1World.setBlock(par2, par3 - 1, par4 + 1, 0, 0, 2); 090 } 091 092 EntityIronGolem entityirongolem = new EntityIronGolem(par1World); 093 entityirongolem.setPlayerCreated(true); 094 entityirongolem.setLocationAndAngles((double)par2 + 0.5D, (double)par3 - 1.95D, (double)par4 + 0.5D, 0.0F, 0.0F); 095 par1World.spawnEntityInWorld(entityirongolem); 096 097 for (int i1 = 0; i1 < 120; ++i1) 098 { 099 par1World.spawnParticle("snowballpoof", (double)par2 + par1World.rand.nextDouble(), (double)(par3 - 2) + par1World.rand.nextDouble() * 3.9D, (double)par4 + par1World.rand.nextDouble(), 0.0D, 0.0D, 0.0D); 100 } 101 102 par1World.notifyBlockChange(par2, par3, par4, 0); 103 par1World.notifyBlockChange(par2, par3 - 1, par4, 0); 104 par1World.notifyBlockChange(par2, par3 - 2, par4, 0); 105 106 if (flag) 107 { 108 par1World.notifyBlockChange(par2 - 1, par3 - 1, par4, 0); 109 par1World.notifyBlockChange(par2 + 1, par3 - 1, par4, 0); 110 } 111 else 112 { 113 par1World.notifyBlockChange(par2, par3 - 1, par4 - 1, 0); 114 par1World.notifyBlockChange(par2, par3 - 1, par4 + 1, 0); 115 } 116 } 117 } 118 } 119 120 /** 121 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 122 */ 123 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 124 { 125 int l = par1World.getBlockId(par2, par3, par4); 126 return (l == 0 || Block.blocksList[l].blockMaterial.isReplaceable()) && par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4); 127 } 128 129 /** 130 * Called when the block is placed in the world. 131 */ 132 public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack) 133 { 134 int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; 135 par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2); 136 } 137 138 @SideOnly(Side.CLIENT) 139 140 /** 141 * When this method is called, your block should register all the icons it needs with the given IconRegister. This 142 * is the only chance you get to register icons. 143 */ 144 public void registerIcons(IconRegister par1IconRegister) 145 { 146 this.field_94475_c = par1IconRegister.registerIcon(this.blockType ? "pumpkin_jack" : "pumpkin_face"); 147 this.field_94474_b = par1IconRegister.registerIcon("pumpkin_top"); 148 this.blockIcon = par1IconRegister.registerIcon("pumpkin_side"); 149 } 150}