Java Code Examples for com.sk89q.worldedit.extent.Extent#getBlock()

The following examples show how to use com.sk89q.worldedit.extent.Extent#getBlock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DesaturatePattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    TextureUtil util = holder.getTextureUtil();
    int color = util.getColor(block);
    int r = (color >> 16) & 0xFF;
    int g = (color >> 8) & 0xFF;
    int b = (color >> 0) & 0xFF;
    int alpha = (color >> 24) & 0xFF;
    double l = 0.3f * r + 0.6f * g + 0.1f * b;
    int red = (int) (r + value * (l - r));
    int green = (int) (g + value * (l - g));
    int blue = (int) (b + value * (l - b));
    int newColor = (alpha << 24) + (red << 16) + (green << 8) + (blue << 0);
    if (newColor == color) {
        return false;
    }
    BaseBlock newBlock = util.getNextNearestBlock(newColor);
    if (block.equals(newBlock)) {
        return false;
    }
    return extent.setBlock(setPosition, newBlock);
}
 
Example 2
Source File: AverageColorPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    TextureUtil util = holder.getTextureUtil();
    int currentColor = util.getColor(block);
    if (currentColor == 0) return false;
    int newColor = util.averageColor(currentColor, color);
    BaseBlock newBlock = util.getNearestBlock(newColor);
    if (newBlock.equals(block)) return false;
    return extent.setBlock(setPosition, newBlock);
}
 
Example 3
Source File: SaturatePattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    TextureUtil util = holder.getTextureUtil();
    int currentColor = util.getColor(block);
    if (currentColor == 0) return false;
    int newColor = util.multiplyColor(currentColor, color);
    BaseBlock newBlock = util.getNearestBlock(newColor);
    if (newBlock.equals(block)) return false;
    return extent.setBlock(setPosition, newBlock);
}
 
Example 4
Source File: AngleColorPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    int slope = getSlope(block, getPosition);
    if (slope == -1) return false;
    int color = util.getTextureUtil().getColor(block);
    if (color == 0) return false;
    int newColor = getColor(color, slope);
    BaseBlock newBlock = util.getTextureUtil().getNearestBlock(newColor);
    if (newBlock == null) return false;
    return extent.setBlock(setPosition, newBlock);
}
 
Example 5
Source File: DataAnglePattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    int slope = getSlope(block, getPosition);
    if (slope == -1) return false;
    int data = (Math.min(slope, 255)) >> 4;
    return extent.setBlock(setPosition, FaweCache.getBlock(block.getId(), data));
}