mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 22:30:52 -04:00
Modularise leaf decay physics.
This commit is contained in:
parent
c1d8e3d7db
commit
e5cd52ac93
107
Levels/Level.cs
107
Levels/Level.cs
@ -75,7 +75,7 @@ namespace MCGalaxy
|
||||
internal readonly List<Check> ListCheck = new List<Check>(); //A list of blocks that need to be updated
|
||||
internal readonly List<Update> ListUpdate = new List<Update>(); //A list of block to change after calculation
|
||||
|
||||
private readonly Dictionary<int, sbyte> leaves = new Dictionary<int, sbyte>();
|
||||
internal readonly Dictionary<int, sbyte> leaves = new Dictionary<int, sbyte>();
|
||||
// Holds block state for leaf decay
|
||||
|
||||
internal readonly Dictionary<int, bool[]> liquids = new Dictionary<int, bool[]>();
|
||||
@ -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) {
|
||||
|
75
Levels/Physics/SimplePhysics.cs
Normal file
75
Levels/Physics/SimplePhysics.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -417,6 +417,7 @@
|
||||
<Compile Include="Levels\Physics\HunterPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\LiquidPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\RocketPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\SimplePhysics.cs" />
|
||||
<Compile Include="Levels\Physics\SnakePhysics.cs" />
|
||||
<Compile Include="Levels\Physics\TrainPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\TntPhysics.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user