Core: Fix mark/click, it should activate mbs/portals/doors at those coords if no selection is in progress. (Thanks xnotx123)

This commit is contained in:
UnknownShadow200 2016-11-19 18:58:28 +11:00
parent 06707b1ee3
commit 1963feafb0
3 changed files with 47 additions and 20 deletions

View File

@ -115,6 +115,7 @@ namespace MCGalaxy.Commands
Player.Message(p, "No Complex Blocks look like \"{0}\"", block);
}
}
static void OutputBlockProps(Player p, byte b) {
BlockProps props = Block.Props[b];

View File

@ -15,6 +15,8 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Blocks;
namespace MCGalaxy.Commands.Building {
public sealed class CmdMark : Command {
public override string name { get { return "mark"; } }
@ -29,22 +31,38 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) {
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (message.CaselessEq("all")) {
if (!p.HasBlockchange) {
Player.Message(p, "Cannot mark, no selection or cuboid in progress."); return;
}
if (message.CaselessEq("all")) {
Level lvl = p.level;
PlaceMark(p, 0, 0, 0);
PlaceMark(p, lvl.Width - 1, lvl.Height - 1, lvl.Length - 1);
} else {
return;
}
// convert player pos to block coords
Vec3U16 P = Vec3U16.ClampPos(p.pos[0], (ushort)(p.pos[1] - 32), p.pos[2], p.level);
P.X /= 32; P.Y /= 32; P.Z /= 32;
if (message != "" && !ParseCoords(message, p, ref P)) return;
P = Vec3U16.Clamp(P.X, P.Y, P.Z, p.level);
if (!p.HasBlockchange) {
PlaceMark(p, P.X, P.Y, P.Z);
} else {
// We only want to activate blocks in the world
byte old = p.level.GetTile(P.X, P.Y, P.Z);
if (!p.CheckManualChange(old, Block.air, false)) return;
HandleDelete handler = BlockBehaviour.deleteHandlers[old];
if (handler != null) {
handler(p, old, P.X, P.Y, P.Z);
} else {
Player.Message(p, "Cannot mark, no selection or cuboid in progress, " +
"nor could the existing block at the coordinates be activated."); return;
}
}
}
@ -79,6 +97,7 @@ namespace MCGalaxy.Commands.Building {
Player.Message(p, "%T/mark [x y z] %H- Places a marker for selections or cuboids");
Player.Message(p, " %HIf no xyz is given, marks at where you are standing");
Player.Message(p, " %He.g. /mark 30 y 20 will mark at (30, last y, 20)");
Player.Message(p, " %HNote: If no selection is in progress, activates (e.g. doors) the existing block at those coordinates.");
Player.Message(p, "%T/mark all %H- Places markers at min and max corners of the map");
}
}

View File

@ -101,13 +101,7 @@ namespace MCGalaxy {
}
}
if (!Block.canPlace(this, old) && !Block.BuildIn(old) && !Block.AllowBreak(old)) {
Formatter.MessageBlock(this, doDelete ? "delete " : "replace ", old);
RevertBlock(x, y, z); return;
}
if (!Block.canPlace(this, block)) {
Formatter.MessageBlock(this, "place ", block);
if (!CheckManualChange(old, block, doDelete)) {
RevertBlock(x, y, z); return;
}
@ -134,6 +128,19 @@ namespace MCGalaxy {
}
}
internal bool CheckManualChange(byte old, byte block, bool replaceMode) {
if (!Block.canPlace(this, old) && !Block.BuildIn(old) && !Block.AllowBreak(old)) {
Formatter.MessageBlock(this, replaceMode ? "replace " : "delete ", old);
return false;
}
if (!Block.canPlace(this, block)) {
Formatter.MessageBlock(this, "place ", block);
return false;
}
return true;
}
bool DeleteBlock(byte old, ushort x, ushort y, ushort z, byte block, byte extBlock) {
if (deleteMode) { return ChangeBlock(x, y, z, Block.air, 0); }
bool changed = true;