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