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