Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ticket on player join #22

Draft
wants to merge 1 commit into
base: mc/1.21.1
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;