void CollideWithReachableBlocks(int count, ref Vector3 size, ref BoundingBox entityBB, ref BoundingBox entityExtentBB) { bool wasOn = onGround; onGround = false; Array.Sort(stateCache, 0, count, comparer); collideX = false; collideY = false; collideZ = false; for (int i = 0; i < count; i++) { State state = stateCache[i]; BoundingBox blockBB = state.BlockBB; if (!entityExtentBB.Intersects(blockBB)) { continue; } float tx = 0, ty = 0, tz = 0; CalcTime(ref Velocity, ref entityBB, ref blockBB, out tx, out ty, out tz); if (tx > 1 || ty > 1 || tz > 1) { Utils.LogDebug("t > 1 in physics calculation.. this shouldn't have happened."); } BoundingBox finalBB = entityBB.Offset(Velocity * new Vector3(tx, ty, tz)); // if we have hit the bottom of a block, we need to change the axis we test first. if (hitYMax) { if (finalBB.Min.Y + Adjustment >= blockBB.Max.Y) { ClipYMax(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Y - Adjustment <= blockBB.Min.Y) { ClipYMin(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } else if (finalBB.Min.X + Adjustment >= blockBB.Max.X) { ClipXMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.X - Adjustment <= blockBB.Min.X) { ClipXMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Min.Z + Adjustment >= blockBB.Max.Z) { ClipZMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Z - Adjustment <= blockBB.Min.Z) { ClipZMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } continue; } // if flying or falling, test the horizontal axes first. if (finalBB.Min.X + Adjustment >= blockBB.Max.X) { ClipXMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.X - Adjustment <= blockBB.Min.X) { ClipXMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Min.Z + Adjustment >= blockBB.Max.Z) { ClipZMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Z - Adjustment <= blockBB.Min.Z) { ClipZMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Min.Y + Adjustment >= blockBB.Max.Y) { ClipYMax(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Y - Adjustment <= blockBB.Min.Y) { ClipYMin(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } } }
void CollideWithReachableBlocks(int count, ref Vector3 size, ref BoundingBox entityBB, ref BoundingBox entityExtentBB) { bool wasOn = entity.onGround; entity.onGround = false; if (count > 0) { QuickSort(stateCache, 0, count - 1); } collideX = false; collideY = false; collideZ = false; BoundingBox blockBB = default(BoundingBox); for (int i = 0; i < count; i++) { State state = stateCache[i]; Vector3 blockPos = new Vector3(state.X >> 3, state.Y >> 3, state.Z >> 3); int block = (state.X & 0x7) | (state.Y & 0x7) << 3 | (state.Z & 0x7) << 6; blockBB.Min = blockPos + info.MinBB[block]; blockBB.Max = blockPos + info.MaxBB[block]; if (!entityExtentBB.Intersects(blockBB)) { continue; } float tx = 0, ty = 0, tz = 0; CalcTime(ref entity.Velocity, ref entityBB, ref blockBB, out tx, out ty, out tz); if (tx > 1 || ty > 1 || tz > 1) { Utils.LogDebug("t > 1 in physics calculation.. this shouldn't have happened."); } BoundingBox finalBB = entityBB.Offset(entity.Velocity * new Vector3(tx, ty, tz)); // if we have hit the bottom of a block, we need to change the axis we test first. if (hitYMax) { if (finalBB.Min.Y + Adjustment >= blockBB.Max.Y) { ClipYMax(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Y - Adjustment <= blockBB.Min.Y) { ClipYMin(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } else if (finalBB.Min.X + Adjustment >= blockBB.Max.X) { ClipXMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.X - Adjustment <= blockBB.Min.X) { ClipXMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Min.Z + Adjustment >= blockBB.Max.Z) { ClipZMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Z - Adjustment <= blockBB.Min.Z) { ClipZMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } continue; } // if flying or falling, test the horizontal axes first. if (finalBB.Min.X + Adjustment >= blockBB.Max.X) { ClipXMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.X - Adjustment <= blockBB.Min.X) { ClipXMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Min.Z + Adjustment >= blockBB.Max.Z) { ClipZMax(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Z - Adjustment <= blockBB.Min.Z) { ClipZMin(ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size); } else if (finalBB.Min.Y + Adjustment >= blockBB.Max.Y) { ClipYMax(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } else if (finalBB.Max.Y - Adjustment <= blockBB.Min.Y) { ClipYMin(ref blockBB, ref entityBB, ref entityExtentBB, ref size); } } }