Skip to content

Commit

Permalink
Port to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Feb 5, 2024
1 parent 84477f9 commit 774001a
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 146 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ archives_base_name=serverreplay
maven_group=me.senseiwells
loom_version=1.5-SNAPSHOT

minecraft_version=1.19.4
parchment_version=1.19.4:2023.06.26
minecraft_version=1.18.2
parchment_version=1.18.2:2022.11.06
loader_version=0.15.2
fabric_kotlin_version=1.9.2+kotlin.1.8.10
permissions_version=0.3-SNAPSHOT
fabric_version=0.87.2+1.19.4
carpet_version=1.4.101
fabric_version=0.77.0+1.18.2
carpet_version=1.4.66

mod_version=1.0.3

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/me/senseiwells/replay/mixin/CommandsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.brigadier.CommandDispatcher;
import me.senseiwells.replay.commands.ReplayCommand;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -22,7 +21,6 @@ public class CommandsMixin {
)
private void onRegisterCommands(
Commands.CommandSelection commandSelection,
CommandBuildContext commandBuildContext,
CallbackInfo ci
) {
ReplayCommand.register(this.dispatcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,24 @@
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MessageSignatureCache;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
import net.minecraft.network.protocol.game.ClientboundChatPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
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;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.UUID;
import java.util.function.Function;
import java.util.function.Predicate;

@Mixin(PlayerList.class)
public class PlayerListMixin {
@Shadow @Final private MinecraftServer server;

@Inject(
method = "broadcastAll(Lnet/minecraft/network/protocol/Packet;)V",
at = @At("HEAD")
Expand Down Expand Up @@ -78,7 +68,7 @@ private void onBroadcast(
}
}

ChunkPos pos = new ChunkPos(BlockPos.containing(x, y, z));
ChunkPos pos = new ChunkPos(new BlockPos(x, y, z));
for (ChunkRecorder recorder : ChunkRecorders.all()) {
if (recorder.getChunks().contains(dimension, pos)) {
recorder.record(packet);
Expand All @@ -87,48 +77,33 @@ private void onBroadcast(
}

@Inject(
method = "broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Z)V",
method = "broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V",
at = @At("HEAD")
)
private void onBroadcastSystemMessage(
Component serverMessage,
Function<ServerPlayer, Component> playerMessageFactory,
boolean bypassHiddenChat,
Component message,
Function<ServerPlayer, Component> filter,
ChatType type,
UUID uuid,
CallbackInfo ci
) {
for (ChunkRecorder recorder : ChunkRecorders.all()) {
recorder.record(new ClientboundSystemChatPacket(serverMessage, bypassHiddenChat));
recorder.record(new ClientboundChatPacket(message, type, uuid));
}
}

@Inject(
method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Ljava/util/function/Predicate;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V",
method = "broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V",
at = @At("HEAD")
)
private void onBroadcastChatMessage(
PlayerChatMessage message,
Predicate<ServerPlayer> shouldFilterMessageTo,
@Nullable ServerPlayer sender,
ChatType.Bound boundChatType,
Component message,
ChatType type,
UUID uuid,
CallbackInfo ci
) {
for (ChunkRecorder recorder : ChunkRecorders.all()) {
if (message.isSystem()) {
recorder.record(new ClientboundDisguisedChatPacket(
message.decoratedContent(),
boundChatType.toNetwork(this.server.registryAccess())
));
continue;
}
recorder.record(new ClientboundPlayerChatPacket(
message.link().sender(),
message.link().index(),
message.signature(),
message.signedBody().pack(MessageSignatureCache.createDefault()),
message.unsignedContent(),
message.filterMask(),
boundChatType.toNetwork(this.server.registryAccess())
));
recorder.record(new ClientboundChatPacket(message, type, uuid));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.senseiwells.replay.mixin.chunk;

import com.llamalad7.mixinextras.sugar.Local;
import me.senseiwells.replay.chunk.ChunkRecordable;
import me.senseiwells.replay.chunk.ChunkRecorder;
import me.senseiwells.replay.chunk.ChunkRecorders;
Expand Down Expand Up @@ -50,7 +49,7 @@ private void onUpdate(CallbackInfo ci) {
method = "playSound",
at = @At("TAIL")
)
private void onPlayerSound(BlockPos pos, CallbackInfo ci, @Local(ordinal = 0) long seed) {
private void onPlayerSound(BlockPos pos, CallbackInfo ci) {
Collection<ChunkRecorder> recorders = ((ChunkRecordable) this.raidEvent).getRecorders();
if (!recorders.isEmpty()) {
ClientboundSoundPacket packet = new ClientboundSoundPacket(
Expand All @@ -60,8 +59,7 @@ private void onPlayerSound(BlockPos pos, CallbackInfo ci, @Local(ordinal = 0) lo
this.center.getY(),
this.center.getZ(),
64,
1.0F,
seed
1.0F
);
for (ChunkRecorder recorder : recorders) {
recorder.record(packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import me.senseiwells.replay.chunk.ChunkRecorders;
import me.senseiwells.replay.ducks.ServerReplay$ChunkRecordable;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ChunkMap;
Expand All @@ -22,7 +20,10 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Mixin(ChunkMap.TrackedEntity.class)
public class TrackedEntityMixin implements ServerReplay$ChunkRecordable {
Expand Down Expand Up @@ -68,9 +69,7 @@ private void onRemoved(CallbackInfo ci) {
public void replay$addRecorder(ChunkRecorder recorder) {
if (this.replay$chunks.add(recorder)) {
recorder.addRecordable(this);
List<Packet<ClientGamePacketListener>> list = new ArrayList<>();
this.serverEntity.sendPairingData(list::add);
recorder.record(new ClientboundBundlePacket(list));
this.serverEntity.sendPairingData(recorder::record);

recorder.onEntityTracked(this.entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MinecraftServerMixin {
method = "runServer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/MinecraftServer;buildServerStatus()Lnet/minecraft/network/protocol/status/ServerStatus;",
target = "Lnet/minecraft/server/MinecraftServer;updateStatusIcon(Lnet/minecraft/network/protocol/status/ServerStatus;)V",
shift = At.Shift.AFTER
)
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import me.senseiwells.replay.player.PlayerRecorders;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
Expand Down Expand Up @@ -37,8 +36,8 @@

@Mixin(ServerLevel.class)
public abstract class ServerLevelMixin extends Level {
protected ServerLevelMixin(WritableLevelData levelData, ResourceKey<Level> dimension, RegistryAccess registryAccess, Holder<DimensionType> dimensionTypeRegistration, Supplier<ProfilerFiller> profiler, boolean isClientSide, boolean isDebug, long biomeZoomSeed, int maxChainedNeighborUpdates) {
super(levelData, dimension, registryAccess, dimensionTypeRegistration, profiler, isClientSide, isDebug, biomeZoomSeed, maxChainedNeighborUpdates);
protected ServerLevelMixin(WritableLevelData levelData, ResourceKey<Level> dimension, Holder<DimensionType> dimensionTypeRegistration, Supplier<ProfilerFiller> profiler, boolean isClientSide, boolean isDebug, long biomeZoomSeed) {
super(levelData, dimension, dimensionTypeRegistration, profiler, isClientSide, isDebug, biomeZoomSeed);
}

@Shadow @Nullable public abstract Entity getEntity(int id);
Expand Down Expand Up @@ -75,11 +74,11 @@ private void onExplode(
double posZ,
float radius,
boolean causeFire,
Level.ExplosionInteraction interaction,
Explosion.BlockInteraction interaction,
CallbackInfoReturnable<Explosion> cir,
@Local Explosion explosion
) {
ChunkPos chunkPos = new ChunkPos(BlockPos.containing(posX, posY, posZ));
ChunkPos chunkPos = new ChunkPos(new BlockPos(posX, posY, posZ));
for (ChunkRecorder recorder : ChunkRecorders.containing(this.dimension(), chunkPos)) {
recorder.record(new ClientboundExplodePacket(
posX, posY, posZ, radius,
Expand Down Expand Up @@ -107,7 +106,7 @@ private <T extends ParticleOptions> void onSendParticles(
CallbackInfoReturnable<Integer> cir,
@Local ClientboundLevelParticlesPacket packet
) {
ChunkPos chunkPos = new ChunkPos(BlockPos.containing(posX, posY, posZ));
ChunkPos chunkPos = new ChunkPos(new BlockPos(posX, posY, posZ));
for (ChunkRecorder recorder : ChunkRecorders.containing(this.dimension(), chunkPos)) {
recorder.record(packet);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package me.senseiwells.replay.mixin.player;

import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import me.senseiwells.replay.player.PlayerRecorder;
import me.senseiwells.replay.player.PlayerRecorders;
import net.minecraft.network.PacketSendListener;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -18,10 +19,10 @@ public class ServerGamePacketListenerImplMixin {
@Shadow public ServerPlayer player;

@Inject(
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V",
method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V",
at = @At("HEAD")
)
private void onPacket(Packet<?> packet, PacketSendListener listener, CallbackInfo ci) {
private void onPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> listener, CallbackInfo ci) {
PlayerRecorder recorder = PlayerRecorders.get(this.player);
if (recorder != null) {
recorder.record(packet);
Expand Down
27 changes: 14 additions & 13 deletions src/main/kotlin/me/senseiwells/replay/chunk/ChunkRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import me.senseiwells.replay.mixin.rejoin.ChunkMapAccessor
import me.senseiwells.replay.recorder.ChunkSender
import me.senseiwells.replay.recorder.ReplayRecorder
import me.senseiwells.replay.rejoin.RejoinedReplayPlayer
import net.minecraft.core.UUIDUtil
import net.minecraft.network.chat.Component
import net.minecraft.Util
import net.minecraft.network.chat.ChatType
import net.minecraft.network.chat.TextComponent
import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket
import net.minecraft.network.protocol.game.ClientboundSetChunkCacheRadiusPacket
Expand All @@ -18,6 +19,7 @@ import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.boss.wither.WitherBoss
import net.minecraft.world.entity.player.Player
import net.minecraft.world.level.ChunkPos
import net.minecraft.world.level.levelgen.Heightmap
import org.jetbrains.annotations.ApiStatus.Internal
Expand Down Expand Up @@ -91,10 +93,7 @@ class ChunkRecorder internal constructor(

override fun spawnPlayer() {
this.record(ClientboundAddEntityPacket(this.dummy))
val tracked = this.dummy.entityData.nonDefaultValues
if (tracked != null) {
this.record(ClientboundSetEntityDataPacket(this.dummy.id, tracked))
}
this.record(ClientboundSetEntityDataPacket(this.dummy.id, this.dummy.entityData, true))
}

override fun getTimestamp(): Long {
Expand Down Expand Up @@ -190,9 +189,10 @@ class ChunkRecorder internal constructor(

if (ServerReplay.config.notifyPlayersLoadingChunks) {
this.ignore {
this.server.playerList.broadcastSystemMessage(
Component.literal("Paused recording for ${this.getName()}, chunks were unloaded"),
false
this.server.playerList.broadcastMessage(
TextComponent("Paused recording for ${this.getName()}, chunks were unloaded"),
ChatType.SYSTEM,
Util.NIL_UUID
)
}
}
Expand All @@ -206,9 +206,10 @@ class ChunkRecorder internal constructor(

if (ServerReplay.config.notifyPlayersLoadingChunks) {
this.ignore {
this.server.playerList.broadcastSystemMessage(
Component.literal("Resumed recording for ${this.getName()}, chunks were loaded"),
false
this.server.playerList.broadcastMessage(
TextComponent("Resumed recording for ${this.getName()}, chunks were loaded"),
ChatType.SYSTEM,
Util.NIL_UUID
)
}
}
Expand All @@ -227,6 +228,6 @@ class ChunkRecorder internal constructor(
}

companion object {
private val PROFILE = GameProfile(UUIDUtil.createOfflinePlayerUUID("-ChunkRecorder-"), "-ChunkRecorder-")
private val PROFILE = GameProfile(Player.createPlayerUUID("-ChunkRecorder-"), "-ChunkRecorder-")
}
}
Loading

0 comments on commit 774001a

Please sign in to comment.