use of org.spongepowered.api.map.color.MapColor in project SpongeCommon by SpongePowered.
the class MapTest method testMapShades.
private CommandResult testMapShades(final CommandContext ctx) throws CommandException {
final Player player = this.requirePlayer(ctx);
final Collection<RegistryEntry<MapShade>> mapShades = Sponge.game().registry(RegistryTypes.MAP_SHADE).streamEntries().collect(Collectors.toList());
for (final RegistryEntry<MapShade> entry : mapShades) {
final MapColor mapColor = MapColor.of(MapColorTypes.COLOR_GREEN.get(), entry.value());
final MapCanvas mapCanvas = MapCanvas.builder().paintAll(mapColor).build();
final MapInfo mapInfo = Sponge.server().mapStorage().createNewMapInfo().orElseThrow(() -> new CommandException(Component.text("Unable to create new map!")));
mapInfo.offer(Keys.MAP_LOCKED, true);
mapInfo.offer(Keys.MAP_CANVAS, mapCanvas);
final ItemStack itemStack = ItemStack.of(ItemTypes.FILLED_MAP);
itemStack.offer(Keys.MAP_INFO, mapInfo);
itemStack.offer(Keys.CUSTOM_NAME, Component.text(entry.key().formatted()));
player.inventory().primary().offer(itemStack);
}
return CommandResult.success();
}
use of org.spongepowered.api.map.color.MapColor 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();
}
use of org.spongepowered.api.map.color.MapColor in project SpongeCommon by SpongePowered.
the class SpongeMapByteCanvas method toImage.
@Override
public Image toImage(final Color color) {
final BufferedImage image = new BufferedImage(Constants.Map.MAP_PIXELS, Constants.Map.MAP_PIXELS, BufferedImage.TYPE_INT_ARGB);
int pos = 0;
for (int y = 0; y < Constants.Map.MAP_PIXELS; y++, pos += Constants.Map.MAP_PIXELS) {
for (int x = 0; x < Constants.Map.MAP_PIXELS; x++, pos++) {
final MapColor foundColor = this.color(x, y);
final Color paintColor = foundColor.type() == MapColorTypes.NONE.get() ? color : foundColor.color().asJavaColor();
image.setRGB(x, y, paintColor.getRGB());
}
}
return image;
}
use of org.spongepowered.api.map.color.MapColor in project SpongeCommon by SpongePowered.
the class MapTest method setColorAndLocked.
private CommandResult setColorAndLocked(final CommandContext ctx) throws CommandException {
final Player player = this.requirePlayer(ctx);
final ItemStack map = player.itemInHand(HandTypes.MAIN_HAND);
if (map.type() != ItemTypes.FILLED_MAP.get()) {
throw new CommandException(Component.text("You must hold a map in your hand"));
}
// map.offer(Keys.MAP_LOCATION, new Vector2i(10000,10000));
final MapColor color = MapColor.of(MapColorTypes.TERRACOTTA_BLACK);
final MapInfo mapInfo = map.require(Keys.MAP_INFO);
mapInfo.offer(Keys.MAP_LOCKED, true);
mapInfo.offer(Keys.MAP_CANVAS, MapCanvas.builder().paintAll(color).build());
player.sendMessage(Component.text(mapInfo.require(Keys.MAP_CANVAS).color(0, 0).toContainer().toString()));
return CommandResult.success();
}
Aggregations