    001package net.minecraft.block;
    002
    003import java.util.Random;
    004import net.minecraft.block.material.Material;
    005import net.minecraft.entity.EntityLiving;
    006import net.minecraft.entity.player.EntityPlayer;
    007import net.minecraft.item.ItemStack;
    008import net.minecraft.tileentity.TileEntity;
    009import net.minecraft.tileentity.TileEntityCommandBlock;
    010import net.minecraft.world.World;
    011
    012public class BlockCommandBlock extends BlockContainer
    013{
    014    public BlockCommandBlock(int par1)
    015    {
    016        super(par1, Material.iron);
    017    }
    018
    019    /**
    020     * Returns a new instance of a block's tile entity class. Called on placing the block.
    021     */
    022    public TileEntity createNewTileEntity(World par1World)
    023    {
    024        return new TileEntityCommandBlock();
    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        if (!par1World.isRemote)
    034        {
    035            boolean flag = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4);
    036            int i1 = par1World.getBlockMetadata(par2, par3, par4);
    037            boolean flag1 = (i1 & 1) != 0;
    038
    039            if (flag && !flag1)
    040            {
    041                par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 | 1, 4);
    042                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));
    043            }
    044            else if (!flag && flag1)
    045            {
    046                par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 & -2, 4);
    047            }
    048        }
    049    }
    050
    051    /**
    052     * Ticks the block if it's been scheduled
    053     */
    054    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    055    {
    056        TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
    057
    058        if (tileentity != null && tileentity instanceof TileEntityCommandBlock)
    059        {
    060            TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
    061            tileentitycommandblock.func_96102_a(tileentitycommandblock.executeCommandOnPowered(par1World));
    062            par1World.func_96440_m(par2, par3, par4, this.blockID);
    063        }
    064    }
    065
    066    /**
    067     * How many world ticks before ticking
    068     */
    069    public int tickRate(World par1World)
    070    {
    071        return 1;
    072    }
    073
    074    /**
    075     * Called upon block activation (right click on the block.)
    076     */
    077    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    078    {
    079        TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)par1World.getBlockTileEntity(par2, par3, par4);
    080
    081        if (tileentitycommandblock != null)
    082        {
    083            par5EntityPlayer.displayGUIEditSign(tileentitycommandblock);
    084        }
    085
    086        return true;
    087    }
    088
    089    /**
    090     * If this returns true, then comparators facing away from this block will use the value from
    091     * getComparatorInputOverride instead of the actual redstone signal strength.
    092     */
    093    public boolean hasComparatorInputOverride()
    094    {
    095        return true;
    096    }
    097
    098    /**
    099     * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
    100     * strength when this block inputs to a comparator.
    101     */
    102    public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
    103    {
    104        TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
    105        return tileentity != null && tileentity instanceof TileEntityCommandBlock ? ((TileEntityCommandBlock)tileentity).func_96103_d() : 0;
    106    }
    107
    108    /**
    109     * Called when the block is placed in the world.
    110     */
    111    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
    112    {
    113        TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)par1World.getBlockTileEntity(par2, par3, par4);
    114
    115        if (par6ItemStack.hasDisplayName())
    116        {
    117            tileentitycommandblock.func_96104_c(par6ItemStack.getDisplayName());
    118        }
    119    }
    120}