use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.
the class LevelChunkMixin method impl$getValidatedUUID.
private Optional<UUID> impl$getValidatedUUID(final int key, final int ownerIndex) {
final PrimaryLevelDataBridge worldInfo = (PrimaryLevelDataBridge) this.level.getLevelData();
final UUID uuid = worldInfo.bridge$getUniqueIdForIndex(ownerIndex).orElse(null);
if (uuid != null) {
// Verify id is valid and not invalid
if (SpongeConfigs.getCommon().get().world.invalidLookupUuids.contains(uuid)) {
if (key <= Short.MAX_VALUE) {
this.impl$trackedShortBlockPositions.remove((short) key);
}
this.impl$trackedIntBlockPositions.remove(key);
return Optional.empty();
}
// player is not online, get or create user from storage
return Optional.of(uuid);
}
return Optional.empty();
}
use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.
the class LevelStemMixin method bridge$populateFromLevelData.
@Override
public void bridge$populateFromLevelData(final PrimaryLevelData levelData) {
final PrimaryLevelDataBridge levelDataBridge = (PrimaryLevelDataBridge) levelData;
this.impl$gameMode = (ResourceLocation) (Object) RegistryTypes.GAME_MODE.get().valueKey((GameMode) (Object) levelData.getGameType());
this.impl$difficulty = (ResourceLocation) (Object) RegistryTypes.DIFFICULTY.get().valueKey((Difficulty) (Object) levelData.getDifficulty());
this.impl$serializationBehavior = levelDataBridge.bridge$serializationBehavior().orElse(null);
this.impl$displayName = levelDataBridge.bridge$displayName().orElse(null);
this.impl$viewDistance = levelDataBridge.bridge$viewDistance().orElse(null);
this.impl$spawnPosition = new Vector3i(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn());
this.impl$loadOnStartup = levelDataBridge.bridge$loadOnStartup();
this.impl$performsSpawnLogic = levelDataBridge.bridge$performsSpawnLogic();
this.impl$hardcore = levelData.isHardcore();
this.impl$commands = levelData.getAllowCommands();
this.impl$pvp = levelDataBridge.bridge$pvp().orElse(null);
}
use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.
the class LevelStorageSourceMixin_Vanilla method impl$readSpongeLevelData.
@Redirect(method = "lambda$getLevelData$4", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelSettings;parse(Lcom/mojang/serialization/Dynamic;Lnet/minecraft/world/level/DataPackConfig;)Lnet/minecraft/world/level/LevelSettings;"), to = @At(value = "RETURN")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;parse(Lcom/mojang/serialization/Dynamic;Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/storage/LevelVersion;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/world/level/storage/PrimaryLevelData;"))
private static PrimaryLevelData impl$readSpongeLevelData(final Dynamic<Tag> p_237369_0_, final DataFixer p_237369_1_, final int p_237369_2_, final CompoundTag p_237369_3_, final LevelSettings p_237369_4_, final LevelVersion p_237369_5_, final WorldGenSettings p_237369_6_, final Lifecycle p_237369_7_) {
final PrimaryLevelData levelData = PrimaryLevelData.parse(p_237369_0_, p_237369_1_, p_237369_2_, p_237369_3_, p_237369_4_, p_237369_5_, p_237369_6_, p_237369_7_);
((PrimaryLevelDataBridge) levelData).bridge$readSpongeLevelData(LevelStorageSourceMixin_Vanilla.impl$spongeLevelData);
LevelStorageSourceMixin_Vanilla.impl$spongeLevelData = null;
return levelData;
}
use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.
the class SpongeWorldManager method loadProperties.
@Override
public CompletableFuture<Optional<ServerWorldProperties>> loadProperties(final ResourceKey key) {
final net.minecraft.resources.ResourceKey<Level> registryKey = SpongeWorldManager.createRegistryKey(Objects.requireNonNull(key, "key"));
if (this.worlds.get(registryKey) != null) {
return CompletableFuture.completedFuture(Optional.empty());
}
if (!this.worldExists(key)) {
return CompletableFuture.completedFuture(Optional.empty());
}
final boolean isVanillaWorld = this.isVanillaWorld(key);
final String directoryName = this.getDirectoryName(key);
final LevelStorageSource.LevelStorageAccess storageSource;
try {
if (isVanillaWorld) {
storageSource = LevelStorageSource.createDefault(this.defaultWorldDirectory).createAccess(directoryName);
} else {
storageSource = LevelStorageSource.createDefault(this.customWorldsDirectory).createAccess(key.namespace() + File.separator + key.value());
}
} catch (final IOException e) {
return FutureUtil.completedWithException(e);
}
final WorldData levelData;
try {
final PrimaryLevelData defaultLevelData = (PrimaryLevelData) this.server.getWorldData();
final LevelSettings defaultLevelSettings = ((PrimaryLevelDataAccessor) defaultLevelData).accessor$settings();
try {
levelData = storageSource.getDataTag((DynamicOps<Tag>) BootstrapProperties.worldSettingsAdapter, defaultLevelSettings.getDataPackConfig());
} catch (final Exception ex) {
return FutureUtil.completedWithException(ex);
}
} finally {
try {
storageSource.close();
} catch (final IOException ex) {
return FutureUtil.completedWithException(ex);
}
}
return this.loadTemplate(key).thenCompose(r -> {
r.ifPresent(template -> {
final LevelStem scratch = ((SpongeWorldTemplate) template).asDimension();
((PrimaryLevelDataBridge) levelData).bridge$populateFromDimension(scratch);
});
return CompletableFuture.completedFuture(Optional.of((ServerWorldProperties) levelData));
});
}
use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.
the class SpongeWorldManager method prepareWorld.
private ServerLevel prepareWorld(final ServerLevel world, final boolean isDebugGeneration) {
final boolean isDefaultWorld = Level.OVERWORLD.equals(world.dimension());
final PrimaryLevelData levelData = (PrimaryLevelData) world.getLevelData();
if (isDefaultWorld) {
// Initialize scoreboard data. This will hook to the ServerScoreboard, needs to be made multi-world aware
((MinecraftServerAccessor) this.server).accessor$readScoreboard(world.getDataStorage());
((MinecraftServerAccessor) this.server).accessor$commandStorage(new CommandStorage(world.getDataStorage()));
}
final boolean isInitialized = levelData.isInitialized();
SpongeCommon.post(SpongeEventFactory.createLoadWorldEvent(PhaseTracker.getCauseStackManager().currentCause(), (org.spongepowered.api.world.server.ServerWorld) world, isInitialized));
PlatformHooks.INSTANCE.getWorldHooks().postLoadWorld(world);
// Set the view distance back on it's self to trigger the logic
((PrimaryLevelDataBridge) world.getLevelData()).bridge$viewDistance().ifPresent(v -> ((PrimaryLevelDataBridge) world.getLevelData()).bridge$setViewDistance(v));
world.getWorldBorder().applySettings(levelData.getWorldBorder());
if (!isInitialized) {
try {
final boolean hasSpawnAlready = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$customSpawnPosition();
if (!hasSpawnAlready) {
if (isDefaultWorld || ((ServerWorldProperties) world.getLevelData()).performsSpawnLogic()) {
MinecraftServerAccessor.invoker$setInitialSpawn(world, levelData, levelData.worldGenSettings().generateBonusChest(), isDebugGeneration, !isDebugGeneration);
} else if (Level.END.equals(world.dimension())) {
((PrimaryLevelData) world.getLevelData()).setSpawn(ServerLevel.END_SPAWN_POINT, 0);
}
} else {
Features.BONUS_CHEST.place(world, world.getChunkSource().getGenerator(), world.random, new BlockPos(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn()));
}
levelData.setInitialized(true);
if (isDebugGeneration) {
((MinecraftServerAccessor) this.server).invoker$setupDebugLevel(levelData);
}
} catch (final Throwable throwable) {
final CrashReport crashReport = CrashReport.forThrowable(throwable, "Exception initializing world '" + world.dimension().location() + "'");
try {
world.fillReportDetails(crashReport);
} catch (final Throwable ignore) {
}
throw new ReportedException(crashReport);
}
levelData.setInitialized(true);
}
// Initialize PlayerData in PlayerList, add WorldBorder listener. We change the method in PlayerList to handle per-world border
this.server.getPlayerList().setLevel(world);
if (levelData.getCustomBossEvents() != null) {
((ServerLevelBridge) world).bridge$getBossBarManager().load(levelData.getCustomBossEvents());
}
return world;
}
Aggregations