From 59b0d8efc700b6b35dbf6ac586d4857fefeea922 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 26 Jun 2016 11:36:23 +1000 Subject: [PATCH] Fix placing grass under grass not changing bottom grass to dirt (Thanks Mirzuuuh), fix placing dirt at top layer not changing to grass, fix level env and level properties not saving. --- Blocks/Behaviour/Block.Behaviour.cs | 3 ++- Blocks/Behaviour/PlaceBehaviour.cs | 20 ++++++++++---------- Levels/IO/LvlProperties.cs | 5 +++-- Player/Player.Handlers.cs | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Blocks/Behaviour/Block.Behaviour.cs b/Blocks/Behaviour/Block.Behaviour.cs index a67f70394..a39aa2e06 100644 --- a/Blocks/Behaviour/Block.Behaviour.cs +++ b/Blocks/Behaviour/Block.Behaviour.cs @@ -49,7 +49,8 @@ namespace MCGalaxy { deleteHandlers[Block.firework] = DeleteBehaviour.Firework; deleteHandlers[Block.c4det] = DeleteBehaviour.C4Det; - placeHandlers[Block.dirt] = PlaceBehaviour.Dirt; + placeHandlers[Block.dirt] = PlaceBehaviour.Grass; + placeHandlers[Block.grass] = PlaceBehaviour.Grass; placeHandlers[Block.staircasestep] = PlaceBehaviour.Stairs; placeHandlers[Block.c4] = PlaceBehaviour.C4; placeHandlers[Block.c4det] = PlaceBehaviour.C4Det; diff --git a/Blocks/Behaviour/PlaceBehaviour.cs b/Blocks/Behaviour/PlaceBehaviour.cs index ff4b66840..06933b6d1 100644 --- a/Blocks/Behaviour/PlaceBehaviour.cs +++ b/Blocks/Behaviour/PlaceBehaviour.cs @@ -22,19 +22,19 @@ namespace MCGalaxy.BlockBehaviour { internal static class PlaceBehaviour { - internal static bool Dirt(Player p, byte block, ushort x, ushort y, ushort z) { - if (!(p.level.physics == 0 || p.level.physics == 5)) { - p.ChangeBlock(x, y, z, Block.dirt, 0); return false; + internal static bool Grass(Player p, byte block, ushort x, ushort y, ushort z) { + Level lvl = p.level; + if (!(lvl.physics == 0 || lvl.physics == 5)) { + p.ChangeBlock(x, y, z, block, 0); return false; } - byte above = p.level.GetTile(x, (ushort)(y + 1), z), extAbove = 0; - if (above == Block.custom_block) - extAbove = p.level.GetExtTile(x, (ushort)(y + 1), z); + byte above = lvl.GetTile(x, (ushort)(y + 1), z), extAbove = 0; + if (above == Block.custom_block) + extAbove = lvl.GetExtTile(x, (ushort)(y + 1), z); - if (Block.LightPass(above, extAbove, p.level.CustomBlockDefs)) - p.ChangeBlock(x, y, z, Block.grass, 0); - else - p.ChangeBlock(x, y, z, Block.dirt, 0); + byte type = (above == Block.Zero || Block.LightPass(above, extAbove, lvl.CustomBlockDefs)) + ? Block.grass : Block.dirt; + p.ChangeBlock(x, y, z, type, 0); return false; } diff --git a/Levels/IO/LvlProperties.cs b/Levels/IO/LvlProperties.cs index 22080fe79..bea3c3f7c 100644 --- a/Levels/IO/LvlProperties.cs +++ b/Levels/IO/LvlProperties.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Levels.IO { public static void Save(Level level, string path) { try { - using (CP437Writer writer = new CP437Writer(path + ".properties")) + using (CP437Writer writer = new CP437Writer(path)) WriteLevelProperties(level, writer); } catch (Exception ex) { Server.s.Log("Failed to save level properties!"); @@ -32,8 +32,9 @@ namespace MCGalaxy.Levels.IO { return; } + path = Path.ChangeExtension(path, ".env"); try { - using (CP437Writer writer = new CP437Writer(path + ".env")) + using (CP437Writer writer = new CP437Writer(path)) WriteEnvProperties(level, writer); } catch (Exception ex) { Server.s.Log("Failed to save environment properties"); diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 64a22ba0a..253c2fb03 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -45,7 +45,7 @@ namespace MCGalaxy { } public void ManualChange(ushort x, ushort y, ushort z, byte action, byte type, byte extType = 0) { - ManualChange(x, y, z, action, type, extType, true); + ManualChange(x, y, z, action, type, extType, true); } public void ManualChange(ushort x, ushort y, ushort z, byte action,