mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Cleanup last few commands to use selection code.
This commit is contained in:
parent
75108aac21
commit
09db06d55e
@ -139,12 +139,12 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, format, cState.UsedBlocks);
|
||||
if (cArgs.allowoffset != -1) {
|
||||
Player.Message(p, "Place a block to determine where to paste from");
|
||||
p.Blockchange += Blockchange3;
|
||||
p.Blockchange += BlockchangeOffset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Blockchange3(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
void BlockchangeOffset(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
p.copyoffset.X = p.copystart.X - x;
|
||||
p.copyoffset.Y = p.copystart.Y - y;
|
||||
|
@ -67,20 +67,18 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (!File.Exists("extra/images/" + bitmapLoc + ".bmp")) {
|
||||
Player.Message(p, "The URL entered was invalid!"); return;
|
||||
}
|
||||
CatchPos cpos = default(CatchPos);
|
||||
cpos.layer = layer;
|
||||
cpos.bitmapLoc = bitmapLoc;
|
||||
cpos.popType = popType;
|
||||
p.blockchangeObject = cpos;
|
||||
|
||||
DrawArgs dArgs = default(DrawArgs);
|
||||
dArgs.layer = layer;
|
||||
dArgs.bitmapLoc = bitmapLoc;
|
||||
dArgs.popType = popType;
|
||||
Player.Message(p, "Place two blocks to determine direction.");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(2, dArgs, DoImage);
|
||||
}
|
||||
|
||||
bool DownloadWebFile(string url, Player p) {
|
||||
if (!(url.StartsWith("http://") || url.StartsWith("https://"))) {
|
||||
if (!(url.StartsWith("http://") || url.StartsWith("https://")))
|
||||
url = "http://" + url;
|
||||
}
|
||||
|
||||
try {
|
||||
using (WebClient web = new WebClient()) {
|
||||
@ -97,33 +95,25 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
}
|
||||
|
||||
void PlacedMark1(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 += PlacedMark2;
|
||||
}
|
||||
|
||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
if (x == cpos.x && z == cpos.z) { Player.Message(p, "No direction was selected"); return; }
|
||||
bool DoImage(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
if (m[0].X == m[1].X && m[0].Z == m[1].Z) { Player.Message(p, "No direction was selected"); return false; }
|
||||
|
||||
int direction;
|
||||
if (Math.Abs(cpos.x - x) > Math.Abs(cpos.z - z))
|
||||
direction = x <= cpos.x ? 1 : 0;
|
||||
int dir;
|
||||
if (Math.Abs(m[1].X - m[0].X) > Math.Abs(m[1].Z - m[0].Z))
|
||||
dir = m[1].X <= m[0].X ? 1 : 0;
|
||||
else
|
||||
direction = z <= cpos.z ? 3 : 2;
|
||||
dir = m[1].Z <= m[0].Z ? 3 : 2;
|
||||
|
||||
Thread thread = new Thread(() => DoDrawImage(p, cpos, direction));
|
||||
Thread thread = new Thread(() => DoDrawImage(p, m[0], (DrawArgs)state, dir));
|
||||
thread.Name = "MCG_ImagePrint";
|
||||
thread.Start();
|
||||
return false;
|
||||
}
|
||||
|
||||
void DoDrawImage(Player p, CatchPos cpos, int direction) {
|
||||
void DoDrawImage(Player p, Vec3S32 p0, DrawArgs dArgs, int direction) {
|
||||
Bitmap bmp = null;
|
||||
try {
|
||||
bmp = new Bitmap("extra/images/" + cpos.bitmapLoc + ".bmp");
|
||||
bmp = new Bitmap("extra/images/" + dArgs.bitmapLoc + ".bmp");
|
||||
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
} catch (Exception ex) {
|
||||
Server.ErrorLog(ex);
|
||||
@ -133,15 +123,15 @@ namespace MCGalaxy.Commands.Building {
|
||||
return;
|
||||
}
|
||||
|
||||
byte popType = cpos.popType;
|
||||
bool layer = cpos.layer;
|
||||
byte popType = dArgs.popType;
|
||||
bool layer = dArgs.layer;
|
||||
if (layer) {
|
||||
if (popType == 1) popType = 2;
|
||||
if (popType == 3) popType = 4;
|
||||
}
|
||||
ColorBlock[] palette = ImagePalette.GetPalette(popType);
|
||||
ColorBlock cur = default(ColorBlock);
|
||||
Vec3U16 P;
|
||||
Vec3S32 P;
|
||||
|
||||
IPalette selector = null;
|
||||
if (popType == 6) selector = new GrayscalePalette();
|
||||
@ -152,24 +142,24 @@ namespace MCGalaxy.Commands.Building {
|
||||
for (int xx = 0; xx < bmp.Width; xx++)
|
||||
{
|
||||
if (layer) {
|
||||
P.Y = cpos.y;
|
||||
P.Y = p0.Y;
|
||||
if (direction <= 1) {
|
||||
if (direction == 0) { P.X = (ushort)(cpos.x + xx); P.Z = (ushort)(cpos.z - yy); }
|
||||
else { P.X = (ushort)(cpos.x - xx); P.Z = (ushort)(cpos.z + yy); }
|
||||
if (direction == 0) { P.X = (ushort)(p0.X + xx); P.Z = (ushort)(p0.Z - yy); }
|
||||
else { P.X = (ushort)(p0.X - xx); P.Z = (ushort)(p0.Z + yy); }
|
||||
} else {
|
||||
if (direction == 2) { P.Z = (ushort)(cpos.z + xx); P.X = (ushort)(cpos.x + yy); }
|
||||
else { P.Z = (ushort)(cpos.z - xx); P.X = (ushort)(cpos.x - yy); }
|
||||
if (direction == 2) { P.Z = (ushort)(p0.Z + xx); P.X = (ushort)(p0.X + yy); }
|
||||
else { P.Z = (ushort)(p0.Z - xx); P.X = (ushort)(p0.X - yy); }
|
||||
}
|
||||
} else {
|
||||
P.Y = (ushort)(cpos.y + yy);
|
||||
P.Y = (ushort)(p0.Y + yy);
|
||||
if (direction <= 1) {
|
||||
if (direction == 0) P.X = (ushort)(cpos.x + xx);
|
||||
else P.X = (ushort)(cpos.x - xx);
|
||||
P.Z = cpos.z;
|
||||
if (direction == 0) P.X = (ushort)(p0.X + xx);
|
||||
else P.X = (ushort)(p0.X - xx);
|
||||
P.Z = p0.Z;
|
||||
} else {
|
||||
if (direction == 2) P.Z = (ushort)(cpos.z + xx);
|
||||
else P.Z = (ushort)(cpos.z - xx);
|
||||
P.X = cpos.x;
|
||||
if (direction == 2) P.Z = (ushort)(p0.X + xx);
|
||||
else P.Z = (ushort)(p0.Z - xx);
|
||||
P.X = p0.X;
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,10 +182,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
if (cur.a < 20) cur.type = Block.air;
|
||||
p.level.UpdateBlock(p, P.X, P.Y, P.Z, cur.type, 0);
|
||||
p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, cur.type, 0);
|
||||
}
|
||||
|
||||
if (cpos.bitmapLoc == "tempImage_" + p.name)
|
||||
if (dArgs.bitmapLoc == "tempImage_" + p.name)
|
||||
File.Delete("extra/images/tempImage_" + p.name + ".bmp");
|
||||
Player.Message(p, "Finished printing image using " + ImagePalette.Names[popType]);
|
||||
}
|
||||
@ -210,7 +200,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, "Use switch (&flayer%S) or (&fl%S) to print horizontally.");
|
||||
}
|
||||
|
||||
struct CatchPos { public bool layer; public byte popType; public string bitmapLoc; public ushort x, y, z; }
|
||||
struct DrawArgs { public bool layer; public byte popType; public string bitmapLoc; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,64 +46,48 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, "The Interval cannot be greater than the distance."); return;
|
||||
}
|
||||
|
||||
CatchPos cpos = default(CatchPos);
|
||||
cpos.givenMessage = message;
|
||||
cpos.distance = distance; cpos.interval = interval;
|
||||
p.blockchangeObject = cpos;
|
||||
DrawArgs dArgs = default(DrawArgs);
|
||||
dArgs.distance = distance; dArgs.interval = interval;
|
||||
Player.Message(p, "Place two blocks to determine direction.");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(2, dArgs, DoSPlace);
|
||||
}
|
||||
|
||||
void PlacedMark1(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 += PlacedMark2;
|
||||
}
|
||||
|
||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
ushort distance = cpos.distance, interval = cpos.interval;
|
||||
if (x == cpos.x && y == cpos.y && z == cpos.z) { Player.Message(p, "No direction was selected"); return; }
|
||||
bool DoSPlace(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
DrawArgs dArgs = (DrawArgs)state;
|
||||
ushort distance = dArgs.distance, interval = dArgs.interval;
|
||||
if (m[0] == m[1]) { Player.Message(p, "No direction was selected"); return false; }
|
||||
|
||||
int dirX = 0, dirY = 0, dirZ = 0;
|
||||
int dx = Math.Abs(cpos.x - x), dy = Math.Abs(cpos.y - y), dz = Math.Abs(cpos.z - z);
|
||||
if (dy > dx && dy > dz) dirY = y > cpos.y ? 1 : -1;
|
||||
else if (dx > dz) dirX = x > cpos.x ? 1 : -1;
|
||||
else dirZ = z > cpos.z ? 1 : -1;
|
||||
int dx = Math.Abs(m[1].X - m[0].X), dy = Math.Abs(m[1].Y - m[0].Y), dz = Math.Abs(m[1].Z - m[0].Z);
|
||||
if (dy > dx && dy > dz)
|
||||
dirY = m[1].Y > m[0].Y ? 1 : -1;
|
||||
else if (dx > dz)
|
||||
dirX = m[1].X > m[0].X ? 1 : -1;
|
||||
else
|
||||
dirZ = m[1].Z > m[0].Z ? 1 : -1;
|
||||
|
||||
ushort endX = (ushort)(cpos.x + dirX * distance);
|
||||
ushort endY = (ushort)(cpos.y + dirY * distance);
|
||||
ushort endZ = (ushort)(cpos.z + dirZ * distance);
|
||||
ushort endX = (ushort)(m[0].X + dirX * distance);
|
||||
ushort endY = (ushort)(m[0].Y + dirY * distance);
|
||||
ushort endZ = (ushort)(m[0].Z + dirZ * distance);
|
||||
p.level.UpdateBlock(p, endX, endY, endZ, Block.rock, 0);
|
||||
|
||||
if (interval > 0) {
|
||||
ushort xx = cpos.x, yy = cpos.y, zz = cpos.z;
|
||||
int x = m[0].X, y = m[0].Y, z = m[0].Z;
|
||||
int delta = 0;
|
||||
while (xx < p.level.Width && yy < p.level.Height && zz < p.level.Length && delta < distance) {
|
||||
p.level.UpdateBlock(p, xx, yy, zz, Block.rock, 0);
|
||||
xx = (ushort)(xx + dirX * interval);
|
||||
yy = (ushort)(yy + dirY * interval);
|
||||
zz = (ushort)(zz + dirZ * interval);
|
||||
delta = Math.Abs(xx - cpos.x) + Math.Abs(yy - cpos.y) + Math.Abs(zz - cpos.z);
|
||||
while (x >= 0 && y >= 0 && z >= 0 && x < p.level.Width && y < p.level.Height && z < p.level.Length && delta < distance) {
|
||||
p.level.UpdateBlock(p, (ushort)x, (ushort)y, (ushort)z, Block.rock, 0);
|
||||
x += dirX * interval; y += dirY * interval; z += dirZ * interval;
|
||||
delta = Math.Abs(x - m[0].X) + Math.Abs(y - m[0].Y) + Math.Abs(z - m[0].Z);
|
||||
}
|
||||
} else {
|
||||
p.level.UpdateBlock(p, cpos.x, cpos.y, cpos.z, Block.rock, 0);
|
||||
p.level.UpdateBlock(p, (ushort)m[0].X, (ushort)m[0].Y, (ushort)m[0].Z, Block.rock, 0);
|
||||
}
|
||||
|
||||
if (interval > 0)
|
||||
Player.Message(p, "Placed stone blocks " + interval + " apart");
|
||||
else
|
||||
Player.Message(p, "Placed stone blocks " + distance + " apart");
|
||||
if (p.staticCommands) p.Blockchange += PlacedMark1;
|
||||
Player.Message(p, "Placed stone blocks {0} apart.", interval > 0 ? interval : distance);
|
||||
return true;
|
||||
}
|
||||
|
||||
struct CatchPos {
|
||||
public ushort x, y, z; public string givenMessage;
|
||||
public ushort distance, interval;
|
||||
}
|
||||
struct DrawArgs { public ushort distance, interval; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/splace [distance] [interval]");
|
||||
|
Loading…
x
Reference in New Issue
Block a user