Search in sources :

Example 1 with TextureUtil

use of com.fastasyncworldedit.core.util.TextureUtil in project FastAsyncWorldEdit by IntellectualSites.

the class DesaturatePattern method applyBlock.

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

Example 2 with TextureUtil

use of com.fastasyncworldedit.core.util.TextureUtil 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 3 with TextureUtil

use of com.fastasyncworldedit.core.util.TextureUtil 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 4 with TextureUtil

use of com.fastasyncworldedit.core.util.TextureUtil in project FastAsyncWorldEdit by IntellectualSites.

the class Fawe method getCachedTextureUtil.

public TextureUtil getCachedTextureUtil(boolean randomize, int min, int max) {
    // TODO NOT IMPLEMENTED - optimize this by caching the default true/0/100 texture util
    TextureUtil tu = getTextureUtil();
    try {
        tu = min == 0 && max == 100 ? tu : new CleanTextureUtil(tu, min, max);
        tu = randomize ? new RandomTextureUtil(tu) : new CachedTextureUtil(tu);
    } catch (FileNotFoundException neverHappens) {
        neverHappens.printStackTrace();
    }
    return tu;
}
Also used : CleanTextureUtil(com.fastasyncworldedit.core.util.CleanTextureUtil) TextureUtil(com.fastasyncworldedit.core.util.TextureUtil) RandomTextureUtil(com.fastasyncworldedit.core.util.RandomTextureUtil) CachedTextureUtil(com.fastasyncworldedit.core.util.CachedTextureUtil) CachedTextureUtil(com.fastasyncworldedit.core.util.CachedTextureUtil) CleanTextureUtil(com.fastasyncworldedit.core.util.CleanTextureUtil) FileNotFoundException(java.io.FileNotFoundException) RandomTextureUtil(com.fastasyncworldedit.core.util.RandomTextureUtil)

Example 5 with TextureUtil

use of com.fastasyncworldedit.core.util.TextureUtil in project FastAsyncWorldEdit by IntellectualSites.

the class Fawe method getTextureUtil.

public TextureUtil getTextureUtil() {
    TextureUtil tmp = textures;
    if (tmp == null) {
        synchronized (this) {
            tmp = textures;
            if (tmp == null) {
                try {
                    textures = tmp = new TextureUtil();
                    tmp.loadModTextures();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return tmp;
}
Also used : CleanTextureUtil(com.fastasyncworldedit.core.util.CleanTextureUtil) TextureUtil(com.fastasyncworldedit.core.util.TextureUtil) RandomTextureUtil(com.fastasyncworldedit.core.util.RandomTextureUtil) CachedTextureUtil(com.fastasyncworldedit.core.util.CachedTextureUtil) IOException(java.io.IOException)

Aggregations

TextureUtil (com.fastasyncworldedit.core.util.TextureUtil)10 BlockType (com.sk89q.worldedit.world.block.BlockType)7 CachedTextureUtil (com.fastasyncworldedit.core.util.CachedTextureUtil)3 CleanTextureUtil (com.fastasyncworldedit.core.util.CleanTextureUtil)3 RandomTextureUtil (com.fastasyncworldedit.core.util.RandomTextureUtil)3 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 IOException (java.io.IOException)2 Command (org.enginehub.piston.annotation.Command)2 Logging (com.sk89q.worldedit.command.util.Logging)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 Mask (com.sk89q.worldedit.function.mask.Mask)1 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 BufferedImage (java.awt.image.BufferedImage)1 FileNotFoundException (java.io.FileNotFoundException)1 URL (java.net.URL)1