Plex-FAWE/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/ArrayImageMask.java

26 lines
835 B
Java
Raw Normal View History

2019-11-02 11:13:42 +00:00
package com.boydti.fawe.beta.implementation.filter;
2019-05-12 13:32:04 +00:00
2019-11-02 11:13:42 +00:00
import com.boydti.fawe.beta.implementation.filter.block.FilterBlock;
2019-05-12 13:32:04 +00:00
import com.boydti.fawe.beta.FilterBlockMask;
import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom;
public class ArrayImageMask implements FilterBlockMask {
2019-08-06 15:28:12 +00:00
2019-07-25 19:09:12 +00:00
private final ThreadLocalRandom random;
2019-05-12 13:32:04 +00:00
private final boolean white;
2019-07-25 19:09:12 +00:00
private final BufferedImage image;
2019-05-12 13:32:04 +00:00
2019-07-25 19:09:12 +00:00
public ArrayImageMask(BufferedImage image, boolean white) {
this.image = image;
2019-05-12 13:32:04 +00:00
this.white = white;
2019-07-25 19:09:12 +00:00
this.random = ThreadLocalRandom.current();
2019-05-12 13:32:04 +00:00
}
2019-08-06 15:28:12 +00:00
2019-05-12 13:32:04 +00:00
@Override
public boolean applyBlock(FilterBlock block) {
2019-07-25 19:09:12 +00:00
int height = image.getRGB(block.getX(), block.getZ()) & 0xFF;
2019-08-06 15:28:12 +00:00
return height == 255 || height > 0 && !white && random.nextInt(256) <= height;
2019-05-12 13:32:04 +00:00
}
}