Search in sources :

Example 6 with BlockType

use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.

the class SaturatePattern method applyBlock.

@Override
public BaseBlock applyBlock(BlockVector3 position) {
    BlockType type = extent.getBlock(position).getBlockType();
    TextureUtil util = holder.getTextureUtil();
    int currentColor;
    if (type == BlockTypes.GRASS_BLOCK) {
        currentColor = holder.getTextureUtil().getColor(extent.getBiome(position));
    } else {
        currentColor = holder.getTextureUtil().getColor(type);
    }
    int newColor = TextureUtil.multiplyColor(currentColor, color);
    return util.getNearestBlock(newColor).getDefaultState().toBaseBlock();
}
Also used : TextureUtil(com.fastasyncworldedit.core.util.TextureUtil) BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 7 with BlockType

use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.

the class GenerationCommands method image.

@Command(name = "/img", aliases = { "/image", "image" }, desc = "Generate an image")
@CommandPermissions("worldedit.generation.image")
@Logging(PLACEMENT)
public void image(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "Image URL (imgur only)") String imageURL, @Arg(desc = "boolean", def = "true") boolean randomize, @Arg(desc = "TODO", def = "100") int threshold, @Arg(desc = "BlockVector2", def = "") BlockVector2 dimensions) throws WorldEditException, IOException {
    TextureUtil tu = Fawe.instance().getCachedTextureUtil(randomize, 0, threshold);
    URL url = new URL(imageURL);
    if (!url.getHost().equalsIgnoreCase("i.imgur.com")) {
        throw new IOException("Only i.imgur.com links are allowed!");
    }
    BufferedImage image = MainUtil.readImage(url);
    if (dimensions != null) {
        image = ImageUtil.getScaledInstance(image, dimensions.getBlockX(), dimensions.getBlockZ(), RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
    }
    BlockVector3 pos1 = session.getPlacementPosition(actor);
    BlockVector3 pos2 = pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1);
    CuboidRegion region = new CuboidRegion(pos1, pos2);
    int[] count = new int[1];
    final BufferedImage finalImage = image;
    RegionVisitor visitor = new RegionVisitor(region, pos -> {
        int x = pos.getBlockX() - pos1.getBlockX();
        int z = pos.getBlockZ() - pos1.getBlockZ();
        int color = finalImage.getRGB(x, z);
        BlockType block = tu.getNearestBlock(color);
        count[0]++;
        if (block != null) {
            return editSession.setBlock(pos, block.getDefaultState());
        }
        return false;
    }, editSession);
    Operations.completeBlindly(visitor);
    actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
}
Also used : RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) TextureUtil(com.fastasyncworldedit.core.util.TextureUtil) BlockType(com.sk89q.worldedit.world.block.BlockType) IOException(java.io.IOException) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 8 with BlockType

use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.

the class SinglePickaxe method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    World world = (World) clicked.getExtent();
    BlockVector3 blockPoint = clicked.toBlockPoint();
    final BlockType blockType = world.getBlock(blockPoint).getBlockType();
    if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return false;
    }
    try (EditSession editSession = session.createEditSession(player)) {
        try {
            editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
            editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState());
        } catch (MaxChangedBlocksException e) {
            player.print(Caption.of("worldedit.tool.max-block-changes"));
        } finally {
            session.remember(editSession);
        }
    }
    return true;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) EditSession(com.sk89q.worldedit.EditSession) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 9 with BlockType

use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.

the class AreaPickaxe method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
    int ox = clicked.getBlockX();
    int oy = clicked.getBlockY();
    int oz = clicked.getBlockZ();
    BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType();
    if (initialType.getMaterial().isAir()) {
        return false;
    }
    if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return false;
    }
    try (EditSession editSession = session.createEditSession(player, "AreaPickaxe")) {
        editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
        int maxY = editSession.getMaxY();
        try {
            for (int x = ox - range; x <= ox + range; ++x) {
                for (int y = oy - range; y <= oy + range && y <= maxY; ++y) {
                    for (int z = oz - range; z <= oz + range; ++z) {
                        if (!initialType.equals(editSession.getBlock(x, y, z).getBlockType())) {
                            continue;
                        }
                        editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
                    }
                }
            }
            editSession.flushQueue();
        } catch (MaxChangedBlocksException e) {
            player.print(Caption.of("worldedit.tool.max-block-changes"));
        } finally {
            session.remember(editSession);
        }
    }
    return true;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) EditSession(com.sk89q.worldedit.EditSession) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 10 with BlockType

use of com.sk89q.worldedit.world.block.BlockType 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)

Aggregations

BlockType (com.sk89q.worldedit.world.block.BlockType)63 BlockState (com.sk89q.worldedit.world.block.BlockState)20 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)18 Map (java.util.Map)12 HashMap (java.util.HashMap)9 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)8 ArrayList (java.util.ArrayList)8 TextureUtil (com.fastasyncworldedit.core.util.TextureUtil)7 World (com.sk89q.worldedit.world.World)7 List (java.util.List)7 CompoundTag (com.sk89q.jnbt.CompoundTag)5 Tag (com.sk89q.jnbt.Tag)5 EditSession (com.sk89q.worldedit.EditSession)5 Property (com.sk89q.worldedit.registry.state.Property)5 Direction (com.sk89q.worldedit.util.Direction)5 IOException (java.io.IOException)5 Locale (java.util.Locale)5 Set (java.util.Set)5 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4