    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.Random;
    006    import net.minecraftforge.common.ForgeDirection;
    007    import static net.minecraftforge.common.ForgeDirection.*;
    008
    009    public class BlockTorch extends Block
    010    {
    011        protected BlockTorch(int par1, int par2)
    012        {
    013            super(par1, par2, Material.circuits);
    014            this.setTickRandomly(true);
    015            this.setCreativeTab(CreativeTabs.tabDecorations);
    016        }
    017
    018        /**
    019         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    020         * cleared to be reused)
    021         */
    022        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    023        {
    024            return null;
    025        }
    026
    027        /**
    028         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    029         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    030         */
    031        public boolean isOpaqueCube()
    032        {
    033            return false;
    034        }
    035
    036        /**
    037         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    038         */
    039        public boolean renderAsNormalBlock()
    040        {
    041            return false;
    042        }
    043
    044        /**
    045         * The type of render function that is called for this block
    046         */
    047        public int getRenderType()
    048        {
    049            return 2;
    050        }
    051
    052        /**
    053         * Gets if we can place a torch on a block.
    054         */
    055        private boolean canPlaceTorchOn(World par1World, int par2, int par3, int par4)
    056        {
    057            if (par1World.doesBlockHaveSolidTopSurface(par2, par3, par4))
    058            {
    059                return true;
    060            }
    061            else
    062            {
    063                int var5 = par1World.getBlockId(par2, par3, par4);
    064                return (Block.blocksList[var5] != null && Block.blocksList[var5].canPlaceTorchOnTop(par1World, par2, par3, par4));
    065            }
    066        }
    067
    068        /**
    069         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    070         */
    071        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    072        {
    073            return par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST,  true) ||
    074                   par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST,  true) ||
    075                   par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true) ||
    076                   par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true) ||
    077                   canPlaceTorchOn(par1World, par2, par3 - 1, par4);
    078        }
    079
    080        /**
    081         * called before onBlockPlacedBy by ItemBlock and ItemReed
    082         */
    083        public void updateBlockMetadata(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8)
    084        {
    085            int var9 = par1World.getBlockMetadata(par2, par3, par4);
    086
    087            if (par5 == 1 && this.canPlaceTorchOn(par1World, par2, par3 - 1, par4))
    088            {
    089                var9 = 5;
    090            }
    091
    092            if (par5 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
    093            {
    094                var9 = 4;
    095            }
    096
    097            if (par5 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
    098            {
    099                var9 = 3;
    100            }
    101
    102            if (par5 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
    103            {
    104                var9 = 2;
    105            }
    106
    107            if (par5 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
    108            {
    109                var9 = 1;
    110            }
    111
    112            par1World.setBlockMetadataWithNotify(par2, par3, par4, var9);
    113        }
    114
    115        /**
    116         * Ticks the block if it's been scheduled
    117         */
    118        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    119        {
    120            super.updateTick(par1World, par2, par3, par4, par5Random);
    121
    122            if (par1World.getBlockMetadata(par2, par3, par4) == 0)
    123            {
    124                this.onBlockAdded(par1World, par2, par3, par4);
    125            }
    126        }
    127
    128        /**
    129         * Called whenever the block is added into the world. Args: world, x, y, z
    130         */
    131        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    132        {
    133            if (par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
    134            {
    135                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
    136            }
    137            else if (par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
    138            {
    139                par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
    140            }
    141            else if (par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
    142            {
    143                par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
    144            }
    145            else if (par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
    146            {
    147                par1World.setBlockMetadataWithNotify(par2, par3, par4, 4);
    148            }
    149            else if (this.canPlaceTorchOn(par1World, par2, par3 - 1, par4))
    150            {
    151                par1World.setBlockMetadataWithNotify(par2, par3, par4, 5);
    152            }
    153
    154            this.dropTorchIfCantStay(par1World, par2, par3, par4);
    155        }
    156
    157        /**
    158         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    159         * their own) Args: x, y, z, neighbor blockID
    160         */
    161        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    162        {
    163            if (this.dropTorchIfCantStay(par1World, par2, par3, par4))
    164            {
    165                int var6 = par1World.getBlockMetadata(par2, par3, par4);
    166                boolean var7 = false;
    167
    168                if (!par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true) && var6 == 1)
    169                {
    170                    var7 = true;
    171                }
    172
    173                if (!par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true) && var6 == 2)
    174                {
    175                    var7 = true;
    176                }
    177
    178                if (!par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true) && var6 == 3)
    179                {
    180                    var7 = true;
    181                }
    182
    183                if (!par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true) && var6 == 4)
    184                {
    185                    var7 = true;
    186                }
    187
    188                if (!this.canPlaceTorchOn(par1World, par2, par3 - 1, par4) && var6 == 5)
    189                {
    190                    var7 = true;
    191                }
    192
    193                if (var7)
    194                {
    195                    this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    196                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    197                }
    198            }
    199        }
    200
    201        /**
    202         * Tests if the block can remain at its current location and will drop as an item if it is unable to stay. Returns
    203         * True if it can stay and False if it drops. Args: world, x, y, z
    204         */
    205        private boolean dropTorchIfCantStay(World par1World, int par2, int par3, int par4)
    206        {
    207            if (!this.canPlaceBlockAt(par1World, par2, par3, par4))
    208            {
    209                if (par1World.getBlockId(par2, par3, par4) == this.blockID)
    210                {
    211                    this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    212                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    213                }
    214
    215                return false;
    216            }
    217            else
    218            {
    219                return true;
    220            }
    221        }
    222
    223        /**
    224         * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world,
    225         * x, y, z, startVec, endVec
    226         */
    227        public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3)
    228        {
    229            int var7 = par1World.getBlockMetadata(par2, par3, par4) & 7;
    230            float var8 = 0.15F;
    231
    232            if (var7 == 1)
    233            {
    234                this.setBlockBounds(0.0F, 0.2F, 0.5F - var8, var8 * 2.0F, 0.8F, 0.5F + var8);
    235            }
    236            else if (var7 == 2)
    237            {
    238                this.setBlockBounds(1.0F - var8 * 2.0F, 0.2F, 0.5F - var8, 1.0F, 0.8F, 0.5F + var8);
    239            }
    240            else if (var7 == 3)
    241            {
    242                this.setBlockBounds(0.5F - var8, 0.2F, 0.0F, 0.5F + var8, 0.8F, var8 * 2.0F);
    243            }
    244            else if (var7 == 4)
    245            {
    246                this.setBlockBounds(0.5F - var8, 0.2F, 1.0F - var8 * 2.0F, 0.5F + var8, 0.8F, 1.0F);
    247            }
    248            else
    249            {
    250                var8 = 0.1F;
    251                this.setBlockBounds(0.5F - var8, 0.0F, 0.5F - var8, 0.5F + var8, 0.6F, 0.5F + var8);
    252            }
    253
    254            return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3);
    255        }
    256
    257        @SideOnly(Side.CLIENT)
    258
    259        /**
    260         * A randomly called display update to be able to add particles or other items for display
    261         */
    262        public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    263        {
    264            int var6 = par1World.getBlockMetadata(par2, par3, par4);
    265            double var7 = (double)((float)par2 + 0.5F);
    266            double var9 = (double)((float)par3 + 0.7F);
    267            double var11 = (double)((float)par4 + 0.5F);
    268            double var13 = 0.2199999988079071D;
    269            double var15 = 0.27000001072883606D;
    270
    271            if (var6 == 1)
    272            {
    273                par1World.spawnParticle("smoke", var7 - var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    274                par1World.spawnParticle("flame", var7 - var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    275            }
    276            else if (var6 == 2)
    277            {
    278                par1World.spawnParticle("smoke", var7 + var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    279                par1World.spawnParticle("flame", var7 + var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    280            }
    281            else if (var6 == 3)
    282            {
    283                par1World.spawnParticle("smoke", var7, var9 + var13, var11 - var15, 0.0D, 0.0D, 0.0D);
    284                par1World.spawnParticle("flame", var7, var9 + var13, var11 - var15, 0.0D, 0.0D, 0.0D);
    285            }
    286            else if (var6 == 4)
    287            {
    288                par1World.spawnParticle("smoke", var7, var9 + var13, var11 + var15, 0.0D, 0.0D, 0.0D);
    289                par1World.spawnParticle("flame", var7, var9 + var13, var11 + var15, 0.0D, 0.0D, 0.0D);
    290            }
    291            else
    292            {
    293                par1World.spawnParticle("smoke", var7, var9, var11, 0.0D, 0.0D, 0.0D);
    294                par1World.spawnParticle("flame", var7, var9, var11, 0.0D, 0.0D, 0.0D);
    295            }
    296        }
    297    }