diff --git a/Levels/Level.cs b/Levels/Level.cs index 8212b6e2e..9188a0766 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -75,7 +75,7 @@ namespace MCGalaxy internal readonly List ListCheck = new List(); //A list of blocks that need to be updated internal readonly List ListUpdate = new List(); //A list of block to change after calculation - private readonly Dictionary leaves = new Dictionary(); + internal readonly Dictionary leaves = new Dictionary(); // Holds block state for leaf decay internal readonly Dictionary liquids = new Dictionary(); @@ -927,8 +927,7 @@ namespace MCGalaxy //Check block above } - if (!leafDecay) - { + if (!leafDecay) { C.time = 255; leaves.Clear(); break; @@ -938,7 +937,8 @@ namespace MCGalaxy if (rand.Next(10) == 0) C.time++; break; } - if (PhysLeaf(C.b)) AddUpdate(C.b, 0); + if (SimplePhysics.DoLeafDecay(this, C)) + AddUpdate(C.b, 0); C.time = 255; break; @@ -1621,105 +1621,6 @@ namespace MCGalaxy } } - //================================================================================================================ - private bool PhysLeaf(int b) - { - byte type, dist = 4; - int i, xx, yy, zz; - ushort x, y, z; - IntToPos(b, out x, out y, out z); - - for (xx = -dist; xx <= dist; xx++) - { - for (yy = -dist; yy <= dist; yy++) - { - for (zz = -dist; zz <= dist; zz++) - { - type = GetTile((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz)); - if (type == Block.trunk) - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz))] = 0; - else if (type == Block.leaf) - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz))] = -2; - else - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz))] = -1; - } - } - } - - for (i = 1; i <= dist; i++) - { - for (xx = -dist; xx <= dist; xx++) - { - for (yy = -dist; yy <= dist; yy++) - { - for (zz = -dist; zz <= dist; zz++) - { - try - { - if (leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz))] == i - 1) - { - if ( - leaves.ContainsKey(PosToInt((ushort)(x + xx - 1), (ushort)(y + yy), - (ushort)(z + zz))) && - leaves[PosToInt((ushort)(x + xx - 1), (ushort)(y + yy), (ushort)(z + zz))] == - -2) - leaves[PosToInt((ushort)(x + xx - 1), (ushort)(y + yy), (ushort)(z + zz))] = - (sbyte)i; - - if ( - leaves.ContainsKey(PosToInt((ushort)(x + xx + 1), (ushort)(y + yy), - (ushort)(z + zz))) && - leaves[PosToInt((ushort)(x + xx + 1), (ushort)(y + yy), (ushort)(z + zz))] == - -2) - leaves[PosToInt((ushort)(x + xx + 1), (ushort)(y + yy), (ushort)(z + zz))] = - (sbyte)i; - - if ( - leaves.ContainsKey(PosToInt((ushort)(x + xx), (ushort)(y + yy - 1), - (ushort)(z + zz))) && - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy - 1), (ushort)(z + zz))] == - -2) - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy - 1), (ushort)(z + zz))] = - (sbyte)i; - - if ( - leaves.ContainsKey(PosToInt((ushort)(x + xx), (ushort)(y + yy + 1), - (ushort)(z + zz))) && - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy + 1), (ushort)(z + zz))] == - -2) - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy + 1), (ushort)(z + zz))] = - (sbyte)i; - - if ( - leaves.ContainsKey(PosToInt((ushort)(x + xx), (ushort)(y + yy), - (ushort)(z + zz - 1))) && - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz - 1))] == - -2) - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz - 1))] = - (sbyte)i; - - if ( - leaves.ContainsKey(PosToInt((ushort)(x + xx), (ushort)(y + yy), - (ushort)(z + zz + 1))) && - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz + 1))] == - -2) - leaves[PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz + 1))] = - (sbyte)i; - } - } - catch - { - Server.s.Log("Leaf decay error!"); - } - } - } - } - } - - //Server.s.Log((leaves[b] < 0).ToString()); // This is a debug line that spams the console to hell! - return leaves[b] < 0; - } - //================================================================================================================ public void MakeExplosion(ushort x, ushort y, ushort z, int size, bool force = false, TntWarsGame CheckForExplosionZone = null) { diff --git a/Levels/Physics/SimplePhysics.cs b/Levels/Physics/SimplePhysics.cs new file mode 100644 index 000000000..20b3ed049 --- /dev/null +++ b/Levels/Physics/SimplePhysics.cs @@ -0,0 +1,75 @@ +/* + Copyright 2015 MCGalaxy + Original level physics copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; + +namespace MCGalaxy.BlockPhysics { + + public static class SimplePhysics { + + public static bool DoLeafDecay(Level lvl, Check C) { + const int dist = 4; + ushort x, y, z; + lvl.IntToPos(C.b, out x, out y, out z); + + for (int xx = -dist; xx <= dist; xx++) + for (int yy = -dist; yy <= dist; yy++) + for (int zz = -dist; zz <= dist; zz++) + { + int index = lvl.PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz)); + if (index < 0) continue; + byte type = lvl.blocks[index]; + + if (type == Block.trunk) + lvl.leaves[index] = 0; + else if (type == Block.leaf) + lvl.leaves[index] = -2; + else + lvl.leaves[index] = -1; + } + + for (int i = 1; i <= dist; i++) + for (int xx = -dist; xx <= dist; xx++) + for (int yy = -dist; yy <= dist; yy++) + for (int zz = -dist; zz <= dist; zz++) + { + int index = lvl.PosToInt((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz)); + if (index < 0) continue; + + if (lvl.leaves[index] == i - 1) { + CheckLeaf(lvl, i, x + xx - 1, y + yy, z + zz); + CheckLeaf(lvl, i, x + xx + 1, y + yy, z + zz); + CheckLeaf(lvl, i, x + xx, y + yy - 1, z + zz); + CheckLeaf(lvl, i, x + xx, y + yy + 1, z + zz); + CheckLeaf(lvl, i, x + xx, y + yy, z + zz - 1); + CheckLeaf(lvl, i, x + xx, y + yy, z + zz + 1); + } + } + return lvl.leaves[C.b] < 0; + } + + static void CheckLeaf(Level lvl, int i, int x, int y, int z) { + int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z); + if (index < 0) return; + + sbyte type; + if (lvl.leaves.TryGetValue(index, out type) && type == -2) + lvl.leaves[index] = (sbyte)i; + } + } +} diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index e33a05138..212058794 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -417,6 +417,7 @@ +