Search in sources :

Example 1 with MapShade

use of org.spongepowered.api.map.color.MapShade 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 MapShade

use of org.spongepowered.api.map.color.MapShade 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));
}
Also used : MapShade(org.spongepowered.api.map.color.MapShade) SpongeMapColor(org.spongepowered.common.map.color.SpongeMapColor) MapColorType(org.spongepowered.api.map.color.MapColorType)

Aggregations

MapShade (org.spongepowered.api.map.color.MapShade)2 CommandException (org.spongepowered.api.command.exception.CommandException)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 MapCanvas (org.spongepowered.api.map.MapCanvas)1 MapInfo (org.spongepowered.api.map.MapInfo)1 MapColor (org.spongepowered.api.map.color.MapColor)1 MapColorType (org.spongepowered.api.map.color.MapColorType)1 RegistryEntry (org.spongepowered.api.registry.RegistryEntry)1 SpongeMapColor (org.spongepowered.common.map.color.SpongeMapColor)1