Search in sources :

Example 11 with BiomeType

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

the class Regenerator method copyToWorld.

private void copyToWorld() {
    // Setting Blocks
    boolean genbiomes = options.shouldRegenBiomes();
    boolean hasBiome = options.hasBiomeType();
    BiomeType biome = options.getBiomeType();
    if (!genbiomes && !hasBiome) {
        target.setBlocks(region, new PlacementPattern());
    }
    if (hasBiome) {
        target.setBlocks(region, new WithBiomePlacementPattern(ignored -> biome));
    } else if (genbiomes) {
        target.setBlocks(region, new WithBiomePlacementPattern(vec -> source.getBiome(vec)));
    }
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Arrays(java.util.Arrays) SingleThreadQueueExtent(com.fastasyncworldedit.core.queue.implementation.SingleThreadQueueExtent) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Future(java.util.concurrent.Future) WorldEditException(com.sk89q.worldedit.WorldEditException) RegenOptions(com.sk89q.worldedit.world.RegenOptions) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) Region(com.sk89q.worldedit.regions.Region) ExecutorService(java.util.concurrent.ExecutorService) BlockPopulator(org.bukkit.generator.BlockPopulator) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) LogManagerCompat(com.sk89q.worldedit.internal.util.LogManagerCompat) Iterator(java.util.Iterator) IChunkCache(com.fastasyncworldedit.core.queue.IChunkCache) Settings(com.fastasyncworldedit.core.configuration.Settings) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) MathMan(com.fastasyncworldedit.core.util.MathMan) List(java.util.List) Logger(org.apache.logging.log4j.Logger) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Comparator(java.util.Comparator) Pattern(com.sk89q.worldedit.function.pattern.Pattern) IChunkGet(com.fastasyncworldedit.core.queue.IChunkGet) Extent(com.sk89q.worldedit.extent.Extent) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BiomeType(com.sk89q.worldedit.world.biome.BiomeType)

Example 12 with BiomeType

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

the class BiomePatternParser method parseFromInput.

// overridden to provide $<biome> too
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    if (input.startsWith(BIOME_PREFIX)) {
        String biomeId = input.substring(1);
        BiomeType biomeType = BiomeTypes.get(biomeId);
        if (biomeType == null) {
            throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(biomeId)));
        }
        return new BiomeApplyingPattern(context.requireExtent(), biomeType);
    } else {
        return super.parseFromInput(input, context);
    }
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BiomeApplyingPattern(com.fastasyncworldedit.core.function.pattern.BiomeApplyingPattern) NoMatchException(com.sk89q.worldedit.extension.input.NoMatchException)

Example 13 with BiomeType

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

the class FastSchematicWriter method writeBiomes.

private void writeBiomes(Clipboard clipboard, NBTOutputStream out) throws IOException {
    ByteArrayOutputStream biomesCompressed = new ByteArrayOutputStream();
    DataOutputStream biomesOut = new DataOutputStream(new LZ4BlockOutputStream(biomesCompressed));
    List<Integer> paletteList = new ArrayList<>();
    int[] palette = new int[BiomeTypes.getMaxId() + 1];
    Arrays.fill(palette, Integer.MAX_VALUE);
    int[] paletteMax = { 0 };
    IntValueReader task = new IntValueReader() {

        @Override
        public void applyInt(int index, int ordinal) {
            try {
                int value = palette[ordinal];
                if (value == Integer.MAX_VALUE) {
                    int size = paletteMax[0]++;
                    palette[ordinal] = value = size;
                    paletteList.add(ordinal);
                }
                IOUtil.writeVarInt(biomesOut, value);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    BlockVector3 min = clipboard.getMinimumPoint();
    int width = clipboard.getRegion().getWidth();
    int length = clipboard.getRegion().getLength();
    MutableBlockVector3 mutable = new MutableBlockVector3();
    for (int z = 0, i = 0; z < length; z++) {
        int z0 = min.getBlockZ() + z;
        for (int x = 0; x < width; x++, i++) {
            int x0 = min.getBlockX() + x;
            BiomeType biome = clipboard.getBiome(mutable.setComponents(x0, min.getY(), z0));
            task.applyInt(i, biome.getInternalId());
        }
    }
    biomesOut.close();
    out.writeNamedTag("BiomePaletteMax", paletteMax[0]);
    out.writeLazyCompoundTag("BiomePalette", out12 -> {
        for (int i = 0; i < paletteList.size(); i++) {
            int ordinal = paletteList.get(i);
            BiomeType state = BiomeTypes.get(ordinal);
            out12.writeNamedTag(state.getId(), i);
        }
    });
    out.writeNamedTagName("BiomeData", NBTConstants.TYPE_BYTE_ARRAY);
    out.writeInt(biomesOut.size());
    try (LZ4BlockInputStream in = new LZ4BlockInputStream(new ByteArrayInputStream(biomesCompressed.toByteArray()))) {
        IOUtil.copy(in, (DataOutput) out);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) LZ4BlockOutputStream(net.jpountz.lz4.LZ4BlockOutputStream) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) ByteArrayInputStream(java.io.ByteArrayInputStream) IntValueReader(com.fastasyncworldedit.core.jnbt.streamer.IntValueReader)

Example 14 with BiomeType

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

the class BiomeCommands method biomeInfo.

@Command(name = "biomeinfo", desc = "Get the biome of the targeted block.", descFooter = "By default, uses all blocks in your selection.")
@CommandPermissions("worldedit.biome.info")
public void biomeInfo(Actor actor, World world, LocalSession session, @Switch(name = 't', desc = "Use the block you are looking at.") boolean useLineOfSight, @Switch(name = 'p', desc = "Use the block you are currently in.") boolean usePosition) throws WorldEditException {
    BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
    Set<BiomeType> biomes = new HashSet<>();
    String messageKey;
    if (useLineOfSight) {
        if (actor instanceof Player) {
            Location blockPosition = ((Player) actor).getBlockTrace(300);
            if (blockPosition == null) {
                actor.print(Caption.of("worldedit.raytrace.noblock"));
                return;
            }
            BiomeType biome = world.getBiome(blockPosition.toVector().toBlockPoint());
            biomes.add(biome);
            messageKey = "worldedit.biomeinfo.lineofsight";
        } else {
            actor.print(Caption.of("worldedit.raytrace.require-player"));
            return;
        }
    } else if (usePosition) {
        if (actor instanceof Locatable) {
            BiomeType biome = world.getBiome(((Locatable) actor).getLocation().toVector().toBlockPoint());
            biomes.add(biome);
            messageKey = "worldedit.biomeinfo.position";
        } else {
            actor.print(Caption.of("worldedit.biomeinfo.not-locatable"));
            return;
        }
    } else {
        Region region = session.getSelection(world);
        for (BlockVector3 pt : region) {
            biomes.add(world.getBiome(pt));
        }
        messageKey = "worldedit.biomeinfo.selection";
    }
    List<Component> components = biomes.stream().map(biome -> biomeRegistry.getRichName(biome).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId())))).collect(Collectors.toList());
    actor.print(Caption.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
}
Also used : EditSession(com.sk89q.worldedit.EditSession) WorldEditAsyncCommandBuilder(com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder) RegionFunction(com.sk89q.worldedit.function.RegionFunction) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Player(com.sk89q.worldedit.entity.Player) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) World(com.sk89q.worldedit.world.World) Switch(org.enginehub.piston.annotation.param.Switch) Caption(com.fastasyncworldedit.core.configuration.Caption) Logging(com.sk89q.worldedit.command.util.Logging) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) Arg(org.enginehub.piston.annotation.param.Arg) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Component(com.sk89q.worldedit.util.formatting.text.Component) HashSet(java.util.HashSet) Preload(com.sk89q.worldedit.command.util.annotation.Preload) WorldEditException(com.sk89q.worldedit.WorldEditException) CommandContainer(org.enginehub.piston.annotation.CommandContainer) TextUtils(com.sk89q.worldedit.util.formatting.component.TextUtils) Operations(com.sk89q.worldedit.function.operation.Operations) Location(com.sk89q.worldedit.util.Location) WorldEdit(com.sk89q.worldedit.WorldEdit) Region(com.sk89q.worldedit.regions.Region) BiomeRegistry(com.sk89q.worldedit.world.registry.BiomeRegistry) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Locatable(com.sk89q.worldedit.extension.platform.Locatable) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Set(java.util.Set) REGION(com.sk89q.worldedit.command.util.Logging.LogMode.REGION) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) Collectors(java.util.stream.Collectors) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) Actor(com.sk89q.worldedit.extension.platform.Actor) List(java.util.List) Command(org.enginehub.piston.annotation.Command) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) Capability(com.sk89q.worldedit.extension.platform.Capability) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) LocalSession(com.sk89q.worldedit.LocalSession) Mask(com.sk89q.worldedit.function.mask.Mask) BiomeReplace(com.sk89q.worldedit.function.biome.BiomeReplace) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) Player(com.sk89q.worldedit.entity.Player) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BiomeRegistry(com.sk89q.worldedit.world.registry.BiomeRegistry) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) HashSet(java.util.HashSet) Location(com.sk89q.worldedit.util.Location) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 15 with BiomeType

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

the class ArbitraryBiomeShape method isInsideCached.

// FAWE start
private boolean isInsideCached(int x, int y, int z, BiomeType baseBiome) {
    final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
    final BiomeType cacheEntry = cache[index];
    if (cacheEntry == null) {
        // unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
        return getBiomeCached(x, y, z, baseBiome) != null;
    }
    return cacheEntry != BiomeTypes.THE_VOID;
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType)

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