public void UpdateBlockHandlers() { for (int i = 0; i < Props.Length; i++) { UpdateBlockHandler(ExtBlock.FromIndex(i)); } }
public Level(string name, ushort width, ushort height, ushort length) { if (width < 1) { width = 1; } if (height < 1) { height = 1; } if (length < 1) { length = 1; } Width = width; Height = height; Length = length; for (int i = 0; i < CustomBlockDefs.Length; i++) { CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i]; } LoadCoreProps(); for (int i = 0; i < blockAABBs.Length; i++) { ExtBlock block = ExtBlock.FromIndex(i); blockAABBs[i] = Block.BlockAABB(block, this); } UpdateBlockHandlers(); this.name = name; MapName = name.ToLower(); BlockDB = new BlockDB(this); Config.EdgeLevel = (short)(height / 2); Config.CloudsHeight = (short)(height + 2); blocks = new byte[Width * Height * Length]; ChunksX = Utils.CeilDiv16(Width); ChunksY = Utils.CeilDiv16(Height); ChunksZ = Utils.CeilDiv16(Length); CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][]; spawnx = (ushort)(Width / 2); spawny = (ushort)(Height * 0.75f); spawnz = (ushort)(Length / 2); rotx = 0; roty = 0; VisitAccess = new LevelAccessController(this, true); BuildAccess = new LevelAccessController(this, false); listCheckExists = new SparseBitSet(Width, Height, Length); listUpdateExists = new SparseBitSet(Width, Height, Length); }
void LoadCoreProps() { for (int i = 0; i < Props.Length; i++) { ExtBlock block = ExtBlock.FromIndex(i); if (!HasCustomProps(block)) { Props[i] = BlockDefinition.DefaultProps(block); } else { Props[i] = BlockProps.MakeDefault(); } } }
/// <summary> Updates the block at the given position, mainly intended for manual changes by the player. </summary> /// <remarks> Adds to the BlockDB. Also turns block below to grass/dirt depending on light. </remarks> /// <returns> Return code from DoBlockchange </returns> public int ChangeBlock(ushort x, ushort y, ushort z, ExtBlock block) { ExtBlock old = level.GetBlock(x, y, z); int type = level.DoBlockchange(this, x, y, z, block); if (type == 0) { return(type); // no change performed } if (type == 2) { Player.GlobalBlockchange(level, x, y, z, block); // different visually } ushort flags = BlockDBFlags.ManualPlace; if (painting && CollideType.IsSolid(level.CollideType(old))) { flags = BlockDBFlags.Painted; } level.BlockDB.Cache.Add(this, x, y, z, flags, old, block); bool autoGrass = level.Config.GrassGrow && (level.physics == 0 || level.physics == 5); if (!autoGrass) { return(type); } ExtBlock below = level.GetBlock(x, (ushort)(y - 1), z); ushort grassIdx = level.Props[below.Index].GrassIndex; if (grassIdx != Block.Invalid && block.BlockID == Block.Air) { level.Blockchange(this, x, (ushort)(y - 1), z, ExtBlock.FromIndex(grassIdx)); } ushort dirtIdx = level.Props[below.Index].DirtIndex; if (dirtIdx != Block.Invalid && !level.LightPasses(block)) { level.Blockchange(this, x, (ushort)(y - 1), z, ExtBlock.FromIndex(dirtIdx)); } return(type); }