Less reliant on old GetTile/GetBlock

This commit is contained in:
UnknownShadow200 2017-06-03 11:03:15 +10:00
parent ec96484611
commit 471552f47a
17 changed files with 102 additions and 107 deletions

View File

@ -35,13 +35,14 @@ namespace MCGalaxy.Blocks {
// Looking straight up or down // Looking straight up or down
byte pitch = p.Rot.HeadX; byte pitch = p.Rot.HeadX;
if (pitch >= 192 && pitch <= 196 || pitch >= 60 && pitch <= 64) { dx = 0; dz = 0; } if (pitch >= 192 && pitch <= 196 || pitch >= 60 && pitch <= 64) { dx = 0; dz = 0; }
Vec3U16 head = new Vec3U16((ushort)(x + dx * 2), (ushort)(y + dy * 2), (ushort)(z + dz * 2));
Vec3U16 tail = new Vec3U16((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz));
byte b1 = p.level.GetBlock(x + dx * 2, y + dy * 2, z + dz * 2); bool headFree = p.level.IsAirAt(head.X, head.Y, head.Z) && p.level.CheckClear(head.X, head.Y, head.Z);
byte b2 = p.level.GetBlock(x + dx , y + dy, z + dz); bool tailFree = p.level.IsAirAt(tail.X, tail.Y, tail.Z) && p.level.CheckClear(tail.X, tail.Y, tail.Z);
if ( b1 == Block.air && b2 == Block.air && p.level.CheckClear((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 )) if (headFree && tailFree) {
&& p.level.CheckClear((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz )) ) { p.level.Blockchange(head.X, head.Y, head.Z, (ExtBlock)Block.rockethead);
p.level.Blockchange((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 ), (ExtBlock)Block.rockethead); p.level.Blockchange(tail.X, tail.Y, tail.Z, (ExtBlock)Block.lava_fire);
p.level.Blockchange((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz ), (ExtBlock)Block.lava_fire);
} }
} }
@ -49,19 +50,21 @@ namespace MCGalaxy.Blocks {
if (p.level.physics == 0 || p.level.physics == 5) { p.RevertBlock(x, y, z); return; } if (p.level.physics == 0 || p.level.physics == 5) { p.RevertBlock(x, y, z); return; }
Random rand = new Random(); Random rand = new Random();
ushort x2 = (ushort)(x + rand.Next(0, 2) - 1); // Offset the firework randomly
ushort z2 = (ushort)(z + rand.Next(0, 2) - 1); Vec3U16 pos = new Vec3U16(0, 0, 0);
byte b1 = p.level.GetBlock(x2, y + 2, z2); pos.X = (ushort)(x + rand.Next(0, 2) - 1);
byte b2 = p.level.GetBlock(x2, y + 1, z2); pos.Z = (ushort)(z + rand.Next(0, 2) - 1);
ushort headY = (ushort)(y + 2), tailY = (ushort)(y + 1);
if (b1 == Block.air && b2 == Block.air && p.level.CheckClear(x2, (ushort)(y + 1), z2) bool headFree = p.level.IsAirAt(pos.X, headY, pos.Z) && p.level.CheckClear(pos.X, headY, pos.Z);
&& p.level.CheckClear(x2, (ushort)(y + 2), z2)) { bool tailFree = p.level.IsAirAt(pos.X, tailY, pos.Z) && p.level.CheckClear(pos.X, tailY, pos.Z);
p.level.Blockchange(x2, (ushort)(y + 2), z2, (ExtBlock)Block.firework); if (headFree && tailFree) {
p.level.Blockchange(pos.X, headY, pos.Z, (ExtBlock)Block.firework);
PhysicsArgs args = default(PhysicsArgs); PhysicsArgs args = default(PhysicsArgs);
args.Type1 = PhysicsArgs.Wait; args.Value1 = 1; args.Type1 = PhysicsArgs.Wait; args.Value1 = 1;
args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 100; args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 100;
p.level.Blockchange(x2, (ushort)(y + 1), z2, (ExtBlock)Block.lavastill, false, args); p.level.Blockchange(pos.X, tailY, pos.Z, (ExtBlock)Block.lavastill, false, args);
} }
p.RevertBlock(x, y, z); p.RevertBlock(x, y, z);
} }

View File

@ -27,12 +27,12 @@ namespace MCGalaxy.Blocks.Physics {
switch (rand.Next(1, 15)) { switch (rand.Next(1, 15)) {
case 1: case 1:
if (lvl.GetTile(x, (ushort)(y - 1), z) == Block.air) if (lvl.IsAirAt(x, (ushort)(y - 1), z))
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), lvl.blocks[C.b]); lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), lvl.blocks[C.b]);
else goto case 3; else goto case 3;
break; break;
case 2: case 2:
if (lvl.GetTile(x, (ushort)(y + 1), z) == Block.air) if (lvl.IsAirAt(x, (ushort)(y + 1), z))
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y + 1), z), lvl.blocks[C.b]); lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y + 1), z), lvl.blocks[C.b]);
else goto case 6; else goto case 6;
break; break;

View File

@ -52,8 +52,7 @@ namespace MCGalaxy.Blocks.Physics {
int i = indices[j]; int i = indices[j];
ushort posX = (ushort)(x + (i / 5) - 2); ushort posX = (ushort)(x + (i / 5) - 2);
ushort posZ = (ushort)(z + (i % 5) - 2); ushort posZ = (ushort)(z + (i % 5) - 2);
if (lvl.GetTile(posX, (ushort)(y - 1), posZ) == Block.air && if (lvl.IsAirAt(posX, (ushort)(y - 1), posZ) && lvl.IsAirAt(posX, y, posZ))
lvl.GetTile(posX, y, posZ) == Block.air)
{ {
if (posX < x) { if (posX < x) {
posX = (ushort)((posX + x) / 2); posX = (ushort)((posX + x) / 2);

View File

@ -120,7 +120,7 @@ namespace MCGalaxy.Blocks.Physics {
tree.SetData(rand, tree.DefaultSize(rand)); tree.SetData(rand, tree.DefaultSize(rand));
tree.Generate(x, y, z, (xT, yT, zT, bT) => tree.Generate(x, y, z, (xT, yT, zT, bT) =>
{ {
if (bT == Block.leaf && lvl.GetTile(xT, yT, zT) != Block.air) return; if (bT == Block.leaf && !lvl.IsAirAt(xT, yT, zT)) return;
lvl.Blockchange(xT, yT, zT, (ExtBlock)bT); lvl.Blockchange(xT, yT, zT, (ExtBlock)bT);
}); });

View File

@ -75,8 +75,8 @@ namespace MCGalaxy.Commands.Fun {
class AimState { class AimState {
public Player player; public Player player;
public Position oldPos = default(Position); public Position oldPos = default(Position);
public List<Vec3U16> lastSent = new List<Vec3U16>(); public List<Vec3U16> lastGlass = new List<Vec3U16>();
public List<Vec3U16> toSend = new List<Vec3U16>(); public List<Vec3U16> glassCoords = new List<Vec3U16>();
} }
static void AimCallback(SchedulerTask task) { static void AimCallback(SchedulerTask task) {
@ -84,7 +84,7 @@ namespace MCGalaxy.Commands.Fun {
Player p = state.player; Player p = state.player;
if (state.player.aiming) { DoAim(state); return; } if (state.player.aiming) { DoAim(state); return; }
foreach (Vec3U16 cP in state.lastSent) { foreach (Vec3U16 cP in state.lastGlass) {
if (!p.level.IsValidPos(cP)) continue; if (!p.level.IsValidPos(cP)) continue;
p.RevertBlock(cP.X, cP.Y, cP.Z); p.RevertBlock(cP.X, cP.Y, cP.Z);
} }
@ -99,39 +99,39 @@ namespace MCGalaxy.Commands.Fun {
ushort z = (ushort)Math.Round(p.Pos.BlockZ + dir.Z * 3); ushort z = (ushort)Math.Round(p.Pos.BlockZ + dir.Z * 3);
int signX = Math.Sign(dir.X) >= 0 ? 1 : -1, signZ = Math.Sign(dir.Z) >= 0 ? 1 : -1; int signX = Math.Sign(dir.X) >= 0 ? 1 : -1, signZ = Math.Sign(dir.Z) >= 0 ? 1 : -1;
CheckTile(p.level, state.toSend, x, y, z); CheckTile(p.level, state.glassCoords, x, y, z);
CheckTile(p.level, state.toSend, x + signX, y, z); CheckTile(p.level, state.glassCoords, x + signX, y, z);
CheckTile(p.level, state.toSend, x, y, z + signZ); CheckTile(p.level, state.glassCoords, x, y, z + signZ);
CheckTile(p.level, state.toSend, x + signX, y, z + signZ); CheckTile(p.level, state.glassCoords, x + signX, y, z + signZ);
// Revert all glass blocks now not in the ray from the player's direction // Revert all glass blocks now not in the ray from the player's direction
for (int i = 0; i < state.lastSent.Count; i++) { for (int i = 0; i < state.lastGlass.Count; i++) {
Vec3U16 cP = state.lastSent[i]; Vec3U16 cP = state.lastGlass[i];
if (state.toSend.Contains(cP)) continue; if (state.glassCoords.Contains(cP)) continue;
if (p.level.IsValidPos(cP)) if (p.level.IsValidPos(cP))
p.RevertBlock(cP.X, cP.Y, cP.Z); p.RevertBlock(cP.X, cP.Y, cP.Z);
state.lastSent.RemoveAt(i); i--; state.lastGlass.RemoveAt(i); i--;
} }
// Place the new glass blocks that are in the ray from the player's direction // Place the new glass blocks that are in the ray from the player's direction
foreach (Vec3U16 cP in state.toSend) { foreach (Vec3U16 cP in state.glassCoords) {
if (state.lastSent.Contains(cP)) continue; if (state.lastGlass.Contains(cP)) continue;
state.lastSent.Add(cP); state.lastGlass.Add(cP);
p.SendBlockchange(cP.X, cP.Y, cP.Z, (ExtBlock)Block.glass); p.SendBlockchange(cP.X, cP.Y, cP.Z, (ExtBlock)Block.glass);
} }
state.toSend.Clear(); state.glassCoords.Clear();
} }
static void CheckTile(Level lvl, List<Vec3U16> toSend, int x, int y, int z) { static void CheckTile(Level lvl, List<Vec3U16> glassCoords, int x, int y, int z) {
Vec3U16 pos; Vec3U16 pos;
if (lvl.GetBlock(x, y - 1, z) == Block.air) { if (lvl.IsAirAt(x, y - 1, z)) {
pos.X = (ushort)x; pos.Y = (ushort)(y - 1); pos.Z = (ushort)z; pos.X = (ushort)x; pos.Y = (ushort)(y - 1); pos.Z = (ushort)z;
toSend.Add(pos); glassCoords.Add(pos);
} }
if (lvl.GetBlock(x, y, z) == Block.air) { if (lvl.IsAirAt(x, y, z)) {
pos.X = (ushort)x; pos.Y = (ushort)y; pos.Z = (ushort)z; pos.X = (ushort)x; pos.Y = (ushort)y; pos.Z = (ushort)z;
toSend.Add(pos); glassCoords.Add(pos);
} }
} }

View File

@ -65,7 +65,7 @@ namespace MCGalaxy.Commands.Misc {
Thread.Sleep(250); Thread.Sleep(250);
p.level.Blockchange(p, cur.X, cur.Y, cur.Z, (ExtBlock)Block.mushroom); p.level.Blockchange(p, cur.X, cur.Y, cur.Z, (ExtBlock)Block.mushroom);
if (p.level.GetTile(next.X, next.Y, next.Z) != 0) { if (!p.level.IsAirAt(next.X, next.Y, next.Z)) {
PullBack(p, next, target, dirX, dirZ); PullBack(p, next, target, dirX, dirZ);
p.level.Blockchange(p, x, y, z, ExtBlock.Air); return; p.level.Blockchange(p, x, y, z, ExtBlock.Air); return;
} }
@ -83,7 +83,7 @@ namespace MCGalaxy.Commands.Misc {
cur.X = (ushort)(cur.X - dirX); cur.Z = (ushort)(cur.Z - dirZ); cur.X = (ushort)(cur.X - dirX); cur.Z = (ushort)(cur.Z - dirZ);
if (cur.X >= p.level.Width || cur.Z >= p.level.Length) return; if (cur.X >= p.level.Width || cur.Z >= p.level.Length) return;
curBlock.BlockID = p.level.GetTile(cur.X, cur.Y, cur.Z); curBlock = p.level.GetExtBlock(cur.X, cur.Y, cur.Z);
if (curBlock.BlockID == Block.mushroom) if (curBlock.BlockID == Block.mushroom)
p.level.Blockchange(p, cur.X, cur.Y, cur.Z, block); p.level.Blockchange(p, cur.X, cur.Y, cur.Z, block);
Thread.Sleep(250); Thread.Sleep(250);

View File

@ -48,8 +48,8 @@ namespace MCGalaxy.Commands.Misc {
class FlyState { class FlyState {
public Player player; public Player player;
public Position oldPos = default(Position); public Position oldPos = default(Position);
public List<Vec3U16> last = new List<Vec3U16>(); public List<Vec3U16> lastGlass = new List<Vec3U16>();
public List<Vec3U16> next = new List<Vec3U16>(); public List<Vec3U16> glassCoords = new List<Vec3U16>();
} }
static void FlyCallback(SchedulerTask task) { static void FlyCallback(SchedulerTask task) {
@ -57,7 +57,7 @@ namespace MCGalaxy.Commands.Misc {
Player p = state.player; Player p = state.player;
if (state.player.isFlying) { DoFly(state); return; } if (state.player.isFlying) { DoFly(state); return; }
foreach (Vec3U16 cP in state.last) { foreach (Vec3U16 cP in state.lastGlass) {
p.SendBlockchange(cP.X, cP.Y, cP.Z, ExtBlock.Air); p.SendBlockchange(cP.X, cP.Y, cP.Z, ExtBlock.Air);
} }
Player.Message(p, "Stopped flying"); Player.Message(p, "Stopped flying");
@ -76,29 +76,26 @@ namespace MCGalaxy.Commands.Misc {
for (int zz = z - 2; zz <= z + 2; zz++) for (int zz = z - 2; zz <= z + 2; zz++)
for (int xx = x - 2; xx <= x + 2; xx++) for (int xx = x - 2; xx <= x + 2; xx++)
{ {
ushort offX = (ushort)xx, offY = (ushort)yy, offZ = (ushort)zz;
if (p.level.GetTile(offX, offY, offZ) != Block.air) continue;
Vec3U16 pos; Vec3U16 pos;
pos.X = offX; pos.Y = offY; pos.Z = offZ; pos.X = (ushort)xx; pos.Y = (ushort)yy; pos.Z = (ushort)zz;
state.next.Add(pos); if (!p.level.IsAirAt(pos.X, pos.Y, pos.Z)) state.glassCoords.Add(pos);
} }
foreach (Vec3U16 P in state.next) { foreach (Vec3U16 P in state.glassCoords) {
if (state.last.Contains(P)) continue; if (state.lastGlass.Contains(P)) continue;
state.last.Add(P); state.lastGlass.Add(P);
p.SendBlockchange(P.X, P.Y, P.Z, glass); p.SendBlockchange(P.X, P.Y, P.Z, glass);
} }
for (int i = 0; i < state.last.Count; i++) { for (int i = 0; i < state.lastGlass.Count; i++) {
Vec3U16 P = state.last[i]; Vec3U16 P = state.lastGlass[i];
if (state.next.Contains(P)) continue; if (state.glassCoords.Contains(P)) continue;
p.SendBlockchange(P.X, P.Y, P.Z, ExtBlock.Air); p.RevertBlock(P.X, P.Y, P.Z);
state.last.RemoveAt(i); i--; state.lastGlass.RemoveAt(i); i--;
} }
state.next.Clear(); state.glassCoords.Clear();
state.oldPos = p.Pos; state.oldPos = p.Pos;
} }

View File

@ -17,11 +17,10 @@
*/ */
//StormCom Object Generator //StormCom Object Generator
// //
//Full use to all StormCom Server System codes (in regards to minecraft classic) have been granted to MCGalaxy without restriction. //Full use to all StormCom Server System codes (in regards to minecraft classic) have been granted to MCForge without restriction.
// //
// ~Merlin33069 // ~Merlin33069
using System; using System;
using System.Collections.Generic;
using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Maths; using MCGalaxy.Maths;
@ -52,9 +51,7 @@ namespace MCGalaxy.Drawing.Ops {
int dist = xx * xx + zz * zz; int dist = xx * xx + zz * zz;
if (dist > curRadius * curRadius) continue; if (dist > curRadius * curRadius) continue;
byte ctile = Level.GetTile(x, y, z); if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush));
if (ctile != 0) continue;
output(Place(x, y, z, brush));
} }
} }
} }
@ -88,9 +85,7 @@ namespace MCGalaxy.Drawing.Ops {
if (dist > curRadius * curRadius || dist < (curRadius - 1) * (curRadius - 1)) if (dist > curRadius * curRadius || dist < (curRadius - 1) * (curRadius - 1))
continue; continue;
byte ctile = Level.GetTile(x, y, z); if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush));
if (ctile != 0) continue;
output(Place(x, y, z, brush));
} }
} }
} }
@ -120,9 +115,7 @@ namespace MCGalaxy.Drawing.Ops {
double curRadius = Radius * ((double)curHeight / (double)height); double curRadius = Radius * ((double)curHeight / (double)height);
int dist = xx * xx + zz * zz; int dist = xx * xx + zz * zz;
if (dist > curRadius * curRadius) continue; if (dist > curRadius * curRadius) continue;
if (!Level.IsAirAt(x, y, z)) continue;
byte ctile = Level.GetTile(x, y, z);
if (ctile != 0) continue;
bool layer = dist >= (curRadius - 1) * (curRadius - 1); bool layer = dist >= (curRadius - 1) * (curRadius - 1);
block.BlockID = layer ? Block.grass : Block.lavastill; block.BlockID = layer ? Block.grass : Block.lavastill;

View File

@ -17,11 +17,10 @@
*/ */
//StormCom Object Generator //StormCom Object Generator
// //
//Full use to all StormCom Server System codes (in regards to minecraft classic) have been granted to MCGalaxy without restriction. //Full use to all StormCom Server System codes (in regards to minecraft classic) have been granted to MCForge without restriction.
// //
// ~Merlin33069 // ~Merlin33069
using System; using System;
using System.Collections.Generic;
using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Maths; using MCGalaxy.Maths;
@ -51,9 +50,7 @@ namespace MCGalaxy.Drawing.Ops {
double curRadius = Radius * ((double)curHeight / (double)height); double curRadius = Radius * ((double)curHeight / (double)height);
if (Math.Abs(xx) > curRadius || Math.Abs(zz) > curRadius) continue; if (Math.Abs(xx) > curRadius || Math.Abs(zz) > curRadius) continue;
byte ctile = Level.GetTile(x, y, z); if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush));
if (ctile != 0) continue;
output(Place(x, y, z, brush));
} }
} }
} }
@ -87,9 +84,7 @@ namespace MCGalaxy.Drawing.Ops {
if (absx > curRadius || absz > curRadius) continue; if (absx > curRadius || absz > curRadius) continue;
if (absx < (curRadius - 1) && absz < (curRadius - 1)) continue; if (absx < (curRadius - 1) && absz < (curRadius - 1)) continue;
byte ctile = Level.GetTile(x, y, z); if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush));
if (ctile != 0) continue;
output(Place(x, y, z, brush));
} }
} }
} }

View File

@ -113,7 +113,7 @@ namespace MCGalaxy.Drawing.Ops {
int startX = i; int startX = i;
for (ushort x = p1.X; x <= p2.X; x++) { for (ushort x = p1.X; x <= p2.X; x++) {
i = (i + stepX) % 13; i = (i + stepX) % 13;
if (Level.GetTile(x, y, z) != Block.air) { if (!Level.IsAirAt(x, y, z)) {
block.BlockID = (byte)(Block.red + i); block.BlockID = (byte)(Block.red + i);
output(Place(x, y, z, block)); output(Place(x, y, z, block));
} }

View File

@ -49,7 +49,7 @@ namespace MCGalaxy.Drawing.Ops {
Tree.Generate(P.X, P.Y, P.Z, (xT, yT, zT, bT) => Tree.Generate(P.X, P.Y, P.Z, (xT, yT, zT, bT) =>
{ {
if (bT == Block.leaf && lvl.GetTile(xT, yT, zT) != Block.air) return; if (bT == Block.leaf && !lvl.IsAirAt(xT, yT, zT)) return;
if (bT != Block.leaf) { if (bT != Block.leaf) {
output(Place(xT, yT, zT, (ExtBlock)bT)); output(Place(xT, yT, zT, (ExtBlock)bT));

View File

@ -46,9 +46,9 @@ namespace MCGalaxy.Games {
case "base.red.z": case "base.red.z":
redbase.z = ushort.Parse(value); break; redbase.z = ushort.Parse(value); break;
case "base.red.block": case "base.red.block":
redbase.block = Block.Byte(value); break; redbase.block = ExtBlock.FromRaw(byte.Parse(value)); break;
case "base.blue.block": case "base.blue.block":
bluebase.block = Block.Byte(value); break; bluebase.block = ExtBlock.FromRaw(byte.Parse(value)); break;
case "base.blue.spawnx": case "base.blue.spawnx":
bluebase.spawnx = ushort.Parse(value); break; bluebase.spawnx = ushort.Parse(value); break;
case "base.blue.spawny": case "base.blue.spawny":

View File

@ -63,7 +63,7 @@ namespace MCGalaxy.Games {
internal sealed class Base { internal sealed class Base {
public ushort x, y, z; public ushort x, y, z;
public ushort spawnx, spawny, spawnz; public ushort spawnx, spawny, spawnz;
public byte block; public ExtBlock block;
public void SendToSpawn(Level mainlevel, CTFGame game, Player p1) { public void SendToSpawn(Level mainlevel, CTFGame game, Player p1) {
Position pos = new Position(spawnx, spawny, spawny); Position pos = new Position(spawnx, spawny, spawny);
@ -74,7 +74,7 @@ namespace MCGalaxy.Games {
xx = (ushort)(rand.Next(0, mainlevel.Width)); xx = (ushort)(rand.Next(0, mainlevel.Width));
yy = (ushort)(rand.Next(0, mainlevel.Height)); yy = (ushort)(rand.Next(0, mainlevel.Height));
zz = (ushort)(rand.Next(0, mainlevel.Length)); zz = (ushort)(rand.Next(0, mainlevel.Length));
} while (mainlevel.GetTile(xx, yy, zz) != Block.air && game.OnSide(zz, this)); } while (!mainlevel.IsAirAt(xx, yy, zz) && game.OnSide(zz, this));
pos.X = xx * 32; pos.Y = yy * 32; pos.Z = zz * 32; pos.X = xx * 32; pos.Y = yy * 32; pos.Z = zz * 32;
} }
@ -191,7 +191,7 @@ namespace MCGalaxy.Games {
if (GetPlayer(other).hasflag) { if (GetPlayer(other).hasflag) {
Chat.MessageLevel(mainlevel, redteam.color + p.name + " DROPPED THE FLAG!"); Chat.MessageLevel(mainlevel, redteam.color + p.name + " DROPPED THE FLAG!");
GetPlayer(other).points -= caplose; GetPlayer(other).points -= caplose;
mainlevel.Blockchange(b.x, b.y, b.z, (ExtBlock)b.block); mainlevel.Blockchange(b.x, b.y, b.z, b.block);
GetPlayer(other).hasflag = false; GetPlayer(other).hasflag = false;
} }
@ -251,8 +251,8 @@ namespace MCGalaxy.Games {
LoadMap(maps[new Random().Next(maps.Count)]); LoadMap(maps[new Random().Next(maps.Count)]);
if (needSetup) AutoSetup(); if (needSetup) AutoSetup();
redbase.block = Block.red; redbase.block = (ExtBlock)Block.red;
bluebase.block = Block.blue; bluebase.block = (ExtBlock)Block.blue;
Server.s.Log("[Auto_CTF] Running..."); Server.s.Log("[Auto_CTF] Running...");
started = true; started = true;

View File

@ -51,7 +51,7 @@ namespace MCGalaxy.Games {
cache[p].bx = x; cache[p].bx = x;
cache[p].by = y; cache[p].by = y;
cache[p].bz = z; cache[p].bz = z;
cache[p].blue = p.level.GetTile(x, y, z); cache[p].blue = p.level.GetExtBlock(x, y, z);
Player.Message(p, "Ok! I got the blue flag, now can you show me the red flag?"); Player.Message(p, "Ok! I got the blue flag, now can you show me the red flag?");
Player.Message(p, "Just hit it"); Player.Message(p, "Just hit it");
cache[p].s = Step.GetRedFlag; cache[p].s = Step.GetRedFlag;
@ -60,7 +60,7 @@ namespace MCGalaxy.Games {
cache[p].rx = x; cache[p].rx = x;
cache[p].ry = y; cache[p].ry = y;
cache[p].rz = z; cache[p].rz = z;
cache[p].red = p.level.GetTile(x, y, z); cache[p].red = p.level.GetExtBlock(x, y, z);
Player.Message(p, "Got it!"); Player.Message(p, "Got it!");
Player.Message(p, "Now I can do random spawns, or do you have a spawn in mind?"); Player.Message(p, "Now I can do random spawns, or do you have a spawn in mind?");
Player.Message(p, "Say - (Random/Set)"); Player.Message(p, "Say - (Random/Set)");
@ -172,7 +172,7 @@ namespace MCGalaxy.Games {
public int middle = 0; public int middle = 0;
public int bx, by, bz; public int bx, by, bz;
public int rx, ry, rz; public int rx, ry, rz;
public byte blue, red; public ExtBlock blue, red;
public int bluex, bluey, bluez; public int bluex, bluey, bluez;
} }

View File

@ -185,25 +185,25 @@ namespace MCGalaxy.Games {
//beneath this is checking the glass next to the square //beneath this is checking the glass next to the square
bool up = false, left = false, right = false, down = false; bool up = false, left = false, right = false, down = false;
//directly next to //directly next to
if (mapon.GetBlock(x1, y, z2 + 2) == Block.air) //right if (mapon.IsAirAt(x1, y, z2 + 2)) //right
{ {
mapon.Blockchange(x1, y, (ushort)(z2 + 1), ExtBlock.Air); mapon.Blockchange(x1, y, (ushort)(z2 + 1), ExtBlock.Air);
mapon.Blockchange(x2, y, (ushort)(z2 + 1), ExtBlock.Air); mapon.Blockchange(x2, y, (ushort)(z2 + 1), ExtBlock.Air);
right = true; right = true;
} }
if (mapon.GetBlock(x1, y, z1 - 2) == Block.air) //left if (mapon.IsAirAt(x1, y, z1 - 2)) //left
{ {
mapon.Blockchange(x1, y, (ushort)(z1 - 1), ExtBlock.Air); mapon.Blockchange(x1, y, (ushort)(z1 - 1), ExtBlock.Air);
mapon.Blockchange(x2, y, (ushort)(z1 - 1), ExtBlock.Air); mapon.Blockchange(x2, y, (ushort)(z1 - 1), ExtBlock.Air);
left = true; left = true;
} }
if (mapon.GetBlock(x2 + 2, y, z1) == Block.air) //up if (mapon.IsAirAt(x2 + 2, y, z1)) //up
{ {
mapon.Blockchange((ushort)(x2 + 1), y, z1, ExtBlock.Air); mapon.Blockchange((ushort)(x2 + 1), y, z1, ExtBlock.Air);
mapon.Blockchange((ushort)(x2 + 1), y, z2, ExtBlock.Air); mapon.Blockchange((ushort)(x2 + 1), y, z2, ExtBlock.Air);
up = true; up = true;
} }
if (mapon.GetBlock(x1 - 2, y, z1) == Block.air) //down if (mapon.IsAirAt(x1 - 2, y, z1)) //down
{ {
mapon.Blockchange((ushort)(x1 - 1), y, z1, ExtBlock.Air); mapon.Blockchange((ushort)(x1 - 1), y, z1, ExtBlock.Air);
mapon.Blockchange((ushort)(x1 - 1), y, z2, ExtBlock.Air); mapon.Blockchange((ushort)(x1 - 1), y, z2, ExtBlock.Air);
@ -211,19 +211,19 @@ namespace MCGalaxy.Games {
} }
//diagonal >:( //diagonal >:(
if ((mapon.GetBlock(x1 - 2, y, z1 - 2) == Block.air) && left && down) //bottom left if (mapon.IsAirAt(x1 - 2, y, z1 - 2) && left && down) //bottom left
{ {
mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z1 - 1), ExtBlock.Air); mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z1 - 1), ExtBlock.Air);
} }
if ((mapon.GetBlock(x1 - 2, y, z2 + 2) == Block.air) && right && down) //bottom right if (mapon.IsAirAt(x1 - 2, y, z2 + 2) && right && down) //bottom right
{ {
mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z2 + 1), ExtBlock.Air); mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z2 + 1), ExtBlock.Air);
} }
if ((mapon.GetBlock(x2 + 2, y, z1 - 2) == Block.air) && left && up) //top left if (mapon.IsAirAt(x2 + 2, y, z1 - 2) && left && up) //top left
{ {
mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z1 - 1), ExtBlock.Air); mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z1 - 1), ExtBlock.Air);
} }
if ((mapon.GetBlock(x2 + 2, y, z2 + 2) == Block.air) && right && up) //top right if (mapon.IsAirAt(x2 + 2, y, z2 + 2) && right && up) //top right
{ {
mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z2 + 1), ExtBlock.Air); mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z2 + 1), ExtBlock.Air);
} }

View File

@ -133,7 +133,7 @@ namespace MCGalaxy.Generator {
} }
if (genParams.GenTrees && overlay[index] < 0.65f && overlay2[index] < treeDens) { if (genParams.GenTrees && overlay[index] < 0.65f && overlay2[index] < treeDens) {
if (Lvl.GetTile(x, (ushort)(y + 1), z) == Block.air) { if (Lvl.IsAirAt(x, (ushort)(y + 1), z)) {
if (Lvl.GetTile(x, y, z) == Block.grass || genParams.UseCactus) { if (Lvl.GetTile(x, y, z) == Block.grass || genParams.UseCactus) {
if (rand.Next(13) == 0 && !Tree.TreeCheck(Lvl, x, y, z, treeDist)) { if (rand.Next(13) == 0 && !Tree.TreeCheck(Lvl, x, y, z, treeDist)) {
Tree tree = null; Tree tree = null;
@ -143,7 +143,7 @@ namespace MCGalaxy.Generator {
tree.SetData(rand, tree.DefaultSize(rand)); tree.SetData(rand, tree.DefaultSize(rand));
tree.Generate(x, (ushort)(y + 1), z, (xT, yT, zT, bT) => tree.Generate(x, (ushort)(y + 1), z, (xT, yT, zT, bT) =>
{ {
if (Lvl.GetTile(xT, yT, zT) == Block.air) if (Lvl.IsAirAt(xT, yT, zT))
Lvl.SetTile(xT, yT, zT, bT); Lvl.SetTile(xT, yT, zT, bT);
}); });
} }

View File

@ -57,6 +57,20 @@ namespace MCGalaxy {
return block; return block;
} }
/// <summary> Gets whether the block at the given coordinates is air. </summary>
public bool IsAirAt(ushort x, ushort y, ushort z) {
if (x >= Width || y >= Height || z >= Length || blocks == null) return false;
return blocks[x + Width * (z + y * Length)] == Block.air;
}
/// <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;
}
/// <summary> Gets the block at the given coordinates. </summary> /// <summary> Gets the block at the given coordinates. </summary>
/// <returns> Block.Invalid if coordinates outside map. </returns> /// <returns> Block.Invalid if coordinates outside map. </returns>
public byte GetBlock(int x, int y, int z) { public byte GetBlock(int x, int y, int z) {
@ -99,12 +113,6 @@ namespace MCGalaxy {
chunk[(y & 0x0F) << 8 | (z & 0x0F) << 4 | (x & 0x0F)]; chunk[(y & 0x0F) << 8 | (z & 0x0F) << 4 | (x & 0x0F)];
} }
public byte GetFallbackExtTile(ushort x, ushort y, ushort z) {
byte tile = GetExtTile(x, y, z);
BlockDefinition def = CustomBlockDefs[tile];
return def == null ? Block.air : def.FallBack;
}
public byte GetFallbackExtTile(int index) { public byte GetFallbackExtTile(int index) {
byte tile = GetExtTile(index); byte tile = GetExtTile(index);
BlockDefinition def = CustomBlockDefs[tile]; BlockDefinition def = CustomBlockDefs[tile];