static bool CheckBlock(Player p, string arg, out ExtBlock block, bool allowAir = false) { block = ExtBlock.Invalid; int raw = 0; int min = allowAir ? 0 : 1; bool success = CommandParser.GetInt(p, arg, "Block ID", ref raw, min, 255); block = ExtBlock.FromRaw((byte)raw); return(success); }
internal static void Stack(Player p, ExtBlock block, ushort x, ushort y, ushort z) { if (p.level.GetBlock(x, (ushort)(y - 1), z) != block) { p.ChangeBlock(x, y, z, block); return; } p.SendBlockchange(x, y, z, ExtBlock.Air); // send the air block back only to the user byte stack = p.level.Props[block.Index].StackId; p.ChangeBlock(x, (ushort)(y - 1), z, ExtBlock.FromRaw(stack)); }
static void GetAllNames(Player p, List <string> names) { GetCoreNames(names, p.level); for (int i = Block.CpeCount; i < Block.Count; i++) { ExtBlock block = ExtBlock.FromRaw((byte)i); string name = Format(block, p.level, p.level.Props); if (name != null) { names.Add(name); } } }
public void UpdateConfig() { Config.SetDefaults(Map); Config.Retrieve(Map.name); CTFConfig cfg = Config; Red.FlagBlock = ExtBlock.FromRaw(cfg.RedFlagBlock); Red.FlagPos = new Vec3U16((ushort)cfg.RedFlagX, (ushort)cfg.RedFlagY, (ushort)cfg.RedFlagZ); Red.SpawnPos = new Position(cfg.RedSpawnX, cfg.RedSpawnY, cfg.RedSpawnZ); Blue.FlagBlock = ExtBlock.FromRaw(cfg.BlueFlagBlock); Blue.FlagPos = new Vec3U16((ushort)cfg.BlueFlagX, (ushort)cfg.BlueFlagY, (ushort)cfg.BlueFlagZ); Blue.SpawnPos = new Position(cfg.BlueSpawnX, cfg.BlueSpawnY, cfg.BlueSpawnZ); }
void RedoBlock(BlockDBEntry e) { ExtBlock block = ExtBlock.FromRaw(e.OldRaw, (e.Flags & BlockDBFlags.OldCustom) != 0); if (block.BlockID == Block.Invalid) { return; // Exported BlockDB SQL table entries don't have previous block } if ((e.Flags & BlockDBFlags.UndoSelf) == 0) { return; // not an undo } int x = e.Index % dims.X; int y = (e.Index / dims.X) / dims.Z; int z = (e.Index / dims.X) % dims.Z; output(Place((ushort)x, (ushort)y, (ushort)z, block)); }
static ExtBlock[] Transform(BlockDefinition[] defs, string[] mirrorDirs, string[] rotateDirs) { ExtBlock[] transform = new ExtBlock[Block.Count * 2]; for (int i = 0; i < transform.Length; i++) { transform[i] = ExtBlock.FromIndex(i); } if (mirrorDirs == null && rotateDirs == null) { return(transform); } // Rotate/Mirror directional blocks for (int i = 0; i < defs.Length; i++) { if (defs[i] == null) { continue; } int dirIndex = defs[i].Name.LastIndexOf('-'); if (dirIndex == -1) { continue; } BlockDefinition transformed = null; if (mirrorDirs != null) { transformed = MirrorTransform(defs, i, dirIndex, mirrorDirs); } else { transformed = RotateTransform(defs, i, dirIndex, rotateDirs); } if (transformed == null) { continue; } ExtBlock src = ExtBlock.FromRaw(defs[i].BlockID); transform[src.Index] = ExtBlock.FromRaw(transformed.BlockID); } return(transform); }
static ExtBlock GetBlock(Player p, BlockProps[] scope, string input) { if (scope == Block.Props) { byte raw; if (!byte.TryParse(input, out raw)) { raw = Block.Byte(input); } if (Block.Name(raw).CaselessEq("unknown")) { Player.Message(p, "&cThere is no block with id or name \"{0}\"", input); return(ExtBlock.Invalid); } return(new ExtBlock(raw, 0)); } else if (scope == BlockDefinition.GlobalProps) { int raw = BlockDefinition.GetBlock(input, BlockDefinition.GlobalDefs); if (raw == -1) { Player.Message(p, "&cThere is no global custom block with id or name \"{0}\"", input); return(ExtBlock.Invalid); } return(ExtBlock.FromRaw((byte)raw)); } else { int raw = BlockDefinition.GetBlock(input, p.level.CustomBlockDefs); if (raw == -1) { Player.Message(p, "&cThere is no level custom block with id or name \"{0}\"", input); return(ExtBlock.Invalid); } if (p.level.CustomBlockDefs[raw] == BlockDefinition.GlobalDefs[raw]) { Player.Message(p, "&cUse %T/BlockProps global &cto modify this custom block."); return(ExtBlock.Invalid); } return(ExtBlock.FromRaw((byte)raw)); } }
public static AABB ModelAABB(Entity entity, Level lvl) { string model = entity.Model; float scale = GetScaleFrom(ref model); AABB bb; byte raw; if (byte.TryParse(model, out raw)) { ExtBlock block = ExtBlock.FromRaw(raw); bb = Block.BlockAABB(block, lvl); bb = bb.Offset(-16, 0, -16); // centre around [-16, 16] instead of [0, 32] } else { bb = AABB.Make(new Vec3S32(0, 0, 0), BaseSize(model)); } bb = bb.Expand(-1); // adjust the model AABB inwards slightly float max = model.CaselessEq("chibi") ? 3 : 2; float scaleX = scale, scaleY = scale, scaleZ = scale; if (entity.ScaleX != 0) { scaleX = Math.Min(entity.ScaleX * scale, max); } if (entity.ScaleY != 0) { scaleY = Math.Min(entity.ScaleY * scale, max); } if (entity.ScaleZ != 0) { scaleZ = Math.Min(entity.ScaleZ * scale, max); } bb.Min.X = (int)(bb.Min.X * scaleX); bb.Max.X = (int)(bb.Max.X * scaleX); bb.Min.Y = (int)(bb.Min.Y * scaleY); bb.Max.Y = (int)(bb.Max.Y * scaleY); bb.Min.Z = (int)(bb.Min.Z * scaleZ); bb.Max.Z = (int)(bb.Max.Z * scaleZ); return(bb); }
static void ListHandler(Player p, string[] parts, bool global, string cmd) { string modifier = parts.Length > 1 ? parts[1] : ""; BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs; List <BlockDefinition> defsInScope = new List <BlockDefinition>(); for (int i = 0; i < Block.Count; i++) { BlockDefinition def = defs[i]; ExtBlock block = ExtBlock.FromRaw((byte)i); if (!ExistsInScope(def, block, global)) { continue; } defsInScope.Add(def); } MultiPageOutput.Output(p, defsInScope, FormatBlock, cmd.Substring(1) + " list", "custom blocks", modifier, true); }
void UndoBlock(BlockDBEntry e) { ExtBlock block = ExtBlock.FromRaw(e.OldRaw, (e.Flags & BlockDBFlags.OldCustom) != 0); if (block.BlockID == Block.Invalid) { return; // Exported BlockDB SQL table entries don't have previous block } int x = e.Index % dims.X; int y = (e.Index / dims.X) / dims.Z; int z = (e.Index / dims.X) % dims.Z; if (x < Min.X || y < Min.Y || z < Min.Z) { return; } if (x > Max.X || y > Max.Y || z > Max.Z) { return; } output(Place((ushort)x, (ushort)y, (ushort)z, block)); found = true; }
static bool AddBlock(Player p, BlockDefinition def, bool global, string cmd, BlockProps props) { BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs; BlockDefinition old = defs[def.BlockID]; if (!global && old == BlockDefinition.GlobalDefs[def.BlockID]) { old = null; } ExtBlock block; // in case the list is modified before we finish the command. if (old != null) { block = GetFreeBlock(global, p == null ? null : p.level); if (block.IsInvalid) { Player.Message(p, "There are no custom block ids left, " + "you must " + cmd + " remove a custom block first."); if (!global) { Player.Message(p, "You may also manually specify the same existing id of a global custom block."); } return(false); } def.BlockID = block.RawID; } string scope = global ? "global" : "level"; Player.Message(p, "Created a new " + scope + " custom block " + def.Name + "(" + def.BlockID + ")"); block = ExtBlock.FromRaw(def.BlockID); BlockDefinition.Add(def, defs, p == null ? null : p.level); UpdateBlockProps(global, p, block, props); return(true); }
void OutputPixels(PixelGetter pixels, DrawOpOutput output) { int width = pixels.Width, height = pixels.Height; for (int yy = 0; yy < height; yy++) { for (int xx = 0; xx < width; xx++) { Pixel P = pixels.Get(xx, yy); ushort x = (ushort)(Origin.X + dx.X * xx + dy.X * yy); ushort y = (ushort)(Origin.Y + dx.Y * xx + dy.Y * yy); ushort z = (ushort)(Origin.Z + dx.Z * xx + dy.Z * yy); if (P.A < 20) { output(Place(x, y, z, ExtBlock.Air)); continue; } byte raw = 0; if (!DualLayer) { raw = selector.BestMatch(P.R, P.G, P.B); } else { bool backLayer; raw = selector.BestMatch(P.R, P.G, P.B, out backLayer); if (backLayer) { x = (ushort)(x + adj.X); z = (ushort)(z + adj.Z); } } output(Place(x, y, z, ExtBlock.FromRaw(raw))); } } }
void CalcLayerColors() { PaletteEntry[] front = new PaletteEntry[Palette.Entries.Length]; PaletteEntry[] back = new PaletteEntry[Palette.Entries.Length]; ColorDesc sun = Colors.ParseHex("FFFFFF"); ColorDesc dark = Colors.ParseHex("9B9B9B"); if (Utils.IsValidHex(Level.Config.LightColor)) { sun = Colors.ParseHex(Level.Config.LightColor); } if (Utils.IsValidHex(Level.Config.ShadowColor)) { dark = Colors.ParseHex(Level.Config.ShadowColor); } for (int i = 0; i < Palette.Entries.Length; i++) { PaletteEntry entry = Palette.Entries[i]; ExtBlock block = ExtBlock.FromRaw(entry.Raw); BlockDefinition def = Level.GetBlockDef(block); if (def != null && def.FullBright) { front[i] = Multiply(entry, Colors.ParseHex("FFFFFF")); back[i] = Multiply(entry, Colors.ParseHex("FFFFFF")); } else { front[i] = Multiply(entry, sun); back[i] = Multiply(entry, dark); } } selector.SetPalette(front, back); }
public override void Use(Player p, string message) { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(); if (args.Length > 2) { Help(p); return; } if (args[0].CaselessEq("clear")) { for (int i = 0; i < p.BlockBindings.Length; i++) { p.BlockBindings[i] = ExtBlock.FromRaw((byte)i); } Player.Message(p, "All bindings were unbound."); return; } if (args.Length == 2) { ExtBlock src, dst; if (!CommandParser.GetBlock(p, args[0], out src)) { return; } if (!CommandParser.GetBlock(p, args[1], out dst)) { return; } if (!CommandParser.IsBlockAllowed(p, "bind a block to", dst)) { return; } if (src.IsPhysicsType) { Player.Message(p, "Physics blocks cannot be bound to another block."); return; } p.BlockBindings[src.RawID] = dst; Player.Message(p, "{0} bound to {1}", p.level.BlockName(src), p.level.BlockName(dst)); } else { ExtBlock src; if (!CommandParser.GetBlock(p, args[0], out src)) { return; } if (src.IsPhysicsType) { Player.Message(p, "Physics blocks cannot be bound to another block."); return; } if (p.BlockBindings[src.RawID] == src) { Player.Message(p, "{0} is not bound.", p.level.BlockName(src)); return; } p.BlockBindings[src.BlockID] = src; Player.Message(p, "Unbound {0}.", p.level.BlockName(src)); } }
public ExtBlock Get(int index) { return(ExtBlock.FromRaw(raw[index], (isExt[index >> 3] & (1 << (index & 0x07))) != 0)); }
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); }
static string FormatEntry(PaletteEntry e, Level lvl) { ExtBlock block = ExtBlock.FromRaw(e.Raw); return(lvl.BlockName(block) + " - " + Utils.Hex(e.R, e.G, e.B)); }