com.sk89q.worldedit.math.transform.Transform Java Examples
The following examples show how to use
com.sk89q.worldedit.math.transform.Transform.
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: RandomFullClipboardPattern.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); AffineTransform transform = new AffineTransform(); if (randomRotate) { transform = transform.rotateY(PseudoRandom.random.random(4) * 90); holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } if (randomFlip) { transform = transform.scale(new Vector(1, 0, 0).multiply(-2).add(1, 1, 1)); } if (!transform.isIdentity()) { holder.setTransform(transform); } Clipboard clipboard = holder.getClipboard(); Schematic schematic = new Schematic(clipboard); Transform newTransform = holder.getTransform(); if (newTransform.isIdentity()) { schematic.paste(extent, setPosition, false); } else { schematic.paste(extent, worldData, setPosition, false, newTransform); } return true; }
Example #2
Source File: BlockTransformExtent.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
/** * Get the new value with the transformed direction. * * @param state the state * @param transform the transform * @param oldDirection the old direction to transform * @return a new state or null if none could be found */ @Nullable private static StateValue getNewStateValue(State state, Transform transform, Vector oldDirection) { Vector newDirection = new Vector(transform.apply(oldDirection)).subtract(transform.apply(Vector.ZERO)).normalize(); StateValue newValue = null; double closest = -2; boolean found = false; for (Map.Entry<String, ? extends StateValue> entry : state.valueMap().entrySet()) { StateValue v = entry.getValue(); if (v.getDirection() != null) { double dot = v.getDirection().normalize().dot(newDirection); if (dot >= closest) { closest = dot; newValue = v; found = true; } } } if (found) { return newValue; } else { return null; } }
Example #3
Source File: SchemGen.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean spawn(PseudoRandom random, int x, int z) throws WorldEditException { mutable.mutX(x); mutable.mutZ(z); int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255); if (y == -1) return false; mutable.mutY(y); if (!mask.test(mutable)) { return false; } mutable.mutY(y + 1); ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); if (randomRotate) { holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } Clipboard clipboard = holder.getClipboard(); Schematic schematic = new Schematic(clipboard); Transform transform = holder.getTransform(); if (transform.isIdentity()) { schematic.paste(extent, mutable, false); } else { schematic.paste(extent, worldData, mutable, false, transform); } mutable.mutY(y); return true; }
Example #4
Source File: Schematic.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public void paste(Extent extent, WorldData worldData, Vector to, boolean pasteAir, Transform transform) { checkNotNull(transform); Region region = clipboard.getRegion(); Extent source = clipboard; if (worldData != null && transform != null) { source = new BlockTransformExtent(clipboard, transform, worldData.getBlockRegistry()); } ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), extent, to); if (transform != null) { copy.setTransform(transform); } copy.setCopyBiomes(!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes()); if (extent instanceof EditSession) { EditSession editSession = (EditSession) extent; Mask sourceMask = editSession.getSourceMask(); if (sourceMask != null) { new MaskTraverser(sourceMask).reset(extent); copy.setSourceMask(sourceMask); editSession.setSourceMask(null); } } if (!pasteAir) { copy.setSourceMask(new ExistingBlockMask(clipboard)); } Operations.completeBlindly(copy); }
Example #5
Source File: BackwardsExtentBlockCopy.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public Operation resume(RunContext run) throws WorldEditException { CuboidRegion destRegion = transform(this.transform, this.region); Transform inverse = this.transform.inverse(); for (Vector pt : destRegion) { Vector copyFrom = transform(inverse, pt); if (region.contains(copyFrom)) { function.apply(pt); } } return null; }
Example #6
Source File: BackwardsExtentBlockCopy.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public BackwardsExtentBlockCopy(Extent source, Region region, Extent destination, Vector origin, Transform transform, RegionFunction function) { this.source = source; this.region = region; this.destination = destination; this.transform = transform; this.function = function; this.origin = origin; }
Example #7
Source File: ExtentBlockCopy.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * Make a new copy. * * @param source the source extent * @param from the source offset * @param destination the destination extent * @param to the destination offset * @param transform a transform to apply to positions (after source offset, before destination offset) */ public ExtentBlockCopy(Extent source, Vector from, Extent destination, Vector to, Transform transform) { checkNotNull(source); checkNotNull(from); checkNotNull(destination); checkNotNull(to); checkNotNull(transform); this.source = source; this.from = from; this.destination = destination; this.to = to; this.transform = transform; }
Example #8
Source File: ExtentEntityCopy.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * Create a new instance. * * @param from the from position * @param destination the destination {@code Extent} * @param to the destination position * @param transform the transformation to apply to both position and orientation */ public ExtentEntityCopy(Vector from, Extent destination, Vector to, Transform transform) { checkNotNull(from); checkNotNull(destination); checkNotNull(to); checkNotNull(transform); this.destination = destination; this.from = from; this.to = to; this.transform = transform; }
Example #9
Source File: BlockTransformExtent.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public BlockTransformExtent(Extent parent, Transform transform, BlockRegistry registry) { super(parent); this.transform = transform; this.transformInverse = this.transform.inverse(); this.registry = registry; cache(); }
Example #10
Source File: FlattenedClipboardTransform.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * Create a new instance. * * @param original the original clipboard * @param transform the transform * @param worldData the world data instance */ private FlattenedClipboardTransform(Clipboard original, Transform transform, WorldData worldData) { checkNotNull(original); checkNotNull(transform); checkNotNull(worldData); this.original = original; this.transform = transform; this.worldData = worldData; }
Example #11
Source File: FAWEFloorRegenerator.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@Override public void regenerate(Floor floor, EditSession session, RegenerationCause cause) { Clipboard clipboard = floor.getClipboard(); Schematic faweSchematic = new Schematic(clipboard); Region region = clipboard.getRegion(); World world = region.getWorld(); if (world == null) { throw new IllegalStateException("World of floor " + floor.getName() + " is null!"); } faweSchematic.paste(world, region.getMinimumPoint(), false, false, (Transform) null); }
Example #12
Source File: BlockTransformExtent.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public Transform getTransform() { return transform; }
Example #13
Source File: BlockTransformExtent.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public void setTransform(Transform affine) { this.transform = affine; this.transformInverse = this.transform.inverse(); cache(); }
Example #14
Source File: DelegateClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public Transform getTransform() { return parent.getTransform(); }
Example #15
Source File: DelegateClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void setTransform(Transform transform) { parent.setTransform(transform); }
Example #16
Source File: FlattenedClipboardTransform.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
/** * Get the transformed region. * * @return the transformed region */ public Region getTransformedRegion() { Region region = original.getRegion(); Vector minimum = region.getMinimumPoint(); Vector maximum = region.getMaximumPoint(); Transform transformAround = new CombinedTransform( new AffineTransform().translate(original.getOrigin().multiply(-1)), transform, new AffineTransform().translate(original.getOrigin())); // new Vector(minimum.getX(), minimum.getY(), minimum.getZ()) // new Vector(maximum.getX(), maximum.getY(), maximum.getZ()) Vector[] corners = new Vector[]{ minimum, maximum, new Vector(maximum.getX(), minimum.getY(), minimum.getZ()), new Vector(minimum.getX(), maximum.getY(), minimum.getZ()), new Vector(minimum.getX(), minimum.getY(), maximum.getZ()), new Vector(minimum.getX(), maximum.getY(), maximum.getZ()), new Vector(maximum.getX(), minimum.getY(), maximum.getZ()), new Vector(maximum.getX(), maximum.getY(), minimum.getZ())}; for (int i = 0; i < corners.length; i++) { corners[i] = transformAround.apply(new Vector(corners[i])); } Vector newMinimum = corners[0]; Vector newMaximum = corners[0]; for (int i = 1; i < corners.length; i++) { newMinimum = Vector.getMinimum(newMinimum, corners[i]); newMaximum = Vector.getMaximum(newMaximum, corners[i]); } // After transformation, the points may not really sit on a block, // so we should expand the region for edge cases newMinimum.mutX(Math.ceil(Math.floor(newMinimum.getX()))); newMinimum.mutY(Math.ceil(Math.floor(newMinimum.getY()))); newMinimum.mutZ(Math.ceil(Math.floor(newMinimum.getZ()))); return new CuboidRegion(newMinimum, newMaximum); }
Example #17
Source File: RegionAdapter7.java From WorldEditSelectionVisualizer with MIT License | 4 votes |
private BlockVector3 applyTransform(Transform transform, Vector3 origin, BlockVector3 vector) { return applyTransform(transform, origin, vector.toVector3()).toBlockPoint(); }
Example #18
Source File: HeightMapMCAGenerator.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public void addSchems(Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException { int scaledRarity = (256 * rarity) / 100; int index = 0; AffineTransform identity = new AffineTransform(); LocalBlockVector2DSet placed = new LocalBlockVector2DSet(); for (int z = 0; z < getLength(); z++) { mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { int y = heights.getByte(index) & 0xFF; if (PseudoRandom.random.nextInt(256) > scaledRarity) { continue; } mutable.mutX(x); mutable.mutY(y); if (!mask.test(mutable)) { continue; } if (placed.containsRadius(x, z, distance)) { continue; } mutable.mutY(y + 1); placed.add(x, z); ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); if (randomRotate) { int rotate = PseudoRandom.random.random(4) * 90; if (rotate != 0) { holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } else { holder.setTransform(identity); } } Clipboard clipboard = holder.getClipboard(); Schematic schematic = new Schematic(clipboard); Transform transform = holder.getTransform(); if (transform.isIdentity()) { schematic.paste(this, mutable, false); } else { schematic.paste(this, worldData, mutable, false, transform); } if (x + distance < getWidth()) { x += distance; index += distance; } else { break; } } } }
Example #19
Source File: HeightMapMCAGenerator.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public void addSchems(BufferedImage img, Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException { if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!"); double doubleRarity = rarity / 100d; int index = 0; AffineTransform identity = new AffineTransform(); LocalBlockVector2DSet placed = new LocalBlockVector2DSet(); for (int z = 0; z < getLength(); z++) { mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { int y = heights.getByte(index) & 0xFF; int height = img.getRGB(x, z) & 0xFF; if (height == 0 || PseudoRandom.random.nextInt(256) > height * doubleRarity) { continue; } mutable.mutX(x); mutable.mutY(y); if (!mask.test(mutable)) { continue; } if (placed.containsRadius(x, z, distance)) { continue; } placed.add(x, z); ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); if (randomRotate) { int rotate = PseudoRandom.random.random(4) * 90; if (rotate != 0) { holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } else { holder.setTransform(identity); } } Clipboard clipboard = holder.getClipboard(); Schematic schematic = new Schematic(clipboard); Transform transform = holder.getTransform(); if (transform.isIdentity()) { schematic.paste(this, mutable, false); } else { schematic.paste(this, worldData, mutable, false, transform); } if (x + distance < getWidth()) { x += distance; index += distance; } else { break; } } } }
Example #20
Source File: ClipboardSpline.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
/** * Constructor with position-correction. Use this constructor for an interpolation implementation that needs position-correction. * <p> * Some interpolation implementations calculate the position on the curve (used by {@link #pastePosition(double)}) * based on an equidistant distribution of the nodes on the curve. For example: on a spline with 5 nodes position 0.0 would refer * to the first node, 0.25 to the second, 0.5 to the third, ... .<br> * By providing this method with the amount of nodes used by the interpolation implementation the distribution of the * nodes is converted to a proportional distribution based on the length between two adjacent nodes calculated by {@link Interpolation#arcLength(double, double)}.<br> * This means that the distance between two positions used to paste the clipboard (e.g. 0.75 - 0.5 = 0.25) on the curve * will always amount to that part of the length (e.g. 40 units) of the curve. In this example it would amount to * 0.25 * 40 = 10 units of curve length between these two positions. * <p> * Be advised that currently subsequent changes to the interpolation parameters may not be supported. * @param editSession The EditSession which will be used when pasting the clipboard content * @param clipboardHolder The clipboard that will be pasted along the spline * @param interpolation An implementation of the interpolation algorithm used to calculate the curve * @param nodeCount The number of nodes provided to the interpolation object */ public ClipboardSpline(EditSession editSession, ClipboardHolder clipboardHolder, Interpolation interpolation, Transform transform, int nodeCount) { super(editSession, interpolation, nodeCount); this.clipboardHolder = clipboardHolder; this.originalTransform = clipboardHolder.getTransform(); Clipboard clipboard = clipboardHolder.getClipboard(); this.originalOrigin = clipboard.getOrigin(); Region region = clipboard.getRegion(); Vector origin = clipboard.getOrigin(); center = region.getCenter().setY(origin.getY() - 1); this.centerOffset = center.subtract(center.round()); this.center = center.subtract(centerOffset); this.transform = transform; this.buffer = new LocalBlockVectorSet(); }
Example #21
Source File: PositionTransformExtent.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public void setTransform(Transform transform) { this.transform = transform; }
Example #22
Source File: PositionTransformExtent.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public PositionTransformExtent(Extent parent, Transform transform) { super(parent); this.transform = transform; }
Example #23
Source File: RegionAdapter6.java From WorldEditSelectionVisualizer with MIT License | 4 votes |
private Vector applyTransform(Transform transform, Vector origin, Vector vector) { return transform.apply(vector.subtract(origin)).add(origin); }
Example #24
Source File: RegionAdapter7.java From WorldEditSelectionVisualizer with MIT License | 4 votes |
private Vector3 applyTransform(Transform transform, Vector3 origin, Vector3 vector) { return transform.apply(vector.subtract(origin)).add(origin); }
Example #25
Source File: WorldEditHelper.java From WorldEditSelectionVisualizer with MIT License | 4 votes |
public void updatePlayerVisualization(PlayerVisualizerInfos playerInfo, SelectionType type) { Player player = playerInfo.getPlayer(); LocalSession session; try { session = worldEditPlugin.getSession(player); } catch (Exception e) { // sometimes after a reload getSession create errors with WorldEdit, this prevent error spam return; } PlayerSelection playerSelection = playerInfo.getSelection(type).orElse(null); if (playerSelection == null || session == null) { return; } Vector3d origin = Vector3d.ZERO; Region region; if (type == SelectionType.CLIPBOARD) { ClipboardHolder clipboardHolder = getClipboardHolder(session); if (clipboardHolder == null) { playerSelection.resetSelection(); return; } Clipboard clipboard = clipboardHolder.getClipboard(); Transform transform = clipboardHolder.getTransform(); origin = plugin.getCompatibilityHelper().adaptClipboard(clipboard).getOrigin(); region = clipboard.getRegion().clone(); if (!transform.isIdentity()) { region = plugin.getCompatibilityHelper().adaptRegion(region).transform(transform, origin); } } else { region = getSelectedRegion(session); } if (region == null) { playerSelection.resetSelection(); return; } if (type == SelectionType.SELECTION && (region.getWorld() == null || !region.getWorld().getName().equals(player.getWorld().getName()))) { playerSelection.resetSelection(); return; } RegionAdapter regionAdapter = plugin.getCompatibilityHelper().adaptRegion(region); RegionInfos regionInfos = regionAdapter.getRegionsInfos(); if (regionInfos.equals(playerSelection.getLastSelectedRegion())) { SelectionPoints points = playerSelection.getSelectionPoints(); if (points == null || points.origin().equals(origin)) { return; } } if (!player.hasPermission("wesv.use")) { playerSelection.resetSelection(regionInfos); return; } GlobalSelectionConfig config = plugin.getSelectionConfig(type); if (region.getArea() > config.getMaxSelectionSize()) { if (!playerSelection.isLastSelectionTooLarge()) { String message = plugin.getMessage("selection-too-large").replace("%blocks%", Integer.toString(config.getMaxSelectionSize())); plugin.getCompatibilityHelper().sendActionBar(player, message); } playerSelection.resetSelection(regionInfos); playerSelection.setLastSelectionTooLarge(true); return; } plugin.updateHoldingSelectionItem(playerInfo); Bukkit.getPluginManager().callEvent(new SelectionChangeEvent(player, region)); ShapeProcessor<?> shapeProcessor = shapeProcessors.get(region.getClass()); if (shapeProcessor != null) { playerSelection.updateSelection(shapeProcessor.processSelection(regionAdapter, config, origin), regionInfos, config.getFadeDelay()); } else { // Unsupported selection type playerSelection.resetSelection(regionInfos); } }
Example #26
Source File: ForwardExtentCopy.java From FastAsyncWorldedit with GNU General Public License v3.0 | 2 votes |
/** * Set the transformation that will occur on every point. * * @param transform a transformation * @see #getTransform() */ public void setTransform(Transform transform) { checkNotNull(transform); this.transform = transform; }
Example #27
Source File: ForwardExtentCopy.java From FastAsyncWorldedit with GNU General Public License v3.0 | 2 votes |
/** * Get the transformation that will occur on every point. * <p> * <p>The transformation will stack with each repetition.</p> * * @return a transformation */ public Transform getTransform() { return transform; }
Example #28
Source File: ClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 2 votes |
/** * Set the transform. * * @param transform the transform */ public void setTransform(Transform transform) { checkNotNull(transform); this.transform = transform; }
Example #29
Source File: ClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 2 votes |
/** * Get the transform. * * @return the transform */ public Transform getTransform() { return transform; }