This commit is contained in:
UnknownShadow200 2018-06-01 17:57:50 +10:00
parent 72fcb02818
commit 9805380698
5 changed files with 63 additions and 44 deletions

View File

@ -30,7 +30,7 @@ namespace MCGalaxy {
public string Name;
public byte CollideType;
public float Speed;
public byte TopTex, SideTex, BottomTex;
public ushort TopTex, SideTex, BottomTex;
public bool BlocksLight;
public byte WalkSound;
public bool FullBright;
@ -43,7 +43,7 @@ namespace MCGalaxy {
public byte MaxX, MaxY, MaxZ;
// BlockDefinitionsExt version 2 fields
public bool Version2;
public byte LeftTex, RightTex, FrontTex, BackTex;
public ushort LeftTex, RightTex, FrontTex, BackTex;
public int InventoryOrder = -1;
@ -224,12 +224,12 @@ namespace MCGalaxy {
}
}
public void SetAllTex(byte id) {
SideTex = id; TopTex = id; BottomTex = id;
LeftTex = id; RightTex = id; FrontTex = id; BackTex = id;
public void SetAllTex(ushort id) {
SetSideTex(id);
TopTex = id; BottomTex = id;
}
public void SetSideTex(byte id) {
public void SetSideTex(ushort id) {
SideTex = id;
LeftTex = id; RightTex = id; FrontTex = id; BackTex = id;
}
@ -312,11 +312,11 @@ namespace MCGalaxy {
public byte[] MakeDefinePacket(Player pl) {
if (pl.Supports(CpeExt.BlockDefinitionsExt, 2) && Shape != 0) {
return Packet.DefineBlockExt(this, true, pl.hasCP437, pl.hasExtBlocks);
return Packet.DefineBlockExt(this, true, pl.hasCP437, pl.hasExtBlocks, pl.hasExtTexs);
} else if (pl.Supports(CpeExt.BlockDefinitionsExt) && Shape != 0) {
return Packet.DefineBlockExt(this, false, pl.hasCP437, pl.hasExtBlocks);
return Packet.DefineBlockExt(this, false, pl.hasCP437, pl.hasExtBlocks, pl.hasExtTexs);
} else {
return Packet.DefineBlock(this, pl.hasCP437, pl.hasExtBlocks);
return Packet.DefineBlock(this, pl.hasCP437, pl.hasExtBlocks, pl.hasExtTexs);
}
}

View File

@ -286,17 +286,17 @@ namespace MCGalaxy.Commands.CPE {
step++;
}
} else if (step == 4) {
if (CommandParser.GetByte(p, value, "Texture ID", ref bd.TopTex)) {
if (CommandParser.GetUShort(p, value, "Texture ID", ref bd.TopTex, 0, 255)) {
step += (bd.Shape == 0 ? 5 : 1); // skip other texture steps for sprites
if (bd.Shape == 0) bd.SetAllTex(bd.TopTex);
}
} else if (step == 5) {
if (CommandParser.GetByte(p, value, "Texture ID", ref bd.SideTex)) {
if (CommandParser.GetUShort(p, value, "Texture ID", ref bd.SideTex, 0, 255)) {
bd.SetSideTex(bd.SideTex);
step++;
}
} else if (step == 6) {
if (CommandParser.GetByte(p, value, "Texture ID", ref bd.BottomTex))
if (CommandParser.GetUShort(p, value, "Texture ID", ref bd.BottomTex, 0, 255))
step++;
} else if (step == 7) {
if (ParseCoords(p, value, ref bd.MinX, ref bd.MinY, ref bd.MinZ))
@ -398,30 +398,30 @@ namespace MCGalaxy.Commands.CPE {
def.Speed = fTemp; break;
case "toptex":
if (!EditByte(p, value, "Top texture", ref def.TopTex, arg)) return;
if (!EditUShort(p, value, "Top texture", ref def.TopTex, arg)) return;
break;
case "alltex":
if (!EditByte(p, value, "All textures", ref def.SideTex, arg)) return;
if (!EditUShort(p, value, "All textures", ref def.SideTex, arg)) return;
def.SetAllTex(def.SideTex);
break;
case "sidetex":
if (!EditByte(p, value, "Side texture", ref def.SideTex, arg)) return;
if (!EditUShort(p, value, "Side texture", ref def.SideTex, arg)) return;
def.SetSideTex(def.SideTex);
break;
case "lefttex":
if (!EditByte(p, value, "Left texture", ref def.LeftTex, arg)) return;
if (!EditUShort(p, value, "Left texture", ref def.LeftTex, arg)) return;
break;
case "righttex":
if (!EditByte(p, value, "Right texture", ref def.RightTex, arg)) return;
if (!EditUShort(p, value, "Right texture", ref def.RightTex, arg)) return;
break;
case "fronttex":
if (!EditByte(p, value, "Front texture", ref def.FrontTex, arg)) return;
if (!EditUShort(p, value, "Front texture", ref def.FrontTex, arg)) return;
break;
case "backtex":
if (!EditByte(p, value, "Back texture", ref def.BackTex, arg)) return;
if (!EditUShort(p, value, "Back texture", ref def.BackTex, arg)) return;
break;
case "bottomtex":
if (!EditByte(p, value, "Bottom texture", ref def.BottomTex, arg)) return;
if (!EditUShort(p, value, "Bottom texture", ref def.BottomTex, arg)) return;
break;
case "blockslight":
@ -583,12 +583,17 @@ namespace MCGalaxy.Commands.CPE {
}
static bool EditByte(Player p, string value, string propName, ref byte target, string help) {
byte temp = 0;
if (!CommandParser.GetByte(p, value, propName, ref temp, 0, 255)) {
SendEditHelp(p, help);
return false;
if (!CommandParser.GetByte(p, value, propName, ref target)) {
SendEditHelp(p, help); return false;
}
target = temp; return true;
return true;
}
static bool EditUShort(Player p, string value, string propName, ref ushort target, string help) {
if (!CommandParser.GetUShort(p, value, propName, ref target)) {
SendEditHelp(p, help); return false;
}
return true;
}
static bool ParseCoords(Player p, string parts, ref byte x, ref byte y, ref byte z) {

View File

@ -47,8 +47,8 @@ namespace MCGalaxy.Commands.Misc {
args.Player = p;
p.cmdTimer = true;
Chat.MessageLevel(p, "Timer lasting for " + TotalTime + " seconds has started.");
Chat.MessageLevel(p, args.Message);
Chat.MessageLevel(p.level, "Timer lasting for " + TotalTime + " seconds has started.");
Chat.MessageLevel(p.level, args.Message);
Server.MainScheduler.QueueRepeat(TimerCallback, args, TimeSpan.FromSeconds(5));
}
@ -68,8 +68,8 @@ namespace MCGalaxy.Commands.Misc {
p.cmdTimer = false;
task.Repeating = false;
} else {
Chat.MessageLevel(p, args.Message);
Chat.MessageLevel(p, "Timer has " + (args.Repeats * 5) + " seconds remaining.");
Chat.MessageLevel(p.level, args.Message);
Chat.MessageLevel(p.level, "Timer has " + (args.Repeats * 5) + " seconds remaining.");
}
}

View File

@ -371,11 +371,12 @@ namespace MCGalaxy.Network {
#region Block definitions
public static byte[] DefineBlock(BlockDefinition def, bool hasCP437, bool extBlocks) {
byte[] buffer = new byte[extBlocks ? 81 : 80];
public static byte[] DefineBlock(BlockDefinition def, bool hasCP437,
bool extBlocks, bool extTexs) {
byte[] buffer = new byte[(extBlocks ? 81 : 80) + (extTexs ? 3 : 0)];
int i = 0;
buffer[i++] = Opcode.CpeDefineBlock;
MakeDefineBlockStart(def, buffer, ref i, false, hasCP437, extBlocks);
MakeDefineBlockStart(def, buffer, ref i, false, hasCP437, extBlocks, extTexs);
buffer[i++] = def.Shape;
MakeDefineBlockEnd(def, ref i, buffer);
return buffer;
@ -388,19 +389,28 @@ namespace MCGalaxy.Network {
return buffer;
}
public static byte[] DefineBlockExt(BlockDefinition def, bool uniqueSideTexs, bool hasCP437, bool extBlocks) {
byte[] buffer = new byte[(extBlocks ? 86 : 85) + (uniqueSideTexs ? 3 : 0)];
public static byte[] DefineBlockExt(BlockDefinition def, bool uniqueSideTexs, bool hasCP437,
bool extBlocks, bool extTexs) {
byte[] buffer = new byte[(extBlocks ? 86 : 85) + (uniqueSideTexs ? 3 : 0) + (extTexs ? 6 : 0)];
int i = 0;
buffer[i++] = Opcode.CpeDefineBlockExt;
MakeDefineBlockStart(def, buffer, ref i, uniqueSideTexs, hasCP437, extBlocks);
MakeDefineBlockStart(def, buffer, ref i, uniqueSideTexs, hasCP437, extBlocks, extTexs);
buffer[i++] = def.MinX; buffer[i++] = def.MinZ; buffer[i++] = def.MinY;
buffer[i++] = def.MaxX; buffer[i++] = def.MaxZ; buffer[i++] = def.MaxY;
MakeDefineBlockEnd(def, ref i, buffer);
return buffer;
}
static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer, ref int i,
bool uniqueSideTexs, bool hasCP437, bool extBlocks) {
static void WriteTex(byte[] buffer, ref int i, ushort value, bool extTexs) {
if (extTexs) {
NetUtils.WriteU16(value, buffer, i); i += 2;
} else {
buffer[i++] = (byte)value;
}
}
static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer, ref int i, bool uniqueSideTexs,
bool hasCP437, bool extBlocks, bool extTexs) {
// speed = 2^((raw - 128) / 64);
// therefore raw = 64log2(speed) + 128
byte rawSpeed = (byte)(64 * Math.Log(def.Speed, 2) + 128);
@ -411,15 +421,15 @@ namespace MCGalaxy.Network {
buffer[i++] = def.CollideType;
buffer[i++] = rawSpeed;
buffer[i++] = def.TopTex;
WriteTex(buffer, ref i, def.TopTex, extTexs);
if (uniqueSideTexs) {
buffer[i++] = def.LeftTex; buffer[i++] = def.RightTex;
buffer[i++] = def.FrontTex; buffer[i++] = def.BackTex;
WriteTex(buffer, ref i, def.LeftTex, extTexs); WriteTex(buffer, ref i, def.RightTex, extTexs);
WriteTex(buffer, ref i, def.FrontTex, extTexs); WriteTex(buffer, ref i, def.BackTex, extTexs);
} else {
buffer[i++] = def.SideTex;
}
WriteTex(buffer, ref i, def.SideTex, extTexs);
}
WriteTex(buffer, ref i, def.BottomTex, extTexs);
buffer[i++] = def.BottomTex;
buffer[i++] = (byte)(def.BlocksLight ? 0 : 1);
buffer[i++] = def.WalkSound;
buffer[i++] = (byte)(def.FullBright ? 1 : 0);

View File

@ -49,6 +49,7 @@ namespace MCGalaxy {
new ExtEntry(CpeExt.EntityProperty), new ExtEntry(CpeExt.ExtEntityPositions),
new ExtEntry(CpeExt.TwoWayPing), new ExtEntry(CpeExt.InventoryOrder),
new ExtEntry(CpeExt.InstantMOTD), new ExtEntry(CpeExt.FastMap),
new ExtEntry(CpeExt.ExtTextures),
#if TEN_BIT_BLOCKS
new ExtEntry(CpeExt.ExtBlocks),
#endif
@ -63,7 +64,7 @@ namespace MCGalaxy {
// these are checked very frequently, so avoid overhead of HasCpeExt
public bool hasCustomBlocks, hasBlockDefs, hasTextColors, hasExtBlocks,
hasChangeModel, hasExtList, hasCP437, hasTwoWayPing, hasBulkBlockUpdate;
hasChangeModel, hasExtList, hasCP437, hasTwoWayPing, hasBulkBlockUpdate, hasExtTexs;
void AddExtension(string extName, int version) {
ExtEntry ext = FindExtension(extName.Trim());
@ -95,6 +96,8 @@ namespace MCGalaxy {
hasTwoWayPing = true;
} else if (ext.ExtName == CpeExt.BulkBlockUpdate) {
hasBulkBlockUpdate = true;
} else if (ext.ExtName == CpeExt.ExtTextures) {
hasExtTexs = true;
}
#if TEN_BIT_BLOCKS
else if (ext.ExtName == CpeExt.ExtBlocks) {
@ -209,6 +212,7 @@ namespace MCGalaxy {
public const string InstantMOTD = "InstantMOTD";
public const string FastMap = "FastMap";
public const string ExtBlocks = "ExtendedBlocks";
public const string ExtTextures = "ExtendedTextures";
}
public enum CpeMessageType : byte {