mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Add lb/gb edit order to change inventory position, fix a few lb/gb edit causing KeyNotFound when given invalid values.
This commit is contained in:
parent
97e009e6f8
commit
0441503bd4
@ -43,6 +43,8 @@ namespace MCGalaxy {
|
||||
public bool Version2;
|
||||
public byte LeftTex, RightTex, FrontTex, BackTex;
|
||||
|
||||
public int InventoryOrder = -1;
|
||||
|
||||
public const string GlobalPath = "blockdefs/global.json", GlobalBackupPath = "blockdefs/global.json.bak";
|
||||
|
||||
public static BlockDefinition[] GlobalDefs;
|
||||
@ -209,6 +211,20 @@ namespace MCGalaxy {
|
||||
Save(global, level);
|
||||
}
|
||||
|
||||
public static void UpdateOrder(BlockDefinition def, bool global, Level level) {
|
||||
if (def.InventoryOrder == -1) return;
|
||||
byte raw = def.BlockID, order = (byte)def.InventoryOrder;
|
||||
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (!global && pl.level != level) continue;
|
||||
if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw]) continue;
|
||||
|
||||
if (!pl.HasCpeExt(CpeExt.InventoryOrder)) continue;
|
||||
pl.Send(Packet.SetInventoryOrder(raw, order));
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateGlobalCustom(byte raw, BlockDefinition def) {
|
||||
Level[] loaded = LevelInfo.Loaded.Items;
|
||||
foreach (Level lvl in loaded) {
|
||||
@ -249,9 +265,16 @@ namespace MCGalaxy {
|
||||
|
||||
internal static void SendLevelCustomBlocks(Player pl) {
|
||||
BlockDefinition[] defs = pl.level.CustomBlockDefs;
|
||||
bool supportsOrder = pl.HasCpeExt(CpeExt.InventoryOrder);
|
||||
|
||||
for (int i = 1; i < defs.Length; i++) {
|
||||
BlockDefinition def = defs[i];
|
||||
if (def != null) pl.Send(def.MakeDefinePacket(pl));
|
||||
if (def == null) continue;
|
||||
|
||||
pl.Send(def.MakeDefinePacket(pl));
|
||||
if (def.InventoryOrder >= 0 && supportsOrder) {
|
||||
pl.Send(Packet.SetInventoryOrder((byte)i, (byte)def.InventoryOrder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,83 +320,84 @@ namespace MCGalaxy.Commands.CPE {
|
||||
string value = parts[3], blockName = def.Name;
|
||||
float fTemp;
|
||||
bool temp = false, changedFallback = false;
|
||||
Level level = p == null ? null : p.level;
|
||||
|
||||
string arg = MapPropertyName(parts[2].ToLower());
|
||||
switch (arg) {
|
||||
case "name":
|
||||
def.Name = value; break;
|
||||
case "collide":
|
||||
if (!EditByte(p, value, "Collide type", ref def.CollideType, "collide", 0, 6)) return;
|
||||
if (!EditByte(p, value, "Collide type", ref def.CollideType, arg, 0, 6)) return;
|
||||
break;
|
||||
case "speed":
|
||||
if (!Utils.TryParseDecimal(value, out fTemp) || fTemp < 0.25f || fTemp > 3.96f) {
|
||||
SendEditHelp(p, "speed"); return;
|
||||
SendEditHelp(p, arg); return;
|
||||
}
|
||||
def.Speed = fTemp; break;
|
||||
|
||||
case "toptex":
|
||||
if (!EditByte(p, value, "Top texture", ref def.TopTex, "top")) return;
|
||||
if (!EditByte(p, value, "Top texture", ref def.TopTex, arg)) return;
|
||||
break;
|
||||
case "alltex":
|
||||
if (!EditByte(p, value, "All textures", ref def.SideTex, "all")) return;
|
||||
if (!EditByte(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, "sides")) return;
|
||||
if (!EditByte(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, "left")) return;
|
||||
if (!EditByte(p, value, "Left texture", ref def.LeftTex, arg)) return;
|
||||
break;
|
||||
case "righttex":
|
||||
if (!EditByte(p, value, "Right texture", ref def.RightTex, "right")) return;
|
||||
if (!EditByte(p, value, "Right texture", ref def.RightTex, arg)) return;
|
||||
break;
|
||||
case "fronttex":
|
||||
if (!EditByte(p, value, "Front texture", ref def.FrontTex, "front")) return;
|
||||
if (!EditByte(p, value, "Front texture", ref def.FrontTex, arg)) return;
|
||||
break;
|
||||
case "backtex":
|
||||
if (!EditByte(p, value, "Back texture", ref def.BackTex, "back")) return;
|
||||
if (!EditByte(p, value, "Back texture", ref def.BackTex, arg)) return;
|
||||
break;
|
||||
case "bottomtex":
|
||||
if (!EditByte(p, value, "Bottom texture", ref def.BottomTex, "bottom")) return;
|
||||
if (!EditByte(p, value, "Bottom texture", ref def.BottomTex, arg)) return;
|
||||
break;
|
||||
|
||||
case "blockslight":
|
||||
if (!CommandParser.GetBool(p, value, ref temp)) {
|
||||
SendEditHelp(p, "shadow"); return;
|
||||
SendEditHelp(p, arg); return;
|
||||
}
|
||||
def.BlocksLight = temp;
|
||||
break;
|
||||
case "sound":
|
||||
if (!EditByte(p, value, "Walk sound", ref def.WalkSound, "sound", 0, 11)) return;
|
||||
if (!EditByte(p, value, "Walk sound", ref def.WalkSound, arg, 0, 11)) return;
|
||||
break;
|
||||
case "fullbright":
|
||||
if (!CommandParser.GetBool(p, value, ref temp)) {
|
||||
SendEditHelp(p, "bright"); return;
|
||||
SendEditHelp(p, arg); return;
|
||||
}
|
||||
def.FullBright = temp;
|
||||
break;
|
||||
|
||||
case "shape":
|
||||
if (!CommandParser.GetBool(p, value, ref temp)) {
|
||||
SendEditHelp(p,"shape"); return;
|
||||
SendEditHelp(p, arg); return;
|
||||
}
|
||||
def.Shape = temp ? (byte)0 : def.MaxZ;
|
||||
break;
|
||||
case "blockdraw":
|
||||
if (!EditByte(p, value, "Block draw", ref def.BlockDraw, "blockdraw", 0, 255)) return;
|
||||
if (!EditByte(p, value, "Block draw", ref def.BlockDraw, arg, 0, 255)) return;
|
||||
break;
|
||||
case "min":
|
||||
if (!ParseCoords(p, value, ref def.MinX, ref def.MinY, ref def.MinZ)) {
|
||||
SendEditHelp(p, "min"); return;
|
||||
SendEditHelp(p, arg); return;
|
||||
} break;
|
||||
case "max":
|
||||
if (!ParseCoords(p, value, ref def.MaxX, ref def.MaxY, ref def.MaxZ)) {
|
||||
SendEditHelp(p, "max"); return;
|
||||
SendEditHelp(p, arg); return;
|
||||
} break;
|
||||
|
||||
case "fogdensity":
|
||||
if (!EditByte(p, value, "Fog density", ref def.FogDensity, "fogdensity")) return;
|
||||
if (!EditByte(p, value, "Fog density", ref def.FogDensity, arg)) return;
|
||||
break;
|
||||
case "fogcolor":
|
||||
ColorDesc rgb = default(ColorDesc);
|
||||
@ -410,14 +411,27 @@ namespace MCGalaxy.Commands.CPE {
|
||||
|
||||
value = Block.Name(fallback);
|
||||
def.FallBack = fallback; break;
|
||||
|
||||
case "order":
|
||||
int order = 0;
|
||||
if (!CommandParser.GetInt(p, value, "Inventory order", ref order, 1, 256)) {
|
||||
SendEditHelp(p, arg); return;
|
||||
}
|
||||
|
||||
def.InventoryOrder = order - 1;
|
||||
BlockDefinition.UpdateOrder(def, global, level);
|
||||
BlockDefinition.Save(global, level);
|
||||
Player.Message(p, "Set inventory order for {0} to {1}", blockName, value);
|
||||
return;
|
||||
default:
|
||||
Player.Message(p, "Unrecognised property: " + arg); return;
|
||||
}
|
||||
|
||||
Player.Message(p, "Set {0} for {1} to {2}", arg, blockName, value);
|
||||
BlockDefinition.Add(def, defs, p == null ? null : p.level);
|
||||
if (changedFallback)
|
||||
BlockDefinition.UpdateFallback(global, def.BlockID, p == null ? null : p.level);
|
||||
BlockDefinition.Add(def, defs, level);
|
||||
if (changedFallback) {
|
||||
BlockDefinition.UpdateFallback(global, def.BlockID, level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -684,6 +698,10 @@ namespace MCGalaxy.Commands.CPE {
|
||||
{ "fallback", new string[] { "Enter the fallback block (Block shown to players who can't see custom blocks).",
|
||||
"You can use any block name or block ID from the normal blocks." }
|
||||
},
|
||||
{ "order", new string[] { "Enter the position/order of this block in the inventory.",
|
||||
"The default position of a block is its ID.",
|
||||
"A position of 255 hides the block from the inventory." }
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
@ -91,6 +91,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Returns whether this player's client supports the given CPE extension. </summary>
|
||||
public bool HasCpeExt(string extName, int version = 1) {
|
||||
if (!hasCpe) return false;
|
||||
ExtEntry ext = FindExtension(extName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user