/// <summary>
        /// Updates the blocks bounds based on its current state. Args: world, x, y, z
        /// </summary>
        public override void SetBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
        {
            TileEntityPiston tileentitypiston = GetTileEntityAtLocation(par1IBlockAccess, par2, par3, par4);

            if (tileentitypiston != null)
            {
                Block block = Block.BlocksList[tileentitypiston.GetStoredBlockID()];

                if (block == null || block == this)
                {
                    return;
                }

                block.SetBlockBoundsBasedOnState(par1IBlockAccess, par2, par3, par4);
                float f = tileentitypiston.GetProgress(0.0F);

                if (tileentitypiston.IsExtending())
                {
                    f = 1.0F - f;
                }

                int i = tileentitypiston.GetPistonOrientation();
                MinX = block.MinX - (Facing.OffsetsXForSide[i] * f);
                MinY = block.MinY - (Facing.OffsetsYForSide[i] * f);
                MinZ = block.MinZ - (Facing.OffsetsZForSide[i] * f);
                MaxX = block.MaxX - (Facing.OffsetsXForSide[i] * f);
                MaxY = block.MaxY - (Facing.OffsetsYForSide[i] * f);
                MaxZ = block.MaxZ - (Facing.OffsetsZForSide[i] * f);
            }
        }
Exemplo n.º 2
0
        public virtual void RenderPiston(TileEntityPiston par1TileEntityPiston, double par2, double par4, double par6, float par8)
        {
            Block block = Block.BlocksList[par1TileEntityPiston.GetStoredBlockID()];

            if (block != null && par1TileEntityPiston.GetProgress(par8) < 1.0F)
            {
                Tessellator tessellator = Tessellator.Instance;
                BindTextureByName("/terrain.png");
                RenderHelper.DisableStandardItemLighting();
                //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                //GL.Enable(EnableCap.Blend);
                //GL.Disable(EnableCap.CullFace);

                if (Minecraft.IsAmbientOcclusionEnabled())
                {
                    //GL.ShadeModel(ShadingModel.Smooth);
                }
                else
                {
                    //GL.ShadeModel(ShadingModel.Flat);
                }

                tessellator.StartDrawingQuads();
                tessellator.SetTranslation(((float)par2 - (float)par1TileEntityPiston.XCoord) + par1TileEntityPiston.GetOffsetX(par8), ((float)par4 - (float)par1TileEntityPiston.YCoord) + par1TileEntityPiston.GetOffsetY(par8), ((float)par6 - (float)par1TileEntityPiston.ZCoord) + par1TileEntityPiston.GetOffsetZ(par8));
                tessellator.SetColorOpaque(1, 1, 1);

                if (block == Block.PistonExtension && par1TileEntityPiston.GetProgress(par8) < 0.5F)
                {
                    BlockRenderer.RenderPistonExtensionAllFaces(block, par1TileEntityPiston.XCoord, par1TileEntityPiston.YCoord, par1TileEntityPiston.ZCoord, false);
                }
                else if (par1TileEntityPiston.ShouldRenderHead() && !par1TileEntityPiston.IsExtending())
                {
                    Block.PistonExtension.SetHeadTexture(((BlockPistonBase)block).GetPistonExtensionTexture());
                    BlockRenderer.RenderPistonExtensionAllFaces(Block.PistonExtension, par1TileEntityPiston.XCoord, par1TileEntityPiston.YCoord, par1TileEntityPiston.ZCoord, par1TileEntityPiston.GetProgress(par8) < 0.5F);
                    Block.PistonExtension.ClearHeadTexture();
                    tessellator.SetTranslation((float)par2 - (float)par1TileEntityPiston.XCoord, (float)par4 - (float)par1TileEntityPiston.YCoord, (float)par6 - (float)par1TileEntityPiston.ZCoord);
                    BlockRenderer.RenderPistonBaseAllFaces(block, par1TileEntityPiston.XCoord, par1TileEntityPiston.YCoord, par1TileEntityPiston.ZCoord);
                }
                else
                {
                    BlockRenderer.RenderBlockAllFaces(block, par1TileEntityPiston.XCoord, par1TileEntityPiston.YCoord, par1TileEntityPiston.ZCoord);
                }

                tessellator.SetTranslation(0.0F, 0.0F, 0.0F);
                tessellator.Draw();
                RenderHelper.EnableStandardItemLighting();
            }
        }
        /// <summary>
        /// Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
        /// cleared to be reused)
        /// </summary>
        public override AxisAlignedBB GetCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
        {
            TileEntityPiston tileentitypiston = GetTileEntityAtLocation(par1World, par2, par3, par4);

            if (tileentitypiston == null)
            {
                return(null);
            }

            float f = tileentitypiston.GetProgress(0.0F);

            if (tileentitypiston.IsExtending())
            {
                f = 1.0F - f;
            }

            return(GetAxisAlignedBB(par1World, par2, par3, par4, tileentitypiston.GetStoredBlockID(), f, tileentitypiston.GetPistonOrientation()));
        }
        /// <summary>
        /// Drops the block items with a specified chance of dropping the specified items
        /// </summary>
        public override void DropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
        {
            if (par1World.IsRemote)
            {
                return;
            }

            TileEntityPiston tileentitypiston = GetTileEntityAtLocation(par1World, par2, par3, par4);

            if (tileentitypiston == null)
            {
                return;
            }
            else
            {
                Block.BlocksList[tileentitypiston.GetStoredBlockID()].DropBlockAsItem(par1World, par2, par3, par4, tileentitypiston.GetBlockMetadata(), 0);
                return;
            }
        }
        public override void PowerBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
        {
            IgnoreUpdates = true;
            int i = par6;

            if (par5 == 0)
            {
                if (TryExtend(par1World, par2, par3, par4, i))
                {
                    par1World.SetBlockMetadataWithNotify(par2, par3, par4, i | 8);
                    par1World.PlaySoundEffect((double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, "tile.piston.out", 0.5F, par1World.Rand.NextFloat() * 0.25F + 0.6F);
                }
                else
                {
                    par1World.SetBlockMetadata(par2, par3, par4, i);
                }
            }
            else if (par5 == 1)
            {
                TileEntity tileentity = par1World.GetBlockTileEntity(par2 + Facing.OffsetsXForSide[i], par3 + Facing.OffsetsYForSide[i], par4 + Facing.OffsetsZForSide[i]);

                if (tileentity != null && (tileentity is TileEntityPiston))
                {
                    ((TileEntityPiston)tileentity).ClearPistonTileEntity();
                }

                par1World.SetBlockAndMetadata(par2, par3, par4, Block.PistonMoving.BlockID, i);
                par1World.SetBlockTileEntity(par2, par3, par4, BlockPistonMoving.GetTileEntity(BlockID, i, i, false, true));

                if (IsSticky)
                {
                    int  j    = par2 + Facing.OffsetsXForSide[i] * 2;
                    int  k    = par3 + Facing.OffsetsYForSide[i] * 2;
                    int  l    = par4 + Facing.OffsetsZForSide[i] * 2;
                    int  i1   = par1World.GetBlockId(j, k, l);
                    int  j1   = par1World.GetBlockMetadata(j, k, l);
                    bool flag = false;

                    if (i1 == Block.PistonMoving.BlockID)
                    {
                        TileEntity tileentity1 = par1World.GetBlockTileEntity(j, k, l);

                        if (tileentity1 != null && (tileentity1 is TileEntityPiston))
                        {
                            TileEntityPiston tileentitypiston = (TileEntityPiston)tileentity1;

                            if (tileentitypiston.GetPistonOrientation() == i && tileentitypiston.IsExtending())
                            {
                                tileentitypiston.ClearPistonTileEntity();
                                i1   = tileentitypiston.GetStoredBlockID();
                                j1   = tileentitypiston.GetBlockMetadata();
                                flag = true;
                            }
                        }
                    }

                    if (!flag && i1 > 0 && CanPushBlock(i1, par1World, j, k, l, false) && (Block.BlocksList[i1].GetMobilityFlag() == 0 || i1 == Block.PistonBase.BlockID || i1 == Block.PistonStickyBase.BlockID))
                    {
                        par2 += Facing.OffsetsXForSide[i];
                        par3 += Facing.OffsetsYForSide[i];
                        par4 += Facing.OffsetsZForSide[i];
                        par1World.SetBlockAndMetadata(par2, par3, par4, Block.PistonMoving.BlockID, j1);
                        par1World.SetBlockTileEntity(par2, par3, par4, BlockPistonMoving.GetTileEntity(i1, j1, i, false, false));
                        IgnoreUpdates = false;
                        par1World.SetBlockWithNotify(j, k, l, 0);
                        IgnoreUpdates = true;
                    }
                    else if (!flag)
                    {
                        IgnoreUpdates = false;
                        par1World.SetBlockWithNotify(par2 + Facing.OffsetsXForSide[i], par3 + Facing.OffsetsYForSide[i], par4 + Facing.OffsetsZForSide[i], 0);
                        IgnoreUpdates = true;
                    }
                }
                else
                {
                    IgnoreUpdates = false;
                    par1World.SetBlockWithNotify(par2 + Facing.OffsetsXForSide[i], par3 + Facing.OffsetsYForSide[i], par4 + Facing.OffsetsZForSide[i], 0);
                    IgnoreUpdates = true;
                }

                par1World.PlaySoundEffect((double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, "tile.piston.in", 0.5F, par1World.Rand.NextFloat() * 0.15F + 0.6F);
            }

            IgnoreUpdates = false;
        }