Ejemplo n.º 1
0
        public float CalculateXOffset(AxisAlignedBB other, float offset)
        {
            //x
            if (other.max.Y > min.Y && other.min.Y < max.Y && other.max.Z > min.Z && other.min.Z < max.Z)
            {
                if (offset > 0.0D && other.max.X <= min.X)
                {
                    float d1 = min.X - other.max.X;

                    if (d1 < offset)
                    {
                        offset = d1;
                    }
                }
                else if (offset < 0.0D && other.min.X >= max.X)
                {
                    float d0 = max.X - other.min.X;

                    if (d0 > offset)
                    {
                        offset = d0;
                    }
                }
            }

            return(offset);
        }
Ejemplo n.º 2
0
        public virtual void Move()
        {
            AxisAlignedBB bbO = boundingBox.Union(boundingBox.offset(Motion));

            List <AxisAlignedBB> list = SharpCraft.Instance.World.GetBlockCollisionBoxes(bbO);

            Vector3 mOrig = Motion;

            for (int i = 0; i < list.Count; i++)
            {
                AxisAlignedBB blockBb = list[i];
                Motion.Y = blockBb.CalculateYOffset(boundingBox, Motion.Y);
            }
            boundingBox = boundingBox.offset(Motion * Vector3.UnitY);

            for (int i = 0; i < list.Count; i++)
            {
                AxisAlignedBB blockBb = list[i];
                Motion.X = blockBb.CalculateXOffset(boundingBox, Motion.X);
            }
            boundingBox = boundingBox.offset(Motion * Vector3.UnitX);

            for (int i = 0; i < list.Count; i++)
            {
                AxisAlignedBB blockBb = list[i];
                Motion.Z = blockBb.CalculateZOffset(boundingBox, Motion.Z);
            }
            boundingBox = boundingBox.offset(Motion * Vector3.UnitZ);

            SetPositionToBB();

            bool stoppedX = Math.Abs(mOrig.X - Motion.X) > 0.00001f;
            bool stoppedY = Math.Abs(mOrig.Y - Motion.Y) > 0.00001f;
            bool stoppedZ = Math.Abs(mOrig.Z - Motion.Z) > 0.00001f;

            onGround = stoppedY && mOrig.Y < 0.0D;

            bool onCeiling = stoppedY && mOrig.Y > 0.0D;

            if (stoppedX)
            {
                Motion.X = 0;
            }

            if (stoppedZ)
            {
                Motion.Z = 0;
            }

            if (onCeiling)
            {
                Motion.Y *= 0.15f;
            }
            else if (onGround)
            {
                Motion.Y = 0;
            }
        }
        public void PlaceBlock()
        {
            MouseOverObject moo = SharpCraft.Instance.MouseOverObject;

            if (moo.hit != HitType.Block)
            {
                return;
            }

            ItemStack stack = GetEquippedItemStack();

            if (!(stack?.Item is ItemBlock itemBlock))
            {
                return;
            }

            Block air   = BlockRegistry.GetBlock <BlockAir>();
            Block glass = BlockRegistry.GetBlock <BlockGlass>();
            Block grass = BlockRegistry.GetBlock <BlockGrass>();
            Block dirt  = BlockRegistry.GetBlock <BlockDirt>();


            BlockState clickedState = World.GetBlockState(moo.blockPos);

            bool replacing;

            BlockPos pos = (replacing = clickedState.Block.IsReplaceable && itemBlock.Block != clickedState.Block) ? moo.blockPos : moo.blockPos.Offset(moo.sideHit);

            Block         heldBlock = itemBlock.Block;
            AxisAlignedBB blockBb   = heldBlock.BoundingBox.offset(pos.ToVec());

            if (!replacing && World.GetBlockState(pos).Block != air || World.GetIntersectingEntitiesBBs(blockBb).Count > 0 && heldBlock.IsSolid)
            {
                return;
            }

            BlockPos posUnder = pos.Offset(FaceSides.Down);

            BlockState stateUnder = World.GetBlockState(posUnder);
            BlockState stateAbove = World.GetBlockState(pos.Offset(FaceSides.Up));

            if (stateUnder.Block == grass && heldBlock != glass && heldBlock.IsSolid)
            {
                World.SetBlockState(posUnder, dirt.GetState());
            }
            if (stateAbove.Block != air && stateAbove.Block != glass && heldBlock == grass && stateAbove.Block.IsSolid)
            {
                World.SetBlockState(pos, dirt.GetState());
            }
            else
            {
                World.SetBlockState(pos, heldBlock.GetState(stack.Meta));
            }

            stack.Count--;

            SharpCraft.Instance.GetMouseOverObject();
        }
Ejemplo n.º 4
0
        protected Entity(World world, Vector3 pos, Vector3 motion = new Vector3())
        {
            World  = world;
            Pos    = LastPos = pos;
            Motion = motion;

            collisionBoundingBox = AxisAlignedBB.BLOCK_FULL;
            boundingBox          = collisionBoundingBox.offset(pos - collisionBoundingBox.size / 2);
        }
        public EntityPlayerSP(World world, Vector3 pos = new Vector3()) : base(world, pos)
        {
            SharpCraft.Instance.Camera.pos = pos + Vector3.UnitY * 1.625f;

            collisionBoundingBox = new AxisAlignedBB(new Vector3(0.6f, 1.65f, 0.6f));
            boundingBox          = collisionBoundingBox.offset(pos - (Vector3.UnitX * collisionBoundingBox.size.X / 2 + Vector3.UnitZ * collisionBoundingBox.size.Z / 2));

            Hotbar    = new ItemStack[9];
            Inventory = new ItemStack[27];
        }
Ejemplo n.º 6
0
        public EntityItem(World world, Vector3 pos, Vector3 motion, ItemStack stack) : base(world, pos, motion)
        {
            this.stack = stack;

            collisionBoundingBox = new AxisAlignedBB(0.25f);
            boundingBox          = collisionBoundingBox.offset(pos - Vector3.One * collisionBoundingBox.size / 2);

            gravity = 1.25f;

            isAlive = stack != null && !stack.IsEmpty;
        }
Ejemplo n.º 7
0
        public AxisAlignedBB Union(AxisAlignedBB other)
        {
            int minX = (int)Math.Floor(MathUtil.Min(min.X, max.X, other.min.X, other.max.X));
            int minY = (int)Math.Floor(MathUtil.Min(min.Y, max.Y, other.min.Y, other.max.Y));
            int minZ = (int)Math.Floor(MathUtil.Min(min.Z, max.Z, other.min.Z, other.max.Z));

            int maxX = (int)Math.Ceiling(MathUtil.Max(min.X, max.X, other.min.X, other.max.X));
            int maxY = (int)Math.Ceiling(MathUtil.Max(min.Y, max.Y, other.min.Y, other.max.Y));
            int maxZ = (int)Math.Ceiling(MathUtil.Max(min.Z, max.Z, other.min.Z, other.max.Z));

            return(new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ));
        }
Ejemplo n.º 8
0
        public virtual void Update()
        {
            LastPos = Pos;

            Motion.Y -= 0.04f * gravity;

            Vector3 motion = Motion;

            motion.Y = 0;

            if (onGround && Motion.Xz.Length > 0.0001f)
            {
                AxisAlignedBB bbO = boundingBox.Union(boundingBox.offset(motion));

                var list = SharpCraft.Instance.World.GetBlockCollisionBoxes(bbO).OrderBy(box => (box.min - new BlockPos(box.min).ToVec() + box.size).Y);

                foreach (var bb in list)
                {
                    var blockPos = new BlockPos(bb.min);
                    var bbTop    = bb.min + bb.size;
                    var b        = bbTop - blockPos.ToVec();

                    var step = bbTop.Y - Pos.Y;

                    if (step <= StepHeight && step > 0)
                    {
                        Motion.Y = 0;
                        Pos.Y    = blockPos.Y + b.Y;

                        TeleportTo(Pos);
                    }
                }
            }

            Move();

            Motion.Xz *= 0.8664021f;

            if (onGround)
            {
                Motion.Xz *= 0.6676801f;
            }
        }
Ejemplo n.º 9
0
        public void TeleportTo(Vector3 pos)
        {
            this.Pos = LastPos = pos;

            boundingBox = collisionBoundingBox.offset(pos - Vector3.UnitX * collisionBoundingBox.size.X / 2 - Vector3.UnitZ * collisionBoundingBox.size.Z / 2);
        }
Ejemplo n.º 10
0
 public bool IntersectsWith(AxisAlignedBB other)
 {
     return(min.X < other.max.X && max.X > other.min.X &&
            min.Y < other.max.Y && max.Y > other.min.Y &&
            min.Z < other.max.Z && max.Z > other.min.Z);
 }