Skip to content

Commit

Permalink
Do not send chunk radius packet from PlayerList#setViewDistance
Browse files Browse the repository at this point in the history
The underlying player chunk loader will do this for us. This fixes
sending possibly the wrong view distance.
  • Loading branch information
Spottedleaf committed Sep 2, 2024
1 parent 901a417 commit ae12fd4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerList.class)
Expand All @@ -28,4 +30,17 @@ private void initRealPlayer(final Connection connection, final ServerPlayer serv
((ChunkSystemServerPlayer)serverPlayer).moonrise$setRealPlayer(true);
}

/**
* @reason The RegionizedPlayerChunkLoader will handle the VD packet
* @author Spottedleaf
*/
@Redirect(
method = "setViewDistance",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastAll(Lnet/minecraft/network/protocol/Packet;)V"
)
)
private void doNotAdjustVD(final PlayerList instance, final Packet<?> packet) {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import ca.spottedleaf.moonrise.common.misc.NearbyPlayers;
import ca.spottedleaf.moonrise.common.util.TickThread;
import ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerTrackedEntity;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerConnection;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Set;

@Mixin(ChunkMap.TrackedEntity.class)
Expand All @@ -25,6 +28,20 @@ abstract class TrackedEntityMixin implements EntityTrackerTrackedEntity {
@Shadow
public abstract void removePlayer(ServerPlayer serverPlayer);

/**
* @reason ReferenceOpenHashSet is a better choice than a wrapped IdentityHashMap
* @author Spottedleaf
*/
@Redirect(
method = "<init>",
at = @At(
value = "INVOKE",
target = "Lcom/google/common/collect/Sets;newIdentityHashSet()Ljava/util/Set;"
)
)
private <E> Set<E> useBetterIdentitySet() {
return new ReferenceOpenHashSet<>();
}

@Unique
private long lastChunkUpdate = -1L;
Expand Down

0 comments on commit ae12fd4

Please sign in to comment.