Search in sources :

Example 1 with MapDecorationBridge

use of org.spongepowered.common.bridge.world.storage.MapDecorationBridge 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)

Example 2 with MapDecorationBridge

use of org.spongepowered.common.bridge.world.storage.MapDecorationBridge in project SpongeCommon by SpongePowered.

the class MapItemSavedDataMixin method bridge$setDecorations.

@SuppressWarnings("SuspiciousMethodCalls")
@Override
public void bridge$setDecorations(final Set<org.spongepowered.api.map.decoration.MapDecoration> newDecorations) {
    this.decorations.clear();
    for (final org.spongepowered.api.map.decoration.MapDecoration decoration : newDecorations) {
        this.impl$addDecorationToDecorationsMapIfNotExists((MapDecoration) decoration);
    }
    for (final MapDecoration existingDecoration : this.decorations.values()) {
        if (!newDecorations.contains(existingDecoration)) {
            // Removed.
            ((MapDecorationBridge) existingDecoration).notifyRemovedFromMap((MapInfo) this);
            this.setDirty();
        }
    }
    if (newDecorations.isEmpty()) {
        ((SpongeDataHolderBridge) this).bridge$remove(Keys.MAP_DECORATIONS);
    } else {
        ((SpongeDataHolderBridge) this).bridge$offer(Keys.MAP_DECORATIONS, newDecorations);
    }
}
Also used : MapDecoration(net.minecraft.world.level.saveddata.maps.MapDecoration) MapDecorationBridge(org.spongepowered.common.bridge.world.storage.MapDecorationBridge) SpongeDataHolderBridge(org.spongepowered.common.bridge.data.SpongeDataHolderBridge)

Example 3 with MapDecorationBridge

use of org.spongepowered.common.bridge.world.storage.MapDecorationBridge in project SpongeCommon by SpongePowered.

the class MapItemSavedDataMixin method impl$addDecorationToDecorationsMapIfNotExists.

public void impl$addDecorationToDecorationsMapIfNotExists(final MapDecoration mapDecoration) {
    final MapDecorationBridge bridge = (MapDecorationBridge) mapDecoration;
    // Anything saved should be persistent so it can save next time too.
    bridge.bridge$setPersistent(true);
    if (this.decorations.containsKey(bridge.bridge$getKey())) {
        return;
    }
    ((MapDecorationBridge) mapDecoration).notifyAddedToMap((MapInfo) this);
    this.decorations.put(bridge.bridge$getKey(), mapDecoration);
    this.setDirty();
}
Also used : MapDecorationBridge(org.spongepowered.common.bridge.world.storage.MapDecorationBridge)

Aggregations

MapDecorationBridge (org.spongepowered.common.bridge.world.storage.MapDecorationBridge)3 MapDecoration (net.minecraft.world.level.saveddata.maps.MapDecoration)1 MapDecoration (org.spongepowered.api.map.decoration.MapDecoration)1 SpongeDataHolderBridge (org.spongepowered.common.bridge.data.SpongeDataHolderBridge)1