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 bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdDrill() { }
public override void Use(Player p, string message)
{
CatchPos cpos;
cpos.distance = 20;
public override void Use(Player p, string message) {
CatchPos cpos = default(CatchPos);
cpos.dist = 20;
if (message != "")
try
{
cpos.distance = int.Parse(message);
if (message != "" && !int.TryParse(message, out cpos.dist)) {
Help(p); return;
}
catch { Help(p); return; }
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
Player.SendMessage(p, "Destroy the block you wish to drill."); p.ClearBlockchange();
p.blockchangeObject = cpos;
Player.SendMessage(p, "Destroy the block you wish to drill.");
p.ClearBlockchange();
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();
CatchPos cpos = (CatchPos)p.blockchangeObject;
byte oldType = p.level.GetTile(x, y, z);
p.SendBlockchange(x, y, z, oldType);
type = p.level.GetTile(x, y, z); extType = 0;
if (type == Block.custom_block) extType = p.level.GetExtTile(x, y, z);
p.RevertBlock(x, y, z);
int diffX = 0, diffZ = 0;
@ -63,53 +54,54 @@ namespace MCGalaxy.Commands
else if (p.rot[0] <= 160) { diffZ = 1; }
else diffX = -1;
List<Pos> buffer = new List<Pos>();
Pos pos;
int total = 0;
List<int> buffer = new List<int>();
int depth = 0;
Level lvl = p.level;
if (diffX != 0)
{
for (ushort xx = x; total < cpos.distance; xx += (ushort)diffX)
if (diffX != 0) {
for (ushort xx = x; depth < cpos.dist; xx += (ushort)diffX)
{
for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++)
for (ushort zz = (ushort)(z - 1); zz <= (ushort)(z + 1); zz++)
{
pos.x = xx; pos.y = yy; pos.z = zz;
buffer.Add(pos);
buffer.Add(lvl.PosToInt(xx, yy, zz));
}
total++;
depth++;
}
}
else
{
for (ushort zz = z; total < cpos.distance; zz += (ushort)diffZ)
} else {
for (ushort zz = z; depth < cpos.dist; zz += (ushort)diffZ)
{
for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++)
for (ushort xx = (ushort)(x - 1); xx <= (ushort)(x + 1); xx++)
{
pos.x = xx; pos.y = yy; pos.z = zz;
buffer.Add(pos);
buffer.Add(lvl.PosToInt(xx, yy, zz));
}
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 cannot drill more than " + p.group.maxBlocks + ".");
return;
}
foreach (Pos pos1 in buffer)
{
if (p.level.GetTile(pos1.x, pos1.y, pos1.z) == oldType)
p.level.Blockchange(p, pos1.x, pos1.y, pos1.z, Block.air);
foreach (int index in buffer) {
if (index < 0) continue;
lvl.IntToPos(index, out x, out y, out z);
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 Pos { public ushort x, y, z; }
struct CatchPos { public int dist; }
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.");
}
}
}