Search in sources :

Example 1 with MapDecoration

use of org.spongepowered.api.map.decoration.MapDecoration in project SpongeCommon by SpongePowered.

the class MapTest method addNamedDecoration.

private CommandResult addNamedDecoration(final CommandContext ctx) throws CommandException {
    final Player player = this.requirePlayer(ctx);
    final ItemStack heldMap = player.itemInHand(HandTypes.MAIN_HAND);
    if (heldMap.type() != ItemTypes.FILLED_MAP.get()) {
        throw new CommandException(Component.text("You must hold a map in your hand"));
    }
    final MapDecoration decoration = MapDecoration.builder().type(MapDecorationTypes.BANNER_BLUE).customName(Component.text("I AM A ").color(NamedTextColor.BLUE).append(BlockTypes.BLUE_BANNER.get())).rotation(MapDecorationOrientations.NORTH).build();
    heldMap.require(Keys.MAP_INFO).offer(Keys.MAP_DECORATIONS, Sets.newHashSet(decoration));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MapDecoration(org.spongepowered.api.map.decoration.MapDecoration) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 2 with MapDecoration

use of org.spongepowered.api.map.decoration.MapDecoration in project SpongeCommon by SpongePowered.

the class MapTest method randomDecorations.

private CommandResult randomDecorations(final CommandContext ctx) throws CommandException {
    final Player player = this.requirePlayer(ctx);
    final ItemStack heldMap = player.itemInHand(HandTypes.MAIN_HAND);
    if (heldMap.type() != ItemTypes.FILLED_MAP.get()) {
        throw new CommandException(Component.text("You must hold a map in your hand"));
    }
    player.sendMessage(Component.text("Getting mapInfo"));
    final MapInfo mapInfo = heldMap.require(Keys.MAP_INFO);
    mapInfo.offer(Keys.MAP_TRACKS_PLAYERS, true);
    final Set<MapDecoration> decorations = new HashSet<>();
    int x = Byte.MIN_VALUE;
    int y = Byte.MIN_VALUE;
    final List<MapDecorationType> types = RegistryTypes.MAP_DECORATION_TYPE.get().stream().collect(Collectors.toList());
    final Collection<MapDecorationOrientation> orientations = Sponge.game().registry(RegistryTypes.MAP_DECORATION_ORIENTATION).stream().collect(Collectors.toList());
    player.sendMessage(Component.text("Number of orientations: " + orientations.size()));
    player.sendMessage(Component.text("EAST: " + MapDecorationOrientations.EAST.get().key(RegistryTypes.MAP_DECORATION_ORIENTATION).toString()));
    for (final MapDecorationOrientation dir : orientations) {
        decorations.add(MapDecoration.builder().type(types.get(player.random().nextInt(types.size()))).rotation(dir).position(Vector2i.from(x, y)).build());
        player.sendMessage(Component.text(dir.key(RegistryTypes.MAP_DECORATION_ORIENTATION).value()).append(Component.text("x: " + x)).append(Component.text("y: " + y)));
        x += 16;
        if (x > Byte.MAX_VALUE) {
            y += 16;
            x = Byte.MIN_VALUE;
            if (y > Byte.MAX_VALUE) {
                player.sendMessage(Component.text("out of room, stopping"));
                mapInfo.offer(Keys.MAP_DECORATIONS, decorations);
                return CommandResult.success();
            }
        }
    }
    mapInfo.offer(Keys.MAP_DECORATIONS, decorations);
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MapDecorationOrientation(org.spongepowered.api.map.decoration.orientation.MapDecorationOrientation) MapInfo(org.spongepowered.api.map.MapInfo) MapDecoration(org.spongepowered.api.map.decoration.MapDecoration) MapDecorationType(org.spongepowered.api.map.decoration.MapDecorationType) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack) HashSet(java.util.HashSet)

Example 3 with MapDecoration

use of org.spongepowered.api.map.decoration.MapDecoration in project SpongeCommon by SpongePowered.

the class SpongeMapDecorationBuilder method build.

@Override
public MapDecoration build() throws IllegalStateException {
    Objects.requireNonNull(this.type, "Type has not been set");
    final MapDecoration decoration = (MapDecoration) new net.minecraft.world.level.saveddata.maps.MapDecoration(((SpongeMapDecorationType) this.type).getType(), (byte) this.x, (byte) this.y, (byte) ((SpongeMapDecorationOrientation) this.rot).getOrientationNumber(), this.customName == null ? null : SpongeAdventure.asVanilla(this.customName));
    // Anything that comes out of this builder should be persistent
    ((MapDecorationBridge) decoration).bridge$setPersistent(true);
    return decoration;
}
Also used : MapDecoration(org.spongepowered.api.map.decoration.MapDecoration) MapDecorationBridge(org.spongepowered.common.bridge.world.storage.MapDecorationBridge)

Aggregations

MapDecoration (org.spongepowered.api.map.decoration.MapDecoration)3 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 HashSet (java.util.HashSet)1 MapInfo (org.spongepowered.api.map.MapInfo)1 MapDecorationType (org.spongepowered.api.map.decoration.MapDecorationType)1 MapDecorationOrientation (org.spongepowered.api.map.decoration.orientation.MapDecorationOrientation)1 MapDecorationBridge (org.spongepowered.common.bridge.world.storage.MapDecorationBridge)1