Search in sources :

Example 1 with MapIndex

use of net.minecraft.world.level.saveddata.maps.MapIndex in project SpongeCommon by SpongePowered.

the class SpongeMapStorage method allMapInfos.

@Override
public Collection<MapInfo> allMapInfos() {
    final Set<MapInfo> mapInfos = new HashSet<>();
    final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
    final int highestId = ((MapIdTrackerBridge) defaultWorld.getDataStorage().computeIfAbsent(MapIndex::new, Constants.Map.MAP_INDEX_DATA_NAME)).bridge$getHighestMapId().orElse(-1);
    for (int i = 0; i <= highestId; i++) {
        @Nullable final MapInfo mapInfo = (MapInfo) defaultWorld.getMapData(Constants.Map.MAP_PREFIX + i);
        if (mapInfo == null) {
            SpongeCommon.logger().warn("Missing map with id: " + i);
            continue;
        }
        this.addMapInfo(mapInfo);
        mapInfos.add(mapInfo);
    }
    return mapInfos;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) MapInfo(org.spongepowered.api.map.MapInfo) MapIndex(net.minecraft.world.level.saveddata.maps.MapIndex) Nullable(org.checkerframework.checker.nullness.qual.Nullable) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 MapIndex (net.minecraft.world.level.saveddata.maps.MapIndex)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 MapInfo (org.spongepowered.api.map.MapInfo)1