mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Fix some block changes not adding to BlockDB
This commit is contained in:
parent
4da9db50d4
commit
836d90c443
@ -61,7 +61,7 @@ namespace MCGalaxy.Commands.World {
|
||||
extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + 1), (ushort)z);
|
||||
|
||||
if (Block.LightPass(above, extAbove, lvl.CustomBlockDefs)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass) == 2) {
|
||||
buffer.Add(index, Block.grass, 0);
|
||||
totalFixed++;
|
||||
}
|
||||
@ -72,7 +72,7 @@ namespace MCGalaxy.Commands.World {
|
||||
extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + 1), (ushort)z);
|
||||
|
||||
if (!Block.LightPass(above, extAbove, lvl.CustomBlockDefs)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt) == 2) {
|
||||
buffer.Add(index, Block.dirt, 0);
|
||||
totalFixed++;
|
||||
}
|
||||
@ -103,7 +103,7 @@ namespace MCGalaxy.Commands.World {
|
||||
}
|
||||
}
|
||||
|
||||
if (!inShadow && p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass)) {
|
||||
if (!inShadow && p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass) == 2) {
|
||||
buffer.Add(index, Block.grass, 0);
|
||||
totalFixed++;
|
||||
}
|
||||
@ -118,7 +118,7 @@ namespace MCGalaxy.Commands.World {
|
||||
}
|
||||
}
|
||||
|
||||
if (inShadow && p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt)) {
|
||||
if (inShadow && p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt) == 2) {
|
||||
buffer.Add(index, Block.dirt, 0);
|
||||
totalFixed++;
|
||||
}
|
||||
@ -143,7 +143,7 @@ namespace MCGalaxy.Commands.World {
|
||||
extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + 1), (ushort)z);
|
||||
|
||||
if (Block.LightPass(above, extAbove, lvl.CustomBlockDefs)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass) == 2) {
|
||||
buffer.Add(index, Block.grass, 0);
|
||||
totalFixed++;
|
||||
}
|
||||
@ -168,7 +168,7 @@ namespace MCGalaxy.Commands.World {
|
||||
extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + 1), (ushort)z);
|
||||
|
||||
if (!Block.LightPass(above, extAbove, lvl.CustomBlockDefs)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt)) {
|
||||
if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt) == 2) {
|
||||
buffer.Add(index, Block.dirt, 0);
|
||||
totalFixed++;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
byte old = p.level.GetTile(x, y, z);
|
||||
if (p.level.CheckAffectPermissions(p, x, y, z, old, data.Block, data.ExtBlock)) {
|
||||
p.level.Blockchange(p, x, y, z, data.Block, data.ExtBlock);
|
||||
p.level.UpdateBlock(p, x, y, z, data.Block, data.ExtBlock);
|
||||
UpdateDatabase(p, data, x, y, z);
|
||||
Player.Message(p, "Message block created.");
|
||||
} else {
|
||||
|
@ -62,7 +62,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
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)block, ext, BlockDBFlags.ManualPlace);
|
||||
p.level.UpdateBlock(p, P.X, P.Y, P.Z, (byte)block, ext);
|
||||
string blockName = p.level.BlockName((byte)block, ext);
|
||||
Player.Message(p, "{3} block was placed at ({0}, {1}, {2}).", P.X, P.Y, P.Z, blockName);
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
if (data.Multi && type == Block.red && data.Entries.Count > 0) { ExitChange(p, x, y, z, type, extType); return; }
|
||||
|
||||
p.level.Blockchange(p, x, y, z, data.Block, data.ExtBlock);
|
||||
p.level.UpdateBlock(p, x, y, z, data.Block, data.ExtBlock);
|
||||
p.SendBlockchange(x, y, z, Block.green, 0);
|
||||
PortalPos Port;
|
||||
|
||||
|
@ -253,23 +253,35 @@ namespace MCGalaxy {
|
||||
|
||||
public void Blockchange(Player p, ushort x, ushort y, ushort z,
|
||||
byte block, byte extBlock = 0) {
|
||||
if (DoBlockchange(p, x, y, z, block, extBlock))
|
||||
if (DoBlockchange(p, x, y, z, block, extBlock) == 2)
|
||||
Player.GlobalBlockchange(this, x, y, z, block, extBlock);
|
||||
}
|
||||
|
||||
public bool DoBlockchange(Player p, ushort x, ushort y, ushort z,
|
||||
/// <summary> Returns: <br/>
|
||||
/// 0 - block change was not performed <br/>
|
||||
/// 1 - old block was same as new block visually (e.g. white to door_white)<br/>
|
||||
/// 2 - old block was different to new block visually </summary>
|
||||
/// <remarks> The return code can be used to avoid sending redundant block changes. </remarks>
|
||||
public int DoBlockchange(Player p, ushort x, ushort y, ushort z,
|
||||
byte block, byte extBlock = 0, bool drawn = false) {
|
||||
string errorLocation = "start";
|
||||
try
|
||||
{
|
||||
//if (x < 0 || y < 0 || z < 0) return;
|
||||
if (x >= Width || y >= Height || z >= Length) return false;
|
||||
if (x >= Width || y >= Height || z >= Length) return 0;
|
||||
byte old = GetTile(x, y, z), extOld = 0;
|
||||
if (old == Block.custom_block) extOld = GetExtTile(x, y, z);
|
||||
|
||||
errorLocation = "Permission checking";
|
||||
if (!CheckAffectPermissions(p, x, y, z, old, block, extBlock)) {
|
||||
p.RevertBlock(x, y, z); return false;
|
||||
p.RevertBlock(x, y, z); return 0;
|
||||
}
|
||||
|
||||
// Test for exact same block ID
|
||||
if (old == Block.custom_block) {
|
||||
if (extOld == extBlock) return 0;
|
||||
} else {
|
||||
if (old == block) return 0;
|
||||
}
|
||||
|
||||
if (old == Block.sponge && physics > 0 && block != Block.sponge)
|
||||
@ -297,14 +309,16 @@ namespace MCGalaxy {
|
||||
|
||||
changed = true;
|
||||
backedup = false;
|
||||
bool diffBlock = old == Block.custom_block ? extOld != extBlock :
|
||||
Block.Convert(old) != Block.Convert(block);
|
||||
return diffBlock;
|
||||
|
||||
if (old != Block.custom_block) {
|
||||
if (Block.Convert(old) == Block.Convert(block)) return 1; // same visually
|
||||
}
|
||||
return 2;
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
Chat.MessageOps(p.name + " triggered a non-fatal error on " + ColoredName + ", %Sat location: " + errorLocation);
|
||||
Server.s.Log(p.name + " triggered a non-fatal error on " + ColoredName + ", %Sat location: " + errorLocation);
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,21 +433,24 @@ namespace MCGalaxy {
|
||||
return x >= 0 && y >= 0 && z >= 0 && x < Width && y < Height && z < Length;
|
||||
}
|
||||
|
||||
public void UpdateBlock(Player p, ushort x, ushort y, ushort z,
|
||||
byte block, byte extBlock, ushort flags) {
|
||||
public void UpdateBlock(Player p, ushort x, ushort y, ushort z, byte block, byte ext,
|
||||
ushort flags = BlockDBFlags.ManualPlace) {
|
||||
byte old = GetTile(x, y, z), oldExt = 0;
|
||||
if (old == Block.custom_block) oldExt = GetExtTile(x, y, z);
|
||||
|
||||
bool drawn = (flags & BlockDBFlags.ManualPlace) != 0;
|
||||
if (!DoBlockchange(p, x, y, z, block, extBlock, drawn)) return;
|
||||
int type = DoBlockchange(p, x, y, z, block, ext, drawn);
|
||||
if (type == 0) return; // no block change performed
|
||||
|
||||
BlockDB.Cache.Add(p, x, y, z, flags,
|
||||
old, oldExt, block, extBlock);
|
||||
old, oldExt, block, ext);
|
||||
if (type == 1) return; // not different visually
|
||||
|
||||
int index = PosToInt(x, y, z);
|
||||
if (bufferblocks)
|
||||
BlockQueue.Addblock(p, index, block, extBlock);
|
||||
BlockQueue.Addblock(p, index, block, ext);
|
||||
else
|
||||
Player.GlobalBlockchange(this, x, y, z, block, extBlock);
|
||||
Player.GlobalBlockchange(this, x, y, z, block, ext);
|
||||
}
|
||||
|
||||
|
||||
|
@ -161,8 +161,9 @@ namespace MCGalaxy {
|
||||
byte old = level.GetTile(x, y, z), extOld = 0;
|
||||
if (old == Block.custom_block) extOld = level.GetExtTile(x, y, z);
|
||||
|
||||
if (!level.DoBlockchange(this, x, y, z, block, extBlock)) return false;
|
||||
Player.GlobalBlockchange(level, x, y, z, block, extBlock);
|
||||
int type = level.DoBlockchange(this, x, y, z, block, extBlock);
|
||||
if (type == 0) return false; // no change performed
|
||||
if (type == 2) Player.GlobalBlockchange(level, x, y, z, block, extBlock); // different visually
|
||||
|
||||
ushort flags = BlockDBFlags.ManualPlace;
|
||||
if (painting && Replacable(old)) flags = BlockDBFlags.Painted;
|
||||
|
Loading…
x
Reference in New Issue
Block a user