static void SetStackId(Player p, BlockProps[] scope, BlockID block, string msg) { BlockID stackBlock; if (msg.Length == 0) { stackBlock = Block.Air; } else { if (!CommandParser.GetBlock(p, msg, out stackBlock)) { return; } } scope[block].StackBlock = stackBlock; string name = BlockProps.ScopedName(scope, p, block); if (stackBlock == Block.Air) { p.Message("Removed stack block for {0}", name); } else { p.Message("Stack block for {0} set to: {1}", name, BlockProps.ScopedName(scope, p, stackBlock)); } }
static void SetBlock(Player p, BlockProps[] scope, BlockID block, string msg, string type, ref BlockID target) { string name = BlockProps.ScopedName(scope, p, block); if (msg.Length == 0) { target = Block.Invalid; p.Message("{1} for {0} removed.", name, type); } else { BlockID other; if (!CommandParser.GetBlockIfAllowed(p, msg, "use", out other)) { return; } if (other == block) { p.Message("ID of {0} must be different.", type); return; } target = other; p.Message("{2} for {0} set to: {1}", name, BlockProps.ScopedName(scope, p, other), type); } }
static void SetDefaultPerms() { for (int i = 0; i < Block.Count; i++) { BlockPerms perms = new BlockPerms(); perms.BlockID = (byte)i; BlockProps props = Block.Props[i]; if (i == Block.Invalid) { perms.MinRank = LevelPermission.Admin; } else if (props.OPBlock) { perms.MinRank = LevelPermission.Operator; } else if (props.IsDoor || props.IsTDoor || props.oDoorIndex != Block.Invalid) { perms.MinRank = LevelPermission.Builder; } else if (props.IsPortal || props.IsMessageBlock) { perms.MinRank = LevelPermission.AdvBuilder; } else { perms.MinRank = DefaultPerm(i); } List[i] = perms; } }
static void Toggle(Player p, BlockProps[] scope, BlockID block, string type, ref bool on) { on = !on; string name = BlockProps.ScopedName(scope, p, block); p.Message("Block {0} is {1}: {2}", name, type, on ? "&aYes" : "&cNo"); }
static void SaveCore(string group, BlockProps[] list, byte scope) { using (StreamWriter w = new StreamWriter("blockprops/" + group + ".txt")) { w.WriteLine("# This represents the physics properties for blocks, in the format of:"); w.WriteLine("# id : Is rails : Is tdoor : Is door : Is message block : Is portal : " + "Killed by water : Killed by lava : Kills players : death message : " + "Animal AI type : Stack block : Is OP block : oDoor block : Drownable : " + "Grass block : Dirt block"); for (int b = 0; b < list.Length; b++) { if ((list[b].ChangedScope & scope) == 0) { continue; } BlockProps props = list[b]; string deathMsg = props.DeathMessage == null ? "" : props.DeathMessage.Replace(":", "\\;"); w.WriteLine(b + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":" + props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":" + props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":" + (byte)props.AnimalAI + ":" + props.StackBlock + ":" + props.OPBlock + ":" + props.oDoorBlock + ":" + props.Drownable + ":" + props.GrassBlock + ":" + props.DirtBlock); } } }
public static void Save(string group, BlockProps[] scope) { if (!Directory.Exists("blockprops")) { Directory.CreateDirectory("blockprops"); } using (StreamWriter w = new StreamWriter("blockprops/" + group + ".txt")) { w.WriteLine("# This represents the physics properties for blocks, in the format of:"); w.WriteLine("# id : Is rails : Is tdoor : Is door : Is message block : Is portal : " + "Killed by water : Killed by lava : Kills players : death message"); for (int i = 0; i < scope.Length; i++) { if (!scope[i].Changed) { continue; } BlockProps props = scope[i]; string deathMsg = props.DeathMessage == null ? "" : props.DeathMessage.Replace(":", "\\;"); w.WriteLine(i + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":" + props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":" + props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg); } } }
static void SetDefaultPerms() { for (BlockID block = 0; block < Block.ExtendedCount; block++) { BlockProps props = Block.Props[block]; LevelPermission min; if (block == Block.Invalid) { min = LevelPermission.Admin; } else if (props.OPBlock) { min = LevelPermission.Operator; } else if (props.IsDoor || props.IsTDoor || props.oDoorBlock != Block.Invalid) { min = LevelPermission.Builder; } else if (props.IsPortal || props.IsMessageBlock) { min = LevelPermission.AdvBuilder; } else { min = DefaultPerm(block); } Set(block, min, null, null); } }
static void SaveCore(string group, BlockProps[] scope, Predicate <int> selector) { using (StreamWriter w = new StreamWriter("blockprops/" + group + ".txt")) { w.WriteLine("# This represents the physics properties for blocks, in the format of:"); w.WriteLine("# id : Is rails : Is tdoor : Is door : Is message block : Is portal : " + "Killed by water : Killed by lava : Kills players : death message : " + "Animal AI type : Stack block : Is OP block : oDoor block : Drownable : " + "Grass block : Dirt block"); for (int i = 0; i < scope.Length; i++) { if (!scope[i].Changed || (selector != null && !selector(i))) { continue; } BlockProps props = scope[i]; // Convert ext to raw ids 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 + ":" + props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":" + props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":" + (byte)props.AnimalAI + ":" + props.StackId + ":" + props.OPBlock + ":" + props.oDoorIndex + ":" + props.Drownable + ":" + props.GrassIndex + ":" + props.DirtIndex); } } }
static void SetAI(Player p, BlockProps[] scope, BlockID block, string msg) { AnimalAI ai = AnimalAI.None; if (!CommandParser.GetEnum(p, msg, "Animal AI", ref ai)) return; scope[block].AnimalAI = ai; string name = BlockProps.ScopedName(scope, p, block); p.Message("Animal AI for {0} set to: {1}", name, ai); }
internal static BlockProps DefaultProps(BlockProps[] scope, Level lvl, BlockID block) { if (scope == Block.Props) { return(Block.MakeDefaultProps(block)); } return(UnchangedProps(lvl, block) ? Block.Props[block] : BlockProps.MakeEmpty()); }
public static BlockProps MakeEmpty() { BlockProps props = default(BlockProps); props.oDoorBlock = Block.Invalid; props.GrassBlock = Block.Invalid; props.DirtBlock = Block.Invalid; return(props); }
public static BlockProps MakeDefault() { BlockProps props = default(BlockProps); props.oDoorIndex = Block.Invalid; props.GrassIndex = Block.Invalid; props.DirtIndex = Block.Invalid; return(props); }
static void SetDeathMsg(Player p, BlockProps[] scope, BlockID block, string msg) { string name = BlockProps.ScopedName(scope, p, block); if (msg.Length == 0) { scope[block].DeathMessage = null; p.Message("Death message for {0} removed.", name); } else { scope[block].DeathMessage = msg; p.Message("Death message for {0} set to: {1}", name, msg); } }
static void ToggleBehaviour(Player p, BlockProps[] scope, BlockID block, string type, ref bool on) { string behaviour; // Check if this would make a block both a door and a portal for instance // If blocks have multiple behaviour, this would confuse users because only 1 behaviour works if (!on && (behaviour = CheckBehaviour(scope, block)) != null) { string name = BlockProps.ScopedName(scope, p, block); p.Message("&WBlock {0} cannot be made {1}, is it already a {2}", name, type, behaviour); return; } Toggle(p, scope, block, type, ref on); }
internal static void ApplyChanges(BlockProps[] scope, Level lvl_, BlockID block, bool save) { byte scopeId = ScopeId(scope); string path; if (scope == Block.Props) { path = "default"; Level[] loaded = LevelInfo.Loaded.Items; foreach (Level lvl in loaded) { if ((lvl.Props[block].ChangedScope & 2) != 0) { continue; } if (!UnchangedProps(lvl, block)) { continue; } lvl.Props[block] = scope[block]; lvl.UpdateBlockHandler(block); } } else { path = "_" + lvl_.name; lvl_.UpdateBlockHandler(block); } if (save) { BlockProps.Save(path, scope, scopeId); } }