static void RemoveBlockProps(bool global, ExtBlock block, Player p) { // Level block reverts to using global block if (!global) { p.level.Props[block.Index] = BlockDefinition.DefaultProps(block); p.level.UpdateBlockHandler(block); return; } BlockProps props = BlockProps.MakeDefault(); if (!block.IsCustomType) { props = Block.Props[block.RawID]; } BlockDefinition.GlobalProps[block.RawID] = props; Level[] loaded = LevelInfo.Loaded.Items; byte raw = block.RawID; foreach (Level lvl in loaded) { if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) { continue; } lvl.Props[block.Index] = BlockDefinition.GlobalProps[block.RawID]; lvl.UpdateBlockHandler(block); } }
static void OnPropsChanged(BlockProps[] scope, Level level, ExtBlock block) { scope[GetIndex(scope, block)].Changed = true; if (scope == Block.Props) { BlockProps.Save("core", scope, Block.CorePropsLock, null); Level[] loaded = LevelInfo.Loaded.Items; if (!block.IsPhysicsType) { BlockDefinition.GlobalProps[block.RawID] = BlockDefinition.DefaultProps(block); } foreach (Level lvl in loaded) { if (lvl.HasCustomProps(block)) { continue; } lvl.Props[block.Index] = BlockDefinition.DefaultProps(block); lvl.UpdateBlockHandler(block); } } else if (scope == BlockDefinition.GlobalProps) { Level[] loaded = LevelInfo.Loaded.Items; BlockProps.Save("global", scope, BlockDefinition.GlobalPropsLock, null); byte raw = block.RawID; foreach (Level lvl in loaded) { if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) { continue; } if (lvl.HasCustomProps(block)) { continue; } lvl.Props[block.Index] = BlockDefinition.DefaultProps(block); lvl.UpdateBlockHandler(block); } } else { BlockProps.Save("lvl_" + level.name, scope, level.PropsLock, idx => SelectLevel(level, idx)); level.UpdateBlockHandler(block); } }
static void EditHandler(Player p, string[] parts, bool global, string cmd) { if (parts.Length <= 3) { if (parts.Length == 1) { Player.Message(p, "Valid properties: " + helpSections.Keys.Join()); } else if (parts.Length == 3) { Help(p, cmd, "edit " + parts[2]); } else { Help(p, cmd); } return; } ExtBlock block; if (!CheckBlock(p, parts[1], out block)) { return; } BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs; BlockDefinition def = defs[block.RawID], globalDef = BlockDefinition.GlobalDefs[block.RawID]; if (def == null && block.BlockID < Block.CpeCount) { def = DefaultSet.MakeCustomBlock(block.BlockID); AddBlock(p, def, global, cmd, BlockDefinition.DefaultProps(block)); } if (def != null && !global && def == globalDef) { def = globalDef.Copy(); AddBlock(p, def, global, cmd, BlockDefinition.DefaultProps(block)); } if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; } 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, arg)) { return; } break; case "speed": if (!Utils.TryParseDecimal(value, out fTemp) || fTemp < 0.25f || fTemp > 3.96f) { SendEditHelp(p, arg); return; } def.Speed = fTemp; break; case "toptex": if (!EditByte(p, value, "Top texture", ref def.TopTex, arg)) { return; } break; case "alltex": 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, arg)) { return; } def.SetSideTex(def.SideTex); break; case "lefttex": if (!EditByte(p, value, "Left texture", ref def.LeftTex, arg)) { return; } break; case "righttex": if (!EditByte(p, value, "Right texture", ref def.RightTex, arg)) { return; } break; case "fronttex": if (!EditByte(p, value, "Front texture", ref def.FrontTex, arg)) { return; } break; case "backtex": if (!EditByte(p, value, "Back texture", ref def.BackTex, arg)) { return; } break; case "bottomtex": if (!EditByte(p, value, "Bottom texture", ref def.BottomTex, arg)) { return; } break; case "blockslight": if (!CommandParser.GetBool(p, value, ref temp)) { SendEditHelp(p, arg); return; } def.BlocksLight = temp; break; case "sound": if (!EditByte(p, value, "Walk sound", ref def.WalkSound, arg)) { return; } break; case "fullbright": if (!CommandParser.GetBool(p, value, ref temp)) { SendEditHelp(p, arg); return; } def.FullBright = temp; break; case "shape": if (!CommandParser.GetBool(p, value, ref temp)) { SendEditHelp(p, arg); return; } def.Shape = temp ? (byte)0 : def.MaxZ; break; case "blockdraw": if (!EditByte(p, value, "Block draw", ref def.BlockDraw, arg)) { return; } break; case "min": if (!ParseCoords(p, value, ref def.MinX, ref def.MinY, ref def.MinZ)) { SendEditHelp(p, arg); return; } break; case "max": if (!ParseCoords(p, value, ref def.MaxX, ref def.MaxY, ref def.MaxZ)) { SendEditHelp(p, arg); return; } break; case "fogdensity": if (!EditByte(p, value, "Fog density", ref def.FogDensity, arg)) { return; } break; case "fogcolor": ColorDesc rgb = default(ColorDesc); if (!CommandParser.GetHex(p, value, ref rgb)) { return; } def.FogR = rgb.R; def.FogG = rgb.G; def.FogB = rgb.B; break; case "fallback": byte fallback = GetFallback(p, value); if (fallback == Block.Invalid) { return; } changedFallback = true; value = Block.Name(fallback); def.FallBack = fallback; break; case "order": int order = 0; if (!CommandParser.GetInt(p, value, "Inventory order", ref order, 1, 255)) { SendEditHelp(p, arg); return; } def.InventoryOrder = order == def.BlockID ? -1 : order; BlockDefinition.UpdateOrder(def, global, level); BlockDefinition.Save(global, level); Player.Message(p, "Set inventory order for {0} to {1}", blockName, order == def.BlockID ? "default" : order.ToString()); 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, level); if (changedFallback) { BlockDefinition.UpdateFallback(global, def.BlockID, level); } }
static void DefineBlockStep(Player p, string value, bool global, string cmd) { string opt = value.ToLower(); int step = GetStep(p, global); BlockDefinition bd = GetBD(p, global); bool temp = false; if (opt == "revert" && step > 2) { if (step == 17 && bd.FogDensity == 0) { step -= 2; } else if (step == 9 && bd.Shape == 0) { step -= 5; } else { step--; } SetStep(p, global, step); SendStepHelp(p, global); return; } if (step == 2) { bd.Name = value; step++; } else if (step == 3) { if (CommandParser.GetBool(p, value, ref temp)) { bd.Shape = temp ? (byte)0 : (byte)16; step++; } } else if (step == 4) { if (CommandParser.GetByte(p, value, "Texture ID", ref bd.TopTex)) { step += (bd.Shape == 0 ? 5 : 1); // skip other texture steps for sprites if (bd.Shape == 0) { bd.SetAllTex(bd.TopTex); } } } else if (step == 5) { if (CommandParser.GetByte(p, value, "Texture ID", ref bd.SideTex)) { bd.SetSideTex(bd.SideTex); step++; } } else if (step == 6) { if (CommandParser.GetByte(p, value, "Texture ID", ref bd.BottomTex)) { step++; } } else if (step == 7) { if (ParseCoords(p, value, ref bd.MinX, ref bd.MinY, ref bd.MinZ)) { step++; } } else if (step == 8) { if (ParseCoords(p, value, ref bd.MaxX, ref bd.MaxY, ref bd.MaxZ)) { step++; } bd.Shape = bd.MaxY; } else if (step == 9) { if (CommandParser.GetByte(p, value, "Collide type", ref bd.CollideType, 0, 6)) { step++; } } else if (step == 10) { if (Utils.TryParseDecimal(value, out bd.Speed) && bd.Speed >= 0.25f && bd.Speed <= 3.96f) { step++; } } else if (step == 11) { if (CommandParser.GetBool(p, value, ref temp)) { bd.BlocksLight = temp; step++; } } else if (step == 12) { if (CommandParser.GetByte(p, value, "Walk sound", ref bd.WalkSound, 0, 11)) { step++; } } else if (step == 13) { if (CommandParser.GetBool(p, value, ref bd.FullBright)) { step++; } } else if (step == 14) { if (CommandParser.GetByte(p, value, "Block draw", ref bd.BlockDraw, 0, 4)) { step++; } } else if (step == 15) { if (CommandParser.GetByte(p, value, "Fog density", ref bd.FogDensity)) { step += (bd.FogDensity == 0 ? 2 : 1); } } else if (step == 16) { ColorDesc rgb = default(ColorDesc); if (CommandParser.GetHex(p, value, ref rgb)) { bd.FogR = rgb.R; bd.FogG = rgb.G; bd.FogB = rgb.B; step++; } } else if (step == 17) { byte fallback = GetFallback(p, value); if (fallback == Block.Invalid) { SendStepHelp(p, global); return; } bd.FallBack = fallback; ExtBlock block = ExtBlock.FromRaw(bd.BlockID); BlockProps props = BlockDefinition.DefaultProps(block); if (!AddBlock(p, bd, global, cmd, props)) { return; } SetBD(p, global, null); SetStep(p, global, 0); return; } SetStep(p, global, step); SendStepHelp(p, global); }