mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Now with less type/exttype usage.
This commit is contained in:
parent
4853612101
commit
b724be1bb2
@ -85,36 +85,36 @@ namespace MCGalaxy
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool Placable(byte type) {
|
||||
return !(type == blackrock || (type >= water && type <= lavastill))
|
||||
&& type < CpeCount;
|
||||
public static bool Placable(byte block) {
|
||||
return !(block == blackrock || (block >= water && block <= lavastill))
|
||||
&& block < CpeCount;
|
||||
}
|
||||
|
||||
public static bool RightClick(byte type, bool countAir = false) {
|
||||
if (countAir && type == air) return true;
|
||||
return type >= water && type <= lavastill;
|
||||
public static bool RightClick(byte block, bool countAir = false) {
|
||||
if (countAir && block == air) return true;
|
||||
return block >= water && block <= lavastill;
|
||||
}
|
||||
|
||||
public static bool OPBlocks(byte type) { return Props[type].OPBlock; }
|
||||
public static bool OPBlocks(byte block) { return Props[block].OPBlock; }
|
||||
|
||||
public static bool Death(byte type) { return Props[type].CollisionDeath; }
|
||||
public static bool Death(byte block) { return Props[block].CollisionDeath; }
|
||||
|
||||
public static bool BuildIn(byte type) {
|
||||
if (type == op_water || type == op_lava || portal(type) || mb(type)) return false;
|
||||
type = Convert(type);
|
||||
return type >= water && type <= lavastill;
|
||||
public static bool BuildIn(byte block) {
|
||||
if (block == op_water || block == op_lava || portal(block) || mb(block)) return false;
|
||||
block = Convert(block);
|
||||
return block >= water && block <= lavastill;
|
||||
}
|
||||
|
||||
public static bool Mover(byte type) { return walkthroughHandlers[type] != null; }
|
||||
public static bool Mover(byte block) { return walkthroughHandlers[block] != null; }
|
||||
|
||||
public static bool FireKill(byte type) { return type != air && Props[type].LavaKills; }
|
||||
public static bool FireKill(byte block) { return block != air && Props[block].LavaKills; }
|
||||
|
||||
public static bool LavaKill(byte type) { return Props[type].LavaKills; }
|
||||
public static bool LavaKill(byte block) { return Props[block].LavaKills; }
|
||||
|
||||
public static bool WaterKill(byte type) { return Props[type].WaterKills; }
|
||||
public static bool WaterKill(byte block) { return Props[block].WaterKills; }
|
||||
|
||||
public static bool LightPass(byte type, byte extType, BlockDefinition[] defs) {
|
||||
switch (Convert(type)) {
|
||||
public static bool LightPass(byte block, byte extBlock, BlockDefinition[] defs) {
|
||||
switch (Convert(block)) {
|
||||
case air:
|
||||
case glass:
|
||||
case leaf:
|
||||
@ -126,16 +126,16 @@ namespace MCGalaxy
|
||||
case rope:
|
||||
return true;
|
||||
case custom_block:
|
||||
BlockDefinition def = defs[extType];
|
||||
BlockDefinition def = defs[extBlock];
|
||||
return def == null ? false : !def.BlocksLight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool NeedRestart(byte type)
|
||||
public static bool NeedRestart(byte block)
|
||||
{
|
||||
switch (type)
|
||||
switch (block)
|
||||
{
|
||||
case train:
|
||||
|
||||
@ -171,13 +171,13 @@ namespace MCGalaxy
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool portal(byte type) { return Props[type].IsPortal; }
|
||||
public static bool portal(byte block) { return Props[block].IsPortal; }
|
||||
|
||||
public static bool mb(byte type) { return Props[type].IsMessageBlock; }
|
||||
public static bool mb(byte block) { return Props[block].IsMessageBlock; }
|
||||
|
||||
public static bool Physics(byte type) //returns false if placing block cant actualy cause any physics to happen
|
||||
public static bool Physics(byte block) //returns false if placing block cant actualy cause any physics to happen
|
||||
{
|
||||
switch (type)
|
||||
switch (block)
|
||||
{
|
||||
case rock:
|
||||
case stone:
|
||||
@ -280,10 +280,10 @@ namespace MCGalaxy
|
||||
}
|
||||
}
|
||||
|
||||
public static byte DoorAirs(byte b) { return Props[b].DoorAirId; }
|
||||
public static byte DoorAirs(byte block) { return Props[block].DoorAirId; }
|
||||
|
||||
public static bool tDoor(byte type) { return Props[type].IsTDoor; }
|
||||
public static bool tDoor(byte block) { return Props[block].IsTDoor; }
|
||||
|
||||
public static byte odoor(byte type) { return Props[type].ODoorId; }
|
||||
public static byte odoor(byte block) { return Props[block].ODoorId; }
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands {
|
||||
Vec3U16 pos = MakePos(p);
|
||||
|
||||
int total = 0;
|
||||
List<FillPos> buffer = new List<FillPos>(2);
|
||||
List<Vec3U16> buffer = new List<Vec3U16>(2);
|
||||
while (true) {
|
||||
Vec3U16 start = MakePos(p);
|
||||
total++;
|
||||
@ -131,9 +131,9 @@ namespace MCGalaxy.Commands {
|
||||
return pos;
|
||||
}
|
||||
|
||||
void FindNext(Vec3U16 lookedAt, ref Vec3U16 pos, List<FillPos> buffer) {
|
||||
void FindNext(Vec3U16 lookedAt, ref Vec3U16 pos, List<Vec3U16> buffer) {
|
||||
LineDrawOp.DrawLine(pos.X, pos.Y, pos.Z, 2, lookedAt.X, lookedAt.Y, lookedAt.Z, buffer);
|
||||
FillPos end = buffer[buffer.Count - 1];
|
||||
Vec3U16 end = buffer[buffer.Count - 1];
|
||||
pos.X = end.X; pos.Y = end.Y; pos.Z = end.Z;
|
||||
buffer.Clear();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
DrawOp op = null;
|
||||
Func<BrushArgs, Brush> constructor = null;
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
AdvDrawOp op = null;
|
||||
switch (cpos.mode) {
|
||||
case DrawMode.cone:
|
||||
|
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (oldType == Block.custom_block)
|
||||
oldExtType = p.level.GetExtTile(x, y, z);
|
||||
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
if (!Block.canPlace(p, oldType) && !Block.BuildIn(oldType)) {
|
||||
Player.Message(p, "Cannot fill with that."); return false;
|
||||
}
|
||||
@ -72,7 +72,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
return true;
|
||||
}
|
||||
|
||||
void FloodFill(Player p, ushort x, ushort y, ushort z, byte oldType, byte oldExtType, DrawMode fillType,
|
||||
void FloodFill(Player p, ushort x, ushort y, ushort z, byte block, byte extBlock, DrawMode fillType,
|
||||
SparseBitSet bits, List<int> buffer, List<int> origins, int depth) {
|
||||
if (bits.Get(x, y, z) || buffer.Count > p.group.maxBlocks) return;
|
||||
int index = p.level.PosToInt(x, y, z);
|
||||
@ -81,38 +81,38 @@ namespace MCGalaxy.Commands.Building {
|
||||
buffer.Add(index);
|
||||
|
||||
if (fillType != DrawMode.verticalX) { // x
|
||||
if (CheckTile(p, (ushort)(x + 1), y, z, oldType, oldExtType))
|
||||
FloodFill(p, (ushort)(x + 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, (ushort)(x - 1), y, z, oldType, oldExtType))
|
||||
FloodFill(p, (ushort)(x - 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, (ushort)(x + 1), y, z, block, extBlock))
|
||||
FloodFill(p, (ushort)(x + 1), y, z, block, extBlock, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, (ushort)(x - 1), y, z, block, extBlock))
|
||||
FloodFill(p, (ushort)(x - 1), y, z, block, extBlock, fillType, bits, buffer, origins, depth + 1);
|
||||
}
|
||||
|
||||
if (fillType != DrawMode.verticalZ) { // z
|
||||
if (CheckTile(p, x, y, (ushort)(z + 1), oldType, oldExtType))
|
||||
FloodFill(p, x, y, (ushort)(z + 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, x, y, (ushort)(z - 1), oldType, oldExtType))
|
||||
FloodFill(p, x, y, (ushort)(z - 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, x, y, (ushort)(z + 1), block, extBlock))
|
||||
FloodFill(p, x, y, (ushort)(z + 1), block, extBlock, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, x, y, (ushort)(z - 1), block, extBlock))
|
||||
FloodFill(p, x, y, (ushort)(z - 1), block, extBlock, fillType, bits, buffer, origins, depth + 1);
|
||||
}
|
||||
|
||||
if (!(fillType == DrawMode.down || fillType == DrawMode.layer)) { // y up
|
||||
if (CheckTile(p, x, (ushort)(y + 1), z, oldType, oldExtType))
|
||||
FloodFill(p, x, (ushort)(y + 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, x, (ushort)(y + 1), z, block, extBlock))
|
||||
FloodFill(p, x, (ushort)(y + 1), z, block, extBlock, fillType, bits, buffer, origins, depth + 1);
|
||||
}
|
||||
|
||||
if (!(fillType == DrawMode.up || fillType == DrawMode.layer)) { // y down
|
||||
if (CheckTile(p, x, (ushort)(y - 1), z, oldType, oldExtType))
|
||||
FloodFill(p, x, (ushort)(y - 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
|
||||
if (CheckTile(p, x, (ushort)(y - 1), z, block, extBlock))
|
||||
FloodFill(p, x, (ushort)(y - 1), z, block, extBlock, fillType, bits, buffer, origins, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckTile(Player p, ushort x, ushort y, ushort z, byte oldTile, byte oldExtTile) {
|
||||
byte tile = p.level.GetTile(x, y, z);
|
||||
bool CheckTile(Player p, ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
byte curBlock = p.level.GetTile(x, y, z);
|
||||
|
||||
if (tile == oldTile && tile == Block.custom_block) {
|
||||
byte extTile = p.level.GetExtTile(x, y, z);
|
||||
return extTile == oldExtTile;
|
||||
if (curBlock == block && curBlock == Block.custom_block) {
|
||||
byte curExtBlock = p.level.GetExtTile(x, y, z);
|
||||
return curExtBlock == extBlock;
|
||||
}
|
||||
return tile == oldTile;
|
||||
return curBlock == block;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
|
||||
if (cpos.mode == DrawMode.straight) {
|
||||
int dx = Math.Abs(m[0].X - m[1].X), dy = Math.Abs(m[0].Y - m[1].Y), dz = Math.Abs(m[0].Z - m[1].Z);
|
||||
|
@ -27,23 +27,23 @@ namespace MCGalaxy.Commands.Building {
|
||||
public CmdPlace() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
int type = -1;
|
||||
byte extType = 0;
|
||||
int block = -1;
|
||||
byte extBlock = 0;
|
||||
ushort x = p.pos[0], y = (ushort)(p.pos[1] - 32), z = p.pos[2];
|
||||
|
||||
try {
|
||||
string[] parts = message.Split(' ');
|
||||
switch (parts.Length) {
|
||||
case 1: type = message == "" ? Block.rock :
|
||||
DrawCmd.GetBlock(p, parts[0], out extType); break;
|
||||
case 1: block = message == "" ? Block.rock :
|
||||
DrawCmd.GetBlock(p, parts[0], out extBlock); break;
|
||||
case 3:
|
||||
type = Block.rock;
|
||||
block = Block.rock;
|
||||
x = (ushort)(Convert.ToUInt16(parts[0]) * 32);
|
||||
y = (ushort)(Convert.ToUInt16(parts[1]) * 32);
|
||||
z = (ushort)(Convert.ToUInt16(parts[2]) * 32);
|
||||
break;
|
||||
case 4:
|
||||
type = DrawCmd.GetBlock(p, parts[0], out extType);
|
||||
block = DrawCmd.GetBlock(p, parts[0], out extBlock);
|
||||
x = (ushort)(Convert.ToUInt16(parts[1]) * 32);
|
||||
y = (ushort)(Convert.ToUInt16(parts[2]) * 32);
|
||||
z = (ushort)(Convert.ToUInt16(parts[3]) * 32);
|
||||
@ -54,12 +54,12 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, "Invalid parameters"); return;
|
||||
}
|
||||
|
||||
if (type == -1 || type == Block.Zero) return;
|
||||
if (!Block.canPlace(p, (byte)type)) { Player.Message(p, "Cannot place that block type."); return; }
|
||||
if (block == -1 || block == Block.Zero) return;
|
||||
if (!Block.canPlace(p, (byte)block)) { Player.Message(p, "Cannot place that block type."); return; }
|
||||
Vec3U16 P = Vec3U16.ClampPos(x, y, z, p.level);
|
||||
|
||||
P.X /= 32; P.Y /= 32; P.Z /= 32;
|
||||
p.level.UpdateBlock(p, P.X, P.Y, P.Z, (byte)type, extType);
|
||||
p.level.UpdateBlock(p, P.X, P.Y, P.Z, (byte)block, extBlock);
|
||||
Player.Message(p, "A block was placed at (" + P.X + ", " + P.Y + ", " + P.Z + ").");
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
DrawOp op = null;
|
||||
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
|
||||
Brush brush = GetBrush(p, cpos, brushOffset);
|
||||
|
@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
|
||||
DrawOp op = null;
|
||||
Func<BrushArgs, Brush> constructor = null;
|
||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
DrawOp op = null;
|
||||
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
|
||||
Brush brush = GetBrush(p, cpos, brushOffset);
|
||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
|
||||
DrawOp drawOp = new TorusDrawOp();
|
||||
Brush brush = GetBrush(p, cpos, 0);
|
||||
|
@ -68,17 +68,17 @@ namespace MCGalaxy.Commands.Building {
|
||||
return DrawOp.DoDrawOp(op, brush, p, marks);
|
||||
}
|
||||
|
||||
static Brush ParseBrush(string brushMsg, Player p, byte type, byte extType) {
|
||||
string[] parts = brushMsg.SplitSpaces(2);
|
||||
static Brush ParseBrush(string raw, Player p, byte block, byte extBlock) {
|
||||
string[] parts = raw.SplitSpaces(2);
|
||||
string brushName = CmdBrush.FindBrush(parts[0]);
|
||||
if (brushName == null) {
|
||||
Player.Message(p, "No brush found with name \"" + parts[0] + "\".");
|
||||
Player.Message(p, "No brush found with name \"{0}\".", parts[0]);
|
||||
Player.Message(p, "Available brushes: " + CmdBrush.AvailableBrushes);
|
||||
return null;
|
||||
}
|
||||
|
||||
string brushMessage = parts.Length >= 2 ? parts[1].ToLower() : "";
|
||||
BrushArgs args = new BrushArgs(p, brushMessage, type, extType);
|
||||
string brushArgs = parts.Length >= 2 ? parts[1].ToLower() : "";
|
||||
BrushArgs args = new BrushArgs(p, brushArgs, block, extBlock);
|
||||
return Brush.Brushes[brushName](args);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
cpos.type = type; cpos.extType = extType;
|
||||
cpos.block = type; cpos.extBlock = extType;
|
||||
|
||||
Brush brush = GetBrush(p, cpos, 0, null);
|
||||
if (brush == null) return false;
|
||||
|
@ -85,13 +85,13 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (end >= 0) brushMsg = dArgs.message.Substring(0, end);
|
||||
if (brushMsg == "") brushMsg = p.DefaultBrushArgs;
|
||||
if (constructor == null) constructor = Brush.Brushes[p.BrushName];
|
||||
BrushArgs args = new BrushArgs(p, brushMsg, dArgs.type, dArgs.extType);
|
||||
BrushArgs args = new BrushArgs(p, brushMsg, dArgs.block, dArgs.extBlock);
|
||||
return constructor(args);
|
||||
}
|
||||
|
||||
protected struct DrawArgs {
|
||||
public DrawMode mode;
|
||||
public byte type, extType;
|
||||
public byte block, extBlock;
|
||||
public object data;
|
||||
public string message;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
|
||||
void DoChain(Player p, ushort x, ushort y, ushort z, int dirX, int dirZ) {
|
||||
FillPos cur, next, target;
|
||||
Vec3U16 cur, next, target;
|
||||
cur.X = next.X = target.X = x;
|
||||
cur.Y = next.Y = target.Y = y;
|
||||
cur.Z = next.Z = target.Z = z;
|
||||
@ -75,7 +75,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
}
|
||||
|
||||
void PullBack(Player p, FillPos cur, FillPos target, int dirX, int dirZ) {
|
||||
void PullBack(Player p, Vec3U16 cur, Vec3U16 target, int dirX, int dirZ) {
|
||||
byte type = p.level.GetTile(cur.X, cur.Y, cur.Z), extType = 0;
|
||||
if (type == Block.custom_block)
|
||||
extType = p.level.GetExtTile(cur.X, cur.Y, cur.Z);
|
||||
|
@ -23,11 +23,11 @@ using MCGalaxy.Drawing.Ops;
|
||||
namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
public sealed class CheckeredBrush : Brush {
|
||||
readonly byte type1, extType1, type2, extType2;
|
||||
readonly byte block1, extBlock1, block2, extBlock2;
|
||||
|
||||
public CheckeredBrush(byte type1, byte extType1, byte type2, byte extType2) {
|
||||
this.type1 = type1; this.extType1 = extType1;
|
||||
this.type2 = type2; this.extType2 = extType2;
|
||||
public CheckeredBrush(byte block1, byte extBlock1, byte block2, byte extBlock2) {
|
||||
this.block1 = block1; this.extBlock1 = extBlock1;
|
||||
this.block2 = block2; this.extBlock2 = extBlock2;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Checkered"; } }
|
||||
@ -59,11 +59,11 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
}
|
||||
|
||||
public override byte NextBlock(DrawOp op) {
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 1) == 0 ? type1 : type2;
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 1) == 0 ? block1 : block2;
|
||||
}
|
||||
|
||||
public override byte NextExtBlock(DrawOp op) {
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 1) == 0 ? extType1 : extType2;
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 1) == 0 ? extBlock1 : extBlock2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
for (int i = 0; i < thresholds.Length; i++) {
|
||||
if (N <= thresholds[i]) { next = i; break; }
|
||||
}
|
||||
return blocks[next].Type;
|
||||
return blocks[next].Block;
|
||||
}
|
||||
|
||||
public override byte NextExtBlock(DrawOp op) {
|
||||
return blocks[next].ExtType;
|
||||
return blocks[next].Ext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
int type = DrawCmd.GetBlock(p, block, out extType);
|
||||
if (type == -1) return null;
|
||||
|
||||
blocks[j].Type = (byte)type; blocks[j].ExtType = extType;
|
||||
blocks[j].Block = (byte)type; blocks[j].Ext = extType;
|
||||
if (sepIndex < 0) { j++; continue; }
|
||||
|
||||
int chance;
|
||||
|
@ -59,11 +59,11 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
n = (n >> 13) ^ n;
|
||||
int raw = (n * (n * n * 60493 + 19990303) + 1376312589) & mask;
|
||||
next = (int)Math.Floor((raw / (double)mask) * blocks.Length);
|
||||
return blocks[next].Type;
|
||||
return blocks[next].Block;
|
||||
}
|
||||
|
||||
public override byte NextExtBlock(DrawOp op) {
|
||||
return blocks[next].ExtType;
|
||||
return blocks[next].Ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
if (toAffect == null) return null;
|
||||
|
||||
ExtBlock target;
|
||||
int block = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.ExtType);
|
||||
int block = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.Ext);
|
||||
if (block == -1) return null;
|
||||
|
||||
target.Type = (byte)block;
|
||||
target.Block = (byte)block;
|
||||
if (not) return new ReplaceNotBrush(toAffect, target);
|
||||
return new ReplaceBrush(toAffect, target);
|
||||
}
|
||||
@ -64,12 +64,12 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
internal static ExtBlock[] GetBlocks(Player p, int start, int max, string[] parts) {
|
||||
ExtBlock[] blocks = new ExtBlock[max - start];
|
||||
for (int i = 0; i < blocks.Length; i++)
|
||||
blocks[i].Type = Block.Zero;
|
||||
blocks[i].Block = Block.Zero;
|
||||
for (int i = 0; start < max; start++, i++ ) {
|
||||
byte extBlock = 0;
|
||||
int block = DrawCmd.GetBlock(p, parts[start], out extBlock);
|
||||
if (block == -1) return null;
|
||||
blocks[i].Type = (byte)block; blocks[i].ExtType = extBlock;
|
||||
blocks[i].Block = (byte)block; blocks[i].Ext = extBlock;
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
@ -81,14 +81,14 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
for (int i = 0; i < include.Length; i++) {
|
||||
ExtBlock block = include[i];
|
||||
if (tile == block.Type && (tile != Block.custom_block || extTile == block.ExtType))
|
||||
return target.Type;
|
||||
if (tile == block.Block && (tile != Block.custom_block || extTile == block.Ext))
|
||||
return target.Block;
|
||||
}
|
||||
return Block.Zero;
|
||||
}
|
||||
|
||||
public override byte NextExtBlock(DrawOp op) {
|
||||
return target.ExtType;
|
||||
return target.Ext;
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,14 +121,14 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
for (int i = 0; i < exclude.Length; i++) {
|
||||
ExtBlock block = exclude[i];
|
||||
if (tile == block.Type && (tile != Block.custom_block || extTile == block.ExtType))
|
||||
if (tile == block.Block && (tile != Block.custom_block || extTile == block.Ext))
|
||||
return Block.Zero;
|
||||
}
|
||||
return target.Type;
|
||||
return target.Block;
|
||||
}
|
||||
|
||||
public override byte NextExtBlock(DrawOp op) {
|
||||
return target.ExtType;
|
||||
return target.Ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ using MCGalaxy.Drawing.Ops;
|
||||
namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
public sealed class StripedBrush : Brush {
|
||||
readonly byte type1, extType1, type2, extType2;
|
||||
readonly byte block1, extBlock1, block2, extBlock2;
|
||||
|
||||
public StripedBrush(byte type1, byte extType1, byte type2, byte extType2) {
|
||||
this.type1 = type1; this.extType1 = extType1;
|
||||
this.type2 = type2; this.extType2 = extType2;
|
||||
public StripedBrush(byte block1, byte extBlock1, byte block2, byte extBlock2) {
|
||||
this.block1 = block1; this.extBlock1 = extBlock1;
|
||||
this.block2 = block2; this.extBlock2 = extBlock2;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Striped"; } }
|
||||
@ -59,11 +59,11 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
}
|
||||
|
||||
public override byte NextBlock(DrawOp op) {
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 3) <= 1 ? type1 : type2;
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 3) <= 1 ? block1 : block2;
|
||||
}
|
||||
|
||||
public override byte NextExtBlock(DrawOp op) {
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 3) <= 1 ? extType1 : extType2;
|
||||
return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 3) <= 1 ? extBlock1 : extBlock2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,8 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
static void AppendDrawOp(Player p, DrawOp op, Brush brush, Vec3S32[] marks, long affected) {
|
||||
if (p == null) {
|
||||
foreach (var block in op.Perform(marks, p, op.Level, brush))
|
||||
op.Level.Blockchange(block.X, block.Y, block.Z, block.Type,
|
||||
false, default(PhysicsArgs), block.ExtType);
|
||||
op.Level.Blockchange(block.X, block.Y, block.Z, block.Block,
|
||||
false, default(PhysicsArgs), block.ExtBlock);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -132,38 +132,38 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
|
||||
if (item.Affected > Server.DrawReloadLimit) {
|
||||
foreach (var b in item.Op.Perform(item.Marks, p, lvl, item.Brush)) {
|
||||
if (b.Type == Block.Zero) continue;
|
||||
if (b.Block == Block.Zero) continue;
|
||||
byte old = lvl.GetTile(b.X, b.Y, b.Z);
|
||||
if (old == Block.Zero || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Type))
|
||||
if (old == Block.Zero || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block))
|
||||
continue;
|
||||
|
||||
lvl.SetTile(b.X, b.Y, b.Z, b.Type, p, b.ExtType);
|
||||
lvl.SetTile(b.X, b.Y, b.Z, b.Block, p, b.ExtBlock);
|
||||
p.loginBlocks++;
|
||||
p.overallBlocks++;
|
||||
}
|
||||
} else if (item.Level.bufferblocks) {
|
||||
foreach (var b in item.Op.Perform(item.Marks, p, lvl, item.Brush)) {
|
||||
if (b.Type == Block.Zero) continue;
|
||||
if (!lvl.DoBlockchange(p, b.X, b.Y, b.Z, b.Type, b.ExtType)) continue;
|
||||
if (b.Block == Block.Zero) continue;
|
||||
if (!lvl.DoBlockchange(p, b.X, b.Y, b.Z, b.Block, b.ExtBlock)) continue;
|
||||
bP.name = p.name;
|
||||
bP.index = lvl.PosToInt(b.X, b.Y, b.Z);
|
||||
bP.SetData(b.Type, b.ExtType, b.Type == 0);
|
||||
bP.SetData(b.Block, b.ExtBlock, b.Block == 0);
|
||||
|
||||
if (lvl.UseBlockDB)
|
||||
lvl.blockCache.Add(bP);
|
||||
BlockQueue.Addblock(p, bP.index, b.Type, b.ExtType);
|
||||
BlockQueue.Addblock(p, bP.index, b.Block, b.ExtBlock);
|
||||
}
|
||||
} else {
|
||||
foreach (var b in item.Op.Perform(item.Marks, p, item.Level, item.Brush)) {
|
||||
if (b.Type == Block.Zero) continue;
|
||||
if (!lvl.DoBlockchange(p, b.X, b.Y, b.Z, b.Type, b.ExtType)) continue;
|
||||
if (b.Block == Block.Zero) continue;
|
||||
if (!lvl.DoBlockchange(p, b.X, b.Y, b.Z, b.Block, b.ExtBlock)) continue;
|
||||
bP.name = p.name;
|
||||
bP.index = lvl.PosToInt(b.X, b.Y, b.Z);
|
||||
|
||||
bP.SetData(b.Type, b.ExtType, b.Type == 0);
|
||||
bP.SetData(b.Block, b.ExtBlock, b.Block == 0);
|
||||
if (lvl.UseBlockDB)
|
||||
lvl.blockCache.Add(bP);
|
||||
Player.GlobalBlockchange(lvl, b.X, b.Y, b.Z, b.Type, b.ExtType);
|
||||
Player.GlobalBlockchange(lvl, b.X, b.Y, b.Z, b.Block, b.ExtBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,19 +21,17 @@ using MCGalaxy.Drawing.Brushes;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public struct FillPos { public ushort X, Y, Z; }
|
||||
|
||||
public struct ExtBlock {
|
||||
public byte Type, ExtType;
|
||||
public byte Block, Ext;
|
||||
|
||||
public ExtBlock(byte type, byte extType) {
|
||||
Type = type; ExtType = extType;
|
||||
public ExtBlock(byte block, byte extBlock) {
|
||||
Block = block; Ext = extBlock;
|
||||
}
|
||||
}
|
||||
|
||||
public struct DrawOpBlock {
|
||||
public ushort X, Y, Z;
|
||||
public byte Type, ExtType;
|
||||
public byte Block, ExtBlock;
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,16 +94,16 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
|
||||
protected DrawOpBlock Place(ushort x, ushort y, ushort z, Brush brush) {
|
||||
Coords.X = x; Coords.Y = y; Coords.Z = z;
|
||||
Coords.Type = brush.NextBlock(this);
|
||||
Coords.Block = brush.NextBlock(this);
|
||||
|
||||
if (Coords.Type != Block.Zero)
|
||||
Coords.ExtType = brush.NextExtBlock(this);
|
||||
if (Coords.Block != Block.Zero)
|
||||
Coords.ExtBlock = brush.NextExtBlock(this);
|
||||
return Coords;
|
||||
}
|
||||
|
||||
protected DrawOpBlock Place(ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
Coords.X = x; Coords.Y = y; Coords.Z = z;
|
||||
Coords.Type = type; Coords.ExtType = extType;
|
||||
Coords.Block = type; Coords.ExtBlock = extType;
|
||||
return Coords;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
|
||||
public override IEnumerable<DrawOpBlock> Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) {
|
||||
Vec3U16 p1 = Clamp(marks[0]), p2 = Clamp(marks[1]);
|
||||
List<FillPos> buffer = new List<FillPos>();
|
||||
List<Vec3U16> buffer = new List<Vec3U16>();
|
||||
DrawLine(p1.X, p1.Y, p1.Z, MaxLength, p2.X, p2.Y, p2.Z, buffer);
|
||||
if (WallsMode) {
|
||||
ushort yy1 = p1.Y, yy2 = p2.Y;
|
||||
@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
}
|
||||
|
||||
for (int i = 0; i < buffer.Count; i++) {
|
||||
FillPos pos = buffer[i];
|
||||
Vec3U16 pos = buffer[i];
|
||||
if (WallsMode) {
|
||||
for (ushort yy = p1.Y; yy <= p2.Y; yy++)
|
||||
yield return Place(pos.X, yy, pos.Z, brush);
|
||||
@ -61,7 +61,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
}
|
||||
|
||||
internal static void DrawLine(ushort x1, ushort y1, ushort z1, int maxLen,
|
||||
ushort x2, ushort y2, ushort z2, List<FillPos> buffer) {
|
||||
ushort x2, ushort y2, ushort z2, List<Vec3U16> buffer) {
|
||||
Line lx, ly, lz;
|
||||
int[] pixel = { x1, y1, z1 };
|
||||
int dx = x2 - x1, dy = y2 - y1, dz = z2 - z1;
|
||||
@ -78,7 +78,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
else
|
||||
DoLine(ly, lx, lz, zLen, pixel, maxLen, buffer);
|
||||
|
||||
FillPos pos;
|
||||
Vec3U16 pos;
|
||||
pos.X = (ushort)pixel[0]; pos.Y = (ushort)pixel[1]; pos.Z = (ushort)pixel[2];
|
||||
buffer.Add(pos);
|
||||
}
|
||||
@ -86,9 +86,9 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
struct Line { public int dx2, inc, index; }
|
||||
|
||||
static void DoLine(Line l1, Line l2, Line l3, int len,
|
||||
int[] pixel, int maxLen, List<FillPos> buffer) {
|
||||
int[] pixel, int maxLen, List<Vec3U16> buffer) {
|
||||
int err_1 = l1.dx2 - len, err_2 = l2.dx2 - len;
|
||||
FillPos pos;
|
||||
Vec3U16 pos;
|
||||
for (int i = 0; i < len && i < (maxLen - 1); i++) {
|
||||
pos.X = (ushort)pixel[0]; pos.Y = (ushort)pixel[1]; pos.Z = (ushort)pixel[2];
|
||||
buffer.Add(pos);
|
||||
|
@ -87,7 +87,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
if (exclude != null) {
|
||||
for (int j = 0; j < exclude.Length; j++) {
|
||||
ExtBlock block = exclude[j];
|
||||
if (b == block.Type && (b != Block.custom_block || extB == block.ExtType)) {
|
||||
if (b == block.Block && (b != Block.custom_block || extB == block.Ext)) {
|
||||
place = false; break;
|
||||
}
|
||||
}
|
||||
@ -98,7 +98,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
if (include != null) {
|
||||
for (int j = 0; j < include.Length; j++) {
|
||||
ExtBlock block = include[j];
|
||||
if (b == block.Type && (b != Block.custom_block || extB == block.ExtType)) {
|
||||
if (b == block.Block && (b != Block.custom_block || extB == block.Ext)) {
|
||||
yield return Place(x, y, z, b, extB); break;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
byte tile = lvl.GetTile(x, y, z), extTile = 0;
|
||||
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
|
||||
|
||||
if (tile == Include.Type && (tile != Block.custom_block || extTile == Include.ExtType))
|
||||
if (tile == Include.Block && (tile != Block.custom_block || extTile == Include.Ext))
|
||||
yield return Place(x, y, z, brush);
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
byte tile = lvl.GetTile(x, y, z), extTile = 0;
|
||||
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
|
||||
|
||||
if (tile != Exclude.Type || (tile == Block.custom_block && extTile != Exclude.ExtType))
|
||||
if (tile != Exclude.Block || (tile == Block.custom_block && extTile != Exclude.Ext))
|
||||
yield return Place(x, y, z, brush);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace MCGalaxy.CTF
|
||||
if (cache.ContainsKey(p))
|
||||
cache.Remove(p);
|
||||
}
|
||||
void blockuse(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
|
||||
void blockuse(Player p, ushort x, ushort y, ushort z, byte block, byte extBlock)
|
||||
{
|
||||
if (cache.ContainsKey(p))
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ namespace MCGalaxy.Generator {
|
||||
treeDrawer.SetMarks(treeCoords);
|
||||
|
||||
foreach (var block in treeDrawer.Perform(treeCoords, null, Lvl, null))
|
||||
Lvl.SetTile(block.X, block.Y, block.Z, block.Type);
|
||||
Lvl.SetTile(block.X, block.Y, block.Z, block.Block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ namespace MCGalaxy {
|
||||
SendRaw(Opcode.SetPermission, op ? (byte)100 : (byte)0);
|
||||
}
|
||||
|
||||
public void SendBlockchange(ushort x, ushort y, ushort z, byte type) {
|
||||
public void SendBlockchange(ushort x, ushort y, ushort z, byte block) {
|
||||
//if (x < 0 || y < 0 || z < 0) return;
|
||||
if (x >= level.Width || y >= level.Height || z >= level.Length) return;
|
||||
|
||||
@ -533,20 +533,20 @@ namespace MCGalaxy {
|
||||
NetUtils.WriteU16(y, buffer, 3);
|
||||
NetUtils.WriteU16(z, buffer, 5);
|
||||
|
||||
if (type == Block.custom_block) {
|
||||
if (block == Block.custom_block) {
|
||||
buffer[7] = hasBlockDefs ? level.GetExtTile(x, y, z)
|
||||
: level.GetFallbackExtTile(x, y, z);
|
||||
if (!hasCustomBlocks) buffer[7] = Block.ConvertCPE(buffer[7]);
|
||||
} else if (hasCustomBlocks) {
|
||||
buffer[7] = Block.Convert(type);
|
||||
buffer[7] = Block.Convert(block);
|
||||
} else {
|
||||
buffer[7] = Block.Convert(Block.ConvertCPE(type));
|
||||
buffer[7] = Block.Convert(Block.ConvertCPE(block));
|
||||
}
|
||||
SendRaw(buffer);
|
||||
}
|
||||
|
||||
// Duplicated as this packet needs to have maximum optimisation.
|
||||
public void SendBlockchange(ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
public void SendBlockchange(ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
//if (x < 0 || y < 0 || z < 0) return;
|
||||
if (x >= level.Width || y >= level.Height || z >= level.Length) return;
|
||||
|
||||
@ -556,13 +556,13 @@ namespace MCGalaxy {
|
||||
NetUtils.WriteU16(y, buffer, 3);
|
||||
NetUtils.WriteU16(z, buffer, 5);
|
||||
|
||||
if (type == Block.custom_block) {
|
||||
buffer[7] = hasBlockDefs ? extType : level.GetFallback(extType);
|
||||
if (block == Block.custom_block) {
|
||||
buffer[7] = hasBlockDefs ? extBlock : level.GetFallback(extBlock);
|
||||
if (!hasCustomBlocks) buffer[7] = Block.ConvertCPE(buffer[7]);
|
||||
} else if (hasCustomBlocks) {
|
||||
buffer[7] = Block.Convert(type);
|
||||
buffer[7] = Block.Convert(block);
|
||||
} else {
|
||||
buffer[7] = Block.Convert(Block.ConvertCPE(type));
|
||||
buffer[7] = Block.Convert(Block.ConvertCPE(block));
|
||||
}
|
||||
SendRaw(buffer);
|
||||
}
|
||||
|
@ -44,30 +44,28 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
public void ManualChange(ushort x, ushort y, ushort z, byte action, byte type, byte extType = 0) {
|
||||
ManualChange(x, y, z, action, type, extType, true);
|
||||
public void ManualChange(ushort x, ushort y, ushort z, byte action, byte block, byte extBlock = 0) {
|
||||
ManualChange(x, y, z, action, block, extBlock, true);
|
||||
}
|
||||
|
||||
public void ManualChange(ushort x, ushort y, ushort z, byte action,
|
||||
byte type, byte extType, bool checkPlaceDist) {
|
||||
byte b = level.GetTile(x, y, z);
|
||||
if ( b == Block.Zero ) { return; }
|
||||
if ( jailed || !agreed ) { RevertBlock(x, y, z); return; }
|
||||
if ( level.IsMuseum && Blockchange == null ) { return; }
|
||||
byte block, byte extBlock, bool checkPlaceDist) {
|
||||
byte old = level.GetTile(x, y, z);
|
||||
if (old == Block.Zero) return;
|
||||
if (jailed || !agreed || !canBuild) { RevertBlock(x, y, z); return; }
|
||||
if (level.IsMuseum && Blockchange == null) return;
|
||||
|
||||
if ( !deleteMode ) {
|
||||
if (!deleteMode) {
|
||||
PhysicsArgs args = level.foundInfo(x, y, z);
|
||||
if (args.HasWait) return;
|
||||
}
|
||||
|
||||
if ( !canBuild ) { RevertBlock(x, y, z); return; }
|
||||
|
||||
if (Server.verifyadmins && adminpen) {
|
||||
SendMessage("&cYou must first verify with %T/pass [Password]");
|
||||
RevertBlock(x, y, z); return;
|
||||
}
|
||||
|
||||
if (Server.zombie.Running && Server.zombie.HandlesManualChange(this, x, y, z, action, type, b))
|
||||
if (Server.zombie.Running && Server.zombie.HandlesManualChange(this, x, y, z, action, block, old))
|
||||
return;
|
||||
|
||||
if ( Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this) ) {
|
||||
@ -78,15 +76,15 @@ namespace MCGalaxy {
|
||||
Level.BlockPos bP = default(Level.BlockPos);
|
||||
bP.name = name;
|
||||
bP.index = level.PosToInt(x, y, z);
|
||||
bP.SetData(type, extType, false);
|
||||
bP.SetData(block, extBlock, false);
|
||||
|
||||
lastClick.X = x; lastClick.Y = y; lastClick.Z = z;
|
||||
if (Blockchange != null) {
|
||||
Blockchange(this, x, y, z, type, extType); return;
|
||||
Blockchange(this, x, y, z, block, extBlock); return;
|
||||
}
|
||||
if (PlayerBlockChange != null)
|
||||
PlayerBlockChange(this, x, y, z, type, extType);
|
||||
OnBlockChangeEvent.Call(this, x, y, z, type, extType);
|
||||
PlayerBlockChange(this, x, y, z, block, extBlock);
|
||||
OnBlockChangeEvent.Call(this, x, y, z, block, extBlock);
|
||||
if ( cancelBlock ) { cancelBlock = false; return; }
|
||||
|
||||
if (group.Permission == LevelPermission.Banned) return;
|
||||
@ -100,44 +98,44 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
if (!Block.canPlace(this, b) && !Block.BuildIn(b) && !Block.AllowBreak(b)) {
|
||||
if (!Block.canPlace(this, old) && !Block.BuildIn(old) && !Block.AllowBreak(old)) {
|
||||
SendMessage("Cannot build here!");
|
||||
RevertBlock(x, y, z); return;
|
||||
}
|
||||
|
||||
if (!Block.canPlace(this, type)) {
|
||||
if (!Block.canPlace(this, block)) {
|
||||
SendMessage("You can't place this block type!");
|
||||
RevertBlock(x, y, z); return;
|
||||
}
|
||||
|
||||
if (b >= 200 && b < 220) {
|
||||
if (old >= 200 && old < 220) {
|
||||
SendMessage("Block is active, you cant disturb it!");
|
||||
RevertBlock(x, y, z); return;
|
||||
}
|
||||
|
||||
if (action > 1 ) { Leave("Unknown block action!", true); return; }
|
||||
byte oldType = type;
|
||||
if (type < 128) type = bindings[type];
|
||||
byte oldType = block;
|
||||
if (block < 128) block = bindings[block];
|
||||
|
||||
//Ignores updating blocks that are the same and send block only to the player
|
||||
byte newBlock = (painting || action == 1) ? type : (byte)0;
|
||||
if (b == newBlock && (painting || oldType != type)) {
|
||||
if (b != Block.custom_block || extType == level.GetExtTile(x, y, z)) {
|
||||
byte newBlock = (painting || action == 1) ? block : (byte)0;
|
||||
if (old == newBlock && (painting || oldType != block)) {
|
||||
if (old != Block.custom_block || extBlock == level.GetExtTile(x, y, z)) {
|
||||
RevertBlock(x, y, z); return;
|
||||
}
|
||||
}
|
||||
//else
|
||||
if (!painting && action == 0) {
|
||||
bP.flags |= 1;
|
||||
if (DeleteBlock(b, x, y, z, type, extType) && level.UseBlockDB)
|
||||
if (DeleteBlock(old, x, y, z, block, extBlock) && level.UseBlockDB)
|
||||
level.blockCache.Add(bP);
|
||||
} else {
|
||||
if (PlaceBlock(b, x, y, z, type, extType) && level.UseBlockDB)
|
||||
if (PlaceBlock(old, x, y, z, block, extBlock) && level.UseBlockDB)
|
||||
level.blockCache.Add(bP);
|
||||
}
|
||||
}
|
||||
|
||||
bool DeleteBlock(byte b, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
bool DeleteBlock(byte b, ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
if (deleteMode) { return ChangeBlock(x, y, z, Block.air, 0); }
|
||||
bool changed = true;
|
||||
|
||||
@ -153,29 +151,29 @@ namespace MCGalaxy {
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool PlaceBlock(byte b, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
bool PlaceBlock(byte b, ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
if (modeType != 0) {
|
||||
if (b == modeType) SendBlockchange(x, y, z, b);
|
||||
else ChangeBlock(x, y, z, modeType, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
Block.HandlePlace handler = Block.placeHandlers[type];
|
||||
Block.HandlePlace handler = Block.placeHandlers[block];
|
||||
if (handler != null) {
|
||||
if (handler(this, b, x, y, z)) return false;
|
||||
} else {
|
||||
return ChangeBlock(x, y, z, type, extType);
|
||||
return ChangeBlock(x, y, z, block, extBlock);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary> Updates the block at the given position, also turning the block below to dirt if the block above blocks light. </summary>
|
||||
internal bool ChangeBlock(ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
if (!level.DoBlockchange(this, x, y, z, type, extType)) return false;
|
||||
Player.GlobalBlockchange(level, x, y, z, type, extType);
|
||||
internal bool ChangeBlock(ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
if (!level.DoBlockchange(this, x, y, z, block, extBlock)) return false;
|
||||
Player.GlobalBlockchange(level, x, y, z, block, extBlock);
|
||||
|
||||
if (level.GetTile(x, (ushort)(y - 1), z) == Block.grass && level.GrassDestroy
|
||||
&& !Block.LightPass(type, extType, level.CustomBlockDefs)) {
|
||||
&& !Block.LightPass(block, extBlock, level.CustomBlockDefs)) {
|
||||
level.Blockchange(this, x, (ushort)(y - 1), z, Block.dirt);
|
||||
}
|
||||
return true;
|
||||
|
@ -136,16 +136,16 @@ namespace MCGalaxy {
|
||||
|
||||
#region == GLOBAL MESSAGES ==
|
||||
|
||||
public static void GlobalBlockchange(Level level, int b, byte type, byte extType) {
|
||||
public static void GlobalBlockchange(Level level, int b, byte block, byte extBlock) {
|
||||
ushort x, y, z;
|
||||
level.IntToPos(b, out x, out y, out z);
|
||||
GlobalBlockchange(level, x, y, z, type, extType);
|
||||
GlobalBlockchange(level, x, y, z, block, extBlock);
|
||||
}
|
||||
|
||||
public static void GlobalBlockchange(Level level, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
public static void GlobalBlockchange(Level level, ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p.level == level) p.SendBlockchange(x, y, z, type, extType);
|
||||
if (p.level == level) p.SendBlockchange(x, y, z, block, extBlock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,11 +188,11 @@ namespace MCGalaxy {
|
||||
internal OnBlockChangeEvent(Player.BlockchangeEventHandler method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
public static void Call(Player p, ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, x, y, z, type, extType);
|
||||
pl.method(p, x, y, z, block, extBlock);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored calling BlockChange Event."); Server.ErrorLog(e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user