From 112c5890887df31c5d7a93009c2bbc3d23300782 Mon Sep 17 00:00:00 2001 From: 123DontMessWitMe <5544543+123DMWM@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:14:36 -0400 Subject: [PATCH] Improve MB/Portal Show for deleted blocks Displays MBs and Portals as black wool if they have been deleted --- MCGalaxy/Commands/building/CmdMessageBlock.cs | 55 +++++++------ MCGalaxy/Commands/building/CmdPortal.cs | 81 +++++++++++-------- 2 files changed, 78 insertions(+), 58 deletions(-) diff --git a/MCGalaxy/Commands/building/CmdMessageBlock.cs b/MCGalaxy/Commands/building/CmdMessageBlock.cs index 5afb40bbb..8eec63a0d 100644 --- a/MCGalaxy/Commands/building/CmdMessageBlock.cs +++ b/MCGalaxy/Commands/building/CmdMessageBlock.cs @@ -1,14 +1,14 @@ /* Copyright 2011 MCForge - + Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may not use this file except in compliance with the Licenses. You may obtain a copy of the Licenses at - + https://opensource.org/license/ecl-2-0/ https://www.gnu.org/licenses/gpl-3.0.html - + Unless required by applicable law or agreed to in writing, software distributed under the Licenses are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express @@ -43,11 +43,11 @@ public override void Use(Player p, string message, CommandData data) { MBArgs mbArgs = new MBArgs(); string[] args = message.SplitSpaces(2); string block = args[0].ToLower(); - + mbArgs.Block = GetBlock(p, block, ref allMessage); if (mbArgs.Block == Block.Invalid) return; if (!CommandParser.IsBlockAllowed(p, "place a message block of", mbArgs.Block)) return; - + if (allMessage) { mbArgs.Message = message; } else if (args.Length == 1) { @@ -55,20 +55,20 @@ public override void Use(Player p, string message, CommandData data) { } else { mbArgs.Message = args[1]; } - + bool allCmds = HasExtraPerm(p, data.Rank, 1); if (!MessageBlock.Validate(p, mbArgs.Message, allCmds)) return; p.Message("Place where you wish the message block to go."); p.MakeSelection(1, mbArgs, PlacedMark); } - + BlockID GetBlock(Player p, string name, ref bool allMessage) { if (name == "show") { ShowMessageBlocks(p); return Block.Invalid; } BlockID block = Block.Parse(p, name); if (block != Block.Invalid && p.level.Props[block].IsMessageBlock) return block; - + // Hardcoded aliases for backwards compatibility block = Block.MB_White; if (name == "white") block = Block.MB_White; @@ -76,17 +76,22 @@ BlockID GetBlock(Player p, string name, ref bool allMessage) { if (name == "air") block = Block.MB_Air; if (name == "water") block = Block.MB_Water; if (name == "lava") block = Block.MB_Lava; - + allMessage = block == Block.MB_White && name != "white"; if (p.level.Props[block].IsMessageBlock) return block; - + Help(p); return Block.Invalid; } + static bool IsMBBlock(Level lvl, Vec3U16 pos) { + BlockID block = lvl.GetBlock(pos.X, pos.Y, pos.Z); + return lvl.Props[block].IsMessageBlock; + } + bool PlacedMark(Player p, Vec3S32[] marks, object state, BlockID block) { ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z; MBArgs args = (MBArgs)state; - + BlockID old = p.level.GetBlock(x, y, z); if (p.level.CheckAffect(p, x, y, z, old, args.Block)) { p.level.UpdateBlock(p, x, y, z, args.Block); @@ -100,11 +105,11 @@ bool PlacedMark(Player p, Vec3S32[] marks, object state, BlockID block) { } return true; } - + void UpdateDatabase(Player p, MBArgs args, ushort x, ushort y, ushort z) { string map = p.level.name; object locker = ThreadSafeCache.DBCache.GetLocker(map); - + lock (locker) { MessageBlock.Set(map, x, y, z, args.Message); } @@ -112,46 +117,47 @@ void UpdateDatabase(Player p, MBArgs args, ushort x, ushort y, ushort z) { class MBArgs { public string Message; public BlockID Block; } - + void ShowMessageBlocks(Player p) { p.showMBs = !p.showMBs; List coords = MessageBlock.GetAllCoords(p.level.MapName); - + foreach (Vec3U16 pos in coords) { if (p.showMBs) { - p.SendBlockchange(pos.X, pos.Y, pos.Z, Block.Green); + BlockID block = IsMBBlock(p.level, pos) ? Block.Green : Block.Black; + p.SendBlockchange(pos.X, pos.Y, pos.Z, block); } else { p.RevertBlock(pos.X, pos.Y, pos.Z); } } - p.Message("Now {0} &SMBs.", + p.Message("Now {0} &SMBs.", p.showMBs ? "showing &a" + coords.Count : "hiding"); } - + static string Format(BlockID block, Player p, BlockProps[] props) { if (!props[block].IsMessageBlock) return null; - + // We want to use the simple aliases if possible if (block == Block.MB_Black) return "black"; if (block == Block.MB_White) return "white"; if (block == Block.MB_Air) return "air"; if (block == Block.MB_Lava) return "lava"; - if (block == Block.MB_Water) return "water"; + if (block == Block.MB_Water) return "water"; return Block.GetName(p, block); } - + static List SupportedBlocks(Player p) { List names = new List(); BlockProps[] props = p.IsSuper ? Block.Props : p.level.Props; - + for (int i = 0; i < props.Length; i++) { string name = Format((BlockID)i, p, props); if (name != null) names.Add(name); } return names; } - + public override void Help(Player p) { p.Message("&T/MB [block] [message]"); p.Message("&HPlaces a message in your next block."); @@ -159,7 +165,8 @@ public override void Help(Player p) { p.Message("&H Supported blocks: &S{0}", names.Join()); p.Message("&H Use | to separate commands, e.g. /say 1 |/say 2"); p.Message("&H Note: \"@p\" is a placeholder for player who clicked."); - p.Message("&T/MB show &H- Shows or hides message blocks"); + p.Message("&T/MB show &H- Shows or hides message blocks on the map"); + p.Message("&H (green = valid message block, black = queued for removal)"); } } } diff --git a/MCGalaxy/Commands/building/CmdPortal.cs b/MCGalaxy/Commands/building/CmdPortal.cs index 9615a2757..31c83126f 100644 --- a/MCGalaxy/Commands/building/CmdPortal.cs +++ b/MCGalaxy/Commands/building/CmdPortal.cs @@ -1,14 +1,14 @@ /* Copyright 2011 MCForge - + Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may not use this file except in compliance with the Licenses. You may obtain a copy of the Licenses at - + https://opensource.org/license/ecl-2-0/ https://www.gnu.org/licenses/gpl-3.0.html - + Unless required by applicable law or agreed to in writing, software distributed under the Licenses are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express @@ -49,18 +49,18 @@ public override void Use(Player p, string message, CommandData data) { if (pArgs.Block == Block.Invalid) return; if (!CommandParser.IsBlockAllowed(p, "place a portal of", pArgs.Block)) return; pArgs.Entries = new List(); - + p.Message("Place an &aEntry block &Sfor the portal"); p.ClearBlockchange(); p.blockchangeObject = pArgs; p.Blockchange += EntryChange; } - + BlockID GetBlock(Player p, string name) { if (name == "show") { ShowPortals(p); return Block.Invalid; } BlockID block = Block.Parse(p, name); if (block != Block.Invalid && p.level.Props[block].IsPortal) return block; - + // Hardcoded aliases for backwards compatibility block = Block.Invalid; if (name.Length == 0) block = Block.Portal_Blue; @@ -69,11 +69,16 @@ BlockID GetBlock(Player p, string name) { if (name == "air") block = Block.Portal_Air; if (name == "water") block = Block.Portal_Water; if (name == "lava") block = Block.Portal_Lava; - + if (p.level.Props[block].IsPortal) return block; Help(p); return Block.Invalid; } + static bool IsPortalBlock(Level lvl, Vec3U16 pos) { + BlockID block = lvl.GetBlock(pos.X, pos.Y, pos.Z); + return lvl.Props[block].IsPortal; + } + void EntryChange(Player p, ushort x, ushort y, ushort z, BlockID block) { PortalArgs args = (PortalArgs)p.blockchangeObject; BlockID old = p.level.GetBlock(x, y, z); @@ -104,11 +109,11 @@ void EntryChange(Player p, ushort x, ushort y, ushort z, BlockID block) { Block.GetName(p, Block.Red)); } } - + void ExitChange(Player p, ushort x, ushort y, ushort z, BlockID block) { p.ClearBlockchange(); p.RevertBlock(x, y, z); - + PortalArgs args = (PortalArgs)p.blockchangeObject; string exitMap = p.level.name; @@ -116,7 +121,7 @@ void ExitChange(Player p, ushort x, ushort y, ushort z, BlockID block) { string map = P.Map; if (map == p.level.name) p.RevertBlock(P.x, P.y, P.z); object locker = ThreadSafeCache.DBCache.GetLocker(map); - + lock (locker) { Portal.Set(map, P.x, P.y, P.z, x, y, z, exitMap); } @@ -133,67 +138,75 @@ void ExitChange(Player p, ushort x, ushort y, ushort z, BlockID block) { class PortalArgs { public List Entries; public BlockID Block; public bool Multi; } struct PortalPos { public ushort x, y, z; public string Map; } - + static void ShowPortals(Player p) { p.showPortals = !p.showPortals; List coords = Portal.GetAllCoords(p.level.MapName); - + List exits = new List(); + foreach (Vec3U16 pos in coords) { + PortalExit exit = Portal.Get(p.level.MapName, pos.X, pos.Y, pos.Z); if (p.showPortals) { - p.SendBlockchange(pos.X, pos.Y, pos.Z, Block.Green); + bool exists = IsPortalBlock(p.Level, pos); + Vec3U16 exitPos = new Vec3U16(exit.X, exit.Y, exit.Z); + if (exists && !exits.Contains(exitPos)) exits.Add(exitPos); + + // Show Entry + BlockID entryBlock = exists ? Block.Green : Block.Black; + p.SendBlockchange(pos.X, pos.Y, pos.Z, entryBlock); + + // Show Exit + if (exit.Map != p.level.MapName) continue; + BlockID exitBlock = exists || exits.Contains(exitPos) ? Block.Red : Block.Black; + p.SendBlockchange(exit.X, exit.Y, exit.Z, exitBlock); } else { + // Revert Entry p.RevertBlock(pos.X, pos.Y, pos.Z); - } - } - - List exits = Portal.GetAllExits(p.level.MapName); - foreach (PortalExit exit in exits) { - if (exit.Map != p.level.MapName) continue; - - if (p.showPortals) { - p.SendBlockchange(exit.X, exit.Y, exit.Z, Block.Red); - } else { + + // Revert Exit + if (exit.Map != p.level.MapName) continue; p.RevertBlock(exit.X, exit.Y, exit.Z); } } - - p.Message("Now {0} &Sportals.", + + p.Message("Now {0} &Sportals.", p.showPortals ? "showing &a" + coords.Count : "hiding"); } - - + + static string Format(BlockID block, Player p, BlockProps[] props) { if (!props[block].IsPortal) return null; - + // We want to use the simple aliases if possible if (block == Block.Portal_Orange) return "orange"; if (block == Block.Portal_Blue) return "blue"; if (block == Block.Portal_Air) return "air"; if (block == Block.Portal_Lava) return "lava"; - if (block == Block.Portal_Water) return "water"; + if (block == Block.Portal_Water) return "water"; return Block.GetName(p, block); } - + static List SupportedBlocks(Player p) { List names = new List(); BlockProps[] props = p.IsSuper ? Block.Props : p.level.Props; - + for (int i = 0; i < props.Length; i++) { string name = Format((BlockID)i, p, props); if (name != null) names.Add(name); } return names; } - + public override void Help(Player p) { p.Message("&T/Portal [block]"); p.Message("&HPlace a block for the entry, then another block for exit."); p.Message("&T/Portal [block] multi"); p.Message("&HPlace multiple blocks for entries, then a {0} block for exit.", Block.GetName(p, Block.Red)); p.Message("&H Note: The exit can be on a different level."); - List names = SupportedBlocks(p); + List names = SupportedBlocks(p); p.Message("&H Supported blocks: &S{0}", names.Join()); - p.Message("&T/Portal show &H- Shows portals (green = entry, red = exit)"); + p.Message("&T/Portal show &H- Shows or hides portals on the map"); + p.Message("&H (green = entry, red = exit, black = queued for removal)"); } } }