Fix remaining issues with custom blocks that replace core blocks not using correct fallbacks

This commit is contained in:
UnknownShadow200 2017-02-20 09:13:48 +11:00
parent f95b31eb03
commit c61a746555
9 changed files with 34 additions and 47 deletions

View File

@ -52,7 +52,7 @@ namespace MCGalaxy.Blocks {
p.ChangeBlock(x, y, z, Block.staircasestep, 0); return;
}
p.SendBlockchange(x, y, z, Block.air); // send the air block back only to the user
p.SendBlockchange(x, y, z, Block.air, 0); // send the air block back only to the user
p.ChangeBlock(x, (ushort)(y - 1), z, Block.staircasefull, 0);
}
@ -62,7 +62,7 @@ namespace MCGalaxy.Blocks {
p.ChangeBlock(x, y, z, Block.cobblestoneslab, 0); return;
}
p.SendBlockchange(x, y, z, Block.air); // send the air block back only to the user
p.SendBlockchange(x, y, z, Block.air, 0); // send the air block back only to the user
p.ChangeBlock(x, (ushort)(y - 1), z, Block.stone, 0);
}

View File

@ -105,7 +105,7 @@ namespace MCGalaxy.Commands {
foreach (Vec3U16 cP in toSend) {
if (lastSent.Contains(cP)) continue;
lastSent.Add(cP);
p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.glass);
p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.glass, 0);
}
toSend.Clear();
}

View File

@ -173,7 +173,7 @@ namespace MCGalaxy.Commands.Building {
static void ShowMessageBlocks(Player p, DataTable table) {
foreach (DataRow row in table.Rows) {
p.SendBlockchange(U16(row["X"]), U16(row["Y"]), U16(row["Z"]), Block.green);
p.SendBlockchange(U16(row["X"]), U16(row["Y"]), U16(row["Z"]), Block.green, 0);
}
Player.Message(p, "Now showing &a" + table.Rows.Count + " %SMBs.");
}

View File

@ -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.SendBlockchange(x, y, z, Block.green);
p.SendBlockchange(x, y, z, Block.green, 0);
PortalPos Port;
Port.Map = p.level.name;
@ -162,8 +162,8 @@ namespace MCGalaxy.Commands.Building {
static void ShowPortals(Player p, DataTable table) {
foreach (DataRow row in table.Rows) {
if (row["ExitMap"].ToString() == p.level.name)
p.SendBlockchange(U16(row["ExitX"]), U16(row["ExitY"]), U16(row["ExitZ"]), Block.red);
p.SendBlockchange(U16(row["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"]), Block.green);
p.SendBlockchange(U16(row["ExitX"]), U16(row["ExitY"]), U16(row["ExitZ"]), Block.red, 0);
p.SendBlockchange(U16(row["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"]), Block.green, 0);
}
Player.Message(p, "Now showing &a" + table.Rows.Count + " %Sportals.");

View File

@ -46,7 +46,7 @@ namespace MCGalaxy.Commands {
DoFly(p, oldpos, last, next);
foreach (Vec3U16 cP in last)
p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.air);
p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.air, 0);
Player.Message(p, "Stopped flying");
}));
flyThread.Name = "MCG_Fly";
@ -77,14 +77,14 @@ namespace MCGalaxy.Commands {
foreach (Vec3U16 P in next) {
if (last.Contains(P)) continue;
last.Add(P);
p.SendBlockchange(P.X, P.Y, P.Z, Block.glass);
p.SendBlockchange(P.X, P.Y, P.Z, Block.glass, 0);
}
for (int i = 0; i < last.Count; i++) {
Vec3U16 P = last[i];
if (next.Contains(P)) continue;
p.SendBlockchange(P.X, P.Y, P.Z, Block.air);
p.SendBlockchange(P.X, P.Y, P.Z, Block.air, 0);
last.RemoveAt(i); i--;
}
next.Clear();

View File

@ -90,9 +90,10 @@ namespace MCGalaxy {
return def == null ? Block.air : def.FallBack;
}
public byte GetFallback(byte extType) {
BlockDefinition def = CustomBlockDefs[extType];
return def == null ? Block.air : def.FallBack;
public byte RawFallback(byte raw) {
BlockDefinition def = CustomBlockDefs[raw];
if (def != null) return def.FallBack;
return raw < Block.CpeCount ? raw : Block.air;
}
public void SetTile(int index, byte block) {

View File

@ -366,29 +366,13 @@ namespace MCGalaxy {
SendRaw(Opcode.RemoveEntity, id);
}
[Obsolete("Prefer SendBlockChange(x, y, z, block, extBlock)")]
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;
byte[] buffer = new byte[8];
buffer[0] = Opcode.SetBlock;
NetUtils.WriteU16(x, buffer, 1);
NetUtils.WriteU16(y, buffer, 3);
NetUtils.WriteU16(z, buffer, 5);
if (block == Block.custom_block) {
block = hasBlockDefs ? level.GetExtTile(x, y, z) : level.GetFallbackExtTile(x, y, z);
} else {
block = Block.Convert(block);
}
// TODO: custom blocks replacing core blocks
if (!hasCustomBlocks) block = Block.ConvertCPE(block);
buffer[7] = block;
Send(buffer);
byte extBlock = 0;
if (block == Block.custom_block) extBlock = level.GetExtTile(x, y, z);
SendBlockchange(x, y, z, block, extBlock);
}
// Duplicated as this packet needs to have maximum optimisation.
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;
@ -400,12 +384,18 @@ namespace MCGalaxy {
NetUtils.WriteU16(z, buffer, 5);
if (block == Block.custom_block) {
block = hasBlockDefs ? extBlock : level.GetFallback(extBlock);
block = hasBlockDefs ? extBlock : level.RawFallback(extBlock);
} else {
block = Block.Convert(block);
}
if (!hasCustomBlocks) block = Block.ConvertCPE(block);
if (!hasCustomBlocks) block = Block.ConvertCPE(block); // client doesn't support CPE
// Custom block replaced a core block
if (!hasBlockDefs && block < Block.CpeCount) {
BlockDefinition def = level.CustomBlockDefs[block];
if (def != null) block = def.FallBack;
}
buffer[7] = block;
Send(buffer);
}
@ -433,10 +423,9 @@ namespace MCGalaxy {
public void SendChangeModel(byte id, string model) {
// Fallback block models for clients that don't support block definitions
byte block;
bool fallback = byte.TryParse(model, out block) && block >= Block.CpeCount;
block = level == null ? block : level.GetFallback(block);
if (fallback && !hasBlockDefs && block != Block.air)
model = block.ToString();
if (byte.TryParse(model, out block) && !hasBlockDefs) {
model = level.RawFallback(block).ToString();
}
Send(Packet.ChangeModel(id, model, hasCP437));
}

View File

@ -149,10 +149,8 @@ namespace MCGalaxy {
string lastUrl = "";
public void SendCurrentMapAppearance() {
byte side = (byte)level.EdgeBlock, edge = (byte)level.HorizonBlock;
if (side >= Block.CpeCount && !hasBlockDefs)
side = level.GetFallback(side);
if (edge >= Block.CpeCount && !hasBlockDefs)
edge = level.GetFallback(edge);
if (!hasBlockDefs) side = level.RawFallback(side);
if (!hasBlockDefs) edge = level.RawFallback(edge);
if (HasCpeExt(CpeExt.EnvMapAspect)) {
string url = GetTextureUrl();

View File

@ -144,7 +144,7 @@ namespace MCGalaxy {
data[j++] = (byte)(x >> 8); data[j++] = (byte)x;
data[j++] = (byte)(y >> 8); data[j++] = (byte)y;
data[j++] = (byte)(z >> 8); data[j++] = (byte)z;
data[j++] = types[i] < Block.CpeCount ? types[i] : level.GetFallback(types[i]);
data[j++] = level.RawFallback(types[i]);
}
return data;
}
@ -161,8 +161,7 @@ namespace MCGalaxy {
data[j++] = (byte)(x >> 8); data[j++] = (byte)x;
data[j++] = (byte)(y >> 8); data[j++] = (byte)y;
data[j++] = (byte)(z >> 8); data[j++] = (byte)z;
data[j++] = types[i] < Block.CpeCount ? Block.ConvertCPE(types[i])
: Block.ConvertCPE(level.GetFallback(types[i]));
data[j++] = types[i] = Block.ConvertCPE(level.RawFallback(types[i]));
}
return data;
}