use of org.spongepowered.api.map.color.MapColorType in project SpongeCommon by SpongePowered.
the class MapUtil method getMapColorFromPixelValue.
public static Optional<MapColor> getMapColorFromPixelValue(final byte value) {
final int intColor = Byte.toUnsignedInt(value);
final int shade = intColor % Constants.Map.MAP_SHADES;
final int colorIndex = (intColor - shade) / Constants.Map.MAP_SHADES;
final Optional<MapColorType> mapColorType = MapUtil.getMapColorTypeByColorIndex(colorIndex);
final MapShade mapShade = MapUtil.getMapShadeById(shade);
if (!mapColorType.isPresent()) {
return Optional.empty();
}
return Optional.of(new SpongeMapColor(mapColorType.get(), mapShade));
}
use of org.spongepowered.api.map.color.MapColorType in project SpongeCommon by SpongePowered.
the class MapTest method savePallete.
private CommandResult savePallete(final CommandContext ctx) {
final File file = new File("pallete.png");
try {
if (!file.isFile()) {
file.createNewFile();
}
final MapCanvas.Builder builder = MapCanvas.builder();
final List<MapColor[]> mapColors = new ArrayList<>();
for (final MapColorType mapColorType : Sponge.game().registry(RegistryTypes.MAP_COLOR_TYPE).stream().collect(Collectors.toList())) {
final MapColor[] colors = new MapColor[] { MapColor.of(mapColorType), MapColor.builder().baseColor(mapColorType).darkest().build(), MapColor.builder().baseColor(mapColorType).base().build(), MapColor.builder().baseColor(mapColorType).darkest().build() };
mapColors.add(colors);
}
int x = 0;
for (final MapColor[] colors : mapColors) {
int y = 0;
builder.paint(x, y, x, y, colors[0]);
y++;
builder.paint(x, y, x, y, colors[1]);
y++;
builder.paint(x, y, x, y, colors[2]);
y++;
builder.paint(x, y, x, y, colors[3]);
x++;
}
final MapCanvas canvas = builder.build();
final Color color = new Color(0, 0, 0, 0);
ImageIO.write((BufferedImage) canvas.toImage(color), "png", file);
} catch (final IOException e) {
Sponge.server().sendMessage(Component.text("IOException"));
}
return CommandResult.success();
}
Aggregations