Java Code Examples for com.sk89q.worldedit.EditSession#setBlock()
The following examples show how to use
com.sk89q.worldedit.EditSession#setBlock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SinglePickaxe.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); final int blockType = world.getBlockType(clicked.toVector()); if (blockType == BlockID.BEDROCK && !player.canDestroyBedrock()) { return true; } EditSession editSession = session.createEditSession(player); editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); try { if (editSession.setBlock(clicked.getBlockX(), clicked.getBlockY(), clicked.getBlockZ(), EditSession.nullBlock)) { world.playEffect(clicked.toVector(), 2001, blockType); } } finally { editSession.flushQueue(); session.remember(editSession); } return true; }
Example 2
Source File: ScatterOverlayBrush.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException { int x = pt.getBlockX(); int y = pt.getBlockY(); int z = pt.getBlockZ(); Vector dir = getDirection(pt); dir.setComponents(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ()); editSession.setBlock(dir, p); }
Example 3
Source File: SurfaceSphereBrush.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { SurfaceMask surface = new SurfaceMask(editSession); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); RecursiveVisitor visitor = new RecursiveVisitor(vector -> surface.test(vector) && radius.test(vector), vector -> editSession.setBlock(vector, pattern)); visitor.visit(position); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); Operations.completeBlindly(visitor); }
Example 4
Source File: RockBrush.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { double seedX = ThreadLocalRandom.current().nextDouble(); double seedY = ThreadLocalRandom.current().nextDouble(); double seedZ = ThreadLocalRandom.current().nextDouble(); int px = position.getBlockX(); int py = position.getBlockY(); int pz = position.getBlockZ(); double distort = this.frequency / size; double modX = 1d/radius.getX(); double modY = 1d/radius.getY(); double modZ = 1d/radius.getZ(); int radiusSqr = (int) (size * size); int sizeInt = (int) size * 2; for (int x = -sizeInt; x <= sizeInt; x++) { double nx = seedX + x * distort; double d1 = x * x * modX; for (int y = -sizeInt; y <= sizeInt; y++) { double d2 = d1 + y * y * modY; double ny = seedY + y * distort; for (int z = -sizeInt; z <= sizeInt; z++) { double nz = seedZ + z * distort; double distance = d2 + z * z * modZ; double noise = this.amplitude * SimplexNoise.noise(nx, ny, nz); if (distance + distance * noise < radiusSqr) { editSession.setBlock(px + x, py + y, pz + z, pattern); } } } } }
Example 5
Source File: FloodFillTool.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
private void recurse(Platform server, EditSession editSession, World world, BlockVector pos, Vector origin, int size, int initialType, Set<BlockVector> visited) throws WorldEditException { if (origin.distance(pos) > size || visited.contains(pos)) { return; } visited.add(pos); if (editSession.getBlock(pos).getType() == initialType) { editSession.setBlock(pos, pattern); } else { return; } recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(), origin, size, initialType, visited); recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(), origin, size, initialType, visited); }
Example 6
Source File: GravityBrush.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { Mask mask = editSession.getMask(); if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) { mask = null; } int size = (int) sizeDouble; int endY = position.getBlockY() + size; int startPerformY = Math.max(0, position.getBlockY() - size); int startCheckY = fullHeight ? 0 : startPerformY; Vector mutablePos = new Vector(0, 0, 0); for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { int freeSpot = startCheckY; for (int y = startCheckY; y <= endY; y++) { BaseBlock block = editSession.getLazyBlock(x, y, z); if (block.getId() != 0) { if (y != freeSpot) { editSession.setBlock(x, y, z, EditSession.nullBlock); editSession.setBlock(x, freeSpot, z, block); } freeSpot = y + 1; } } } } }
Example 7
Source File: AreaPickaxe.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { int ox = clicked.getBlockX(); int oy = clicked.getBlockY(); int oz = clicked.getBlockZ(); int initialType = ((World) clicked.getExtent()).getBlockType(clicked.toVector()); if (initialType == 0) { return true; } if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) { return true; } EditSession editSession = session.createEditSession(player); editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); for (int x = ox - range; x <= ox + range; ++x) { for (int z = oz - range; z <= oz + range; ++z) { for (int y = oy + range; y >= oy - range; --y) { if (editSession.getLazyBlock(x, y, z).getId() != initialType) { continue; } editSession.setBlock(x, y, z, air); } } } editSession.flushQueue(); session.remember(editSession); return true; }
Example 8
Source File: SurfaceSpline.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void build(EditSession editSession, Vector pos, Pattern pattern, double radius) throws MaxChangedBlocksException { int maxY = editSession.getMaxY(); boolean vis = editSession.getExtent() instanceof VisualExtent; if (path.isEmpty() || !pos.equals(path.get(path.size() - 1))) { int max = editSession.getNearestSurfaceTerrainBlock(pos.getBlockX(), pos.getBlockZ(), pos.getBlockY(), 0, editSession.getMaxY()); if (max == -1) return; pos.mutY(max); path.add(pos); editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_PRIMARY_2.s()); if (!vis) return; } LocalBlockVectorSet vset = new LocalBlockVectorSet(); final List<Node> nodes = new ArrayList<>(path.size()); final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation(); for (final Vector nodevector : path) { final Node n = new Node(nodevector); n.setTension(tension); n.setBias(bias); n.setContinuity(continuity); nodes.add(n); } interpol.setNodes(nodes); final double splinelength = interpol.arcLength(0, 1); for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) { final Vector tipv = interpol.getPosition(loop); final int tipx = MathMan.roundInt(tipv.getX()); final int tipz = (int) tipv.getZ(); int tipy = MathMan.roundInt(tipv.getY()); tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY); if (tipy == -1) continue; if (radius == 0) { editSession.setBlock(tipx, tipy, tipz, pattern.next(tipx, tipy, tipz)); } else { vset.add(tipx, tipy, tipz); } } if (radius != 0) { double radius2 = (radius * radius); LocalBlockVectorSet newSet = new LocalBlockVectorSet(); final int ceilrad = (int) Math.ceil(radius); for (final Vector v : vset) { final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ(); for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) { for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) { if (MathMan.hypot2(loopx - tipx, 0, loopz - tipz) <= radius2) { int y = editSession.getNearestSurfaceTerrainBlock(loopx, loopz, v.getBlockY(), 0, maxY); if (y == -1) continue; newSet.add(loopx, y, loopz); } } } } editSession.setBlocks(newSet, pattern); if (!vis) path.clear(); } editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_SECONDARY.s()); }
Example 9
Source File: FallingSphere.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { int px = position.getBlockX(); int py = position.getBlockY(); int pz = position.getBlockZ(); int maxY = editSession.getMaxY(); int lastY = py; int radius = (int) Math.round(size); int radiusSqr = (int) Math.round(size * size); for (int z = -radius; z <= radius; z++) { int zz = z * z; int az = pz + z; int remaining = radiusSqr - zz; int xRadius = MathMan.usqrt(remaining); for (int x = -xRadius; x <= xRadius; x++) { int xx = x * x; int ax = px + x; int remainingY = remaining - xx; if (remainingY < 0) continue; int yRadius = MathMan.usqrt(remainingY); int startY = Math.max(0, py - yRadius); int endY = Math.min(maxY, py + yRadius); int heightY = editSession.getHighestTerrainBlock(ax, az, 0, endY); if (heightY < startY) { int diff = startY - heightY; startY -= diff; endY -= diff; } for (int y = startY; y <= heightY; y++) { editSession.setBlock(ax, y, az, pattern); } for (int y = heightY + 1; y <= endY; y++) { editSession.setBlock(ax, y, az, pattern); } } } }
Example 10
Source File: BlendBall.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { final int outsetSize = (int) (size + 1); double brushSizeSquared = size * size; int tx = position.getBlockX(); int ty = position.getBlockY(); int tz = position.getBlockZ(); Map<BaseBlock, Integer> frequency = Maps.newHashMap(); int maxY = editSession.getMaximumPoint().getBlockY(); for (int x = -outsetSize; x <= outsetSize; x++) { int x0 = x + tx; for (int y = -outsetSize; y <= outsetSize; y++) { int y0 = y + ty; for (int z = -outsetSize; z <= outsetSize; z++) { if (x * x + y * y + z * z >= brushSizeSquared) { continue; } int z0 = z + tz; int highest = 1; BaseBlock currentState = editSession.getBlock(x0, y0, z0); BaseBlock highestState = currentState; frequency.clear(); boolean tie = false; for (int ox = -1; ox <= 1; ox++) { for (int oz = -1; oz <= 1; oz++) { for (int oy = -1; oy <= 1; oy++) { if (oy + y0 < 0 || oy + y0 > maxY) { continue; } BaseBlock state = editSession.getBlock(x0 + ox, y0 + oy, z0 + oz); Integer count = frequency.get(state); if (count == null) { count = 1; } else { count++; } if (count > highest) { highest = count; highestState = state; tie = false; } else if (count == highest) { tie = true; } frequency.put(state, count); } } } if (!tie && currentState != highestState) { editSession.setBlock(x0, y0, z0, highestState); } } } } }
Example 11
Source File: StencilBrush.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { final int cx = position.getBlockX(); final int cy = position.getBlockY(); final int cz = position.getBlockZ(); int size = (int) sizeDouble; int size2 = (int) (sizeDouble * sizeDouble); int maxY = editSession.getMaxY(); int add; if (yscale < 0) { add = maxY; } else { add = 0; } double scale = (yscale / sizeDouble) * (maxY + 1); final HeightMap map = getHeightMap(); map.setSize(size); int cutoff = onlyWhite ? maxY : 0; final SolidBlockMask solid = new SolidBlockMask(editSession); final AdjacentAnyMask adjacent = new AdjacentAnyMask(Masks.negate(solid)); Player player = editSession.getPlayer().getPlayer(); Vector pos = player.getPosition(); Location loc = editSession.getPlayer().getPlayer().getLocation(); float yaw = loc.getYaw(); float pitch = loc.getPitch(); AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX(pitch - 90).inverse(); RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { private final MutableBlockVector mutable = new MutableBlockVector(); @Override public boolean test(Vector vector) { if (solid.test(vector)) { int dx = vector.getBlockX() - cx; int dy = vector.getBlockY() - cy; int dz = vector.getBlockZ() - cz; Vector srcPos = transform.apply(mutable.setComponents(dx, dy, dz)); dx = srcPos.getBlockX(); dz = srcPos.getBlockZ(); int distance = dx * dx + dz * dz; if (distance > size2 || Math.abs(dx) > 256 || Math.abs(dz) > 256) return false; double raise = map.getHeight(dx, dz); int val = (int) Math.ceil(raise * scale) + add; if (val < cutoff) { return true; } if (val >= 255 || PseudoRandom.random.random(maxY) < val) { editSession.setBlock(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), pattern); } return true; } return false; } }, vector -> true, Integer.MAX_VALUE, editSession); visitor.setDirections(Arrays.asList(visitor.DIAGONAL_DIRECTIONS)); visitor.visit(position); Operations.completeBlindly(visitor); }
Example 12
Source File: ScatterBrush.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException { editSession.setBlock(pt, p); }
Example 13
Source File: Spigot_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean regenerate(org.bukkit.World bukkitWorld, Region region, EditSession editSession) { WorldServer originalWorld = ((CraftWorld) bukkitWorld).getHandle(); File saveFolder = Files.createTempDir(); // register this just in case something goes wrong // normally it should be deleted at the end of this method saveFolder.deleteOnExit(); saveFolder.deleteOnExit(); try { Environment env = bukkitWorld.getEnvironment(); ChunkGenerator gen = bukkitWorld.getGenerator(); MinecraftServer server = originalWorld.getServer().getServer(); WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null), server.dataConverterManager, getDataVersion(), null); newWorldData.checkName("worldeditregentempworld"); WorldNBTStorage saveHandler = new WorldNBTStorage(saveFolder, originalWorld.getDataManager().getDirectory().getName(), server, server.dataConverterManager); try (WorldServer freshWorld = new WorldServer(server, saveHandler, new PersistentCollection(saveHandler), newWorldData, originalWorld.worldProvider.getDimensionManager(), originalWorld.methodProfiler, env, gen)) { freshWorld.savingDisabled = true; // Pre-gen all the chunks // We need to also pull one more chunk in every direction CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16)); for (BlockVector2 chunk : expandedPreGen.getChunks()) { freshWorld.getChunkAt(chunk.getBlockX(), chunk.getBlockZ()); } CraftWorld craftWorld = freshWorld.getWorld(); BukkitWorld from = new BukkitWorld(craftWorld); for (BlockVector3 vec : region) { editSession.setBlock(vec, from.getFullBlock(vec)); } } } catch (MaxChangedBlocksException e) { throw new RuntimeException(e); } finally { saveFolder.delete(); try { Map<String, org.bukkit.World> map = (Map<String, org.bukkit.World>) serverWorldsField.get(Bukkit.getServer()); map.remove("worldeditregentempworld"); } catch (IllegalAccessException ignored) { } } return true; }