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();
}
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));
}
Aggregations