private void CmdGenHouse(IServerPlayer player, int groupId, CmdArgs args) { IBlockAccessor blockAccessor = api.World.GetBlockAccessorBulkUpdate(true, true); int blockID = api.WorldManager.GetBlockId(new AssetLocation("log-placed-oak-ud")); BlockPos pos = player.Entity.Pos.AsBlockPos; for (int dx = -3; dx <= 3; dx++) { for (int dz = -3; dz <= 3; dz++) { for (int dy = 0; dy <= 3; dy++) { if (Math.Abs(dx) != 3 && Math.Abs(dz) != 3 && dy < 3) { continue; // Hollow } if (dx == -3 && dz == 0 && dy < 2) { continue; // Door } blockAccessor.SetBlock(blockID, pos.AddCopy(dx, dy, dz)); } } } blockAccessor.Commit(); }
void TreeLineup(IServerPlayer player, CmdArgs arguments) { if (arguments.Length < 2) { player.SendMessage(groupId, "/wgen treelineup {treeWorldPropertyCode} [0.1 - 3]", EnumChatType.CommandError); return; } EntityPos pos = player.Entity.Pos; BlockPos center = pos.HorizontalAheadCopy(25).AsBlockPos; IBlockAccessor blockAccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true, true); int size = 12; for (int dx = -2 * size; dx < 2 * size; dx++) { for (int dz = -size; dz < size; dz++) { for (int dy = 0; dy < 2 * size; dy++) { blockAccessor.SetBlock(0, center.AddCopy(dx, dy, dz)); } } } treeGenerators.ReloadTreeGenerators(); treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(0, -1, 0)); treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(-9, -1, 0)); treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(9, -1, 0)); blockAccessor.Commit(); }
private void BlockLineup(BlockPos pos) { IBlockAccessor blockAccess = api.WorldManager.GetBlockAccessorBulkUpdate(true, true); Block[] blocks = api.WorldManager.BlockTypes; List <Block> existingBlocks = new List <Block>(); for (int i = 0; i < blocks.Length; i++) { if (blocks[i] == null || blocks[i].Code == null) { continue; } existingBlocks.Add(blocks[i]); } int width = (int)Math.Sqrt(existingBlocks.Count); FillArea(0, pos.AddCopy(0, 0, 0), pos.AddCopy(width + 1, 10, width + 1)); for (int i = 0; i < existingBlocks.Count; i++) { if (existingBlocks[i] == null || existingBlocks[i].Code == null) { continue; } blockAccess.SetBlock(blocks[i].BlockId, pos.AddCopy(i / width, 0, i % width)); } blockAccess.Commit(); }
public override bool ApplyToolBuild(WorldEdit worldEdit, Block block, BlockPos pos, ushort oldBlockId, BlockFacing onBlockFace, Vec3f hitPos, bool didOffset) { if (heights == null) { return(false); } worldEdit.Good("Ok, placing blocks, this may take a while"); int width = heights.GetLength(0); int length = heights.GetLength(1); BlockPos tmpPos = new BlockPos(); IBlockAccessor blockAccessorBulk = worldEdit.sapi.World.BulkBlockAccessor; for (int x = 0; x < width; x++) { for (int z = 0; z < length; z++) { int height = heights[x, z]; tmpPos.Set(pos.X + x - width / 2, pos.Y, pos.Z + z - length / 2); for (int y = 0; y < height; y++) { blockAccessorBulk.SetBlock(block.BlockId, tmpPos); tmpPos.Up(); } } } blockAccessorBulk.Commit(); return(false); }
private void ImportArea(string filename, BlockPos startPos, EnumOrigin origin) { string infilepath = Path.Combine(exportFolderPath, filename); if (!File.Exists(infilepath) && File.Exists(infilepath + ".json")) { infilepath += ".json"; } if (!File.Exists(infilepath)) { Bad("Can't import " + filename + ", it does not exist"); return; } BlockSchematic blockdata = null; try { using (TextReader textReader = new StreamReader(infilepath)) { blockdata = JsonConvert.DeserializeObject <BlockSchematic>(textReader.ReadToEnd()); textReader.Close(); } } catch (IOException e) { Good("Failed loading " + filename + " : " + e.Message); return; } BlockPos originPos = startPos.Copy(); if (origin == EnumOrigin.TopCenter) { originPos.X -= blockdata.SizeX / 2; originPos.Y -= blockdata.SizeY; originPos.Z -= blockdata.SizeZ / 2; } if (origin == EnumOrigin.BottomCenter) { originPos.X -= blockdata.SizeX / 2; originPos.Z -= blockdata.SizeZ / 2; } IBlockAccessor blockAcccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true, false); blockdata.Place(blockAcccessor, api.World, originPos); blockAcccessor.Commit(); }
private int FillArea(ushort blockId, BlockPos start, BlockPos end) { int updated = 0; IBlockAccessor blockAcccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true); BlockPos startPos = new BlockPos(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z)); BlockPos finalPos = new BlockPos(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z)); BlockPos curPos = startPos.Copy(); int dx = finalPos.X - startPos.X; int dy = finalPos.Y - startPos.Y; int dz = finalPos.Z - startPos.Z; if (dx * dy * dz > 1000) { Good((blockId == 0 ? "Clearing" : "Placing") + " " + (dx * dy * dz) + " blocks..."); } while (curPos.X < finalPos.X) { curPos.Y = startPos.Y; while (curPos.Y < finalPos.Y) { curPos.Z = startPos.Z; while (curPos.Z < finalPos.Z) { blockAcccessor.SetBlock(blockId, curPos); curPos.Z++; updated++; } curPos.Y++; } curPos.X++; } blockAcccessor.Commit(); return(updated); }
//-- Creates a spherical crater where the meteor made contact with the ground --// private void CreateCrater(Vec3d meteorDirection, Vec3d shrapnelDirection) { blockAccessor = serverAPI.World.GetBlockAccessorBulkUpdate(true, true); Vec3i centerPos = this.entity.ServerPos.XYZInt; BlockPos craterPos = new BlockPos(); //-- Initial scan to see if the meteor crater should fill with liquid instead of air --// blockAccessor.WalkBlocks(new BlockPos(centerPos.X - explosionRadius, centerPos.Y - explosionRadius, centerPos.Z - explosionRadius), new BlockPos(centerPos.X + explosionRadius, centerPos.Y + explosionRadius, centerPos.Z + explosionRadius), (block, bpos) => { if (block.DrawType == EnumDrawType.Liquid) { liquidAsset = new AssetLocation(block.Code.Domain, block.Code.Path); fillWithLiquid = true; fillHeight = bpos.Y; return; } }); //-- Scans every block in a cube determined by the explosion radius and determines whether that block fits within the explosion sphere --// blockAccessor.WalkBlocks(new BlockPos(centerPos.X - explosionRadius, centerPos.Y - explosionRadius, centerPos.Z - explosionRadius), new BlockPos(centerPos.X + explosionRadius, centerPos.Y + explosionRadius, centerPos.Z + explosionRadius), (block, bpos) => { if (bpos.DistanceTo(centerPos.ToBlockPos()) < explosionRadius) { ExplodeBlock(block, bpos, shrapnelDirection); } }); PlaceMeteorResources(meteorDirection, shrapnelDirection, centerPos, explosionRadius); blockAccessor.Commit(); }
void TestTree(IServerPlayer player, CmdArgs arguments) { if (arguments.Length < 2) { player.SendMessage(groupId, "/wgen tree {treeWorldPropertyCode} [0.1 - 3] [aheadoffset]", EnumChatType.CommandError); return; } float size = 1f; int aheadoffset = 0; if (arguments.Length > 2) { float.TryParse(arguments[2], out size); } if (arguments.Length > 3) { int.TryParse(arguments[3], out aheadoffset); } BlockPos pos = player.Entity.Pos.HorizontalAheadCopy(aheadoffset).AsBlockPos; IBlockAccessor blockAccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true); while (blockAccessor.GetBlockId(pos) == 0 && pos.Y > 1) { pos.Down(); } treeGenerators.ReloadTreeGenerators(); treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, pos, size); blockAccessor.Commit(); player.SendMessage(groupId, arguments[1] + " size " + size + " generated.", EnumChatType.CommandError); }
//-- Creates a spherical crater where the meteor made contact with the ground --// private void CreateCrater(Vec3d meteorDirection, Vec3d shrapnelDirection) { List <LandClaim> claims = serverAPI.World.Claims.All; List <BlockPos> ashPositions = new List <BlockPos>(); blockAccessor = serverAPI.World.GetBlockAccessorBulkUpdate(true, true); Vec3i centerPos = this.entity.ServerPos.XYZInt; BlockPos craterPos = new BlockPos(); //-- Initial scan to see if the meteor crater should fill with liquid instead of air --// blockAccessor.SearchFluidBlocks(new BlockPos(centerPos.X - explosionRadius, centerPos.Y - explosionRadius, centerPos.Z - explosionRadius), new BlockPos(centerPos.X + explosionRadius, centerPos.Y + explosionRadius, centerPos.Z + explosionRadius), (block, bPos) => { if (block.DrawType == EnumDrawType.Liquid) { liquidAsset = new AssetLocation(block.Code.Domain, block.Code.Path); fillWithLiquid = true; fillHeight = bPos.Y; return(true); } return(false); }); //-- Scans every block in a cube determined by the explosion radius and determines whether that block fits within the explosion sphere --// blockAccessor.WalkBlocks(new BlockPos(centerPos.X - explosionRadius, centerPos.Y - explosionRadius, centerPos.Z - explosionRadius), new BlockPos(centerPos.X + explosionRadius, centerPos.Y + explosionRadius, centerPos.Z + explosionRadius), (block, xPos, yPos, zPos) => { BlockPos blockPos = new BlockPos(xPos, yPos, zPos); float distanceToCenter = blockPos.DistanceTo(centerPos.ToBlockPos()); if (distanceToCenter < explosionRadius) { if (serverAPI.World.Config.GetBool("ClaimsProtected") == true) { bool isClaimed = false; foreach (LandClaim claim in claims) { if (claim.PositionInside(blockPos)) { isClaimed = true; } } if (isClaimed == false) { ExplodeBlock(block, blockPos, shrapnelDirection); if (fillWithLiquid == false) { if (centerPos.Y - blockPos.Y == explosionRadius - 1) { if (explosionRand.Next(0, 100) < ashBlockChance) { ashPositions.Add(blockPos + new BlockPos(0, 1, 0)); } } } } } else { ExplodeBlock(block, blockPos, shrapnelDirection); if (fillWithLiquid == false) { if (centerPos.Y - blockPos.Y == explosionRadius - 1) { if (explosionRand.Next(0, 100) < ashBlockChance) { ashPositions.Add(blockPos.Copy() + new BlockPos(0, 1, 0)); } } } } } }); PlaceMeteor(meteorDirection, shrapnelDirection, centerPos, explosionRadius, claims); PlaceAsh(ashPositions); blockAccessor.Commit(); }