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