From 471552f47a1ce2c78187c7d3c523da2c82bb63bd Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 3 Jun 2017 11:03:15 +1000 Subject: [PATCH] Less reliant on old GetTile/GetBlock --- MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs | 35 ++++++++-------- MCGalaxy/Blocks/Physics/BirdPhysics.cs | 4 +- MCGalaxy/Blocks/Physics/FinitePhysics.cs | 3 +- MCGalaxy/Blocks/Physics/OtherPhysics.cs | 2 +- MCGalaxy/Commands/Fun/WeaponCmd.cs | 40 +++++++++---------- MCGalaxy/Commands/other/CmdChain.cs | 4 +- MCGalaxy/Commands/other/CmdFly.cs | 31 +++++++------- MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs | 15 ++----- MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs | 11 ++--- MCGalaxy/Drawing/DrawOps/CuboidDrawOps.cs | 2 +- MCGalaxy/Drawing/DrawOps/TreeDrawOp.cs | 2 +- MCGalaxy/Games/CTF/CtfConfig.cs | 4 +- MCGalaxy/Games/CTF/CtfGame.cs | 10 ++--- MCGalaxy/Games/CTF/Setup.cs | 6 +-- MCGalaxy/Games/Countdown/CountdownGame.cs | 16 ++++---- MCGalaxy/Generator/RealisticMapGen.cs | 4 +- MCGalaxy/Levels/Level.Blocks.cs | 20 +++++++--- 17 files changed, 102 insertions(+), 107 deletions(-) diff --git a/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs b/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs index 67dc2a888..7a525d288 100644 --- a/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs @@ -35,13 +35,14 @@ namespace MCGalaxy.Blocks { // Looking straight up or down byte pitch = p.Rot.HeadX; if (pitch >= 192 && pitch <= 196 || pitch >= 60 && pitch <= 64) { dx = 0; dz = 0; } - - byte b1 = p.level.GetBlock(x + dx * 2, y + dy * 2, z + dz * 2); - byte b2 = p.level.GetBlock(x + dx , y + dy, z + dz); - if ( b1 == Block.air && b2 == Block.air && p.level.CheckClear((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 )) - && p.level.CheckClear((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz )) ) { - p.level.Blockchange((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 ), (ExtBlock)Block.rockethead); - p.level.Blockchange((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz ), (ExtBlock)Block.lava_fire); + 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)); + + bool headFree = p.level.IsAirAt(head.X, head.Y, head.Z) && p.level.CheckClear(head.X, head.Y, head.Z); + bool tailFree = p.level.IsAirAt(tail.X, tail.Y, tail.Z) && p.level.CheckClear(tail.X, tail.Y, tail.Z); + if (headFree && tailFree) { + p.level.Blockchange(head.X, head.Y, head.Z, (ExtBlock)Block.rockethead); + p.level.Blockchange(tail.X, tail.Y, tail.Z, (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; } Random rand = new Random(); - ushort x2 = (ushort)(x + rand.Next(0, 2) - 1); - ushort z2 = (ushort)(z + rand.Next(0, 2) - 1); - byte b1 = p.level.GetBlock(x2, y + 2, z2); - byte b2 = p.level.GetBlock(x2, y + 1, z2); - - if (b1 == Block.air && b2 == Block.air && p.level.CheckClear(x2, (ushort)(y + 1), z2) - && p.level.CheckClear(x2, (ushort)(y + 2), z2)) { - p.level.Blockchange(x2, (ushort)(y + 2), z2, (ExtBlock)Block.firework); + // Offset the firework randomly + Vec3U16 pos = new Vec3U16(0, 0, 0); + pos.X = (ushort)(x + rand.Next(0, 2) - 1); + pos.Z = (ushort)(z + rand.Next(0, 2) - 1); + ushort headY = (ushort)(y + 2), tailY = (ushort)(y + 1); + + bool headFree = p.level.IsAirAt(pos.X, headY, pos.Z) && p.level.CheckClear(pos.X, headY, pos.Z); + bool tailFree = p.level.IsAirAt(pos.X, tailY, pos.Z) && p.level.CheckClear(pos.X, tailY, pos.Z); + if (headFree && tailFree) { + p.level.Blockchange(pos.X, headY, pos.Z, (ExtBlock)Block.firework); PhysicsArgs args = default(PhysicsArgs); args.Type1 = PhysicsArgs.Wait; args.Value1 = 1; 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); } diff --git a/MCGalaxy/Blocks/Physics/BirdPhysics.cs b/MCGalaxy/Blocks/Physics/BirdPhysics.cs index 2a5f9b6bf..6e9517263 100644 --- a/MCGalaxy/Blocks/Physics/BirdPhysics.cs +++ b/MCGalaxy/Blocks/Physics/BirdPhysics.cs @@ -27,12 +27,12 @@ namespace MCGalaxy.Blocks.Physics { switch (rand.Next(1, 15)) { 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]); else goto case 3; break; 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]); else goto case 6; break; diff --git a/MCGalaxy/Blocks/Physics/FinitePhysics.cs b/MCGalaxy/Blocks/Physics/FinitePhysics.cs index 4cd675bfb..f257e7334 100644 --- a/MCGalaxy/Blocks/Physics/FinitePhysics.cs +++ b/MCGalaxy/Blocks/Physics/FinitePhysics.cs @@ -52,8 +52,7 @@ namespace MCGalaxy.Blocks.Physics { int i = indices[j]; ushort posX = (ushort)(x + (i / 5) - 2); ushort posZ = (ushort)(z + (i % 5) - 2); - if (lvl.GetTile(posX, (ushort)(y - 1), posZ) == Block.air && - lvl.GetTile(posX, y, posZ) == Block.air) + if (lvl.IsAirAt(posX, (ushort)(y - 1), posZ) && lvl.IsAirAt(posX, y, posZ)) { if (posX < x) { posX = (ushort)((posX + x) / 2); diff --git a/MCGalaxy/Blocks/Physics/OtherPhysics.cs b/MCGalaxy/Blocks/Physics/OtherPhysics.cs index d9f98df89..c5efa90d1 100644 --- a/MCGalaxy/Blocks/Physics/OtherPhysics.cs +++ b/MCGalaxy/Blocks/Physics/OtherPhysics.cs @@ -120,7 +120,7 @@ namespace MCGalaxy.Blocks.Physics { tree.SetData(rand, tree.DefaultSize(rand)); 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); }); diff --git a/MCGalaxy/Commands/Fun/WeaponCmd.cs b/MCGalaxy/Commands/Fun/WeaponCmd.cs index 34c04c6d2..6be629a47 100644 --- a/MCGalaxy/Commands/Fun/WeaponCmd.cs +++ b/MCGalaxy/Commands/Fun/WeaponCmd.cs @@ -75,8 +75,8 @@ namespace MCGalaxy.Commands.Fun { class AimState { public Player player; public Position oldPos = default(Position); - public List lastSent = new List(); - public List toSend = new List(); + public List lastGlass = new List(); + public List glassCoords = new List(); } static void AimCallback(SchedulerTask task) { @@ -84,7 +84,7 @@ namespace MCGalaxy.Commands.Fun { Player p = state.player; 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; 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); 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.toSend, x + signX, y, z); - CheckTile(p.level, state.toSend, x, y, z + signZ); - CheckTile(p.level, state.toSend, x + signX, y, z + signZ); + CheckTile(p.level, state.glassCoords, x, y, z); + CheckTile(p.level, state.glassCoords, x + signX, y, z); + CheckTile(p.level, state.glassCoords, x, 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 - for (int i = 0; i < state.lastSent.Count; i++) { - Vec3U16 cP = state.lastSent[i]; - if (state.toSend.Contains(cP)) continue; + for (int i = 0; i < state.lastGlass.Count; i++) { + Vec3U16 cP = state.lastGlass[i]; + if (state.glassCoords.Contains(cP)) continue; if (p.level.IsValidPos(cP)) 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 - foreach (Vec3U16 cP in state.toSend) { - if (state.lastSent.Contains(cP)) continue; - state.lastSent.Add(cP); + foreach (Vec3U16 cP in state.glassCoords) { + if (state.lastGlass.Contains(cP)) continue; + state.lastGlass.Add(cP); p.SendBlockchange(cP.X, cP.Y, cP.Z, (ExtBlock)Block.glass); } - state.toSend.Clear(); + state.glassCoords.Clear(); } - static void CheckTile(Level lvl, List toSend, int x, int y, int z) { + static void CheckTile(Level lvl, List glassCoords, int x, int y, int z) { 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; - 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; - toSend.Add(pos); + glassCoords.Add(pos); } } diff --git a/MCGalaxy/Commands/other/CmdChain.cs b/MCGalaxy/Commands/other/CmdChain.cs index 6f0019c4a..6cacbcc2d 100644 --- a/MCGalaxy/Commands/other/CmdChain.cs +++ b/MCGalaxy/Commands/other/CmdChain.cs @@ -65,7 +65,7 @@ namespace MCGalaxy.Commands.Misc { Thread.Sleep(250); 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); 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); 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) p.level.Blockchange(p, cur.X, cur.Y, cur.Z, block); Thread.Sleep(250); diff --git a/MCGalaxy/Commands/other/CmdFly.cs b/MCGalaxy/Commands/other/CmdFly.cs index e8e243003..159cefe08 100644 --- a/MCGalaxy/Commands/other/CmdFly.cs +++ b/MCGalaxy/Commands/other/CmdFly.cs @@ -48,8 +48,8 @@ namespace MCGalaxy.Commands.Misc { class FlyState { public Player player; public Position oldPos = default(Position); - public List last = new List(); - public List next = new List(); + public List lastGlass = new List(); + public List glassCoords = new List(); } static void FlyCallback(SchedulerTask task) { @@ -57,7 +57,7 @@ namespace MCGalaxy.Commands.Misc { Player p = state.player; 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); } Player.Message(p, "Stopped flying"); @@ -76,29 +76,26 @@ namespace MCGalaxy.Commands.Misc { for (int zz = z - 2; zz <= z + 2; zz++) 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; - pos.X = offX; pos.Y = offY; pos.Z = offZ; - state.next.Add(pos); + pos.X = (ushort)xx; pos.Y = (ushort)yy; pos.Z = (ushort)zz; + if (!p.level.IsAirAt(pos.X, pos.Y, pos.Z)) state.glassCoords.Add(pos); } - foreach (Vec3U16 P in state.next) { - if (state.last.Contains(P)) continue; - state.last.Add(P); + foreach (Vec3U16 P in state.glassCoords) { + if (state.lastGlass.Contains(P)) continue; + state.lastGlass.Add(P); p.SendBlockchange(P.X, P.Y, P.Z, glass); } - for (int i = 0; i < state.last.Count; i++) { - Vec3U16 P = state.last[i]; - if (state.next.Contains(P)) continue; + for (int i = 0; i < state.lastGlass.Count; i++) { + Vec3U16 P = state.lastGlass[i]; + if (state.glassCoords.Contains(P)) continue; - p.SendBlockchange(P.X, P.Y, P.Z, ExtBlock.Air); - state.last.RemoveAt(i); i--; + p.RevertBlock(P.X, P.Y, P.Z); + state.lastGlass.RemoveAt(i); i--; } - state.next.Clear(); + state.glassCoords.Clear(); state.oldPos = p.Pos; } diff --git a/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs b/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs index ddec4f912..d992d3595 100644 --- a/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs +++ b/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs @@ -17,11 +17,10 @@ */ //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 using System; -using System.Collections.Generic; using MCGalaxy.Drawing.Brushes; using MCGalaxy.Maths; @@ -52,9 +51,7 @@ namespace MCGalaxy.Drawing.Ops { int dist = xx * xx + zz * zz; if (dist > curRadius * curRadius) continue; - byte ctile = Level.GetTile(x, y, z); - if (ctile != 0) continue; - output(Place(x, y, z, brush)); + if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush)); } } } @@ -88,9 +85,7 @@ namespace MCGalaxy.Drawing.Ops { if (dist > curRadius * curRadius || dist < (curRadius - 1) * (curRadius - 1)) continue; - byte ctile = Level.GetTile(x, y, z); - if (ctile != 0) continue; - output(Place(x, y, z, brush)); + if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush)); } } } @@ -120,9 +115,7 @@ namespace MCGalaxy.Drawing.Ops { double curRadius = Radius * ((double)curHeight / (double)height); int dist = xx * xx + zz * zz; if (dist > curRadius * curRadius) continue; - - byte ctile = Level.GetTile(x, y, z); - if (ctile != 0) continue; + if (!Level.IsAirAt(x, y, z)) continue; bool layer = dist >= (curRadius - 1) * (curRadius - 1); block.BlockID = layer ? Block.grass : Block.lavastill; diff --git a/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs b/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs index 0c2edad52..f2045a0ab 100644 --- a/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs +++ b/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs @@ -17,11 +17,10 @@ */ //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 using System; -using System.Collections.Generic; using MCGalaxy.Drawing.Brushes; using MCGalaxy.Maths; @@ -51,9 +50,7 @@ namespace MCGalaxy.Drawing.Ops { double curRadius = Radius * ((double)curHeight / (double)height); if (Math.Abs(xx) > curRadius || Math.Abs(zz) > curRadius) continue; - byte ctile = Level.GetTile(x, y, z); - if (ctile != 0) continue; - output(Place(x, y, z, brush)); + if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush)); } } } @@ -87,9 +84,7 @@ namespace MCGalaxy.Drawing.Ops { if (absx > curRadius || absz > curRadius) continue; if (absx < (curRadius - 1) && absz < (curRadius - 1)) continue; - byte ctile = Level.GetTile(x, y, z); - if (ctile != 0) continue; - output(Place(x, y, z, brush)); + if (Level.IsAirAt(x, y, z)) output(Place(x, y, z, brush)); } } } diff --git a/MCGalaxy/Drawing/DrawOps/CuboidDrawOps.cs b/MCGalaxy/Drawing/DrawOps/CuboidDrawOps.cs index 494f8402c..574fca708 100644 --- a/MCGalaxy/Drawing/DrawOps/CuboidDrawOps.cs +++ b/MCGalaxy/Drawing/DrawOps/CuboidDrawOps.cs @@ -113,7 +113,7 @@ namespace MCGalaxy.Drawing.Ops { int startX = i; for (ushort x = p1.X; x <= p2.X; x++) { i = (i + stepX) % 13; - if (Level.GetTile(x, y, z) != Block.air) { + if (!Level.IsAirAt(x, y, z)) { block.BlockID = (byte)(Block.red + i); output(Place(x, y, z, block)); } diff --git a/MCGalaxy/Drawing/DrawOps/TreeDrawOp.cs b/MCGalaxy/Drawing/DrawOps/TreeDrawOp.cs index 19318eb83..2a836516f 100644 --- a/MCGalaxy/Drawing/DrawOps/TreeDrawOp.cs +++ b/MCGalaxy/Drawing/DrawOps/TreeDrawOp.cs @@ -49,7 +49,7 @@ namespace MCGalaxy.Drawing.Ops { 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) { output(Place(xT, yT, zT, (ExtBlock)bT)); diff --git a/MCGalaxy/Games/CTF/CtfConfig.cs b/MCGalaxy/Games/CTF/CtfConfig.cs index bb3319cd0..47e5af422 100644 --- a/MCGalaxy/Games/CTF/CtfConfig.cs +++ b/MCGalaxy/Games/CTF/CtfConfig.cs @@ -46,9 +46,9 @@ namespace MCGalaxy.Games { case "base.red.z": redbase.z = ushort.Parse(value); break; case "base.red.block": - redbase.block = Block.Byte(value); break; + redbase.block = ExtBlock.FromRaw(byte.Parse(value)); break; case "base.blue.block": - bluebase.block = Block.Byte(value); break; + bluebase.block = ExtBlock.FromRaw(byte.Parse(value)); break; case "base.blue.spawnx": bluebase.spawnx = ushort.Parse(value); break; case "base.blue.spawny": diff --git a/MCGalaxy/Games/CTF/CtfGame.cs b/MCGalaxy/Games/CTF/CtfGame.cs index a6af98842..31e27547d 100644 --- a/MCGalaxy/Games/CTF/CtfGame.cs +++ b/MCGalaxy/Games/CTF/CtfGame.cs @@ -63,7 +63,7 @@ namespace MCGalaxy.Games { internal sealed class Base { public ushort x, y, z; public ushort spawnx, spawny, spawnz; - public byte block; + public ExtBlock block; public void SendToSpawn(Level mainlevel, CTFGame game, Player p1) { Position pos = new Position(spawnx, spawny, spawny); @@ -74,7 +74,7 @@ namespace MCGalaxy.Games { xx = (ushort)(rand.Next(0, mainlevel.Width)); yy = (ushort)(rand.Next(0, mainlevel.Height)); 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; } @@ -191,7 +191,7 @@ namespace MCGalaxy.Games { if (GetPlayer(other).hasflag) { Chat.MessageLevel(mainlevel, redteam.color + p.name + " DROPPED THE FLAG!"); 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; } @@ -251,8 +251,8 @@ namespace MCGalaxy.Games { LoadMap(maps[new Random().Next(maps.Count)]); if (needSetup) AutoSetup(); - redbase.block = Block.red; - bluebase.block = Block.blue; + redbase.block = (ExtBlock)Block.red; + bluebase.block = (ExtBlock)Block.blue; Server.s.Log("[Auto_CTF] Running..."); started = true; diff --git a/MCGalaxy/Games/CTF/Setup.cs b/MCGalaxy/Games/CTF/Setup.cs index 41f448bb9..25257359e 100644 --- a/MCGalaxy/Games/CTF/Setup.cs +++ b/MCGalaxy/Games/CTF/Setup.cs @@ -51,7 +51,7 @@ namespace MCGalaxy.Games { cache[p].bx = x; cache[p].by = y; 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, "Just hit it"); cache[p].s = Step.GetRedFlag; @@ -60,7 +60,7 @@ namespace MCGalaxy.Games { cache[p].rx = x; cache[p].ry = y; 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, "Now I can do random spawns, or do you have a spawn in mind?"); Player.Message(p, "Say - (Random/Set)"); @@ -172,7 +172,7 @@ namespace MCGalaxy.Games { public int middle = 0; public int bx, by, bz; public int rx, ry, rz; - public byte blue, red; + public ExtBlock blue, red; public int bluex, bluey, bluez; } diff --git a/MCGalaxy/Games/Countdown/CountdownGame.cs b/MCGalaxy/Games/Countdown/CountdownGame.cs index 92d5b499a..b3c1204ee 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.cs @@ -185,25 +185,25 @@ namespace MCGalaxy.Games { //beneath this is checking the glass next to the square bool up = false, left = false, right = false, down = false; //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(x2, y, (ushort)(z2 + 1), ExtBlock.Air); 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(x2, y, (ushort)(z1 - 1), ExtBlock.Air); 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, z2, ExtBlock.Air); 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, z2, ExtBlock.Air); @@ -211,19 +211,19 @@ namespace MCGalaxy.Games { } //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); } - 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); } - 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); } - 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); } diff --git a/MCGalaxy/Generator/RealisticMapGen.cs b/MCGalaxy/Generator/RealisticMapGen.cs index 66b8abc20..287c35d19 100644 --- a/MCGalaxy/Generator/RealisticMapGen.cs +++ b/MCGalaxy/Generator/RealisticMapGen.cs @@ -133,7 +133,7 @@ namespace MCGalaxy.Generator { } 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 (rand.Next(13) == 0 && !Tree.TreeCheck(Lvl, x, y, z, treeDist)) { Tree tree = null; @@ -143,7 +143,7 @@ namespace MCGalaxy.Generator { tree.SetData(rand, tree.DefaultSize(rand)); 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); }); } diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index 88970c635..71abb871a 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -55,6 +55,20 @@ namespace MCGalaxy { block.ExtID = block.BlockID == Block.custom_block ? GetExtTileNoCheck(x, y, z) : Block.air; return block; + } + + /// Gets whether the block at the given coordinates is air. + 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; + } + + /// 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; } /// Gets the block at the given coordinates. @@ -99,12 +113,6 @@ namespace MCGalaxy { 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) { byte tile = GetExtTile(index); BlockDefinition def = CustomBlockDefs[tile];