Skip to content

Commit

Permalink
Add ticket on player join
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Sep 13, 2024
1 parent fe7bcfc commit a523823
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ca.spottedleaf.moonrise.mixin.chunk_system;

import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer;
import ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader;
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 net.minecraft.util.Unit;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -30,6 +33,26 @@ private void initRealPlayer(final Connection connection, final ServerPlayer serv
((ChunkSystemServerPlayer)serverPlayer).moonrise$setRealPlayer(true);
}

/**
* @reason prevent chunk load cycling on join
* @author jpenilla
*/
@Inject(
method = "placeNewPlayer",
at = @At(
target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V",
value = "INVOKE"
)
)
private void addJoinTicket(final Connection connection, final ServerPlayer serverPlayer,
final CommonListenerCookie commonListenerCookie, final CallbackInfo ci) {
((ChunkSystemServerLevel) serverPlayer.serverLevel()).moonrise$getChunkTaskScheduler().chunkHolderManager.addTicketAtLevel(
RegionizedPlayerChunkLoader.PLAYER_JOIN,
serverPlayer.chunkPosition(),
RegionizedPlayerChunkLoader.TICK_TICKET_LEVEL,
Unit.INSTANCE);
}

/**
* @reason The RegionizedPlayerChunkLoader will handle the VD packet
* @author Spottedleaf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.TicketType;
import net.minecraft.server.network.PlayerChunkSender;
import net.minecraft.util.Unit;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.chunk.ChunkAccess;
Expand All @@ -52,6 +53,7 @@ public final class RegionizedPlayerChunkLoader {

public static final TicketType<Long> PLAYER_TICKET = TicketType.create("chunk_system:player_ticket", Long::compareTo);
public static final TicketType<Long> PLAYER_TICKET_DELAYED = TicketType.create("chunk_system:player_ticket_delayed", Long::compareTo, 5 * 20);
public static final TicketType<Unit> PLAYER_JOIN = TicketType.create("chunk_system:player_join", (a, b) -> 0, 5 * 20);

public static final int MIN_VIEW_DISTANCE = 2;
public static final int MAX_VIEW_DISTANCE = 32;
Expand Down

0 comments on commit a523823

Please sign in to comment.