From 3e5e122951d42b073ee012556f0ce10465d4ed1e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 4 Mar 2018 19:28:08 +1100 Subject: [PATCH] Fix InventoryOrder from recent changes --- MCGalaxy/Blocks/Block.Convert.cs | 5 ++--- MCGalaxy/Blocks/Block.cs | 11 ++++++++--- MCGalaxy/Blocks/BlockDefinitions.cs | 16 ++++++---------- MCGalaxy/Commands/CPE/CustomBlockCommand.cs | 8 ++++---- MCGalaxy/Commands/Information/CmdAbout.cs | 2 +- MCGalaxy/Player/Player.Handlers.cs | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/MCGalaxy/Blocks/Block.Convert.cs b/MCGalaxy/Blocks/Block.Convert.cs index c18c6f73f..8f2018cc7 100644 --- a/MCGalaxy/Blocks/Block.Convert.cs +++ b/MCGalaxy/Blocks/Block.Convert.cs @@ -32,8 +32,7 @@ namespace MCGalaxy { } public static string GetName(Player p, BlockID block) { - BlockRaw raw = (BlockRaw)block; - if (IsPhysicsType(block)) return coreNames[raw]; + if (IsPhysicsType(block)) return coreNames[block]; BlockDefinition def; if (!Player.IsSuper(p)) { @@ -43,7 +42,7 @@ namespace MCGalaxy { } if (def != null) return def.Name.Replace(" ", ""); - return block < Block.Extended ? coreNames[block] : raw.ToString(); + return block < Block.Extended ? coreNames[block] : ToRaw(block).ToString(); } public static BlockID Parse(Player p, string input) { diff --git a/MCGalaxy/Blocks/Block.cs b/MCGalaxy/Blocks/Block.cs index d1b32109c..a20fc22a3 100644 --- a/MCGalaxy/Blocks/Block.cs +++ b/MCGalaxy/Blocks/Block.cs @@ -182,8 +182,12 @@ namespace MCGalaxy { } } - public static BlockID FromRaw(byte raw) { - return raw < Block.CpeCount ? raw : (BlockID)(Block.Extended | raw); + public static BlockID FromRaw(BlockID raw) { + return raw < CpeCount ? raw : (BlockID)(raw + Block.Extended); + } + + public static BlockID ToRaw(BlockID raw) { + return raw < CpeCount ? raw : (BlockID)(raw - Block.Extended); } public static BlockID FromRaw(byte raw, bool extended) { @@ -192,7 +196,8 @@ namespace MCGalaxy { public static BlockID MapOldRaw(BlockID raw) { // old raw form was: 0 - 65 core block ids, 66 - 255 custom block ids - return IsPhysicsType(raw) ? ((BlockID)(Block.Extended | raw)) : raw; + // 256+ remain unchanged + return IsPhysicsType(raw) ? ((BlockID)(raw + Block.Extended)) : raw; } public static bool IsPhysicsType(BlockID block) { diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index d9bb01011..354604105 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -26,7 +26,7 @@ using BlockRaw = System.Byte; namespace MCGalaxy { public sealed class BlockDefinition { - public ushort BlockID; + public ushort BlockID; // really raw block ID public string Name; public byte CollideType; public float Speed; @@ -47,12 +47,8 @@ namespace MCGalaxy { public int InventoryOrder = -1; - public BlockID_ GetBlock() { - return (BlockID_)(BlockID < Block.CpeCount ? BlockID : (Block.Extended + BlockID)); - } - public void SetBlock(BlockID_ b) { - BlockID = (BlockID_)(b < Block.CpeCount ? b : (b - Block.Extended)); - } + public BlockID_ GetBlock() { return Block.FromRaw(BlockID); } + public void SetBlock(BlockID_ b) { BlockID = Block.ToRaw(b); } public const string GlobalPath = "blockdefs/global.json", GlobalBackupPath = "blockdefs/global.json.bak"; @@ -262,10 +258,10 @@ namespace MCGalaxy { internal static void SendLevelInventoryOrder(Player pl) { BlockDefinition[] defs = pl.level.CustomBlockDefs; - for (int i = 0; i < defs.Length; i++) { - BlockDefinition def = defs[i]; + for (int b = 0; b < defs.Length; b++) { + BlockDefinition def = defs[b]; if (def != null && def.InventoryOrder >= 0) { - pl.Send(Packet.SetInventoryOrder((byte)i, (byte)def.InventoryOrder)); + pl.Send(Packet.SetInventoryOrder((byte)def.BlockID, (byte)def.InventoryOrder)); } } } diff --git a/MCGalaxy/Commands/CPE/CustomBlockCommand.cs b/MCGalaxy/Commands/CPE/CustomBlockCommand.cs index 1bad2ada3..a7682f06b 100644 --- a/MCGalaxy/Commands/CPE/CustomBlockCommand.cs +++ b/MCGalaxy/Commands/CPE/CustomBlockCommand.cs @@ -128,7 +128,7 @@ namespace MCGalaxy.Commands.CPE { AddBlock(p, dstDef, global, cmd, props); string scope = global ? "global" : "level"; Player.Message(p, "Duplicated the {0} custom block with id \"{1}\" to \"{2}\".", scope, - (BlockRaw)src, (BlockRaw)dst); + Block.ToRaw(src), Block.ToRaw(dst)); } static void InfoHandler(Player p, string[] parts, bool global, string cmd) { @@ -140,7 +140,7 @@ namespace MCGalaxy.Commands.CPE { BlockDefinition def = defs[block]; if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; } - Player.Message(p, "About {0} ({1})", def.Name, (BlockRaw)def.BlockID); + Player.Message(p, "About {0} ({1})", def.Name, Block.ToRaw(block)); Player.Message(p, " Draw type: {0}, Blocks light: {1}, collide type: {2}", def.BlockDraw, def.BlocksLight, def.CollideType); Player.Message(p, " Fallback ID: {0}, Sound: {1}, Speed: {2}", @@ -512,13 +512,13 @@ namespace MCGalaxy.Commands.CPE { static void MessageNoBlock(Player p, BlockID block, bool global, string cmd) { string scope = global ? "global" : "level"; - Player.Message(p, "&cThere is no {1} custom block with the id \"{0}\".", (BlockRaw)block, scope); + Player.Message(p, "&cThere is no {1} custom block with the id \"{0}\".", Block.ToRaw(block), scope); Player.Message(p, "Type \"%T{0} list\" %Sto see a list of {1} custom blocks.", cmd, scope); } static void MessageAlreadyBlock(Player p, BlockID block, bool global, string cmd) { string scope = global ? "global" : "level"; - Player.Message(p, "&cThere is already a {1} custom block with the id \"{0}\".", (BlockRaw)block, scope); + Player.Message(p, "&cThere is already a {1} custom block with the id \"{0}\".", Block.ToRaw(block), scope); Player.Message(p, "Type \"%T{0} list\" %Sto see a list of {1} custom blocks.", cmd, scope); } diff --git a/MCGalaxy/Commands/Information/CmdAbout.cs b/MCGalaxy/Commands/Information/CmdAbout.cs index 17b99cae7..14fb96b56 100644 --- a/MCGalaxy/Commands/Information/CmdAbout.cs +++ b/MCGalaxy/Commands/Information/CmdAbout.cs @@ -66,7 +66,7 @@ namespace MCGalaxy.Commands.Info { string blockName = Block.GetName(p, block); Player.Message(p, "Block ({0}, {1}, {2}): &f{3} = {4}%S.", - x, y, z, (BlockRaw)block, blockName); + x, y, z, Block.ToRaw(block), blockName); if (HasExtraPerm(p, 1)) { BlockDBChange.OutputMessageBlock(p, block, x, y, z); diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index b77af755d..11349457c 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -296,7 +296,7 @@ namespace MCGalaxy { if (held >= Block.Extended) { if (!hasBlockDefs || level.CustomBlockDefs[held] == null) { - SendMessage("Invalid block type: " + (BlockRaw)held); + SendMessage("Invalid block type: " + Block.ToRaw(held)); RevertBlock(x, y, z); return; } }