Search in sources :

Example 1 with MapDecorationOrientation

use of org.spongepowered.api.map.decoration.orientation.MapDecorationOrientation 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)

Aggregations

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