mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Make /outline a drawop.
This commit is contained in:
parent
2ab8c39e86
commit
5414321fc1
@ -19,10 +19,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
|
||||
namespace MCGalaxy.Commands
|
||||
{
|
||||
public sealed class CmdHollow : Command
|
||||
{
|
||||
namespace MCGalaxy.Commands {
|
||||
public sealed class CmdHollow : Command {
|
||||
public override string name { get { return "hollow"; } }
|
||||
public override string shortcut { get { return ""; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
|
@ -17,10 +17,10 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace MCGalaxy.Commands
|
||||
{
|
||||
public sealed class CmdOutline : Command
|
||||
{
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
|
||||
namespace MCGalaxy.Commands {
|
||||
public sealed class CmdOutline : Command {
|
||||
public override string name { get { return "outline"; } }
|
||||
public override string shortcut { get { return ""; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
@ -28,84 +28,45 @@ namespace MCGalaxy.Commands
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
public CmdOutline() { }
|
||||
|
||||
public override void Use(Player p, string message)
|
||||
{
|
||||
int number = message.Split(' ').Length;
|
||||
if (number != 2) { Help(p); return; }
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.Split(' ');
|
||||
if (args.Length != 2) { Help(p); return; }
|
||||
CatchPos cpos = default(CatchPos);
|
||||
|
||||
int pos = message.IndexOf(' ');
|
||||
string t = message.Substring(0, pos).ToLower();
|
||||
string t2 = message.Substring(pos + 1).ToLower();
|
||||
byte type = Block.Byte(t);
|
||||
if (type == 255) { Player.Message(p, "There is no block \"" + t + "\"."); return; }
|
||||
byte type2 = Block.Byte(t2);
|
||||
if (type2 == 255) { Player.Message(p, "There is no block \"" + t2 + "\"."); return; }
|
||||
if (!Block.canPlace(p, type2)) { Player.Message(p, "Cannot place that block type."); return; }
|
||||
cpos.type = Block.Byte(args[0]);
|
||||
if (cpos.type == Block.Zero) { Player.Message(p, "There is no block \"{0}\".", args[0]); return; }
|
||||
cpos.newType = Block.Byte(args[1]);
|
||||
if (cpos.newType == Block.Zero) { Player.Message(p, "There is no block \"{0}\".", args[1]); return; }
|
||||
if (!Block.canPlace(p, cpos.newType)) { Player.Message(p, "Cannot place that block type."); return; }
|
||||
|
||||
CatchPos cpos; cpos.newType = type2; cpos.type = type;
|
||||
|
||||
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
|
||||
p.blockchangeObject = cpos;
|
||||
Player.Message(p, "Place two blocks to determine the edges.");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||
}
|
||||
public override void Help(Player p)
|
||||
{
|
||||
Player.Message(p, "/outline [type] [type2] - Outlines [type] with [type2]");
|
||||
}
|
||||
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
|
||||
{
|
||||
|
||||
void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos bp = (CatchPos)p.blockchangeObject;
|
||||
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
|
||||
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
|
||||
}
|
||||
public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
|
||||
{
|
||||
|
||||
void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
if (cpos.type != Block.Zero)
|
||||
type = cpos.type;
|
||||
List<Vec3U16> buffer = new List<Vec3U16>();
|
||||
Vec3U16 pos;
|
||||
|
||||
bool AddMe = false;
|
||||
|
||||
for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
|
||||
for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
|
||||
for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
|
||||
{
|
||||
AddMe = false;
|
||||
|
||||
if (p.level.GetTile((ushort)(xx - 1), yy, zz) == cpos.type) AddMe = true;
|
||||
else if (p.level.GetTile((ushort)(xx + 1), yy, zz) == cpos.type) AddMe = true;
|
||||
else if (p.level.GetTile(xx, (ushort)(yy - 1), zz) == cpos.type) AddMe = true;
|
||||
else if (p.level.GetTile(xx, (ushort)(yy + 1), zz) == cpos.type) AddMe = true;
|
||||
else if (p.level.GetTile(xx, yy, (ushort)(zz - 1)) == cpos.type) AddMe = true;
|
||||
else if (p.level.GetTile(xx, yy, (ushort)(zz + 1)) == cpos.type) AddMe = true;
|
||||
|
||||
if (AddMe && p.level.GetTile(xx, yy, zz) != cpos.type) { pos.X = xx; pos.Y = yy; pos.Z = zz; buffer.Add(pos); }
|
||||
}
|
||||
|
||||
if (buffer.Count > p.group.maxBlocks)
|
||||
{
|
||||
Player.Message(p, "You tried to outline more than " + buffer.Count + " blocks.");
|
||||
Player.Message(p, "You cannot outline more than " + p.group.maxBlocks + ".");
|
||||
OutlineDrawOp op = new OutlineDrawOp();
|
||||
op.Type = cpos.type; op.NewType = cpos.newType;
|
||||
if (!DrawOp.DoDrawOp(op, null, p, x, y, z, cpos.x, cpos.y, cpos.z ))
|
||||
return;
|
||||
if (p.staticCommands)
|
||||
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||
}
|
||||
struct CatchPos { public byte type, newType; public ushort x, y, z; }
|
||||
|
||||
buffer.ForEach(P => p.level.UpdateBlock(p, P.X, P.Y, P.Z, cpos.newType, 0));
|
||||
Player.Message(p, "You outlined " + buffer.Count + " blocks.");
|
||||
|
||||
if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "/outline [type] [type2] - Outlines [type] with [type2]");
|
||||
}
|
||||
|
||||
struct CatchPos
|
||||
{
|
||||
public byte type;
|
||||
public byte newType;
|
||||
public ushort x, y, z;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,16 +20,11 @@ using MCGalaxy.Drawing.Brushes;
|
||||
|
||||
namespace MCGalaxy.Drawing.Ops {
|
||||
|
||||
public class HollowDrawOp : DrawOp {
|
||||
public class HollowDrawOp : CuboidDrawOp {
|
||||
|
||||
public override string Name { get { return "Hollow"; } }
|
||||
public byte Skip;
|
||||
|
||||
public override long GetBlocksAffected(Level lvl, Vec3U16[] marks) {
|
||||
Vec3U16 p1 = marks[0], p2 = marks[1];
|
||||
return (p2.X - p1.X + 1) * (p2.Y - p1.Y + 1) * (p2.Z - p1.Z + 1);
|
||||
}
|
||||
|
||||
public override void Perform(Vec3U16[] marks, Player p, Level lvl, Brush brush) {
|
||||
Vec3U16 p1 = marks[0], p2 = marks[1];
|
||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||
|
47
Drawing/DrawOps/OutlineDrawOp.cs
Normal file
47
Drawing/DrawOps/OutlineDrawOp.cs
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
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
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://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
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.Drawing.Brushes;
|
||||
|
||||
namespace MCGalaxy.Drawing.Ops {
|
||||
|
||||
public class OutlineDrawOp : CuboidDrawOp {
|
||||
|
||||
public override string Name { get { return "Outline"; } }
|
||||
public byte Type, NewType;
|
||||
|
||||
public override void Perform(Vec3U16[] marks, Player p, Level lvl, Brush brush) {
|
||||
Vec3U16 p1 = marks[0], p2 = marks[1];
|
||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||
for (ushort z = p1.Z; z <= p2.Z; z++)
|
||||
for (ushort x = p1.X; x <= p2.X; x++)
|
||||
{
|
||||
bool outline = false;
|
||||
if (lvl.GetTile((ushort)(x - 1), y, z) == Type) outline = true;
|
||||
else if (lvl.GetTile((ushort)(x + 1), y, z) == Type) outline = true;
|
||||
else if (lvl.GetTile(x, (ushort)(y - 1), z) == Type) outline = true;
|
||||
else if (lvl.GetTile(x, (ushort)(y + 1), z) == Type) outline = true;
|
||||
else if (lvl.GetTile(x, y, (ushort)(z - 1)) == Type) outline = true;
|
||||
else if (lvl.GetTile(x, y, (ushort)(z + 1)) == Type) outline = true;
|
||||
|
||||
if (outline && p.level.GetTile(x, y, z) != Type)
|
||||
PlaceBlock(p, lvl, x, y, z, NewType, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -466,12 +466,6 @@ namespace MCGalaxy {
|
||||
return pos.X < Width && pos.Y < Height && pos.Z < Length;
|
||||
}
|
||||
|
||||
public void UpdateBlock(Player p, int index, byte type, byte extType) {
|
||||
ushort x, y, z;
|
||||
IntToPos(index, out x, out y, out z);
|
||||
UpdateBlock(p, x, y, z, type, extType);
|
||||
}
|
||||
|
||||
public void UpdateBlock(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
if (!DoBlockchange(p, x, y, z, type, extType)) return;
|
||||
BlockPos bP = default(BlockPos);
|
||||
|
@ -451,6 +451,7 @@
|
||||
<Compile Include="Drawing\DrawOps\HollowDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\LineDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\MazeDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\OutlineDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\PasteDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\RedoDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\ReplaceDrawOp.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user