From 52241a5ea326ce333cca18a335a4df85d96d1ffe Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 20 Apr 2015 14:26:15 -0600 Subject: [PATCH] Fix falling sand entities --- TrueCraft.API/BoundingBox.cs | 4 ++-- TrueCraft.Core/Entities/FallingSandEntity.cs | 6 +++--- TrueCraft/PhysicsEngine.cs | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/TrueCraft.API/BoundingBox.cs b/TrueCraft.API/BoundingBox.cs index 59f8b5a..37b8b13 100644 --- a/TrueCraft.API/BoundingBox.cs +++ b/TrueCraft.API/BoundingBox.cs @@ -146,7 +146,7 @@ namespace TrueCraft.API public void Intersects(ref BoundingBox box, out bool result) { - if ((this.Max.X >= box.Min.X) && (this.Min.X <= box.Max.X)) + if ((this.Max.X > box.Min.X) && (this.Min.X < box.Max.X)) { if ((this.Max.Y < box.Min.Y) || (this.Min.Y > box.Max.Y)) { @@ -154,7 +154,7 @@ namespace TrueCraft.API return; } - result = (this.Max.Z >= box.Min.Z) && (this.Min.Z <= box.Max.Z); + result = (this.Max.Z > box.Min.Z) && (this.Min.Z < box.Max.Z); return; } diff --git a/TrueCraft.Core/Entities/FallingSandEntity.cs b/TrueCraft.Core/Entities/FallingSandEntity.cs index 974dd45..e02dba3 100644 --- a/TrueCraft.Core/Entities/FallingSandEntity.cs +++ b/TrueCraft.Core/Entities/FallingSandEntity.cs @@ -51,7 +51,7 @@ namespace TrueCraft.Core.Entities { get { - return new BoundingBox(Vector3.Zero, Vector3.One); + return new BoundingBox(Position, Position + Size); } } @@ -71,7 +71,7 @@ namespace TrueCraft.Core.Entities { get { - return 0.4f; + return 0.04f; } } @@ -79,7 +79,7 @@ namespace TrueCraft.Core.Entities { get { - return 0.2f; + return 0.02f; } } diff --git a/TrueCraft/PhysicsEngine.cs b/TrueCraft/PhysicsEngine.cs index c22c530..440ce1c 100644 --- a/TrueCraft/PhysicsEngine.cs +++ b/TrueCraft/PhysicsEngine.cs @@ -54,8 +54,9 @@ namespace TrueCraft if (multipler < 0.1) multipler = 0.1; lock (EntityLock) { - foreach (var entity in Entities) + for (int i = 0; i < Entities.Count; i++) { + var entity = Entities[i]; if (entity.BeginUpdate()) { entity.Velocity -= new Vector3(0, entity.AccelerationDueToGravity * multipler, 0); @@ -145,7 +146,7 @@ namespace TrueCraft var boundingBox = BlockPhysicsProvider.GetBoundingBox(world, position); if (boundingBox == null) continue; - blockBox = boundingBox.Value.OffsetBy(position); + blockBox = boundingBox.Value.OffsetBy(position + new Vector3(0.5)); if (TempBoundingBox.Intersects(blockBox)) { if (entity.Velocity.X < 0) @@ -253,7 +254,7 @@ namespace TrueCraft var boundingBox = BlockPhysicsProvider.GetBoundingBox(world, position); if (boundingBox == null) continue; - blockBox = boundingBox.Value.OffsetBy(position); + blockBox = boundingBox.Value.OffsetBy(position + new Vector3(0.5)); if (TempBoundingBox.Intersects(blockBox)) { if (entity.Velocity.Y < 0) @@ -351,7 +352,7 @@ namespace TrueCraft var boundingBox = BlockPhysicsProvider.GetBoundingBox(world, position); if (boundingBox == null) continue; - blockBox = boundingBox.Value.OffsetBy(position); + blockBox = boundingBox.Value.OffsetBy(position + new Vector3(0.5)); if (TempBoundingBox.Intersects(blockBox)) { if (entity.Velocity.Z < 0)