    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.Random;
    006import net.minecraft.block.material.Material;
    007import net.minecraft.client.renderer.texture.IconRegister;
    008import net.minecraft.world.World;
    009
    010public class BlockRedstoneLight extends Block
    011{
    012    /** Whether this lamp block is the powered version. */
    013    private final boolean powered;
    014
    015    public BlockRedstoneLight(int par1, boolean par2)
    016    {
    017        super(par1, Material.redstoneLight);
    018        this.powered = par2;
    019
    020        if (par2)
    021        {
    022            this.setLightValue(1.0F);
    023        }
    024    }
    025
    026    @SideOnly(Side.CLIENT)
    027
    028    /**
    029     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
    030     * is the only chance you get to register icons.
    031     */
    032    public void registerIcons(IconRegister par1IconRegister)
    033    {
    034        if (this.powered)
    035        {
    036            this.blockIcon = par1IconRegister.registerIcon("redstoneLight_lit");
    037        }
    038        else
    039        {
    040            this.blockIcon = par1IconRegister.registerIcon("redstoneLight");
    041        }
    042    }
    043
    044    /**
    045     * Called whenever the block is added into the world. Args: world, x, y, z
    046     */
    047    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    048    {
    049        if (!par1World.isRemote)
    050        {
    051            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    052            {
    053                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 4);
    054            }
    055            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    056            {
    057                par1World.setBlock(par2, par3, par4, Block.redstoneLampActive.blockID, 0, 2);
    058            }
    059        }
    060    }
    061
    062    /**
    063     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    064     * their own) Args: x, y, z, neighbor blockID
    065     */
    066    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    067    {
    068        if (!par1World.isRemote)
    069        {
    070            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    071            {
    072                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 4);
    073            }
    074            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    075            {
    076                par1World.setBlock(par2, par3, par4, Block.redstoneLampActive.blockID, 0, 2);
    077            }
    078        }
    079    }
    080
    081    /**
    082     * Ticks the block if it's been scheduled
    083     */
    084    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    085    {
    086        if (!par1World.isRemote && this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    087        {
    088            par1World.setBlock(par2, par3, par4, Block.redstoneLampIdle.blockID, 0, 2);
    089        }
    090    }
    091
    092    /**
    093     * Returns the ID of the items to drop on destruction.
    094     */
    095    public int idDropped(int par1, Random par2Random, int par3)
    096    {
    097        return Block.redstoneLampIdle.blockID;
    098    }
    099
    100    @SideOnly(Side.CLIENT)
    101
    102    /**
    103     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    104     */
    105    public int idPicked(World par1World, int par2, int par3, int par4)
    106    {
    107        return Block.redstoneLampIdle.blockID;
    108    }
    109}