Search in sources :

Example 1 with SpongeMapStorage

use of org.spongepowered.common.map.SpongeMapStorage in project SpongeCommon by SpongePowered.

the class SpongeCommonEventFactory method fireCreateMapEvent.

public static Optional<MapInfo> fireCreateMapEvent(final Cause cause, final Set<Value<?>> values) {
    final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
    final MapIdTrackerBridge mapIdTrackerBridge = (MapIdTrackerBridge) defaultWorld.getDataStorage().computeIfAbsent(MapIndex::new, Constants.Map.MAP_INDEX_DATA_NAME);
    final int id = mapIdTrackerBridge.bridge$getHighestMapId().orElse(-1) + 1;
    final String s = Constants.Map.MAP_PREFIX + id;
    final MapItemSavedData mapData = new MapItemSavedData(s);
    // Set default to prevent NPEs
    mapData.dimension = Level.OVERWORLD;
    final MapInfo mapInfo = (MapInfo) mapData;
    for (final Value<?> value : values) {
        mapInfo.offer(value);
    }
    final CreateMapEvent event = SpongeEventFactory.createCreateMapEvent(cause, mapInfo);
    SpongeCommon.post(event);
    if (event.isCancelled()) {
        return Optional.empty();
    }
    // Advance map id.
    final int mcId = defaultWorld.getFreeMapId();
    if (id != mcId) {
        // TODO: REMOVE OR replace for Integer.MAX_VALUE
        SpongeCommon.logger().warn("Map size corruption, vanilla only allows " + Integer.MAX_VALUE + "! " + "Expected next number was not equal to the true next number.");
        SpongeCommon.logger().warn("Expected: " + id + ". Got: " + mcId);
        SpongeCommon.logger().warn("Automatically cancelling map creation");
        mapIdTrackerBridge.bridge$setHighestMapId(id - 1);
        return Optional.empty();
    }
    defaultWorld.setMapData(mapData);
    ((SpongeMapStorage) Sponge.server().mapStorage()).addMapInfo(mapInfo);
    return Optional.of(mapInfo);
}
Also used : MapIdTrackerBridge(org.spongepowered.common.bridge.map.MapIdTrackerBridge) ServerLevel(net.minecraft.server.level.ServerLevel) MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData) CreateMapEvent(org.spongepowered.api.event.action.CreateMapEvent) MapInfo(org.spongepowered.api.map.MapInfo) SpongeMapStorage(org.spongepowered.common.map.SpongeMapStorage)

Example 2 with SpongeMapStorage

use of org.spongepowered.common.map.SpongeMapStorage in project SpongeCommon by SpongePowered.

the class MinecraftServerMixin_API method api$initializeSpongeFields.

@Inject(method = "<init>", at = @At("TAIL"))
public void api$initializeSpongeFields(final Thread p_i232576_1_, final RegistryAccess.RegistryHolder p_i232576_2_, final LevelStorageSource.LevelStorageAccess p_i232576_3_, final WorldData p_i232576_4_, final PackRepository p_i232576_5_, final Proxy p_i232576_6_, final DataFixer p_i232576_7_, final ServerResources p_i232576_8_, final MinecraftSessionService p_i232576_9_, final GameProfileRepository p_i232576_10_, final GameProfileCache p_i232576_11_, final ChunkProgressListenerFactory p_i232576_12_, final CallbackInfo ci) {
    this.api$scheduler = new ServerScheduler();
    this.api$playerDataHandler = new SpongePlayerDataManager(this);
    this.api$teleportHelper = new SpongeTeleportHelper();
    this.api$mapStorage = new SpongeMapStorage();
    this.api$registryHolder = new RegistryHolderLogic(p_i232576_2_);
    this.api$userManager = new SpongeUserManager((MinecraftServer) (Object) this);
}
Also used : ServerScheduler(org.spongepowered.common.scheduler.ServerScheduler) SpongePlayerDataManager(org.spongepowered.common.world.storage.SpongePlayerDataManager) RegistryHolderLogic(org.spongepowered.common.registry.RegistryHolderLogic) SpongeUserManager(org.spongepowered.common.user.SpongeUserManager) SpongeTeleportHelper(org.spongepowered.common.world.teleport.SpongeTeleportHelper) SpongeMapStorage(org.spongepowered.common.map.SpongeMapStorage) MinecraftServer(net.minecraft.server.MinecraftServer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with SpongeMapStorage

use of org.spongepowered.common.map.SpongeMapStorage in project SpongeCommon by SpongePowered.

the class MapItemSavedDataMixin method impl$setMapId.

@Inject(method = "<init>", at = @At("RETURN"))
public void impl$setMapId(final String mapname, final CallbackInfo ci) {
    final int underscore = mapname.lastIndexOf('_');
    if (underscore != -1) {
        final String id = mapname.substring(underscore + 1);
        try {
            this.impl$mapId = Integer.parseInt(id);
            final SpongeMapStorage mapStorage = (SpongeMapStorage) Sponge.server().mapStorage();
            mapStorage.addMapInfo((MapInfo) this);
            this.impl$uuid = mapStorage.requestUUID(this.impl$mapId);
            return;
        } catch (final NumberFormatException e) {
        // ignored
        }
    }
    SpongeCommon.logger().error("Map id could not be got from map name, (" + mapname + ")");
}
Also used : SpongeMapStorage(org.spongepowered.common.map.SpongeMapStorage) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SpongeMapStorage (org.spongepowered.common.map.SpongeMapStorage)3 Inject (org.spongepowered.asm.mixin.injection.Inject)2 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 MapItemSavedData (net.minecraft.world.level.saveddata.maps.MapItemSavedData)1 CreateMapEvent (org.spongepowered.api.event.action.CreateMapEvent)1 MapInfo (org.spongepowered.api.map.MapInfo)1 MapIdTrackerBridge (org.spongepowered.common.bridge.map.MapIdTrackerBridge)1 RegistryHolderLogic (org.spongepowered.common.registry.RegistryHolderLogic)1 ServerScheduler (org.spongepowered.common.scheduler.ServerScheduler)1 SpongeUserManager (org.spongepowered.common.user.SpongeUserManager)1 SpongePlayerDataManager (org.spongepowered.common.world.storage.SpongePlayerDataManager)1 SpongeTeleportHelper (org.spongepowered.common.world.teleport.SpongeTeleportHelper)1