Make /drill work with custom blocks.

This commit is contained in:
UnknownShadow200 2016-02-28 17:11:20 +11:00
parent 3bab1c78af
commit ff46ad26c2

View File

@ -25,36 +25,27 @@ namespace MCGalaxy.Commands
public override string type { get { return CommandTypes.Building; } } public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return false; } } public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdDrill() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ CatchPos cpos = default(CatchPos);
CatchPos cpos; cpos.dist = 20;
cpos.distance = 20;
if (message != "") if (message != "" && !int.TryParse(message, out cpos.dist)) {
try Help(p); return;
{
cpos.distance = int.Parse(message);
} }
catch { Help(p); return; }
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos; p.blockchangeObject = cpos;
Player.SendMessage(p, "Destroy the block you wish to drill.");
Player.SendMessage(p, "Destroy the block you wish to drill."); p.ClearBlockchange(); p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
public override void Help(Player p)
{
Player.SendMessage(p, "/drill [distance] - Drills a hole, destroying all similar blocks in a 3x3 rectangle ahead of you.");
}
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) {
{
if (!p.staticCommands) p.ClearBlockchange(); if (!p.staticCommands) p.ClearBlockchange();
CatchPos cpos = (CatchPos)p.blockchangeObject; CatchPos cpos = (CatchPos)p.blockchangeObject;
byte oldType = p.level.GetTile(x, y, z); type = p.level.GetTile(x, y, z); extType = 0;
p.SendBlockchange(x, y, z, oldType); if (type == Block.custom_block) extType = p.level.GetExtTile(x, y, z);
p.RevertBlock(x, y, z);
int diffX = 0, diffZ = 0; int diffX = 0, diffZ = 0;
@ -63,53 +54,54 @@ namespace MCGalaxy.Commands
else if (p.rot[0] <= 160) { diffZ = 1; } else if (p.rot[0] <= 160) { diffZ = 1; }
else diffX = -1; else diffX = -1;
List<Pos> buffer = new List<Pos>(); List<int> buffer = new List<int>();
Pos pos; int depth = 0;
int total = 0; Level lvl = p.level;
if (diffX != 0) if (diffX != 0) {
{ for (ushort xx = x; depth < cpos.dist; xx += (ushort)diffX)
for (ushort xx = x; total < cpos.distance; xx += (ushort)diffX)
{ {
for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++) for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++)
for (ushort zz = (ushort)(z - 1); zz <= (ushort)(z + 1); zz++) for (ushort zz = (ushort)(z - 1); zz <= (ushort)(z + 1); zz++)
{ {
pos.x = xx; pos.y = yy; pos.z = zz; buffer.Add(lvl.PosToInt(xx, yy, zz));
buffer.Add(pos);
} }
total++; depth++;
} }
} } else {
else for (ushort zz = z; depth < cpos.dist; zz += (ushort)diffZ)
{
for (ushort zz = z; total < cpos.distance; zz += (ushort)diffZ)
{ {
for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++) for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++)
for (ushort xx = (ushort)(x - 1); xx <= (ushort)(x + 1); xx++) for (ushort xx = (ushort)(x - 1); xx <= (ushort)(x + 1); xx++)
{ {
pos.x = xx; pos.y = yy; pos.z = zz; buffer.Add(lvl.PosToInt(xx, yy, zz));
buffer.Add(pos);
} }
total++; depth++;
} }
} }
if (buffer.Count > p.group.maxBlocks) if (buffer.Count > p.group.maxBlocks) {
{
Player.SendMessage(p, "You tried to drill " + buffer.Count + " blocks."); Player.SendMessage(p, "You tried to drill " + buffer.Count + " blocks.");
Player.SendMessage(p, "You cannot drill more than " + p.group.maxBlocks + "."); Player.SendMessage(p, "You cannot drill more than " + p.group.maxBlocks + ".");
return; return;
} }
foreach (Pos pos1 in buffer) foreach (int index in buffer) {
{ if (index < 0) continue;
if (p.level.GetTile(pos1.x, pos1.y, pos1.z) == oldType) lvl.IntToPos(index, out x, out y, out z);
p.level.Blockchange(p, pos1.x, pos1.y, pos1.z, Block.air); byte tile = lvl.blocks[index], extTile = 0;
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
bool sameBlock = type == Block.custom_block ? extType == extTile : type == tile;
if (sameBlock) p.level.UpdateBlock(p, x, y, z, Block.air, 0);
} }
Player.SendMessage(p, buffer.Count + " blocks."); Player.SendMessage(p, "Drilled " + buffer.Count + " blocks.");
} }
struct CatchPos { public ushort x, y, z; public int distance; } struct CatchPos { public int dist; }
struct Pos { public ushort x, y, z; }
public override void Help(Player p) {
Player.SendMessage(p, "/drill [distance] - Drills a hole, destroying all similar blocks in a 3x3 rectangle ahead of you.");
}
} }
} }