Add IsAirAt overload that outputs index too

This commit is contained in:
UnknownShadow200 2017-08-26 16:20:42 +10:00
parent d4cb1a9cb3
commit a03f1e616c
7 changed files with 56 additions and 57 deletions

View File

@ -24,16 +24,17 @@ namespace MCGalaxy.Blocks.Physics {
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:

View File

@ -22,12 +22,13 @@ 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;
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,
int dx, int dy, int dz) {

View File

@ -124,15 +124,11 @@ namespace MCGalaxy.Commands.Fun {
}
static void CheckTile(Level lvl, List<Vec3U16> 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);

View File

@ -91,15 +91,16 @@ namespace MCGalaxy.Commands.Building {
bool DoRestart(Player p, Vec3S32[] m, object state, ExtBlock block) {
PhysicsArgs extraInfo = (PhysicsArgs)state;
List<int> buffer = new List<int>();
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) {
if (buffer.Count > ServerConfig.PhysicsRestartNormLimit) {
@ -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;
}

View File

@ -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);
}
}

View File

@ -77,11 +77,10 @@ namespace MCGalaxy {
}
/// <summary> Gets whether the block at the given coordinates is air. </summary>
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) {