Fix block ids > 255 not working with sides/horizon blocks

This commit is contained in:
UnknownShadow200 2018-03-29 15:53:15 +11:00
parent 29d1ebf66a
commit 7864af6e3b
3 changed files with 17 additions and 15 deletions

View File

@ -18,6 +18,7 @@ using MCGalaxy.Events.EntityEvents;
using MCGalaxy.Games;
using MCGalaxy.Network;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
namespace MCGalaxy {
@ -214,10 +215,14 @@ namespace MCGalaxy {
}
static void SendModel(Player pl, byte id, string model) {
byte block;
// Fallback block models for clients that don't support block definitions
if (byte.TryParse(model, out block) && !pl.hasBlockDefs) {
model = pl.level.RawFallback(block).ToString();
BlockID raw;
if (BlockID.TryParse(model, out raw) && raw > pl.MaxRawBlock) {
BlockID block = Block.FromRaw(raw);
if (block >= Block.ExtendedCount) {
model = "humanoid"; // invalid block ids
} else {
model = pl.level.RawFallback(block).ToString();
}
}
pl.Send(Packet.ChangeModel(id, model, pl.hasCP437));
}

View File

@ -113,28 +113,26 @@ namespace MCGalaxy {
string lastUrl = "";
public void SendCurrentTextures() {
byte side = (byte)level.Config.EdgeBlock;
byte edge = (byte)level.Config.HorizonBlock;
if (!hasBlockDefs) side = level.RawFallback(level.Config.EdgeBlock);
if (!hasBlockDefs) edge = level.RawFallback(level.Config.HorizonBlock);
BlockID side = level.Config.EdgeBlock; if (side > MaxRawBlock) side = level.RawFallback(side);
BlockID edge = level.Config.HorizonBlock; if (edge > MaxRawBlock) edge = level.RawFallback(edge);
string url = GetTextureUrl();
if (Supports(CpeExt.EnvMapAspect)) {
if (Supports(CpeExt.EnvMapAspect)) {
// reset all other textures back to client default.
if (url != lastUrl) Send(Packet.EnvMapUrl("", hasCP437));
Send(Packet.EnvMapUrl(url, hasCP437));
} else if (Supports(CpeExt.EnvMapAppearance, 2)) {
// reset all other textures back to client default.
if (url != lastUrl) {
Send(Packet.MapAppearanceV2("", side, edge, level.Config.EdgeLevel,
Send(Packet.MapAppearanceV2("", (byte)side, (byte)edge, level.Config.EdgeLevel,
level.Config.CloudsHeight, level.Config.MaxFogDistance, hasCP437));
}
Send(Packet.MapAppearanceV2(url, side, edge, level.Config.EdgeLevel,
Send(Packet.MapAppearanceV2(url, (byte)side, (byte)edge, level.Config.EdgeLevel,
level.Config.CloudsHeight, level.Config.MaxFogDistance, hasCP437));
lastUrl = url;
} else if (Supports(CpeExt.EnvMapAppearance)) {
url = level.Config.Terrain.Length == 0 ? ServerConfig.DefaultTerrain : level.Config.Terrain;
Send(Packet.MapAppearance(url, side, edge, level.Config.EdgeLevel, hasCP437));
Send(Packet.MapAppearance(url, (byte)side, (byte)edge, level.Config.EdgeLevel, hasCP437));
}
}

View File

@ -396,8 +396,7 @@ namespace MCGalaxy {
value = zone.Config.GetEnvProp(i);
}
if (!hasBlockDefs) value = level.RawFallback((BlockID)value);
value = (byte)value;
if (value > MaxRawBlock) value = level.RawFallback((BlockID)value);
} else {
if (zone != null && zone.Config.GetEnvProp(i) != -1) {
value = zone.Config.GetEnvProp(i);