Search in sources :

Example 1 with BiomeType

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

the class ArbitraryBiomeShape method generate.

/**
 * Generates the shape.
 *
 * @param editSession The EditSession to use.
 * @param baseBiome   The default biome type.
 * @param hollow      Specifies whether to generate a hollow shape.
 * @return number of affected blocks.
 */
public int generate(EditSession editSession, BiomeType baseBiome, boolean hollow) {
    int affected = 0;
    for (BlockVector3 position : getExtent()) {
        int x = position.getBlockX();
        int y = position.getBlockY();
        int z = position.getBlockZ();
        if (!hollow) {
            final BiomeType material = getBiome(x, y, z, baseBiome);
            if (material != null) {
                editSession.setBiome(position, material);
                ++affected;
            }
            continue;
        }
        final BiomeType material = getBiomeCached(x, y, z, baseBiome);
        if (material == null) {
            continue;
        }
        if (!shouldDraw(x, y, z, material)) {
            continue;
        }
        editSession.setBiome(position, material);
        ++affected;
    }
    return affected;
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 2 with BiomeType

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

the class ArbitraryBiomeShape method getBiomeCached.

private BiomeType getBiomeCached(int x, int y, int z, BiomeType baseBiome) {
    final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
    if (!isCached.get(index)) {
        final BiomeType material = getBiome(x, y, z, baseBiome);
        isCached.set(index);
        cache[index] = material;
        return material;
    }
    return cache[index];
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType)

Example 3 with BiomeType

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

the class PlotSetBiome method execute.

@Override
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
    final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
    checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.generatebiome"), TranslatableCaption.of("permission.no_plot_perms"));
    if (plot.getRunning() != 0) {
        player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
        return null;
    }
    checkTrue(args.length == 1, TranslatableCaption.of("commandconfig.command_syntax"), Templates.of("value", getUsage()));
    final Set<CuboidRegion> regions = plot.getRegions();
    BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
    Collection<BiomeType> knownBiomes = BiomeTypes.values();
    final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
    if (biome == null) {
        String biomes = StringMan.join(BiomeType.REGISTRY.values(), TranslatableCaption.of("blocklist.block_list_separator").getComponent(player));
        player.sendMessage(TranslatableCaption.of("biome.need_biome"));
        player.sendMessage(TranslatableCaption.of("commandconfig.subcommand_set_options_header"), Templates.of("values", biomes));
        return CompletableFuture.completedFuture(false);
    }
    confirm.run(this, () -> {
        if (plot.getRunning() != 0) {
            player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
            return;
        }
        plot.addRunning();
        TaskManager.taskManager().async(() -> {
            EditSession session = WorldEdit.getInstance().newEditSessionBuilder().world(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().getWorldName()))).checkMemory(false).allowedRegionsEverywhere().actor(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID()))).limitUnlimited().build();
            long seed = ThreadLocalRandom.current().nextLong();
            for (CuboidRegion region : regions) {
                session.regenerate(region, biome, seed);
            }
            session.flushQueue();
            plot.removeRunning();
        });
    }, null);
    return CompletableFuture.completedFuture(true);
}
Also used : BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BiomeRegistry(com.sk89q.worldedit.world.registry.BiomeRegistry) Plot(com.plotsquared.core.plot.Plot) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) EditSession(com.sk89q.worldedit.EditSession)

Example 4 with BiomeType

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

the class FaweDelegateRegionManager method handleClear.

public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager) {
    TaskManager.taskManager().async(() -> {
        synchronized (FaweDelegateRegionManager.class) {
            final HybridPlotWorld hybridPlotWorld = ((HybridPlotManager) manager).getHybridPlotWorld();
            World world = BukkitAdapter.adapt(getWorld(hybridPlotWorld.getWorldName()));
            EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
            if (!hybridPlotWorld.PLOT_SCHEMATIC || !Settings.Schematics.PASTE_ON_TOP) {
                final BlockType bedrock;
                final BlockType air = BlockTypes.AIR;
                if (hybridPlotWorld.PLOT_BEDROCK) {
                    bedrock = BlockTypes.BEDROCK;
                } else {
                    bedrock = air;
                }
                final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
                final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
                final BiomeType biome = hybridPlotWorld.getPlotBiome();
                BlockVector3 pos1 = plot.getBottomAbs().getBlockVector3();
                BlockVector3 pos2 = pos1.add(BlockVector3.at(hybridPlotWorld.PLOT_WIDTH - 1, hybridPlotWorld.getMaxGenHeight(), hybridPlotWorld.PLOT_WIDTH - 1));
                if (hybridPlotWorld.PLOT_BEDROCK) {
                    Region bedrockRegion = new CuboidRegion(pos1, pos2.withY(hybridPlotWorld.getMinGenHeight()));
                    editSession.setBlocks(bedrockRegion, bedrock);
                }
                Region fillingRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.getMinGenHeight() + 1), pos2.withY(hybridPlotWorld.PLOT_HEIGHT - 1));
                Region floorRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT), pos2.withY(hybridPlotWorld.PLOT_HEIGHT));
                Region airRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT + 1), pos2.withY(hybridPlotWorld.getMaxGenHeight()));
                editSession.setBlocks(fillingRegion, filling);
                editSession.setBlocks(floorRegion, plotfloor);
                editSession.setBlocks(airRegion, air);
            }
            if (hybridPlotWorld.PLOT_SCHEMATIC) {
                // We cannot reuse the editsession
                EditSession scheditsession = !Settings.Schematics.PASTE_ON_TOP ? editSession : WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
                File schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schem");
                if (!schematicFile.exists()) {
                    schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schematic");
                }
                BlockVector3 to = plot.getBottomAbs().getBlockVector3().withY(Settings.Schematics.PASTE_ON_TOP ? hybridPlotWorld.SCHEM_Y : hybridPlotWorld.getMinBuildHeight());
                try {
                    Clipboard clip = ClipboardFormats.findByFile(schematicFile).getReader(new FileInputStream(schematicFile)).read();
                    clip.paste(scheditsession, to, true, true, true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                // Be verbose in editsession flushing
                scheditsession.flushQueue();
            }
            editSession.flushQueue();
            FaweAPI.fixLighting(world, new CuboidRegion(plot.getBottomAbs().getBlockVector3(), plot.getTopAbs().getBlockVector3()), null, RelightMode.valueOf(com.fastasyncworldedit.core.configuration.Settings.settings().LIGHTING.MODE));
            if (whenDone != null) {
                TaskManager.taskManager().task(whenDone);
            }
        }
    });
    return true;
}
Also used : Pattern(com.sk89q.worldedit.function.pattern.Pattern) HybridPlotWorld(com.plotsquared.core.generator.HybridPlotWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) Bukkit.getWorld(org.bukkit.Bukkit.getWorld) HybridPlotWorld(com.plotsquared.core.generator.HybridPlotWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) FileInputStream(java.io.FileInputStream) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BlockType(com.sk89q.worldedit.world.block.BlockType) HybridPlotManager(com.plotsquared.core.generator.HybridPlotManager) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) File(java.io.File)

Example 5 with BiomeType

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

the class SpongeSchematicReader method readBiomes.

private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
    ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class);
    IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class);
    CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class);
    Map<Integer, BiomeType> palette = new HashMap<>();
    if (maxTag.getValue() != paletteTag.getValue().size()) {
        throw new IOException("Biome palette size does not match expected size.");
    }
    for (Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
        String key = palettePart.getKey();
        if (fixer != null) {
            key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
        }
        BiomeType biome = BiomeTypes.get(key);
        if (biome == null) {
            LOGGER.warn("Unknown biome type :" + key + " in palette. Are you missing a mod or using a schematic made in a newer version of Minecraft?");
        }
        Tag idTag = palettePart.getValue();
        if (!(idTag instanceof IntTag)) {
            throw new IOException("Biome mapped to non-Int tag.");
        }
        palette.put(((IntTag) idTag).getValue(), biome);
    }
    int width = clipboard.getDimensions().getX();
    byte[] biomes = dataTag.getValue();
    int biomeIndex = 0;
    int biomeJ = 0;
    int bVal;
    int varIntLength;
    BlockVector3 min = clipboard.getMinimumPoint();
    while (biomeJ < biomes.length) {
        bVal = 0;
        varIntLength = 0;
        while (true) {
            bVal |= (biomes[biomeJ] & 127) << (varIntLength++ * 7);
            if (varIntLength > 5) {
                throw new IOException("VarInt too big (probably corrupted data)");
            }
            if (((biomes[biomeJ] & 128) != 128)) {
                biomeJ++;
                break;
            }
            biomeJ++;
        }
        int z = biomeIndex / width;
        int x = biomeIndex % width;
        BiomeType type = palette.get(bVal);
        for (int y = 0; y < clipboard.getRegion().getHeight(); y++) {
            clipboard.setBiome(min.add(x, y, z), type);
        }
        biomeIndex++;
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) NamedTag(com.sk89q.jnbt.NamedTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag)

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