public override void Init(IBlockAccessor blockAccessor) { base.Init(blockAccessor); mapheight = blockAccessor.MapSizeY; blocksByPos = new Block[SizeX + 1, SizeY + 1, SizeZ + 1]; for (int i = 0; i < Indices.Count; i++) { uint index = Indices[i]; int storedBlockid = BlockIds[i]; int dx = (int)(index & 0x1ff); int dy = (int)((index >> 20) & 0x1ff); int dz = (int)((index >> 10) & 0x1ff); Block block = blockAccessor.GetBlock(BlockCodes[storedBlockid]); if (block == null) { continue; } blocksByPos[dx, dy, dz] = block; } handler = null; switch (ReplaceMode) { case EnumReplaceMode.ReplaceAll: handler = PlaceReplaceAllReplaceMeta; break; case EnumReplaceMode.Replaceable: handler = PlaceReplaceableReplaceMeta; break; case EnumReplaceMode.ReplaceAllNoAir: handler = PlaceReplaceAllNoAirReplaceMeta; break; case EnumReplaceMode.ReplaceOnlyAir: handler = PlaceReplaceOnlyAirReplaceMeta; break; } }
/// <summary> /// Will place all blocks using the supplied replace mode. Note: If you use a revertable or bulk block accessor you will have to call PlaceBlockEntities() after the Commit() /// </summary> /// <param name="blockAccessor"></param> /// <param name="worldForCollectibleResolve"></param> /// <param name="startPos"></param> /// <param name="mode"></param> /// <param name="replaceMetaBlocks"></param> /// <returns></returns> public virtual int Place(IBlockAccessor blockAccessor, IWorldAccessor worldForCollectibleResolve, BlockPos startPos, EnumReplaceMode mode, bool replaceMetaBlocks = true) { BlockPos curPos = new BlockPos(); int placed = 0; PlaceBlockDelegate handler = null; switch (ReplaceMode) { case EnumReplaceMode.ReplaceAll: if (replaceMetaBlocks) { handler = PlaceReplaceAllReplaceMeta; } else { handler = PlaceReplaceAllKeepMeta; } break; case EnumReplaceMode.Replaceable: if (replaceMetaBlocks) { handler = PlaceReplaceableReplaceMeta; } else { handler = PlaceReplaceableKeepMeta; } break; case EnumReplaceMode.ReplaceAllNoAir: if (replaceMetaBlocks) { handler = PlaceReplaceAllNoAirReplaceMeta; } else { handler = PlaceReplaceAllNoAirKeepMeta; } break; case EnumReplaceMode.ReplaceOnlyAir: if (replaceMetaBlocks) { handler = PlaceReplaceOnlyAirReplaceMeta; } else { handler = PlaceReplaceOnlyAirKeepMeta; } break; } for (int i = 0; i < Indices.Count; i++) { uint index = Indices[i]; int storedBlockid = BlockIds[i]; int dx = (int)(index & 0x1ff); int dy = (int)((index >> 20) & 0x1ff); int dz = (int)((index >> 10) & 0x1ff); AssetLocation blockCode = BlockCodes[storedBlockid]; Block newBlock = blockAccessor.GetBlock(blockCode); if (newBlock == null || (replaceMetaBlocks && newBlock == undergroundBlock)) { continue; } curPos.Set(dx + startPos.X, dy + startPos.Y, dz + startPos.Z); Block oldBlock = blockAccessor.GetBlock(curPos); placed += handler(blockAccessor, curPos, oldBlock, newBlock); if (newBlock.LightHsv[2] > 0 && blockAccessor is IWorldGenBlockAccessor) { ((IWorldGenBlockAccessor)blockAccessor).ScheduleBlockLightUpdate(curPos.Copy(), oldBlock.BlockId, newBlock.BlockId); } } if (!(blockAccessor is IBlockAccessorRevertable)) { PlaceEntitiesAndBlockEntities(blockAccessor, worldForCollectibleResolve, startPos); } return(placed); }