Search in sources :

Example 16 with BiomeType

use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method makeBiomeShape.

public int makeBiomeShape(final Region region, final Vector3 zero, final Vector3 unit, final BiomeType biomeType, final String expressionString, final boolean hollow, final int timeout) throws ExpressionException {
    final Expression expression = Expression.compile(expressionString, "x", "y", "z");
    expression.optimize();
    final EditSession editSession = this;
    final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(editSession, unit, zero);
    expression.setEnvironment(environment);
    AtomicInteger timedOut = new AtomicInteger();
    final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {

        @Override
        protected BiomeType getBiome(int x, int y, int z, BiomeType defaultBiomeType) {
            environment.setCurrentBlock(x, y, z);
            double scaledX = (x - zero.getX()) / unit.getX();
            double scaledY = (y - zero.getY()) / unit.getY();
            double scaledZ = (z - zero.getZ()) / unit.getZ();
            try {
                if (expression.evaluate(new double[] { scaledX, scaledY, scaledZ }, timeout) <= 0) {
                    return null;
                }
                // TODO: Allow biome setting via a script variable (needs BiomeType<->int mapping)
                return defaultBiomeType;
            } catch (ExpressionTimeoutException e) {
                timedOut.getAndIncrement();
                return null;
            } catch (Exception e) {
                LOGGER.warn("Failed to create shape", e);
                return null;
            }
        }
    };
    int changed = shape.generate(this, biomeType, hollow);
    if (timedOut.get() > 0) {
        throw new ExpressionTimeoutException(String.format("%d biomes changed. %d biomes took too long to evaluate (increase time with //timeout)", changed, timedOut.get()));
    }
    return changed;
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType) WorldEditExpressionEnvironment(com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment) Expression(com.sk89q.worldedit.internal.expression.Expression) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArbitraryBiomeShape(com.sk89q.worldedit.regions.shape.ArbitraryBiomeShape) ExpressionTimeoutException(com.sk89q.worldedit.internal.expression.ExpressionTimeoutException) ExpressionException(com.sk89q.worldedit.internal.expression.ExpressionException) EvaluationException(com.sk89q.worldedit.internal.expression.EvaluationException) IOException(java.io.IOException) ExpressionTimeoutException(com.sk89q.worldedit.internal.expression.ExpressionTimeoutException)

Example 17 with BiomeType

use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.

the class ChangeSetExtent method setBiome.

@Override
public boolean setBiome(BlockVector3 position, BiomeType biome) {
    BiomeType previous = getBiome(position);
    changeSet.add(new BiomeChange3D(position, previous, biome));
    return super.setBiome(position, biome);
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BiomeChange3D(com.sk89q.worldedit.history.change.BiomeChange3D)

Example 18 with BiomeType

use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.

the class ExtentBiomeCopy method apply.

@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
    BiomeType biome = source.getBiome(position);
    BlockVector3 orig = position.subtract(from);
    BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint().add(to);
    return destination.setBiome(transformed, biome);
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Aggregations

BiomeType (com.sk89q.worldedit.world.biome.BiomeType)18 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)10 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 IOException (java.io.IOException)4 CompoundTag (com.sk89q.jnbt.CompoundTag)3 EditSession (com.sk89q.worldedit.EditSession)3 Region (com.sk89q.worldedit.regions.Region)3 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)2 IntArrayTag (com.sk89q.jnbt.IntArrayTag)2 IntTag (com.sk89q.jnbt.IntTag)2 ListTag (com.sk89q.jnbt.ListTag)2 ShortTag (com.sk89q.jnbt.ShortTag)2 StringTag (com.sk89q.jnbt.StringTag)2 Tag (com.sk89q.jnbt.Tag)2 WorldEditException (com.sk89q.worldedit.WorldEditException)2 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2