    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        public int func_85104_a(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    081        {
    082            int var10 = par9;
    083
    084            if (par5 == 1 && this.canPlaceTorchOn(par1World, par2, par3 - 1, par4))
    085            {
    086                var10 = 5;
    087            }
    088
    089            if (par5 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
    090            {
    091                var10 = 4;
    092            }
    093
    094            if (par5 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
    095            {
    096                var10 = 3;
    097            }
    098
    099            if (par5 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
    100            {
    101                var10 = 2;
    102            }
    103
    104            if (par5 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
    105            {
    106                var10 = 1;
    107            }
    108
    109            return var10;
    110        }
    111
    112        /**
    113         * Ticks the block if it's been scheduled
    114         */
    115        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    116        {
    117            super.updateTick(par1World, par2, par3, par4, par5Random);
    118
    119            if (par1World.getBlockMetadata(par2, par3, par4) == 0)
    120            {
    121                this.onBlockAdded(par1World, par2, par3, par4);
    122            }
    123        }
    124
    125        /**
    126         * Called whenever the block is added into the world. Args: world, x, y, z
    127         */
    128        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    129        {
    130            if (par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
    131            {
    132                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
    133            }
    134            else if (par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
    135            {
    136                par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
    137            }
    138            else if (par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
    139            {
    140                par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
    141            }
    142            else if (par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
    143            {
    144                par1World.setBlockMetadataWithNotify(par2, par3, par4, 4);
    145            }
    146            else if (this.canPlaceTorchOn(par1World, par2, par3 - 1, par4))
    147            {
    148                par1World.setBlockMetadataWithNotify(par2, par3, par4, 5);
    149            }
    150
    151            this.dropTorchIfCantStay(par1World, par2, par3, par4);
    152        }
    153
    154        /**
    155         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    156         * their own) Args: x, y, z, neighbor blockID
    157         */
    158        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    159        {
    160            if (this.dropTorchIfCantStay(par1World, par2, par3, par4))
    161            {
    162                int var6 = par1World.getBlockMetadata(par2, par3, par4);
    163                boolean var7 = false;
    164
    165                if (!par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true) && var6 == 1)
    166                {
    167                    var7 = true;
    168                }
    169
    170                if (!par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true) && var6 == 2)
    171                {
    172                    var7 = true;
    173                }
    174
    175                if (!par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true) && var6 == 3)
    176                {
    177                    var7 = true;
    178                }
    179
    180                if (!par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true) && var6 == 4)
    181                {
    182                    var7 = true;
    183                }
    184
    185                if (!this.canPlaceTorchOn(par1World, par2, par3 - 1, par4) && var6 == 5)
    186                {
    187                    var7 = true;
    188                }
    189
    190                if (var7)
    191                {
    192                    this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    193                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    194                }
    195            }
    196        }
    197
    198        /**
    199         * Tests if the block can remain at its current location and will drop as an item if it is unable to stay. Returns
    200         * True if it can stay and False if it drops. Args: world, x, y, z
    201         */
    202        private boolean dropTorchIfCantStay(World par1World, int par2, int par3, int par4)
    203        {
    204            if (!this.canPlaceBlockAt(par1World, par2, par3, par4))
    205            {
    206                if (par1World.getBlockId(par2, par3, par4) == this.blockID)
    207                {
    208                    this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    209                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    210                }
    211
    212                return false;
    213            }
    214            else
    215            {
    216                return true;
    217            }
    218        }
    219
    220        /**
    221         * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world,
    222         * x, y, z, startVec, endVec
    223         */
    224        public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3)
    225        {
    226            int var7 = par1World.getBlockMetadata(par2, par3, par4) & 7;
    227            float var8 = 0.15F;
    228
    229            if (var7 == 1)
    230            {
    231                this.setBlockBounds(0.0F, 0.2F, 0.5F - var8, var8 * 2.0F, 0.8F, 0.5F + var8);
    232            }
    233            else if (var7 == 2)
    234            {
    235                this.setBlockBounds(1.0F - var8 * 2.0F, 0.2F, 0.5F - var8, 1.0F, 0.8F, 0.5F + var8);
    236            }
    237            else if (var7 == 3)
    238            {
    239                this.setBlockBounds(0.5F - var8, 0.2F, 0.0F, 0.5F + var8, 0.8F, var8 * 2.0F);
    240            }
    241            else if (var7 == 4)
    242            {
    243                this.setBlockBounds(0.5F - var8, 0.2F, 1.0F - var8 * 2.0F, 0.5F + var8, 0.8F, 1.0F);
    244            }
    245            else
    246            {
    247                var8 = 0.1F;
    248                this.setBlockBounds(0.5F - var8, 0.0F, 0.5F - var8, 0.5F + var8, 0.6F, 0.5F + var8);
    249            }
    250
    251            return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3);
    252        }
    253
    254        @SideOnly(Side.CLIENT)
    255
    256        /**
    257         * A randomly called display update to be able to add particles or other items for display
    258         */
    259        public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    260        {
    261            int var6 = par1World.getBlockMetadata(par2, par3, par4);
    262            double var7 = (double)((float)par2 + 0.5F);
    263            double var9 = (double)((float)par3 + 0.7F);
    264            double var11 = (double)((float)par4 + 0.5F);
    265            double var13 = 0.2199999988079071D;
    266            double var15 = 0.27000001072883606D;
    267
    268            if (var6 == 1)
    269            {
    270                par1World.spawnParticle("smoke", var7 - var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    271                par1World.spawnParticle("flame", var7 - var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    272            }
    273            else if (var6 == 2)
    274            {
    275                par1World.spawnParticle("smoke", var7 + var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    276                par1World.spawnParticle("flame", var7 + var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
    277            }
    278            else if (var6 == 3)
    279            {
    280                par1World.spawnParticle("smoke", var7, var9 + var13, var11 - var15, 0.0D, 0.0D, 0.0D);
    281                par1World.spawnParticle("flame", var7, var9 + var13, var11 - var15, 0.0D, 0.0D, 0.0D);
    282            }
    283            else if (var6 == 4)
    284            {
    285                par1World.spawnParticle("smoke", var7, var9 + var13, var11 + var15, 0.0D, 0.0D, 0.0D);
    286                par1World.spawnParticle("flame", var7, var9 + var13, var11 + var15, 0.0D, 0.0D, 0.0D);
    287            }
    288            else
    289            {
    290                par1World.spawnParticle("smoke", var7, var9, var11, 0.0D, 0.0D, 0.0D);
    291                par1World.spawnParticle("flame", var7, var9, var11, 0.0D, 0.0D, 0.0D);
    292            }
    293        }
    294    }