diff --git a/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs b/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs index ad260481e..7b36a178c 100644 --- a/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs +++ b/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs @@ -66,7 +66,7 @@ namespace MCGalaxy.Blocks.Physics { int i = block.Index; if (lvl.BlockProps[i].IsDoor) { byte physForm; - PhysicsArgs args = GetDoorArgs(block, out physForm); + PhysicsArgs args = GetDoorArgs(block, out physForm); if (!instant) lvl.AddUpdate(index, physForm, false, args); else lvl.Blockchange(index, (ExtBlock)physForm, false, args); } else if (lvl.BlockProps[i].IsTDoor) { @@ -74,10 +74,10 @@ namespace MCGalaxy.Blocks.Physics { lvl.AddUpdate(index, Block.Air, false, args); } else { ushort oDoorIndex = lvl.BlockProps[i].oDoorIndex; - if (oDoorIndex == Block.Invalid) return; + if (oDoorIndex == Block.Invalid) return; ExtBlock oDoor = ExtBlock.FromIndex(oDoorIndex); - PhysicsArgs args = default(PhysicsArgs); + PhysicsArgs args = default(PhysicsArgs); args.ExtBlock = oDoor.BlockID == Block.custom_block; lvl.AddUpdate(index, oDoor.RawID, true, args); } diff --git a/MCGalaxy/Blocks/Physics/BirdPhysics.cs b/MCGalaxy/Blocks/Physics/BirdPhysics.cs index 2f2ca430d..4ec999cd0 100644 --- a/MCGalaxy/Blocks/Physics/BirdPhysics.cs +++ b/MCGalaxy/Blocks/Physics/BirdPhysics.cs @@ -21,19 +21,20 @@ namespace MCGalaxy.Blocks.Physics { public static class BirdPhysics { public static void Do(Level lvl, ref Check C) { - Random rand = lvl.physRandom; + Random rand = lvl.physRandom; ushort x, y, z; lvl.IntToPos(C.b, out x, out y, out z); + int index; switch (rand.Next(1, 15)) { case 1: - if (lvl.IsAirAt(x, (ushort)(y - 1), z)) - lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), lvl.blocks[C.b]); + if (lvl.IsAirAt(x, (ushort)(y - 1), z, out index)) + lvl.AddUpdate(index, lvl.blocks[C.b]); else goto case 3; break; case 2: - if (lvl.IsAirAt(x, (ushort)(y + 1), z)) - lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y + 1), z), lvl.blocks[C.b]); + if (lvl.IsAirAt(x, (ushort)(y + 1), z, out index)) + lvl.AddUpdate(index, lvl.blocks[C.b]); else goto case 6; break; case 3: diff --git a/MCGalaxy/Blocks/Physics/FirePhysics.cs b/MCGalaxy/Blocks/Physics/FirePhysics.cs index 5ed39b9f3..aaaab6613 100644 --- a/MCGalaxy/Blocks/Physics/FirePhysics.cs +++ b/MCGalaxy/Blocks/Physics/FirePhysics.cs @@ -22,11 +22,12 @@ namespace MCGalaxy.Blocks.Physics { public static class FirePhysics { static bool ExpandSimple(Level lvl, int x, int y, int z) { - int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z); - if (index < 0 || lvl.blocks[index] != Block.Air) return false; - - lvl.AddUpdate(index, Block.Fire); - return true; + int index; + if (lvl.IsAirAt((ushort)x, (ushort)y, (ushort)z, out index)) { + lvl.AddUpdate(index, Block.Fire); + return true; + } + return false; } static void ExpandDiagonal(Level lvl, ushort x, ushort y, ushort z, diff --git a/MCGalaxy/Commands/Fun/WeaponCmd.cs b/MCGalaxy/Commands/Fun/WeaponCmd.cs index aeef7ffc0..7cbfc4998 100644 --- a/MCGalaxy/Commands/Fun/WeaponCmd.cs +++ b/MCGalaxy/Commands/Fun/WeaponCmd.cs @@ -124,15 +124,11 @@ namespace MCGalaxy.Commands.Fun { } static void CheckTile(Level lvl, List glassCoords, int x, int y, int z) { - Vec3U16 pos; - if (lvl.IsAirAt(x, y - 1, z)) { - pos.X = (ushort)x; pos.Y = (ushort)(y - 1); pos.Z = (ushort)z; - glassCoords.Add(pos); - } - if (lvl.IsAirAt(x, y, z)) { - pos.X = (ushort)x; pos.Y = (ushort)y; pos.Z = (ushort)z; - glassCoords.Add(pos); - } + Vec3U16 pos = new Vec3U16((ushort)x, (ushort)(y - 1), (ushort)z); + if (lvl.IsAirAt(pos.X, pos.Y, pos.Z)) glassCoords.Add(pos); + + pos.Y++; + if (lvl.IsAirAt(pos.X, pos.Y, pos.Z)) glassCoords.Add(pos); } protected abstract void PlacedMark(Player p, ushort x, ushort y, ushort z, ExtBlock block); diff --git a/MCGalaxy/Commands/building/CmdRestartPhysics.cs b/MCGalaxy/Commands/building/CmdRestartPhysics.cs index 734f717b7..c016837d3 100644 --- a/MCGalaxy/Commands/building/CmdRestartPhysics.cs +++ b/MCGalaxy/Commands/building/CmdRestartPhysics.cs @@ -91,14 +91,15 @@ namespace MCGalaxy.Commands.Building { bool DoRestart(Player p, Vec3S32[] m, object state, ExtBlock block) { PhysicsArgs extraInfo = (PhysicsArgs)state; List buffer = new List(); + int index; for (int y = Math.Min(m[0].Y, m[1].Y); y <= Math.Max(m[0].Y, m[1].Y); y++) for (int z = Math.Min(m[0].Z, m[1].Z); z <= Math.Max(m[0].Z, m[1].Z); z++) for (int x = Math.Min(m[0].X, m[1].X); x <= Math.Max(m[0].X, m[1].X); x++) { - int index = p.level.PosToInt((ushort)x, (ushort)y, (ushort)z); - if (index >= 0 && p.level.blocks[index] != Block.Air) + if (p.level.IsAirAt((ushort)x, (ushort)y, (ushort)z, out index)) { buffer.Add(index); + } } if (extraInfo.Raw == 0) { @@ -113,8 +114,9 @@ namespace MCGalaxy.Commands.Building { return false; } - foreach (int index in buffer) - p.level.AddCheck(index, true, extraInfo); + foreach (int index1 in buffer) { + p.level.AddCheck(index1, true, extraInfo); + } Player.Message(p, "Activated " + buffer.Count + " blocks."); return true; } diff --git a/MCGalaxy/Games/Countdown/CountdownGame.cs b/MCGalaxy/Games/Countdown/CountdownGame.cs index 55410333c..f4a0adf66 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.cs @@ -218,50 +218,50 @@ namespace MCGalaxy.Games { } void RemoveSquare(SquarePos pos) { - ushort minX = pos.X, maxX = (ushort)(pos.X + 1), y = 4, minZ = pos.Z, maxZ = (ushort)(pos.Z + 1); - Cuboid(minX, y, minZ, maxX, y, maxZ, Block.Yellow, Map); + ushort x1 = pos.X, x2 = (ushort)(pos.X + 1), y = 4, z1 = pos.Z, z2 = (ushort)(pos.Z + 1); + Cuboid(x1, y, z1, x2, y, z2, Block.Yellow, Map); Thread.Sleep(Interval); - Cuboid(minX, y, minZ, maxX, y, maxZ, Block.Orange, Map); + Cuboid(x1, y, z1, x2, y, z2, Block.Orange, Map); Thread.Sleep(Interval); - Cuboid(minX, y, minZ, maxX, y, maxZ, Block.Red, Map); + Cuboid(x1, y, z1, x2, y, z2, Block.Red, Map); Thread.Sleep(Interval); - Cuboid(minX, y, minZ, maxX, y, maxZ, Block.Air, Map); + Cuboid(x1, y, z1, x2, y, z2, Block.Air, Map); // Remove glass borders if neighbouring squared were previously removed. bool airMaxX = false, airMinZ = false, airMaxZ = false, airMinX = false; - if (Map.IsAirAt(minX, y, maxZ + 2)) { - Map.Blockchange(minX, y, (ushort)(maxZ + 1), ExtBlock.Air); - Map.Blockchange(maxX, y, (ushort)(maxZ + 1), ExtBlock.Air); + if (Map.IsAirAt(x1, y, (ushort)(z2 + 2))) { + Map.Blockchange(x1, y, (ushort)(z2 + 1), ExtBlock.Air); + Map.Blockchange(x2, y, (ushort)(z2 + 1), ExtBlock.Air); airMaxZ = true; } - if (Map.IsAirAt(minX, y, minZ - 2)) { - Map.Blockchange(minX, y, (ushort)(minZ - 1), ExtBlock.Air); - Map.Blockchange(maxX, y, (ushort)(minZ - 1), ExtBlock.Air); + if (Map.IsAirAt(x1, y, (ushort)(z1 - 2))) { + Map.Blockchange(x1, y, (ushort)(z1 - 1), ExtBlock.Air); + Map.Blockchange(x2, y, (ushort)(z1 - 1), ExtBlock.Air); airMinZ = true; } - if (Map.IsAirAt(maxX + 2, y, minZ)) { - Map.Blockchange((ushort)(maxX + 1), y, minZ, ExtBlock.Air); - Map.Blockchange((ushort)(maxX + 1), y, maxZ, ExtBlock.Air); + if (Map.IsAirAt((ushort)(x2 + 2), y, z1)) { + Map.Blockchange((ushort)(x2 + 1), y, z1, ExtBlock.Air); + Map.Blockchange((ushort)(x2 + 1), y, z2, ExtBlock.Air); airMaxX = true; } - if (Map.IsAirAt(minX - 2, y, minZ)) { - Map.Blockchange((ushort)(minX - 1), y, minZ, ExtBlock.Air); - Map.Blockchange((ushort)(minX - 1), y, maxZ, ExtBlock.Air); + if (Map.IsAirAt((ushort)(x1 - 2), y, z1)) { + Map.Blockchange((ushort)(x1 - 1), y, z1, ExtBlock.Air); + Map.Blockchange((ushort)(x1 - 1), y, z2, ExtBlock.Air); airMinX = true; } // Remove glass borders for diagonals too. - if (Map.IsAirAt(minX - 2, y, minZ - 2) && airMinZ && airMinX) { - Map.Blockchange((ushort)(minX - 1), y, (ushort)(minZ - 1), ExtBlock.Air); + if (Map.IsAirAt((ushort)(x1 - 2), y, (ushort)(z1 - 2)) && airMinX && airMinZ) { + Map.Blockchange((ushort)(x1 - 1), y, (ushort)(z1 - 1), ExtBlock.Air); } - if (Map.IsAirAt(minX - 2, y, maxZ + 2) && airMaxZ && airMinX) { - Map.Blockchange((ushort)(minX - 1), y, (ushort)(maxZ + 1), ExtBlock.Air); + if (Map.IsAirAt((ushort)(x1 - 2), y, (ushort)(z2 + 2)) && airMinX && airMaxZ) { + Map.Blockchange((ushort)(x1 - 1), y, (ushort)(z2 + 1), ExtBlock.Air); } - if (Map.IsAirAt(maxX + 2, y, minZ - 2) && airMinZ && airMaxX) { - Map.Blockchange((ushort)(maxX + 1), y, (ushort)(minZ - 1), ExtBlock.Air); + if (Map.IsAirAt((ushort)(x2 + 2), y, (ushort)(z1 - 2)) && airMaxX && airMinZ) { + Map.Blockchange((ushort)(x2 + 1), y, (ushort)(z1 - 1), ExtBlock.Air); } - if (Map.IsAirAt(maxX + 2, y, maxZ + 2) && airMaxZ && airMaxX) { - Map.Blockchange((ushort)(maxX + 1), y, (ushort)(maxZ + 1), ExtBlock.Air); + if (Map.IsAirAt((ushort)(x2 + 2), y, (ushort)(z2 + 2)) && airMaxX && airMaxZ) { + Map.Blockchange((ushort)(x2 + 1), y, (ushort)(z2 + 1), ExtBlock.Air); } } diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index 5244414b1..920595d53 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -75,13 +75,12 @@ namespace MCGalaxy { if (x >= Width || y >= Height || z >= Length || blocks == null) return false; return blocks[x + Width * (z + y * Length)] == Block.Air; } - + /// Gets whether the block at the given coordinates is air. - public bool IsAirAt(int x, int y, int z) { - if (x < 0 || y < 0 || z < 0 || blocks == null) return false; - if (x >= Width || y >= Height || z >= Length) return false; - - return blocks[x + Width * (z + y * Length)] == Block.Air; + public bool IsAirAt(ushort x, ushort y, ushort z, out int index) { + if (x >= Width || y >= Height || z >= Length || blocks == null) { index = -1; return false; } + index = x + Width * (z + y * Length); + return blocks[index] == Block.Air; } public byte GetTile(int b) {