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.item.Item;
008import net.minecraft.tileentity.TileEntity;
009import net.minecraft.util.AxisAlignedBB;
010import net.minecraft.world.IBlockAccess;
011import net.minecraft.world.World;
012
013public class BlockSign extends BlockContainer
014{
015    private Class signEntityClass;
016
017    /** Whether this is a freestanding sign or a wall-mounted sign */
018    private boolean isFreestanding;
019
020    protected BlockSign(int par1, Class par2Class, boolean par3)
021    {
022        super(par1, Material.wood);
023        this.isFreestanding = par3;
024        this.blockIndexInTexture = 4;
025        this.signEntityClass = par2Class;
026        float var4 = 0.25F;
027        float var5 = 1.0F;
028        this.setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var5, 0.5F + var4);
029    }
030
031    /**
032     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
033     * cleared to be reused)
034     */
035    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
036    {
037        return null;
038    }
039
040    @SideOnly(Side.CLIENT)
041
042    /**
043     * Returns the bounding box of the wired rectangular prism to render.
044     */
045    public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
046    {
047        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
048        return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
049    }
050
051    /**
052     * Updates the blocks bounds based on its current state. Args: world, x, y, z
053     */
054    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
055    {
056        if (!this.isFreestanding)
057        {
058            int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
059            float var6 = 0.28125F;
060            float var7 = 0.78125F;
061            float var8 = 0.0F;
062            float var9 = 1.0F;
063            float var10 = 0.125F;
064            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
065
066            if (var5 == 2)
067            {
068                this.setBlockBounds(var8, var6, 1.0F - var10, var9, var7, 1.0F);
069            }
070
071            if (var5 == 3)
072            {
073                this.setBlockBounds(var8, var6, 0.0F, var9, var7, var10);
074            }
075
076            if (var5 == 4)
077            {
078                this.setBlockBounds(1.0F - var10, var6, var8, 1.0F, var7, var9);
079            }
080
081            if (var5 == 5)
082            {
083                this.setBlockBounds(0.0F, var6, var8, var10, var7, var9);
084            }
085        }
086    }
087
088    /**
089     * The type of render function that is called for this block
090     */
091    public int getRenderType()
092    {
093        return -1;
094    }
095
096    /**
097     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
098     */
099    public boolean renderAsNormalBlock()
100    {
101        return false;
102    }
103
104    public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
105    {
106        return true;
107    }
108
109    /**
110     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
111     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
112     */
113    public boolean isOpaqueCube()
114    {
115        return false;
116    }
117
118    /**
119     * Returns a new instance of a block's tile entity class. Called on placing the block.
120     */
121    public TileEntity createNewTileEntity(World par1World)
122    {
123        try
124        {
125            return (TileEntity)this.signEntityClass.newInstance();
126        }
127        catch (Exception var3)
128        {
129            throw new RuntimeException(var3);
130        }
131    }
132
133    /**
134     * Returns the ID of the items to drop on destruction.
135     */
136    public int idDropped(int par1, Random par2Random, int par3)
137    {
138        return Item.sign.itemID;
139    }
140
141    /**
142     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
143     * their own) Args: x, y, z, neighbor blockID
144     */
145    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
146    {
147        boolean var6 = false;
148
149        if (this.isFreestanding)
150        {
151            if (!par1World.getBlockMaterial(par2, par3 - 1, par4).isSolid())
152            {
153                var6 = true;
154            }
155        }
156        else
157        {
158            int var7 = par1World.getBlockMetadata(par2, par3, par4);
159            var6 = true;
160
161            if (var7 == 2 && par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
162            {
163                var6 = false;
164            }
165
166            if (var7 == 3 && par1World.getBlockMaterial(par2, par3, par4 - 1).isSolid())
167            {
168                var6 = false;
169            }
170
171            if (var7 == 4 && par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
172            {
173                var6 = false;
174            }
175
176            if (var7 == 5 && par1World.getBlockMaterial(par2 - 1, par3, par4).isSolid())
177            {
178                var6 = false;
179            }
180        }
181
182        if (var6)
183        {
184            this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
185            par1World.setBlockWithNotify(par2, par3, par4, 0);
186        }
187
188        super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
189    }
190
191    @SideOnly(Side.CLIENT)
192
193    /**
194     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
195     */
196    public int idPicked(World par1World, int par2, int par3, int par4)
197    {
198        return Item.sign.itemID;
199    }
200}