More fixes for recent few commits

This commit is contained in:
UnknownShadow200 2017-06-11 18:42:55 +10:00
parent 5f3be2b529
commit b8625b0a22
9 changed files with 26 additions and 24 deletions

View File

@ -120,10 +120,6 @@ namespace MCGalaxy {
GlobalDefs[Block.air] = DefaultSet.MakeCustomBlock(Block.air);
GlobalDefs[Block.air].Name = "Air fallback";
GlobalProps = new BlockProps[Block.Count * 2];
for (int i = 0; i < Block.Count; i++)
GlobalProps[i] = Block.Props[i];
try {
if (File.Exists(GlobalPath)) {
File.Copy(GlobalPath, GlobalBackupPath, true);
@ -132,14 +128,21 @@ namespace MCGalaxy {
Server.ErrorLog(ex);
}
Save(true, null);
BlockProps.Load("global", BlockDefinition.GlobalProps, true);
Save(true, null);
// As the BlockDefinition instances in levels will now be different
// to the instances in GlobalDefs, we need to update them.
if (oldDefs != null) UpdateLoadedLevels(oldDefs);
}
public static void LoadGlobalProps() {
GlobalProps = new BlockProps[Block.Count * 2];
for (int i = 0; i < Block.Count; i++) {
GlobalProps[i] = Block.Props[i];
GlobalProps[i + Block.Count] = new BlockProps((byte)i);
}
BlockProps.Load("global", GlobalProps, true);
}
static void UpdateLoadedLevels(BlockDefinition[] oldGlobalDefs) {
Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level lvl in loaded) {

View File

@ -48,7 +48,7 @@ namespace MCGalaxy.Blocks {
return perms;
}
public static BlockPerms[] List = new BlockPerms[256];
public static BlockPerms[] List = new BlockPerms[Block.Count];
/// <summary> Returns whether the given rank can modify the given block. </summary>

View File

@ -92,7 +92,7 @@ namespace MCGalaxy.Blocks {
// Don't save physics blocks
if (custom && (i > Block.CpeCount && i < Block.Count)) continue;
// Convert ext to raw ids
int id = i >= Block.Count ? (i - 256) : i;
int id = i >= Block.Count ? (i - Block.Count) : i;
string deathMsg = props.DeathMessage == null ? "" : props.DeathMessage.Replace(":", "\\;");
w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":"
@ -124,7 +124,7 @@ namespace MCGalaxy.Blocks {
continue;
}
int idx = raw;
if (custom && raw >= Block.CpeCount) idx += 256;
if (custom && raw >= Block.CpeCount) idx += Block.Count;
bool.TryParse(parts[1], out scope[idx].IsRails);
bool.TryParse(parts[2], out scope[idx].IsTDoor);

View File

@ -48,7 +48,7 @@ namespace MCGalaxy {
public bool IsAir { get { return BlockID == Block.air; } }
/// <summary> Returns the index of this block within an array. </summary>
public int Index { get { return BlockID != Block.custom_block ? BlockID : (ExtID + 256); } }
public int Index { get { return BlockID != Block.custom_block ? BlockID : (ExtID + Block.Count); } }
/// <summary> Returns the raw (for client side) block ID of this block. </summary>

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Blocks.Physics {
if (!C.data.HasWait) return false;
if (C.data.Door && C.data.Data == 0) {
int i = C.data.Value2 + (C.data.ExtBlock ? 256 : 0);
int i = C.data.Value2 + (C.data.ExtBlock ? Block.Count : 0);
bool tdoor = lvl.BlockProps[i].IsTDoor;
if (tdoor) DoorPhysics.tDoor(lvl, ref C);
@ -68,7 +68,7 @@ namespace MCGalaxy.Blocks.Physics {
if (args.Wait) {
if (C.data.Door && C.data.Data == 0) {
int i = C.data.Value2 + (C.data.ExtBlock ? 256 : 0);
int i = C.data.Value2 + (C.data.ExtBlock ? Block.Count : 0);
bool tdoor = lvl.BlockProps[i].IsTDoor;
if (tdoor) DoorPhysics.tDoor(lvl, ref C);

View File

@ -121,7 +121,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, src, dst);
Player.Message(p, "Duplicated the {0} custom block with id \"{1}\" to \"{2}\".", scope, src.RawID, dst.RawID);
}
static void InfoHandler(Player p, string[] parts, bool global, string cmd) {

View File

@ -154,7 +154,10 @@ namespace MCGalaxy {
OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
if ((C.data.Raw & mask) == 0 || extraHandler(this, ref C)) {
HandlePhysics handler = handlers[blocks[C.b]];
int idx = blocks[C.b];
if (idx == Block.custom_block) idx = Block.Count + GetExtTileNoCheck(x, y, z);
HandlePhysics handler = handlers[idx];
if (handler != null) {
handler(this, ref C);
} else if ((C.data.Raw & mask) == 0 || !C.data.HasWait) {
@ -246,7 +249,7 @@ namespace MCGalaxy {
ExtBlock block;
block.BlockID = type;
block.ExtID = 0;
// Is the Ext flag just an indicator for the block update?
if (data.ExtBlock && (data.Raw & PhysicsArgs.TypeMask) == 0) {
block.ExtID = block.BlockID;

View File

@ -76,6 +76,7 @@ namespace MCGalaxy {
BlockProps = new BlockProps[Block.Count * 2];
for (int i = 0; i < BlockProps.Length; i++)
BlockProps[i] = BlockDefinition.GlobalProps[i];
SetBlockHandlers();
name = n; MapName = n.ToLower();
BlockDB = new BlockDB(this);
@ -92,7 +93,6 @@ namespace MCGalaxy {
spawny = (ushort)(Height * 0.75f);
spawnz = (ushort)(Length / 2);
rotx = 0; roty = 0;
SetBlockHandlers();
ZoneList = new List<Zone>();
VisitAccess = new LevelAccessController(this, true);
@ -405,10 +405,8 @@ namespace MCGalaxy {
lvl.CustomBlockDefs[i] = defs[i];
}
for (int i = 0; i < lvl.BlockProps.Length; i++) {
lvl.BlockProps[i] = BlockDefinition.GlobalProps[i];
}
MCGalaxy.Blocks.BlockProps.Load("lvl_" + lvl.MapName, lvl.BlockProps, true);
lvl.SetBlockHandlers();
}
public static bool CheckLoadOnGoto(string givenName) {
@ -513,11 +511,8 @@ namespace MCGalaxy {
}
public void SetBlockHandler(ExtBlock block) {
bool notCustom = !block.IsCustomType &&
(block.BlockID >= Block.CpeCount || CustomBlockDefs[block.BlockID] == null);
bool nonSolid;
if (notCustom) {
if (GetBlockDef(block) == null) {
nonSolid = Block.Walkthrough(Block.Convert(block.BlockID));
} else {
nonSolid = CustomBlockDefs[block.BlockID].CollideType != CollideType.Solid;

View File

@ -195,6 +195,7 @@ namespace MCGalaxy {
Command.InitAll();
CommandPerms.Load();
Block.SetBlocks();
BlockDefinition.LoadGlobalProps();
Awards.Load();
Economy.Load();
WarpList.Global.Load(null);