-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: reimplementation of async chunks on login
- Loading branch information
Showing
6 changed files
with
80 additions
and
347 deletions.
There are no files selected for viewing
19 changes: 0 additions & 19 deletions
19
.../com/ishland/vmp/common/chunk/loading/async_chunks_on_player_login/IAsyncChunkPlayer.java
This file was deleted.
Oops, something went wrong.
164 changes: 0 additions & 164 deletions
164
.../com/ishland/vmp/mixins/chunk/loading/async_chunk_on_player_login/MixinPlayerManager.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
...ins/chunk/loading/async_chunk_on_player_login/MixinServerConfigurationNetworkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.ishland.vmp.mixins.chunk.loading.async_chunk_on_player_login; | ||
|
||
import com.google.common.base.Stopwatch; | ||
import com.ishland.vmp.common.chunk.loading.async_chunks_on_player_login.AsyncChunkLoadUtil; | ||
import com.ishland.vmp.common.config.Config; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.mojang.authlib.GameProfile; | ||
import com.mojang.serialization.Dynamic; | ||
import net.minecraft.nbt.NbtOps; | ||
import net.minecraft.network.ClientConnection; | ||
import net.minecraft.network.listener.ServerConfigurationPacketListener; | ||
import net.minecraft.network.listener.TickablePacketListener; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.PlayerManager; | ||
import net.minecraft.server.network.ConnectedClientData; | ||
import net.minecraft.server.network.ServerCommonNetworkHandler; | ||
import net.minecraft.server.network.ServerConfigurationNetworkHandler; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.dimension.DimensionType; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(ServerConfigurationNetworkHandler.class) | ||
public abstract class MixinServerConfigurationNetworkHandler extends ServerCommonNetworkHandler implements ServerConfigurationPacketListener, TickablePacketListener { | ||
|
||
@Shadow @Final private static Logger LOGGER; | ||
|
||
@Shadow public abstract boolean isConnectionOpen(); | ||
|
||
@Shadow @Final private GameProfile profile; | ||
|
||
public MixinServerConfigurationNetworkHandler(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) { | ||
super(server, connection, clientData); | ||
} | ||
|
||
@WrapOperation(method = "onReady", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/server/network/ConnectedClientData;)V")) | ||
private void wrapOnPlayerConnect(PlayerManager instance, ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, Operation<Void> original) { | ||
RegistryKey<World> registryKey = instance.loadPlayerData(player) | ||
.flatMap(nbt -> DimensionType.worldFromDimensionNbt(new Dynamic<>(NbtOps.INSTANCE, nbt.get("Dimension"))).resultOrPartial(LOGGER::error)) | ||
.orElse(World.OVERWORLD); | ||
ServerWorld storedWorld = instance.getServer().getWorld(registryKey); | ||
ServerWorld actualWorld; | ||
if (storedWorld == null) { | ||
LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", registryKey); | ||
actualWorld = instance.getServer().getOverworld(); | ||
} else { | ||
actualWorld = storedWorld; | ||
} | ||
|
||
Stopwatch timing = Stopwatch.createStarted(); | ||
AsyncChunkLoadUtil.scheduleChunkLoad(actualWorld, new ChunkPos(player.getBlockPos())) | ||
.thenRunAsync(() -> { | ||
if (!this.isConnectionOpen()) { | ||
return; | ||
} | ||
|
||
if (instance.getPlayer(this.profile.getId()) != null) { | ||
this.disconnect(PlayerManager.DUPLICATE_LOGIN_TEXT); | ||
return; | ||
} | ||
|
||
if (Config.SHOW_ASYNC_LOADING_MESSAGES) { | ||
LOGGER.info("Async chunk loading for player {} completed after {}", profile.getName(), timing); | ||
} | ||
|
||
original.call(instance, connection, player, clientData); | ||
}, instance.getServer()); | ||
} | ||
|
||
} |
103 changes: 0 additions & 103 deletions
103
...d/vmp/mixins/chunk/loading/async_chunk_on_player_login/MixinServerPlayNetworkHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
7e0b751
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still disabled in the config btw
7e0b751
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is intentional to allow more testing before it becomes enabled by default.