diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index 904f37b66..140f4df1f 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -117,8 +117,8 @@ namespace MCGalaxy { public static void LoadGlobal() { BlockDefinition[] oldDefs = GlobalDefs; GlobalDefs = Load(true, null); - GlobalDefs[0] = new BlockDefinition(); - GlobalDefs[0].Name = "Air fallback"; + GlobalDefs[Block.air] = DefaultSet.MakeCustomBlock(Block.air); + GlobalDefs[Block.air].Name = "Air fallback"; GlobalProps = new BlockProps[Block.Count]; for (int i = 0; i < Block.Count; i++) diff --git a/MCGalaxy/Blocks/Physics/AirPhysics.cs b/MCGalaxy/Blocks/Physics/AirPhysics.cs index f44fde9d9..b7ba65f75 100644 --- a/MCGalaxy/Blocks/Physics/AirPhysics.cs +++ b/MCGalaxy/Blocks/Physics/AirPhysics.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Blocks.Physics { lvl.IntToPos(C.b, out x, out y, out z); ActivateablePhysics.CheckNeighbours(lvl, x, y, z); - ActivateablePhysics.CheckAt(lvl, lvl.PosToInt(x, (ushort)(y - 1), z)); + ActivateablePhysics.CheckAt(lvl, lvl.PosToInt(x, (ushort)(y - 1), z)); //Edge of map water if (lvl.edgeWater && (y < lvl.EdgeLevel && y >= (lvl.EdgeLevel + lvl.SidesOffset))) { diff --git a/MCGalaxy/Commands/CPE/CmdEnvironment.cs b/MCGalaxy/Commands/CPE/CmdEnvironment.cs index 5b8c7ce8f..b63b7c2cc 100644 --- a/MCGalaxy/Commands/CPE/CmdEnvironment.cs +++ b/MCGalaxy/Commands/CPE/CmdEnvironment.cs @@ -108,7 +108,7 @@ namespace MCGalaxy.Commands.CPE { case "edge": case "water": LevelEnv.SetBlock(p, value, EnvProp.EdgeBlock, - "edge block", Block.waterstill, ref lvl.HorizonBlock); break; + "edge block", Block.water, ref lvl.HorizonBlock); break; case "side": case "border": case "bedrock": @@ -130,7 +130,7 @@ namespace MCGalaxy.Commands.CPE { LevelEnv.SetWeather(p, lvl, "normal"); LevelEnv.SetBlock(p, "normal", EnvProp.EdgeBlock, - "edge block", Block.waterstill, ref lvl.HorizonBlock); + "edge block", Block.water, ref lvl.HorizonBlock); LevelEnv.SetBlock(p, "normal", EnvProp.SidesBlock, "sides block", Block.blackrock, ref lvl.EdgeBlock); diff --git a/MCGalaxy/Levels/BlockQueue.cs b/MCGalaxy/Levels/BlockQueue.cs index fd1892ed3..3f0454309 100644 --- a/MCGalaxy/Levels/BlockQueue.cs +++ b/MCGalaxy/Levels/BlockQueue.cs @@ -14,7 +14,7 @@ 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; using MCGalaxy.Network; @@ -22,35 +22,20 @@ namespace MCGalaxy { public static class BlockQueue { - public static int time { get { return (int)blocktimer.Interval; } set { blocktimer.Interval = value; } } + public static int time = 100; public static int blockupdates = 250; - static System.Timers.Timer blocktimer = new System.Timers.Timer(100); - static bool started = false; static BufferedBlockSender bulkSender = new BufferedBlockSender(); - public static void Start() { - blocktimer.Elapsed += delegate { - if (started) return; - started = true; - try { - Level[] loaded = LevelInfo.Loaded.Items; - foreach (Level lvl in loaded) { - lock (lvl.queueLock) - ProcessLevelBlocks(lvl); - } - bulkSender.level = null; - } catch (Exception ex) { - Server.ErrorLog(ex); - throw; - } finally { - started = false; - } - }; - blocktimer.Start(); + public static void Loop(SchedulerTask task) { + Level[] loaded = LevelInfo.Loaded.Items; + foreach (Level lvl in loaded) { + lock (lvl.queueLock) + ProcessLevelBlocks(lvl); + } + + bulkSender.level = null; + task.Delay = TimeSpan.FromMilliseconds(time); } - - public static void Pause() { blocktimer.Enabled = false; } - public static void Resume() { blocktimer.Enabled = true; } public static void Addblock(Player p, int index, byte type, byte extType = 0) { if (index == -1) return; @@ -71,16 +56,18 @@ namespace MCGalaxy { static void ProcessLevelBlocks(Level lvl) { try { if (lvl.blockqueue.Count == 0) return; + if (!lvl.HasPlayers()) { lvl.blockqueue.Clear(); return; } + bulkSender.level = lvl; int count = blockupdates; - if (lvl.blockqueue.Count < blockupdates || !lvl.HasPlayers()) + if (lvl.blockqueue.Count < blockupdates) count = lvl.blockqueue.Count; for (int i = 0; i < count; i++) { ulong flags = lvl.blockqueue[i]; - int index = (int)(flags >> 32); + int index = (int)(flags >> 32); byte block = (flags & 0x100) != 0 ? Block.custom_block : (byte)flags; - byte extBlock = (flags & 0x100) != 0 ? (byte)flags : Block.air; + byte extBlock = (flags & 0x100) != 0 ? (byte)flags : Block.air; bulkSender.Add(index, block, extBlock); } bulkSender.Send(true); diff --git a/MCGalaxy/Server/Server.Init.cs b/MCGalaxy/Server/Server.Init.cs index 9b1ee7a3a..43e685152 100644 --- a/MCGalaxy/Server/Server.Init.cs +++ b/MCGalaxy/Server/Server.Init.cs @@ -128,7 +128,8 @@ namespace MCGalaxy { InitZombieSurvival(); InitLavaSurvival(); - BlockQueue.Start(); + MainScheduler.QueueRepeat(BlockQueue.Loop, null, + TimeSpan.FromMilliseconds(BlockQueue.time)); Log("Finished setting up server, finding classicube.net url.."); ServerSetupFinished = true;