Esempio n. 1
0
    /** Instantiate all block types and store them in the array */
    static Block()
    {
        blocks          = new Block[ushort.MaxValue + 1];
        blocks[AIR]     = new BlockAir();
        blocks[BEDROCK] = new BlockBedrock();
        for (uint i = 0; i < STONE.Length; i++)
        {
            blocks[STONE[i]] = new BlockStone(i);
        }
        blocks[DIRT]       = new BlockDirt();
        blocks[GRASS]      = new BlockGrass();
        blocks[ROCKY_DIRT] = new BlockDirtStone();
        blocks[SAND]       = new BlockSand();
        for (uint i = 0; i < WATER.Length; i++)
        {
            blocks[WATER[i]] = new BlockWater(i);
        }

        for (int i = 0; i < blocks.Length; i++)
        {
            if (blocks[i] != null)
            {
                blocks[i].id = (ushort)i;
            }
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            if (BlockID == 0)
            {
                SetDead();
                return;
            }

            PrevPosX = PosX;
            PrevPosY = PosY;
            PrevPosZ = PosZ;
            FallTime++;
            MotionY -= 0.039999999105930328F;
            MoveEntity(MotionX, MotionY, MotionZ);
            MotionX *= 0.98000001907348633F;
            MotionY *= 0.98000001907348633F;
            MotionZ *= 0.98000001907348633F;
            int i = MathHelper2.Floor_double(PosX);
            int j = MathHelper2.Floor_double(PosY);
            int k = MathHelper2.Floor_double(PosZ);

            if (FallTime == 1 && WorldObj.GetBlockId(i, j, k) == BlockID)
            {
                WorldObj.SetBlockWithNotify(i, j, k, 0);
            }
            else if (!WorldObj.IsRemote && FallTime == 1)
            {
                SetDead();
            }

            if (OnGround)
            {
                MotionX *= 0.69999998807907104F;
                MotionZ *= 0.69999998807907104F;
                MotionY *= -0.5F;

                if (WorldObj.GetBlockId(i, j, k) != Block.PistonMoving.BlockID)
                {
                    SetDead();

                    if ((!WorldObj.CanBlockBePlacedAt(BlockID, i, j, k, true, 1) || BlockSand.CanFallBelow(WorldObj, i, j - 1, k) || !WorldObj.SetBlockWithNotify(i, j, k, BlockID)) && !WorldObj.IsRemote)
                    {
                        DropItem(BlockID, 1);
                    }
                }
            }
            else if (FallTime > 100 && !WorldObj.IsRemote && (j < 1 || j > 256) || FallTime > 600)
            {
                DropItem(BlockID, 1);
                SetDead();
            }
        }