diff --git a/MCGalaxy/Blocks/Block.ID.cs b/MCGalaxy/Blocks/Block.ID.cs index 2cff7cccd..573a90e81 100644 --- a/MCGalaxy/Blocks/Block.ID.cs +++ b/MCGalaxy/Blocks/Block.ID.cs @@ -331,5 +331,6 @@ namespace MCGalaxy public const byte Invalid = 0xff; public const ushort Extended = 256; + public const int ExtendedShift = 8; } } \ No newline at end of file diff --git a/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs b/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs index 07cf6f85a..88c7e29c0 100644 --- a/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs +++ b/MCGalaxy/Blocks/Physics/ActivateablePhysics.cs @@ -86,7 +86,7 @@ namespace MCGalaxy.Blocks.Physics { PhysicsArgs args = default(PhysicsArgs); args.Type1 = PhysicsArgs.Custom; args.Value1 = 16 - 1; args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block; - args.ExtBlock = block >= Block.Extended; + args.ExtBlock = (byte)(block >> Block.ExtendedShift); physForm = Block.Door_Log_air; // air if (block == Block.Door_Air || block == Block.Door_AirActivatable) { @@ -103,7 +103,7 @@ namespace MCGalaxy.Blocks.Physics { PhysicsArgs args = default(PhysicsArgs); args.Type1 = PhysicsArgs.Custom; args.Value1 = 16; args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block; - args.ExtBlock = block >= Block.Extended; + args.ExtBlock = (byte)(block >> Block.ExtendedShift); return args; } diff --git a/MCGalaxy/Blocks/Physics/DoorPhysics.cs b/MCGalaxy/Blocks/Physics/DoorPhysics.cs index 17a42b18c..79fd89bcc 100644 --- a/MCGalaxy/Blocks/Physics/DoorPhysics.cs +++ b/MCGalaxy/Blocks/Physics/DoorPhysics.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Blocks.Physics { public static void Do(Level lvl, ref PhysInfo C) { if (C.Data.Type1 != PhysicsArgs.Custom) return; if (C.Data.Data == 0) { - BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock ? Block.Extended : 0)); + BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock << Block.ExtendedShift)); bool tdoor = lvl.Props[block].IsTDoor; if (tdoor) tDoor(lvl, ref C); @@ -44,7 +44,7 @@ namespace MCGalaxy.Blocks.Physics { // Change anys door blocks nearby into air forms static void Door(Level lvl, ref PhysInfo C) { ushort x = C.X, y = C.Y, z = C.Z; - BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock ? Block.Extended : 0)); + BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock << Block.ExtendedShift)); bool instant = block == Block.Door_Air || block == Block.Door_AirActivatable; ActivateablePhysics.DoDoors(lvl, (ushort)(x + 1), y, z, instant); diff --git a/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs b/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs index da394b30a..f417a232a 100644 --- a/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs +++ b/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs @@ -85,7 +85,7 @@ namespace MCGalaxy.Blocks.Physics { if (args.Revert) { PhysicsArgs revertArgs = default(PhysicsArgs); - if (args.ExtBlock) revertArgs.Raw |= PhysicsArgs.ExtBit; + revertArgs.ExtBlock = args.ExtBlock; lvl.AddUpdate(C.Index, args.RevertType, revertArgs); C.Data.ResetTypes(); @@ -141,9 +141,9 @@ namespace MCGalaxy.Blocks.Physics { } struct ExtraInfoArgs { - public bool Wait, Drop, Dissipate, Revert, Explode, Rainbow, ExtBlock; + public bool Wait, Drop, Dissipate, Revert, Explode, Rainbow; public int WaitTime, DropNum, DissipateNum, ExplodeNum, RainbowNum; - public byte RevertType; + public byte RevertType, ExtBlock; } } } \ No newline at end of file diff --git a/MCGalaxy/Blocks/Physics/PhysicsArgs.cs b/MCGalaxy/Blocks/Physics/PhysicsArgs.cs index 2382e20ce..65204261f 100644 --- a/MCGalaxy/Blocks/Physics/PhysicsArgs.cs +++ b/MCGalaxy/Blocks/Physics/PhysicsArgs.cs @@ -28,6 +28,7 @@ namespace MCGalaxy.Blocks.Physics { public const uint TypeBitsMask = 0x07; public const uint ValueBitsMask = 0xFF; public const uint ExtBit = 1u << 30; + public const uint ExtBits = (1u << 30) | (1u << 31); /// Indicates that this physics entry should be removed from the list of /// entries that are checked for physics, at the end of the current tick. @@ -58,9 +59,9 @@ namespace MCGalaxy.Blocks.Physics { set { Raw &= ~(ValueBitsMask << 22); Raw |= (uint)value << 22; } } - public bool ExtBlock { - get { return (Raw & ExtBit) != 0; } - set { Raw &= ~ExtBit; Raw |= value ? ExtBit : 0u; } + public byte ExtBlock { + get { return (byte)(Raw >> 30); } + set { Raw &= ~ExtBits; Raw |= (uint)value << 30; } } diff --git a/MCGalaxy/Blocks/Physics/TrainPhysics.cs b/MCGalaxy/Blocks/Physics/TrainPhysics.cs index 26196d923..8010d19b4 100644 --- a/MCGalaxy/Blocks/Physics/TrainPhysics.cs +++ b/MCGalaxy/Blocks/Physics/TrainPhysics.cs @@ -49,7 +49,7 @@ namespace MCGalaxy.Blocks.Physics { PhysicsArgs args = default(PhysicsArgs); args.Type1 = PhysicsArgs.Wait; args.Value1 = 5; args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)below; - args.ExtBlock = below >= Block.Extended; + args.ExtBlock = (byte)(below >> Block.ExtendedShift); lvl.AddUpdate(belowIndex, newBlock, args, true); return; diff --git a/MCGalaxy/Chat/Colors.cs b/MCGalaxy/Chat/Colors.cs index a28d60a8c..fee3f63d6 100644 --- a/MCGalaxy/Chat/Colors.cs +++ b/MCGalaxy/Chat/Colors.cs @@ -54,7 +54,7 @@ namespace MCGalaxy { /// Returns whether the given color code is defined. /// NOTE: This returns false for A to F, be warned! public static bool IsDefined(char c) { - if (c >= '~' && c <= '~') return List[c].Fallback != '\0'; + if (c >= ' ' && c <= '~') return List[c].Fallback != '\0'; return List[c.UnicodeToCp437()].Fallback != '\0'; } diff --git a/MCGalaxy/Commands/building/CmdRestartPhysics.cs b/MCGalaxy/Commands/building/CmdRestartPhysics.cs index 3cb8cf355..2b87e0bce 100644 --- a/MCGalaxy/Commands/building/CmdRestartPhysics.cs +++ b/MCGalaxy/Commands/building/CmdRestartPhysics.cs @@ -47,31 +47,31 @@ namespace MCGalaxy.Commands.Building { Help(p); return false; } byte type = 0, value = 0; - bool isExt = false; + byte extBits = 0; if (parts.Length >= 2) { - if (!Parse(p, parts[0], parts[1], ref type, ref value, ref isExt)) return false; + if (!Parse(p, parts[0], parts[1], ref type, ref value, ref extBits)) return false; args.Type1 = type; args.Value1 = value; } if (parts.Length >= 4) { - if (!Parse(p, parts[2], parts[3], ref type, ref value, ref isExt)) return false; + if (!Parse(p, parts[2], parts[3], ref type, ref value, ref extBits)) return false; args.Type2 = type; args.Value2 = value; } if (parts.Length >= 6) { Player.Message(p, "You can only use up to two types of physics."); return false; } - args.ExtBlock = isExt; + args.ExtBlock = extBits; return true; } - bool Parse(Player p, string name, string arg, ref byte type, ref byte value, ref bool isExt) { + bool Parse(Player p, string name, string arg, ref byte type, ref byte value, ref byte isExt) { if (name == "revert") { BlockID block; if (!CommandParser.GetBlock(p, arg, out block)) return false; type = PhysicsArgs.Revert; value = (BlockRaw)block; - isExt = block >= Block.Extended; + isExt = (byte)(block >> Block.ExtendedShift); return true; } diff --git a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs index bc7d17ec5..c01169a43 100644 --- a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs +++ b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs @@ -175,13 +175,16 @@ namespace MCGalaxy.Drawing.Ops { // Check to make sure the block is actually different and that we can change it if (old == b.Block || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block)) return; - // Set the block (inlined) - lvl.blocks[index] = b.Block >= Block.Extended ? Block.custom_block : (BlockRaw)b.Block; + // Set the block (inlined) lvl.Changed = true; if (b.Block >= Block.Extended) { + lvl.blocks[index] = Block.custom_block; lvl.SetExtTileNoCheck(b.X, b.Y, b.Z, (BlockRaw)b.Block); - } else if (old >= Block.Extended) { - lvl.RevertExtTileNoCheck(b.X, b.Y, b.Z); + } else { + lvl.blocks[index] = (BlockRaw)b.Block; + if (old >= Block.Extended) { + lvl.RevertExtTileNoCheck(b.X, b.Y, b.Z); + } } if (p != null) { diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index 5a5ff92de..f2044525c 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -247,12 +247,14 @@ namespace MCGalaxy { else p.TotalPlaced++; errorLocation = "Setting tile"; - BlockRaw raw = block >= Block.Extended ? Block.custom_block : (BlockRaw)block; - SetTile(x, y, z, raw); if (block >= Block.Extended) { + SetTile(x, y, z, Block.custom_block); SetExtTileNoCheck(x, y, z, (BlockRaw)block); - } else if (old >= Block.Extended) { - RevertExtTileNoCheck(x, y, z); + } else { + SetTile(x, y, z, (BlockRaw)block); + if (old >= Block.Extended) { + RevertExtTileNoCheck(x, y, z); + } } errorLocation = "Adding physics"; @@ -329,17 +331,20 @@ namespace MCGalaxy { } currentUndo++; } - - blocks[b] = block >= Block.Extended ? Block.custom_block : (BlockRaw)block; + Changed = true; if (block >= Block.Extended) { + blocks[b] = Block.custom_block; ushort x, y, z; IntToPos(b, out x, out y, out z); SetExtTileNoCheck(x, y, z, (BlockRaw)block); - } else if (old >= Block.Extended) { - ushort x, y, z; - IntToPos(b, out x, out y, out z); - RevertExtTileNoCheck(x, y, z); + } else { + blocks[b] = (BlockRaw)block; + if (old >= Block.Extended) { + ushort x, y, z; + IntToPos(b, out x, out y, out z); + RevertExtTileNoCheck(x, y, z); + } } if (physics > 0 && (ActivatesPhysics(block) || data.Raw != 0)) { AddCheck(b, false, data); @@ -348,7 +353,6 @@ namespace MCGalaxy { // Save bandwidth sending identical looking blocks, like air/op_air changes. return !Block.VisuallyEquals(old, block); } catch { - blocks[b] = block >= Block.Extended ? Block.custom_block : (BlockRaw)block; return false; } } diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs index 96254491c..8b2df9e83 100644 --- a/MCGalaxy/Levels/Level.Physics.cs +++ b/MCGalaxy/Levels/Level.Physics.cs @@ -184,9 +184,10 @@ namespace MCGalaxy { U.data.Data = 0; // Is the Ext flag just an indicator for the block update? - if (U.data.ExtBlock && (U.data.Raw & PhysicsArgs.TypeMask) == 0) { - block |= Block.Extended; - U.data.Raw &= ~PhysicsArgs.ExtBit; + byte extBits = U.data.ExtBlock; + if (extBits != 0 && (U.data.Raw & PhysicsArgs.TypeMask) == 0) { + block |= (BlockID)(extBits << Block.ExtendedShift); + U.data.Raw &= ~PhysicsArgs.ExtBits; } if (DoPhysicsBlockchange(U.Index, block, false, U.data, true)) @@ -235,7 +236,7 @@ namespace MCGalaxy { internal bool AddUpdate(int index, BlockID block, bool overRide = false) { PhysicsArgs args = default(PhysicsArgs); - if (block >= Block.Extended) args.Raw |= PhysicsArgs.ExtBit; + args.Raw |= (uint)(PhysicsArgs.ExtBit * (block >> Block.ExtendedShift)); return AddUpdate(index, block, args, overRide); } @@ -248,8 +249,8 @@ namespace MCGalaxy { if (overRide) { // Is the Ext flag just an indicator for the block update? - if (data.ExtBlock && (data.Raw & PhysicsArgs.TypeMask) == 0) { - data.Raw &= ~PhysicsArgs.ExtBit; + if (data.ExtBlock != 0 && (data.Raw & PhysicsArgs.TypeMask) == 0) { + data.Raw &= ~PhysicsArgs.ExtBits; } AddCheck(index, true, data); //Dont need to check physics here....AddCheck will do that Blockchange((ushort)x, (ushort)y, (ushort)z, block, true, data); @@ -331,13 +332,13 @@ namespace MCGalaxy { ushort x, y, z; IntToPos(C.Index, out x, out y, out z); - BlockID block = Block.FromRaw(args.Value1, args.ExtBlock); + BlockID block = (BlockID)(args.Value1 | (args.ExtBlock << 8)); Blockchange(C.Index, block, true, default(PhysicsArgs)); } else if (args.Type2 == PhysicsArgs.Revert) { ushort x, y, z; IntToPos(C.Index, out x, out y, out z); - BlockID block = Block.FromRaw(args.Value2, args.ExtBlock); + BlockID block = (BlockID)(args.Value2 | (args.ExtBlock << 8)); Blockchange(C.Index, block, true, default(PhysicsArgs)); } } catch (Exception e) {