mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 15:38:35 +00:00
Merge remote-tracking branch 'upstream/master' into breaking
This commit is contained in:
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
@ -32,6 +33,7 @@ public class EditContext {
|
||||
private Extent destination;
|
||||
@Nullable private Region region;
|
||||
@Nullable private Pattern fill;
|
||||
@Nullable private LocalSession session;
|
||||
|
||||
public Extent getDestination() {
|
||||
return destination;
|
||||
@ -60,4 +62,12 @@ public class EditContext {
|
||||
this.fill = fill;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LocalSession getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(@Nullable LocalSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.function;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
/**
|
||||
* Passes calls to {@link #apply(BlockVector2)} to the
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.function;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
/**
|
||||
* Applies a {@link RegionFunction} to the first ground block.
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.function;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
/**
|
||||
* Passes calls to {@link #apply(BlockVector3)} to the
|
||||
|
@ -21,11 +21,11 @@ package com.sk89q.worldedit.function.biome;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.FlatRegionFunction;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
|
||||
/**
|
||||
* Replaces the biome at the locations that this function is applied to.
|
||||
@ -33,7 +33,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
public class BiomeReplace implements FlatRegionFunction {
|
||||
|
||||
private final Extent extent;
|
||||
private BaseBiome biome;
|
||||
private BiomeType biome;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -41,7 +41,7 @@ public class BiomeReplace implements FlatRegionFunction {
|
||||
* @param extent an extent
|
||||
* @param biome a biome
|
||||
*/
|
||||
public BiomeReplace(Extent extent, BaseBiome biome) {
|
||||
public BiomeReplace(Extent extent, BiomeType biome) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(biome);
|
||||
this.extent = extent;
|
||||
|
@ -26,9 +26,6 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Replaces blocks with a given pattern.
|
||||
|
@ -28,7 +28,6 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.jnbt.CompoundTagBuilder;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
@ -37,13 +36,9 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Direction.Flag;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
//import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
/**
|
||||
* Copies blocks from one extent to another.
|
||||
|
@ -29,11 +29,11 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.function.LayerFunction;
|
||||
import com.sk89q.worldedit.function.mask.BlockTypeMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Makes a layer of grass on top, three layers of dirt below, and smooth stone
|
||||
* only below that for all layers that originally consist of grass, dirt,
|
||||
|
@ -26,6 +26,7 @@ import com.sk89q.jnbt.FloatTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.jnbt.CompoundTagBuilder;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
@ -101,19 +102,6 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
Location newLocation;
|
||||
Location location = entity.getLocation();
|
||||
|
||||
//<<<<<<< HEAD
|
||||
// Vector pivot = from.round().add(0.5, 0.5, 0.5);
|
||||
// Vector newPosition = transform.apply(location.subtract(pivot));
|
||||
// Vector newDirection;
|
||||
// if (transform.isIdentity()) {
|
||||
// newDirection = entity.getLocation().getDirection();
|
||||
// newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection);
|
||||
// } else {
|
||||
// newDirection = new Vector(transform.apply(location.getDirection())).subtract(transform.apply(Vector.ZERO)).normalize();
|
||||
// newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection);
|
||||
// state = transformNbtData(state);
|
||||
// }
|
||||
//=======
|
||||
Vector3 pivot = from.round().add(0.5, 0.5, 0.5);
|
||||
Vector3 newPosition = transform.apply(location.subtract(pivot));
|
||||
Vector3 newDirection;
|
||||
@ -123,9 +111,7 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
: transform.apply(location.getDirection()).subtract(transform.apply(Vector3.ZERO)).normalize();
|
||||
newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection);
|
||||
|
||||
// Some entities store their position data in NBT
|
||||
state = transformNbtData(state);
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
|
||||
boolean success = destination.createEntity(newLocation, state) != null;
|
||||
|
||||
@ -163,14 +149,9 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
boolean hasFacing = tag.containsKey("Facing");
|
||||
|
||||
if (hasTilePosition) {
|
||||
//<<<<<<< HEAD
|
||||
changed = true;
|
||||
// Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
|
||||
// Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to);
|
||||
//=======
|
||||
Vector3 tilePosition = Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
|
||||
BlockVector3 newTilePosition = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
|
||||
values.put("TileX", new IntTag(newTilePosition.getBlockX()));
|
||||
values.put("TileY", new IntTag(newTilePosition.getBlockY()));
|
||||
|
@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
@ -147,7 +149,9 @@ public class Deform implements Contextual<Operation> {
|
||||
unit = Vector3.ONE;
|
||||
}
|
||||
|
||||
return new DeformOperation(context.getDestination(), region, zero, unit, expression);
|
||||
LocalSession session = context.getSession();
|
||||
return new DeformOperation(context.getDestination(), region, zero, unit, expression,
|
||||
session == null ? WorldEdit.getInstance().getConfiguration().calculationTimeout : session.getTimeout());
|
||||
}
|
||||
|
||||
private static final class DeformOperation implements Operation {
|
||||
@ -156,6 +160,7 @@ public class Deform implements Contextual<Operation> {
|
||||
private final Vector3 zero;
|
||||
private final Vector3 unit;
|
||||
private final String expression;
|
||||
private final int timeout;
|
||||
|
||||
private DeformOperation(Extent destination, Region region, Vector3 zero, Vector3 unit, String expression) {
|
||||
this.destination = destination;
|
||||
@ -163,6 +168,7 @@ public class Deform implements Contextual<Operation> {
|
||||
this.zero = zero;
|
||||
this.unit = unit;
|
||||
this.expression = expression;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.function.generator;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
|
@ -20,9 +20,9 @@
|
||||
package com.sk89q.worldedit.function.generator;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
@ -58,11 +58,14 @@ public class ForestGenerator implements RegionFunction {
|
||||
return true;
|
||||
} else if (t == BlockTypes.TALL_GRASS || t == BlockTypes.DEAD_BUSH || t == BlockTypes.POPPY || t == BlockTypes.DANDELION) { // TODO: This list needs to be moved
|
||||
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
|
||||
treeType.generate(editSession, position);
|
||||
return true;
|
||||
} else if (t == BlockTypes.SNOW) {
|
||||
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
|
||||
return false;
|
||||
// and then trick the generator here by directly setting into the world
|
||||
editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState());
|
||||
// so that now the generator can generate the tree
|
||||
boolean success = treeType.generate(editSession, position);
|
||||
if (!success) {
|
||||
editSession.setBlock(position, block); // restore on failure
|
||||
}
|
||||
return success;
|
||||
} else { // Trees won't grow on this!
|
||||
return false;
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ package com.sk89q.worldedit.function.generator;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -36,7 +36,7 @@ import java.util.Set;
|
||||
public class BiomeMask2D extends AbstractMask2D {
|
||||
|
||||
private final Extent extent;
|
||||
private final Set<BaseBiome> biomes = new HashSet<>();
|
||||
private final Set<BiomeType> biomes = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Create a new biome mask.
|
||||
@ -44,7 +44,7 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
* @param extent the extent
|
||||
* @param biomes a list of biomes to match
|
||||
*/
|
||||
public BiomeMask2D(Extent extent, Collection<BaseBiome> biomes) {
|
||||
public BiomeMask2D(Extent extent, Collection<BiomeType> biomes) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(biomes);
|
||||
this.extent = extent;
|
||||
@ -57,7 +57,7 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
* @param extent the extent
|
||||
* @param biome an array of biomes to match
|
||||
*/
|
||||
public BiomeMask2D(Extent extent, BaseBiome... biome) {
|
||||
public BiomeMask2D(Extent extent, BiomeType... biome) {
|
||||
this(extent, Arrays.asList(checkNotNull(biome)));
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
*
|
||||
* @param biomes a list of biomes
|
||||
*/
|
||||
public void add(Collection<BaseBiome> biomes) {
|
||||
public void add(Collection<BiomeType> biomes) {
|
||||
checkNotNull(biomes);
|
||||
this.biomes.addAll(biomes);
|
||||
}
|
||||
@ -76,7 +76,7 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
*
|
||||
* @param biome an array of biomes
|
||||
*/
|
||||
public void add(BaseBiome... biome) {
|
||||
public void add(BiomeType... biome) {
|
||||
add(Arrays.asList(checkNotNull(biome)));
|
||||
}
|
||||
|
||||
@ -85,13 +85,13 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
*
|
||||
* @return a list of biomes
|
||||
*/
|
||||
public Collection<BaseBiome> getBiomes() {
|
||||
public Collection<BiomeType> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
BaseBiome biome = extent.getBiome(vector);
|
||||
BiomeType biome = extent.getBiome(vector);
|
||||
return biomes.contains(biome);
|
||||
}
|
||||
|
||||
|
@ -129,12 +129,6 @@ public class BlockMask extends AbstractExtentMask {
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
// public boolean test(BlockVector3 vector) {
|
||||
// BlockStateHolder block = getExtent().getBlock(vector);
|
||||
// for (BlockStateHolder testBlock : blocks) {
|
||||
// if (testBlock.equalsFuzzy(block)) {
|
||||
// return true;
|
||||
|
||||
|
||||
private Mask getOptimizedMask(BlockType type, long[] bitSet) {
|
||||
boolean single = true;
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.worldedit.blocks.Blocks;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockStateMask extends AbstractExtentMask {
|
||||
|
||||
private final Map<String, String> states;
|
||||
private final boolean strict;
|
||||
private Map<BlockType, Map<Property<Object>, Object>> cache = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* Creates a mask that checks if a given block has the desired properties set to the desired value.
|
||||
*
|
||||
* @param extent the extent to get blocks from
|
||||
* @param states the desired states (property -> value) that a block should have to match the mask
|
||||
* @param strict true to only match blocks that have all properties and values, false to also match blocks that
|
||||
* do not have the properties (but only fail blocks with the properties but wrong values)
|
||||
*/
|
||||
public BlockStateMask(Extent extent, Map<String, String> states, boolean strict) {
|
||||
super(extent);
|
||||
this.states = states;
|
||||
this.strict = strict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
BlockState block = getExtent().getBlock(vector);
|
||||
final Map<Property<Object>, Object> checkProps = cache
|
||||
.computeIfAbsent(block.getBlockType(), (b -> Blocks.resolveProperties(states, b)));
|
||||
if (strict && checkProps.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return checkProps.entrySet().stream()
|
||||
.allMatch(entry -> block.getState(entry.getKey()) == entry.getValue());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,8 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -21,13 +21,15 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
/**
|
||||
* A mask that evaluates an expression.
|
||||
@ -38,6 +40,7 @@ import javax.annotation.Nullable;
|
||||
public class ExpressionMask extends AbstractMask {
|
||||
|
||||
private final Expression expression;
|
||||
private final IntSupplier timeout;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -46,8 +49,7 @@ public class ExpressionMask extends AbstractMask {
|
||||
* @throws ExpressionException thrown if there is an error with the expression
|
||||
*/
|
||||
public ExpressionMask(String expression) throws ExpressionException {
|
||||
checkNotNull(expression);
|
||||
this.expression = Expression.compile(expression, "x", "y", "z");
|
||||
this(Expression.compile(checkNotNull(expression), "x", "y", "z"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,8 +58,13 @@ public class ExpressionMask extends AbstractMask {
|
||||
* @param expression the expression
|
||||
*/
|
||||
public ExpressionMask(Expression expression) {
|
||||
this(expression, null);
|
||||
}
|
||||
|
||||
public ExpressionMask(Expression expression, @Nullable IntSupplier timeout) {
|
||||
checkNotNull(expression);
|
||||
this.expression = expression;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,7 +82,7 @@ public class ExpressionMask extends AbstractMask {
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return new ExpressionMask2D(expression);
|
||||
return new ExpressionMask2D(expression, timeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,14 +21,19 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public class ExpressionMask2D extends AbstractMask2D {
|
||||
|
||||
private final Expression expression;
|
||||
private final IntSupplier timeout;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -37,8 +42,7 @@ public class ExpressionMask2D extends AbstractMask2D {
|
||||
* @throws ExpressionException thrown if there is an error with the expression
|
||||
*/
|
||||
public ExpressionMask2D(String expression) throws ExpressionException {
|
||||
checkNotNull(expression);
|
||||
this.expression = Expression.compile(expression, "x", "z");
|
||||
this(Expression.compile(checkNotNull(expression), "x", "z"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,14 +51,23 @@ public class ExpressionMask2D extends AbstractMask2D {
|
||||
* @param expression the expression
|
||||
*/
|
||||
public ExpressionMask2D(Expression expression) {
|
||||
this(expression, null);
|
||||
}
|
||||
|
||||
public ExpressionMask2D(Expression expression, @Nullable IntSupplier timeout) {
|
||||
checkNotNull(expression);
|
||||
this.expression = expression;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
try {
|
||||
return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0;
|
||||
if (timeout != null) {
|
||||
return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0;
|
||||
} else {
|
||||
return expression.evaluate(new double[]{vector.getX(), 0, vector.getZ()}, timeout.getAsInt()) > 0;
|
||||
}
|
||||
} catch (EvaluationException e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -55,33 +55,6 @@ public final class Masks {
|
||||
//<<<<<<< HEAD
|
||||
public static Mask negate(final Mask finalMask) {
|
||||
return finalMask.inverse();
|
||||
//=======
|
||||
// public static Mask negate(final Mask mask) {
|
||||
// if (mask instanceof AlwaysTrue) {
|
||||
// return ALWAYS_FALSE;
|
||||
// } else if (mask instanceof AlwaysFalse) {
|
||||
// return ALWAYS_TRUE;
|
||||
// }
|
||||
//
|
||||
// checkNotNull(mask);
|
||||
// return new AbstractMask() {
|
||||
// @Override
|
||||
// public boolean test(BlockVector3 vector) {
|
||||
// return !mask.test(vector);
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public Mask2D toMask2D() {
|
||||
// Mask2D mask2d = mask.toMask2D();
|
||||
// if (mask2d != null) {
|
||||
// return negate(mask2d);
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.operation;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Sets block from an iterator of {@link Map.Entry} containing a
|
||||
* {@link BlockVector} as the key and a {@link BaseBlock} as the value.
|
||||
*/
|
||||
public class BlockMapEntryPlacer implements Operation {
|
||||
|
||||
private final Extent extent;
|
||||
private final Iterator<Map.Entry<BlockVector3, BlockStateHolder>> iterator;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param extent the extent to set the blocks on
|
||||
* @param iterator the iterator
|
||||
*/
|
||||
public BlockMapEntryPlacer(Extent extent, Iterator<Map.Entry<BlockVector3, BlockStateHolder>> iterator) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(iterator);
|
||||
this.extent = extent;
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<BlockVector3, BlockStateHolder> entry = iterator.next();
|
||||
extent.setBlock(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
}
|
||||
|
||||
}
|
@ -53,4 +53,4 @@ public class SetLocatedBlocks implements Operation {
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public abstract class AbstractExtentPattern extends AbstractPattern implements ExtentPattern {
|
||||
|
||||
private final Extent extent;
|
||||
|
||||
public AbstractExtentPattern(Extent extent) {
|
||||
this.extent = extent;
|
||||
checkNotNull(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
}
|
@ -1,25 +1,12 @@
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A pattern that reads from {@link Clipboard}.
|
||||
*/
|
||||
public class ClipboardPattern extends AbstractPattern {
|
||||
|
||||
private final Clipboard clipboard;
|
||||
private final int sx, sy, sz;
|
||||
private final BlockVector3 min;
|
||||
// private final BlockVector3 size;
|
||||
public class ClipboardPattern extends RepeatingExtentPattern {
|
||||
|
||||
/**
|
||||
* Create a new clipboard pattern.
|
||||
@ -27,25 +14,16 @@ public class ClipboardPattern extends AbstractPattern {
|
||||
* @param clipboard the clipboard
|
||||
*/
|
||||
public ClipboardPattern(Clipboard clipboard) {
|
||||
checkNotNull(clipboard);
|
||||
this.clipboard = clipboard;
|
||||
BlockVector3 size = clipboard.getMaximumPoint().subtract(clipboard.getMinimumPoint()).add(1, 1, 1);
|
||||
this.sx = size.getBlockX();
|
||||
this.sy = size.getBlockY();
|
||||
this.sz = size.getBlockZ();
|
||||
this.min = clipboard.getMinimumPoint();
|
||||
this(clipboard, BlockVector3.ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
int xp = position.getBlockX() % sx;
|
||||
int yp = position.getBlockY() % sy;
|
||||
int zp = position.getBlockZ() % sz;
|
||||
if (xp < 0) xp += sx;
|
||||
if (yp < 0) yp += sy;
|
||||
if (zp < 0) zp += sz;
|
||||
return clipboard.getFullBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
|
||||
/**
|
||||
* Create a new clipboard pattern.
|
||||
*
|
||||
* @param clipboard the clipboard
|
||||
* @param offset the offset
|
||||
*/
|
||||
public ClipboardPattern(Clipboard clipboard, BlockVector3 offset) {
|
||||
super(clipboard, clipboard.getMinimumPoint(), offset);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.buffer.ExtentBuffer;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* A pattern that composes multiple patterns consecutively, ensuring that changes from one
|
||||
* pattern are realized by the subsequent one(s). For best results, use an {@link ExtentBuffer}
|
||||
* to avoid changing blocks in an underlying extent (e.g. the world).
|
||||
*/
|
||||
public class ExtentBufferedCompositePattern extends AbstractExtentPattern {
|
||||
|
||||
private final Pattern[] patterns;
|
||||
|
||||
/**
|
||||
* Construct a new instance of this pattern.
|
||||
*
|
||||
* <p>Note that all patterns passed which are ExtentPatterns should use the same extent as the one
|
||||
* passed to this constructor, or block changes may not be realized by those patterns.</p>
|
||||
*
|
||||
* @param extent the extent to buffer changes to
|
||||
* @param patterns the patterns to apply, in order
|
||||
*/
|
||||
public ExtentBufferedCompositePattern(Extent extent, Pattern... patterns) {
|
||||
super(extent);
|
||||
checkArgument(patterns.length != 0, "patterns cannot be empty");
|
||||
this.patterns = patterns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
BaseBlock lastBlock = null;
|
||||
for (Pattern pattern : patterns) {
|
||||
lastBlock = pattern.apply(position);
|
||||
try {
|
||||
getExtent().setBlock(position, lastBlock);
|
||||
} catch (WorldEditException ignored) { // buffer doesn't throw
|
||||
}
|
||||
}
|
||||
return lastBlock;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
public interface ExtentPattern extends Pattern {
|
||||
|
||||
/**
|
||||
* Get the extent associated with this pattern.
|
||||
*
|
||||
* @return the extent for this pattern
|
||||
*/
|
||||
public Extent getExtent();
|
||||
}
|
@ -19,14 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Link;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Return;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
@ -12,12 +12,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RandomStatePattern implements Pattern {
|
||||
|
||||
private final Random rand = new Random();
|
||||
private final List<BaseBlock> blocks;
|
||||
|
||||
public RandomStatePattern(FuzzyBlockState state) {
|
||||
blocks = state.getBlockType().getAllStates().stream().filter(state::equalsFuzzy)
|
||||
.map(BlockState::toBaseBlock).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
return blocks.get(rand.nextInt(blocks.size()));
|
||||
}
|
||||
}
|
@ -28,9 +28,10 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
/**
|
||||
* Returns the blocks from {@link Extent}, repeating when out of bounds.
|
||||
*/
|
||||
public class RepeatingExtentPattern extends AbstractPattern {
|
||||
public class RepeatingExtentPattern extends AbstractExtentPattern {
|
||||
|
||||
private Extent extent;
|
||||
private final BlockVector3 size;
|
||||
private BlockVector3 origin;
|
||||
private BlockVector3 offset;
|
||||
|
||||
/**
|
||||
@ -39,28 +40,11 @@ public class RepeatingExtentPattern extends AbstractPattern {
|
||||
* @param extent the extent
|
||||
* @param offset the offset
|
||||
*/
|
||||
public RepeatingExtentPattern(Extent extent, BlockVector3 offset) {
|
||||
setExtent(extent);
|
||||
public RepeatingExtentPattern(Extent extent, BlockVector3 origin, BlockVector3 offset) {
|
||||
super(extent);
|
||||
setOrigin(origin);
|
||||
setOffset(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent.
|
||||
*
|
||||
* @return the extent
|
||||
*/
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the extent.
|
||||
*
|
||||
* @param extent the extent
|
||||
*/
|
||||
public void setExtent(Extent extent) {
|
||||
checkNotNull(extent);
|
||||
this.extent = extent;
|
||||
size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,13 +66,31 @@ public class RepeatingExtentPattern extends AbstractPattern {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin.
|
||||
*
|
||||
* @return the origin
|
||||
*/
|
||||
public BlockVector3 getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the origin.
|
||||
*
|
||||
* @param origin the origin
|
||||
*/
|
||||
public void setOrigin(BlockVector3 origin) {
|
||||
checkNotNull(origin);
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
BlockVector3 base = position.add(offset);
|
||||
BlockVector3 size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
|
||||
int x = base.getBlockX() % size.getBlockX();
|
||||
int y = base.getBlockY() % size.getBlockY();
|
||||
int z = base.getBlockZ() % size.getBlockZ();
|
||||
return extent.getFullBlock(BlockVector3.at(x, y, z));
|
||||
int x = Math.abs(base.getBlockX()) % size.getBlockX();
|
||||
int y = Math.abs(base.getBlockY()) % size.getBlockY();
|
||||
int z = Math.abs(base.getBlockZ()) % size.getBlockZ();
|
||||
return getExtent().getFullBlock(BlockVector3.at(x, y, z).add(origin));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.sk89q.worldedit.blocks.Blocks.resolveProperties;
|
||||
|
||||
public class StateApplyingPattern extends AbstractExtentPattern {
|
||||
|
||||
private final Map<String, String> states;
|
||||
private Map<BlockType, Map<Property<Object>, Object>> cache = Maps.newHashMap();
|
||||
|
||||
public StateApplyingPattern(Extent extent, Map<String, String> statesToSet) {
|
||||
super(extent);
|
||||
this.states = statesToSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
BlockState block = getExtent().getBlock(position);
|
||||
for (Entry<Property<Object>, Object> entry : cache
|
||||
.computeIfAbsent(block.getBlockType(), (b -> resolveProperties(states, b))).entrySet()) {
|
||||
block = block.with(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return block.toBaseBlock();
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Applies a block type while retaining all possible states.
|
||||
*/
|
||||
public class TypeApplyingPattern extends AbstractExtentPattern {
|
||||
private final BlockState blockState;
|
||||
|
||||
public TypeApplyingPattern(Extent extent, BlockState blockState) {
|
||||
super(extent);
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
BlockState oldBlock = getExtent().getBlock(position);
|
||||
BlockState newBlock = blockState;
|
||||
for (Entry<Property<?>, Object> entry : oldBlock.getStates().entrySet()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> prop = (Property<Object>) entry.getKey();
|
||||
newBlock = newBlock.with(prop, entry.getValue());
|
||||
}
|
||||
return newBlock.toBaseBlock();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
/**
|
||||
* Removes the waterlogged state from blocks if possible. If not possible, returns air.
|
||||
*/
|
||||
public class WaterloggedRemover extends AbstractExtentPattern {
|
||||
|
||||
public WaterloggedRemover(Extent extent) {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
BaseBlock block = getExtent().getFullBlock(position);
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> prop = (Property<Object>) block.getBlockType().getPropertyMap().getOrDefault("waterlogged", null);
|
||||
if (prop != null) {
|
||||
return block.with(prop, false);
|
||||
}
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.FlatRegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
/**
|
||||
* Offsets the position parameter by adding a given offset vector.
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
/**
|
||||
* Offsets the position parameter by adding a given offset vector.
|
||||
|
@ -264,17 +264,6 @@ public abstract class BreadthFirstSearch implements Operation {
|
||||
}
|
||||
}
|
||||
}
|
||||
//=======
|
||||
// BlockVector3 position;
|
||||
//
|
||||
// while ((position = queue.poll()) != null) {
|
||||
// if (function.apply(position)) {
|
||||
// affected++;
|
||||
// }
|
||||
//
|
||||
// for (BlockVector3 dir : directions) {
|
||||
// visit(position, position.add(dir));
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
}
|
||||
if (currentDepth == maxDepth) {
|
||||
break;
|
||||
|
@ -32,7 +32,6 @@ import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.Vector2;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
import java.util.List;
|
||||
|
||||
@ -81,7 +80,6 @@ public class FlatRegionVisitor implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
//<<<<<<< HEAD
|
||||
public Operation resume(final RunContext run) throws WorldEditException {
|
||||
if (this.queue != null) {
|
||||
for (final BlockVector2 pt : new Fast2DIterator(this.iterator, queue)) {
|
||||
@ -90,12 +88,6 @@ public class FlatRegionVisitor implements Operation {
|
||||
} else {
|
||||
for (final BlockVector2 pt : this.iterator) {
|
||||
if (this.function.apply(pt)) affected++;
|
||||
//=======
|
||||
// public Operation resume(RunContext run) throws WorldEditException {
|
||||
// for (BlockVector2 pt : flatRegion.asFlatRegion()) {
|
||||
// if (function.apply(pt)) {
|
||||
// affected++;
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -103,7 +103,7 @@ public class LayerVisitor implements Operation {
|
||||
|
||||
// Abort if we are underground
|
||||
if (function.isGround(column.toBlockVector3(maxY + 1))) {
|
||||
return null;
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
|
@ -26,9 +26,6 @@ import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An implementation of an {@link BreadthFirstSearch} that uses a mask to
|
||||
* determine where a block should be visited.
|
||||
|
Reference in New Issue
Block a user