Search in sources :

Example 6 with PrimaryLevelDataBridge

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

the class SpongeWorldManager method postWorldLoad.

private CompletableFuture<ServerLevel> postWorldLoad(final ServerLevel world, final boolean blocking) {
    final PrimaryLevelData levelData = (PrimaryLevelData) world.getLevelData();
    final PrimaryLevelDataBridge levelBridge = (PrimaryLevelDataBridge) levelData;
    final boolean isDefaultWorld = this.isDefaultWorld((ResourceKey) (Object) world.dimension().location());
    if (isDefaultWorld || levelBridge.bridge$performsSpawnLogic()) {
        MinecraftServerAccessor.accessor$LOGGER().info("Preparing start region for world '{}' ({})", world.dimension().location(), RegistryTypes.WORLD_TYPE.get().valueKey((WorldType) world.dimensionType()));
        if (blocking) {
            this.loadSpawnChunks(world);
            // Chunk are generated
            return CompletableFuture.completedFuture(world);
        } else {
            // Chunks are NOT generated yet BUT will be when the future returns
            return this.loadSpawnChunksAsync(world);
        }
    }
    // Chunks are NOT generated AND will not generate unless prompted
    return CompletableFuture.completedFuture(world);
}
Also used : PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) WorldType(org.spongepowered.api.world.WorldType) JsonObject(com.google.gson.JsonObject) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)

Example 7 with PrimaryLevelDataBridge

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

the class ChunkMapMixin method impl$useSerializationBehaviorForChunkSave.

@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/storage/ChunkSerializer;write(Lnet/minecraft/server/level/ServerLevel;" + "Lnet/minecraft/world/level/chunk/ChunkAccess;)Lnet/minecraft/nbt/CompoundTag;"))
private CompoundTag impl$useSerializationBehaviorForChunkSave(final ServerLevel worldIn, final ChunkAccess chunkIn) {
    final PrimaryLevelDataBridge infoBridge = (PrimaryLevelDataBridge) this.level.getLevelData();
    final SerializationBehavior serializationBehavior = infoBridge.bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
    if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
        return ChunkSerializer.write(worldIn, chunkIn);
    }
    return null;
}
Also used : SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 8 with PrimaryLevelDataBridge

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

the class ChunkMapMixin method impl$useSerializationBehaviorForPOI.

@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;flush(Lnet/minecraft/world/level/ChunkPos;)V"))
private void impl$useSerializationBehaviorForPOI(final PoiManager pointOfInterestManager, final ChunkPos p_219112_1_) {
    final PrimaryLevelDataBridge infoBridge = (PrimaryLevelDataBridge) this.level.getLevelData();
    final SerializationBehavior serializationBehavior = infoBridge.bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
    if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
        pointOfInterestManager.flush(p_219112_1_);
    }
}
Also used : SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 9 with PrimaryLevelDataBridge

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

the class MinecraftServerMixin method saveAllChunks.

/**
 * @author Zidane - November, 24th 2020 - Minecraft 1.15
 * @reason To allow per-world auto-save tick intervals or disable auto-saving entirely
 */
@Overwrite
public boolean saveAllChunks(final boolean suppressLog, final boolean flush, final boolean isForced) {
    boolean var0 = false;
    for (final ServerLevel world : this.shadow$getAllLevels()) {
        final SerializationBehavior serializationBehavior = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
        final InheritableConfigHandle<WorldConfig> adapter = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter();
        // Sponge start - use our own config
        boolean log = adapter.get().world.logAutoSave;
        // by a command, save our configs
        if (!this.shadow$isRunning() || this.tickCount % 6000 == 0 || isForced) {
            ((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter().save();
        }
        final boolean canSaveAtAll = serializationBehavior != SerializationBehavior.NONE;
        // This world is set to not save of any time, no reason to check the auto-save/etc, skip it
        if (!canSaveAtAll) {
            continue;
        }
        // Only run auto-save skipping if the server is still running and the save is not forced
        if (this.bridge$performAutosaveChecks() && !isForced) {
            final int autoSaveInterval = adapter.get().world.autoSaveInterval;
            // Do not process properties or chunks if the world is not set to do so unless the server is shutting down
            if (autoSaveInterval <= 0 || serializationBehavior != SerializationBehavior.AUTOMATIC) {
                continue;
            }
            // Now check the interval vs the tick counter and skip it
            if (this.tickCount % autoSaveInterval != 0) {
                continue;
            }
        }
        if (log) {
            LOGGER.info("Saving chunks for level '{}'/{}", world, world.dimension().location());
        }
        world.save((ProgressListener) null, flush, world.noSave && !isForced);
        var0 = true;
    }
    // Save the usercache.json file every 10 minutes or if forced to
    if (isForced || this.tickCount % 6000 == 0) {
        // We want to save the username cache json, as we normally bypass it.
        ((GameProfileCacheBridge) this.profileCache).bridge$setCanSave(true);
        this.profileCache.save();
        ((GameProfileCacheBridge) this.profileCache).bridge$setCanSave(false);
    }
    return var0;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) GameProfileCacheBridge(org.spongepowered.common.bridge.server.players.GameProfileCacheBridge) WorldConfig(org.spongepowered.common.config.inheritable.WorldConfig) SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 10 with PrimaryLevelDataBridge

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

the class EntityMixin_EntityCollision method collision$initializeCollisionState.

@Override
public void collision$initializeCollisionState(final net.minecraft.world.level.Level world) {
    final InheritableConfigHandle<WorldConfig> worldConfigAdapter = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter();
    final ConfigHandle<CommonConfig> globalConfigAdapter = SpongeConfigs.getCommon();
    final EntityCollisionCategory.ModSubCategory worldCollMod = worldConfigAdapter.getOrCreateValue(s -> s.entityCollision.mods.get(this.entityCollision$key.namespace()), c -> {
        // TODO: save after populating?
        final EntityCollisionCategory.ModSubCategory globalCollision = new EntityCollisionCategory.ModSubCategory(this.entityCollision$key.namespace());
        c.entityCollision.mods.put(this.entityCollision$key.namespace(), globalCollision);
        globalCollision.entities.put(this.entityCollision$key.namespace(), this.collision$getMaxCollisions());
    }, worldConfigAdapter.get().entityCollision.autoPopulate);
    final EntityCollisionCategory worldCollCat = worldConfigAdapter.get().entityCollision;
    this.collision$setMaxCollisions(worldCollCat.maxEntitiesWithinAABB);
    boolean requiresSave = false;
    if (worldCollMod != null) {
        if (!worldCollMod.enabled) {
            this.collision$setMaxCollisions(-1);
            return;
        }
        // check mod overrides
        final Integer modCollisionMax = worldCollMod.entityDefault;
        if (modCollisionMax != null) {
            this.collision$setMaxCollisions(modCollisionMax);
        }
        Integer entityMaxCollision = null;
        if ((net.minecraft.world.entity.Entity) (Object) this instanceof ItemEntity) {
            // check if all items are overridden
            entityMaxCollision = worldCollMod.entities.get(this.entityCollision$key.value());
        }
        if (entityMaxCollision == null) {
            entityMaxCollision = worldCollMod.entities.get(this.entityCollision$key.value());
        }
        // entity overrides
        if (entityMaxCollision == null && worldCollCat.autoPopulate) {
            // TODO(zml): Populate better
            // globalCollMod.getEntityList().put(this.entityCollision$key.getValue(), this.collision$getMaxCollisions());
            requiresSave = true;
        } else if (entityMaxCollision != null) {
            this.collision$setMaxCollisions(entityMaxCollision);
        }
    }
    // don't bother saving for negative values
    if (this.collision$getMaxCollisions() <= 0) {
        return;
    }
    if (requiresSave) {
        globalConfigAdapter.save();
    }
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) WorldConfig(org.spongepowered.common.config.inheritable.WorldConfig) CommonConfig(org.spongepowered.common.applaunch.config.common.CommonConfig) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) EntityCollisionCategory(org.spongepowered.common.config.inheritable.EntityCollisionCategory)

Aggregations

PrimaryLevelDataBridge (org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)15 PrimaryLevelData (net.minecraft.world.level.storage.PrimaryLevelData)7 WorldConfig (org.spongepowered.common.config.inheritable.WorldConfig)6 ServerLevel (net.minecraft.server.level.ServerLevel)5 JsonObject (com.google.gson.JsonObject)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Level (net.minecraft.world.level.Level)4 LevelSettings (net.minecraft.world.level.LevelSettings)4 LevelStem (net.minecraft.world.level.dimension.LevelStem)4 LevelStorageSource (net.minecraft.world.level.storage.LevelStorageSource)4 WorldType (org.spongepowered.api.world.WorldType)4 MinecraftServerAccessor (org.spongepowered.common.accessor.server.MinecraftServerAccessor)4 PrimaryLevelDataAccessor (org.spongepowered.common.accessor.world.level.storage.PrimaryLevelDataAccessor)4 DynamicOps (com.mojang.serialization.DynamicOps)3 Map (java.util.Map)3 Tag (net.minecraft.nbt.Tag)3 ChunkProgressListener (net.minecraft.server.level.progress.ChunkProgressListener)3 Difficulty (net.minecraft.world.Difficulty)3 VillageSiege (net.minecraft.world.entity.ai.village.VillageSiege)3