Search in sources :

Example 1 with MapColor

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();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MapCanvas(org.spongepowered.api.map.MapCanvas) MapShade(org.spongepowered.api.map.color.MapShade) MapInfo(org.spongepowered.api.map.MapInfo) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack) RegistryEntry(org.spongepowered.api.registry.RegistryEntry) MapColor(org.spongepowered.api.map.color.MapColor)

Example 2 with MapColor

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();
}
Also used : MapCanvas(org.spongepowered.api.map.MapCanvas) Color(java.awt.Color) MapColor(org.spongepowered.api.map.color.MapColor) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) MapColorType(org.spongepowered.api.map.color.MapColorType) MapColor(org.spongepowered.api.map.color.MapColor)

Example 3 with MapColor

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;
}
Also used : Color(java.awt.Color) MapColor(org.spongepowered.api.map.color.MapColor) BufferedImage(java.awt.image.BufferedImage) MapColor(org.spongepowered.api.map.color.MapColor)

Example 4 with MapColor

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();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MapInfo(org.spongepowered.api.map.MapInfo) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack) MapColor(org.spongepowered.api.map.color.MapColor)

Aggregations

MapColor (org.spongepowered.api.map.color.MapColor)4 Color (java.awt.Color)2 CommandException (org.spongepowered.api.command.exception.CommandException)2 Player (org.spongepowered.api.entity.living.player.Player)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 MapCanvas (org.spongepowered.api.map.MapCanvas)2 MapInfo (org.spongepowered.api.map.MapInfo)2 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)1 MapColorType (org.spongepowered.api.map.color.MapColorType)1 MapShade (org.spongepowered.api.map.color.MapShade)1 RegistryEntry (org.spongepowered.api.registry.RegistryEntry)1