    001package net.minecraft.block;
    002
    003import net.minecraft.block.material.Material;
    004import net.minecraft.creativetab.CreativeTabs;
    005import net.minecraft.entity.EntityLiving;
    006import net.minecraft.entity.monster.EntityIronGolem;
    007import net.minecraft.entity.monster.EntitySnowman;
    008import net.minecraft.util.MathHelper;
    009import net.minecraft.world.World;
    010
    011public class BlockPumpkin extends BlockDirectional
    012{
    013    /** Boolean used to seperate different states of blocks */
    014    private boolean blockType;
    015
    016    protected BlockPumpkin(int par1, int par2, boolean par3)
    017    {
    018        super(par1, Material.pumpkin);
    019        this.blockIndexInTexture = par2;
    020        this.setTickRandomly(true);
    021        this.blockType = par3;
    022        this.setCreativeTab(CreativeTabs.tabBlock);
    023    }
    024
    025    /**
    026     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    027     */
    028    public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    029    {
    030        if (par1 == 1)
    031        {
    032            return this.blockIndexInTexture;
    033        }
    034        else if (par1 == 0)
    035        {
    036            return this.blockIndexInTexture;
    037        }
    038        else
    039        {
    040            int var3 = this.blockIndexInTexture + 1 + 16;
    041
    042            if (this.blockType)
    043            {
    044                ++var3;
    045            }
    046
    047            return par2 == 2 && par1 == 2 ? var3 : (par2 == 3 && par1 == 5 ? var3 : (par2 == 0 && par1 == 3 ? var3 : (par2 == 1 && par1 == 4 ? var3 : this.blockIndexInTexture + 16)));
    048        }
    049    }
    050
    051    /**
    052     * Returns the block texture based on the side being looked at.  Args: side
    053     */
    054    public int getBlockTextureFromSide(int par1)
    055    {
    056        return par1 == 1 ? this.blockIndexInTexture : (par1 == 0 ? this.blockIndexInTexture : (par1 == 3 ? this.blockIndexInTexture + 1 + 16 : this.blockIndexInTexture + 16));
    057    }
    058
    059    /**
    060     * Called whenever the block is added into the world. Args: world, x, y, z
    061     */
    062    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    063    {
    064        super.onBlockAdded(par1World, par2, par3, par4);
    065
    066        if (par1World.getBlockId(par2, par3 - 1, par4) == Block.blockSnow.blockID && par1World.getBlockId(par2, par3 - 2, par4) == Block.blockSnow.blockID)
    067        {
    068            if (!par1World.isRemote)
    069            {
    070                par1World.setBlock(par2, par3, par4, 0);
    071                par1World.setBlock(par2, par3 - 1, par4, 0);
    072                par1World.setBlock(par2, par3 - 2, par4, 0);
    073                EntitySnowman var9 = new EntitySnowman(par1World);
    074                var9.setLocationAndAngles((double)par2 + 0.5D, (double)par3 - 1.95D, (double)par4 + 0.5D, 0.0F, 0.0F);
    075                par1World.spawnEntityInWorld(var9);
    076                par1World.notifyBlockChange(par2, par3, par4, 0);
    077                par1World.notifyBlockChange(par2, par3 - 1, par4, 0);
    078                par1World.notifyBlockChange(par2, par3 - 2, par4, 0);
    079            }
    080
    081            for (int var10 = 0; var10 < 120; ++var10)
    082            {
    083                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);
    084            }
    085        }
    086        else if (par1World.getBlockId(par2, par3 - 1, par4) == Block.blockSteel.blockID && par1World.getBlockId(par2, par3 - 2, par4) == Block.blockSteel.blockID)
    087        {
    088            boolean var5 = par1World.getBlockId(par2 - 1, par3 - 1, par4) == Block.blockSteel.blockID && par1World.getBlockId(par2 + 1, par3 - 1, par4) == Block.blockSteel.blockID;
    089            boolean var6 = par1World.getBlockId(par2, par3 - 1, par4 - 1) == Block.blockSteel.blockID && par1World.getBlockId(par2, par3 - 1, par4 + 1) == Block.blockSteel.blockID;
    090
    091            if (var5 || var6)
    092            {
    093                par1World.setBlock(par2, par3, par4, 0);
    094                par1World.setBlock(par2, par3 - 1, par4, 0);
    095                par1World.setBlock(par2, par3 - 2, par4, 0);
    096
    097                if (var5)
    098                {
    099                    par1World.setBlock(par2 - 1, par3 - 1, par4, 0);
    100                    par1World.setBlock(par2 + 1, par3 - 1, par4, 0);
    101                }
    102                else
    103                {
    104                    par1World.setBlock(par2, par3 - 1, par4 - 1, 0);
    105                    par1World.setBlock(par2, par3 - 1, par4 + 1, 0);
    106                }
    107
    108                EntityIronGolem var7 = new EntityIronGolem(par1World);
    109                var7.setPlayerCreated(true);
    110                var7.setLocationAndAngles((double)par2 + 0.5D, (double)par3 - 1.95D, (double)par4 + 0.5D, 0.0F, 0.0F);
    111                par1World.spawnEntityInWorld(var7);
    112
    113                for (int var8 = 0; var8 < 120; ++var8)
    114                {
    115                    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);
    116                }
    117
    118                par1World.notifyBlockChange(par2, par3, par4, 0);
    119                par1World.notifyBlockChange(par2, par3 - 1, par4, 0);
    120                par1World.notifyBlockChange(par2, par3 - 2, par4, 0);
    121
    122                if (var5)
    123                {
    124                    par1World.notifyBlockChange(par2 - 1, par3 - 1, par4, 0);
    125                    par1World.notifyBlockChange(par2 + 1, par3 - 1, par4, 0);
    126                }
    127                else
    128                {
    129                    par1World.notifyBlockChange(par2, par3 - 1, par4 - 1, 0);
    130                    par1World.notifyBlockChange(par2, par3 - 1, par4 + 1, 0);
    131                }
    132            }
    133        }
    134    }
    135
    136    /**
    137     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    138     */
    139    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    140    {
    141        int var5 = par1World.getBlockId(par2, par3, par4);
    142        return (var5 == 0 || Block.blocksList[var5].blockMaterial.isReplaceable()) && par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4);
    143    }
    144
    145    /**
    146     * Called when the block is placed in the world.
    147     */
    148    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
    149    {
    150        int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
    151        par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
    152    }
    153}