From 497236be31aef3e4188297b0a56ecf896b507b74 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 1 Mar 2018 16:02:18 +1100 Subject: [PATCH] Fix /bind with source block being custom causing error --- MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs | 2 +- MCGalaxy/Commands/Moderation/ModActionCmd.cs | 9 ++++----- MCGalaxy/Commands/building/CmdBind.cs | 4 ++-- MCGalaxy/Levels/Level.Physics.cs | 4 ++-- MCGalaxy/Player/Player.Fields.cs | 2 +- MCGalaxy/Player/Player.Handlers.cs | 2 +- MCGalaxy/Player/Player.cs | 8 ++++---- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs index 88f21f014..234272005 100644 --- a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs @@ -67,7 +67,7 @@ namespace MCGalaxy.Blocks { } // Use red wool to detonate c4 - BlockID held = p.BlockBindings[(BlockRaw)p.RawHeldBlock]; + BlockID held = p.BlockBindings[p.RawHeldBlock]; if (held == Block.Red) { Player.Message(p, "Placed detonator block, delete it to detonate."); C4Det(p, Block.C4Detonator, x, y, z); return; diff --git a/MCGalaxy/Commands/Moderation/ModActionCmd.cs b/MCGalaxy/Commands/Moderation/ModActionCmd.cs index abf23b169..116954506 100644 --- a/MCGalaxy/Commands/Moderation/ModActionCmd.cs +++ b/MCGalaxy/Commands/Moderation/ModActionCmd.cs @@ -114,13 +114,12 @@ namespace MCGalaxy.Commands.Moderation { Block.GetName(who, block)); } - for (int i = 0; i < who.BlockBindings.Length; i++) { - block = who.BlockBindings[i]; - BlockID defaultBinding = Block.FromRaw((byte)i); - if (block == defaultBinding) continue; + for (int b = 0; b < who.BlockBindings.Length; b++) { + block = who.BlockBindings[b]; + if (block == b) continue; if (!CommandParser.IsBlockAllowed(who, "place", block)) { - who.BlockBindings[i] = defaultBinding; + who.BlockBindings[b] = (BlockID)b; Player.Message(who, " Hence, binding for &b{0} %Swas unbound", Block.GetName(who, defaultBinding)); } diff --git a/MCGalaxy/Commands/building/CmdBind.cs b/MCGalaxy/Commands/building/CmdBind.cs index bbca68104..5b72ca17b 100644 --- a/MCGalaxy/Commands/building/CmdBind.cs +++ b/MCGalaxy/Commands/building/CmdBind.cs @@ -31,8 +31,8 @@ namespace MCGalaxy.Commands.Building { if (args.Length > 2) { Help(p); return; } if (args[0].CaselessEq("clear")) { - for (int i = 0; i < p.BlockBindings.Length; i++) { - p.BlockBindings[i] = Block.FromRaw((byte)i); + for (int b = 0; b < p.BlockBindings.Length; b++) { + p.BlockBindings[b] = (BlockID)b; } Player.Message(p, "All bindings were unbound."); return; diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs index 8b2df9e83..07a181544 100644 --- a/MCGalaxy/Levels/Level.Physics.cs +++ b/MCGalaxy/Levels/Level.Physics.cs @@ -332,13 +332,13 @@ namespace MCGalaxy { ushort x, y, z; IntToPos(C.Index, out x, out y, out z); - BlockID block = (BlockID)(args.Value1 | (args.ExtBlock << 8)); + BlockID block = (BlockID)(args.Value1 | (args.ExtBlock << Block.ExtendedShift)); Blockchange(C.Index, block, true, default(PhysicsArgs)); } else if (args.Type2 == PhysicsArgs.Revert) { ushort x, y, z; IntToPos(C.Index, out x, out y, out z); - BlockID block = (BlockID)(args.Value2 | (args.ExtBlock << 8)); + BlockID block = (BlockID)(args.Value2 | (args.ExtBlock << Block.ExtendedShift)); Blockchange(C.Index, block, true, default(PhysicsArgs)); } } catch (Exception e) { diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 704fa4e85..bf61fe736 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -195,7 +195,7 @@ namespace MCGalaxy { public BlockID ModeBlock; public BlockID RawHeldBlock = Block.Stone; - public BlockID[] BlockBindings = new BlockID[Block.Count]; + public BlockID[] BlockBindings = new BlockID[Block.ExtendedCount]; public string[] CmdBindings = new string[10]; public string[] CmdArgsBindings = new string[10]; diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 6773940bf..97a1c35e6 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -110,7 +110,7 @@ namespace MCGalaxy { } BlockID held = block; - if (!Block.IsPhysicsType(block)) block = BlockBindings[(BlockRaw)block]; + block = BlockBindings[block]; if (!CheckManualChange(old, block, deletingBlock)) { RevertBlock(x, y, z); return; } diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index 87384d8c5..c778a3cb6 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -54,8 +54,8 @@ namespace MCGalaxy { internal Player() { spamChecker = new SpamChecker(this); SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask; - for (int i = 0; i < BlockBindings.Length; i++) { - BlockBindings[i] = Block.FromRaw((byte)i); + for (int b = 0; b < BlockBindings.Length; b++) { + BlockBindings[b] = (BlockID)b; } } @@ -93,7 +93,7 @@ namespace MCGalaxy { public BlockID GetHeldBlock() { if (ModeBlock != Block.Air) return ModeBlock; - return BlockBindings[(BlockRaw)RawHeldBlock]; + return BlockBindings[RawHeldBlock]; } public void SetPrefix() { @@ -472,7 +472,7 @@ namespace MCGalaxy { SelectionHandler callback = selCallback; ClearSelection(); - if (!Block.IsPhysicsType(block)) block = p.BlockBindings[(BlockRaw)block]; + block = p.BlockBindings[block]; bool canRepeat = callback(this, selMarks, state, block); if (canRepeat && staticCommands) {