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 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; } }
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]; }
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; }