    001package net.minecraft.block;
    002
    003import java.util.Random;
    004import net.minecraft.block.material.Material;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.tileentity.TileEntity;
    007import net.minecraft.tileentity.TileEntityCommandBlock;
    008import net.minecraft.world.World;
    009
    010public class BlockCommandBlock extends BlockContainer
    011{
    012    public BlockCommandBlock(int par1)
    013    {
    014        super(par1, 184, Material.iron);
    015    }
    016
    017    /**
    018     * Returns a new instance of a block's tile entity class. Called on placing the block.
    019     */
    020    public TileEntity createNewTileEntity(World par1World)
    021    {
    022        return new TileEntityCommandBlock();
    023    }
    024
    025    /**
    026     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    027     * their own) Args: x, y, z, neighbor blockID
    028     */
    029    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    030    {
    031        if (!par1World.isRemote)
    032        {
    033            boolean var6 = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4);
    034            int var7 = par1World.getBlockMetadata(par2, par3, par4);
    035            boolean var8 = (var7 & 1) != 0;
    036
    037            if (var6 && !var8)
    038            {
    039                par1World.setBlockMetadata(par2, par3, par4, var7 | 1);
    040                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    041            }
    042            else if (!var6 && var8)
    043            {
    044                par1World.setBlockMetadata(par2, par3, par4, var7 & -2);
    045            }
    046        }
    047    }
    048
    049    /**
    050     * Ticks the block if it's been scheduled
    051     */
    052    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    053    {
    054        TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4);
    055
    056        if (var6 != null && var6 instanceof TileEntityCommandBlock)
    057        {
    058            ((TileEntityCommandBlock)var6).executeCommandOnPowered(par1World);
    059        }
    060    }
    061
    062    /**
    063     * How many world ticks before ticking
    064     */
    065    public int tickRate()
    066    {
    067        return 1;
    068    }
    069
    070    /**
    071     * Called upon block activation (right click on the block.)
    072     */
    073    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    074    {
    075        TileEntityCommandBlock var10 = (TileEntityCommandBlock)par1World.getBlockTileEntity(par2, par3, par4);
    076
    077        if (var10 != null)
    078        {
    079            par5EntityPlayer.displayGUIEditSign(var10);
    080        }
    081
    082        return true;
    083    }
    084}