Fix InventoryOrder from recent changes

This commit is contained in:
UnknownShadow200 2018-03-04 19:28:08 +11:00
parent 8329520c06
commit 3e5e122951
6 changed files with 22 additions and 22 deletions

View File

@ -32,8 +32,7 @@ namespace MCGalaxy {
}
public static string GetName(Player p, BlockID block) {
BlockRaw raw = (BlockRaw)block;
if (IsPhysicsType(block)) return coreNames[raw];
if (IsPhysicsType(block)) return coreNames[block];
BlockDefinition def;
if (!Player.IsSuper(p)) {
@ -43,7 +42,7 @@ namespace MCGalaxy {
}
if (def != null) return def.Name.Replace(" ", "");
return block < Block.Extended ? coreNames[block] : raw.ToString();
return block < Block.Extended ? coreNames[block] : ToRaw(block).ToString();
}
public static BlockID Parse(Player p, string input) {

View File

@ -182,8 +182,12 @@ namespace MCGalaxy {
}
}
public static BlockID FromRaw(byte raw) {
return raw < Block.CpeCount ? raw : (BlockID)(Block.Extended | raw);
public static BlockID FromRaw(BlockID raw) {
return raw < CpeCount ? raw : (BlockID)(raw + Block.Extended);
}
public static BlockID ToRaw(BlockID raw) {
return raw < CpeCount ? raw : (BlockID)(raw - Block.Extended);
}
public static BlockID FromRaw(byte raw, bool extended) {
@ -192,7 +196,8 @@ namespace MCGalaxy {
public static BlockID MapOldRaw(BlockID raw) {
// old raw form was: 0 - 65 core block ids, 66 - 255 custom block ids
return IsPhysicsType(raw) ? ((BlockID)(Block.Extended | raw)) : raw;
// 256+ remain unchanged
return IsPhysicsType(raw) ? ((BlockID)(raw + Block.Extended)) : raw;
}
public static bool IsPhysicsType(BlockID block) {

View File

@ -26,7 +26,7 @@ using BlockRaw = System.Byte;
namespace MCGalaxy {
public sealed class BlockDefinition {
public ushort BlockID;
public ushort BlockID; // really raw block ID
public string Name;
public byte CollideType;
public float Speed;
@ -47,12 +47,8 @@ namespace MCGalaxy {
public int InventoryOrder = -1;
public BlockID_ GetBlock() {
return (BlockID_)(BlockID < Block.CpeCount ? BlockID : (Block.Extended + BlockID));
}
public void SetBlock(BlockID_ b) {
BlockID = (BlockID_)(b < Block.CpeCount ? b : (b - Block.Extended));
}
public BlockID_ GetBlock() { return Block.FromRaw(BlockID); }
public void SetBlock(BlockID_ b) { BlockID = Block.ToRaw(b); }
public const string GlobalPath = "blockdefs/global.json", GlobalBackupPath = "blockdefs/global.json.bak";
@ -262,10 +258,10 @@ namespace MCGalaxy {
internal static void SendLevelInventoryOrder(Player pl) {
BlockDefinition[] defs = pl.level.CustomBlockDefs;
for (int i = 0; i < defs.Length; i++) {
BlockDefinition def = defs[i];
for (int b = 0; b < defs.Length; b++) {
BlockDefinition def = defs[b];
if (def != null && def.InventoryOrder >= 0) {
pl.Send(Packet.SetInventoryOrder((byte)i, (byte)def.InventoryOrder));
pl.Send(Packet.SetInventoryOrder((byte)def.BlockID, (byte)def.InventoryOrder));
}
}
}

View File

@ -128,7 +128,7 @@ namespace MCGalaxy.Commands.CPE {
AddBlock(p, dstDef, global, cmd, props);
string scope = global ? "global" : "level";
Player.Message(p, "Duplicated the {0} custom block with id \"{1}\" to \"{2}\".", scope,
(BlockRaw)src, (BlockRaw)dst);
Block.ToRaw(src), Block.ToRaw(dst));
}
static void InfoHandler(Player p, string[] parts, bool global, string cmd) {
@ -140,7 +140,7 @@ namespace MCGalaxy.Commands.CPE {
BlockDefinition def = defs[block];
if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; }
Player.Message(p, "About {0} ({1})", def.Name, (BlockRaw)def.BlockID);
Player.Message(p, "About {0} ({1})", def.Name, Block.ToRaw(block));
Player.Message(p, " Draw type: {0}, Blocks light: {1}, collide type: {2}",
def.BlockDraw, def.BlocksLight, def.CollideType);
Player.Message(p, " Fallback ID: {0}, Sound: {1}, Speed: {2}",
@ -512,13 +512,13 @@ namespace MCGalaxy.Commands.CPE {
static void MessageNoBlock(Player p, BlockID block, bool global, string cmd) {
string scope = global ? "global" : "level";
Player.Message(p, "&cThere is no {1} custom block with the id \"{0}\".", (BlockRaw)block, scope);
Player.Message(p, "&cThere is no {1} custom block with the id \"{0}\".", Block.ToRaw(block), scope);
Player.Message(p, "Type \"%T{0} list\" %Sto see a list of {1} custom blocks.", cmd, scope);
}
static void MessageAlreadyBlock(Player p, BlockID block, bool global, string cmd) {
string scope = global ? "global" : "level";
Player.Message(p, "&cThere is already a {1} custom block with the id \"{0}\".", (BlockRaw)block, scope);
Player.Message(p, "&cThere is already a {1} custom block with the id \"{0}\".", Block.ToRaw(block), scope);
Player.Message(p, "Type \"%T{0} list\" %Sto see a list of {1} custom blocks.", cmd, scope);
}

View File

@ -66,7 +66,7 @@ namespace MCGalaxy.Commands.Info {
string blockName = Block.GetName(p, block);
Player.Message(p, "Block ({0}, {1}, {2}): &f{3} = {4}%S.",
x, y, z, (BlockRaw)block, blockName);
x, y, z, Block.ToRaw(block), blockName);
if (HasExtraPerm(p, 1)) {
BlockDBChange.OutputMessageBlock(p, block, x, y, z);

View File

@ -296,7 +296,7 @@ namespace MCGalaxy {
if (held >= Block.Extended) {
if (!hasBlockDefs || level.CustomBlockDefs[held] == null) {
SendMessage("Invalid block type: " + (BlockRaw)held);
SendMessage("Invalid block type: " + Block.ToRaw(held));
RevertBlock(x, y, z); return;
}
}