Skip to content

Commit

Permalink
Fix compatability for C2ME #54
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Sep 17, 2024
1 parent 67407a2 commit 3b73bb8
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 64 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.fabric.loom)
alias(libs.plugins.mod.publish)
alias(libs.plugins.shadow)
alias(libs.plugins.explosion)
`maven-publish`
java
}
Expand Down Expand Up @@ -45,6 +46,7 @@ dependencies {

modCompileOnly(libs.carpet)
modCompileOnly(libs.vmp)
modCompileOnly(explosion.fabric(libs.c2me))
modCompileOnly(libs.servux)
modCompileOnly(libs.syncmatica)
modCompileOnly(libs.voicechat)
Expand Down
6 changes: 5 additions & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fabric-loom = "1.7-SNAPSHOT"
mod-publish = "0.7.0"
kotlin-serialization = "1.9.21"
shadow = "8.1.1"
explosion = "0.2.0"
minecraft = "1.21.1"
fabric-loader = "0.16.5"
parchment = "1.21:2024.07.28"
Expand All @@ -13,6 +14,7 @@ carpet = "1.4.147"
voicechat = "fabric-1.21.1-2.5.20"
voicechat-api = "2.5.0"
vmp = "0.2.0+beta.7.162+1.21"
c2me = "0.3.0+alpha.0.206+1.21.1"
servux = "1.21-0.3.8-sakura.1"
syncmatica = "1.21-sakura.6"
replay-studio = "1e96fda605"
Expand All @@ -27,6 +29,7 @@ carpet = { module = "com.github.gnembon:fabric-carpet" , version.ref
voicechat = { module = "maven.modrinth:simple-voice-chat" , version.ref = "voicechat" }
voicechat-api = { module = "de.maxhenkel.voicechat:voicechat-api" , version.ref = "voicechat-api" }
vmp = { module = "maven.modrinth:vmp-fabric" , version.ref = "vmp" }
c2me = { module = "maven.modrinth:c2me-fabric" , version.ref = "c2me" }
servux = { module = "com.github.sakura-ryoko:servux" , version.ref = "servux" }
syncmatica = { module = "com.github.sakura-ryoko:syncmatica" , version.ref = "syncmatica" }
replay-studio = { module = "com.github.ReplayMod:ReplayStudio" , version.ref = "replay-studio" }
Expand All @@ -35,4 +38,5 @@ replay-studio = { module = "com.github.ReplayMod:ReplayStudio" , version.ref
fabric-loom = { id = "fabric-loom", version.ref = "fabric-loom" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-serialization" }
mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
explosion = { id = "lol.bai.explosion", version.ref = "explosion"}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pluginManagement {
maven("https://maven.fabricmc.net/") {
name = "Fabric"
}
maven("https://maven2.bai.lol")
mavenCentral()
gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.senseiwells.replay.ducks;

import me.senseiwells.replay.chunk.ChunkRecordable;
import me.senseiwells.replay.chunk.ChunkRecorder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

public interface ServerReplay$ChunkRecordable extends ChunkRecordable {
@ApiStatus.Internal
public interface ChunkRecordable extends me.senseiwells.replay.chunk.ChunkRecordable {
@NotNull
@Override
default Collection<ChunkRecorder> getRecorders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package me.senseiwells.replay.ducks;

import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket;
import org.jetbrains.annotations.ApiStatus;

import java.util.Collection;

public interface ServerReplay$PackTracker {
@ApiStatus.Internal
public interface PackTracker {
void replay$addPacks(Collection<ClientboundResourcePackPushPacket> packs);

Collection<ClientboundResourcePackPushPacket> replay$getPacks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import me.senseiwells.replay.viewer.ReplayViewer;
import net.minecraft.network.protocol.Packet;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

public interface ServerReplay$ReplayViewable {
@ApiStatus.Internal
public interface ReplayViewable {
void replay$startViewingReplay(ReplayViewer viewer);

void replay$stopViewingReplay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.senseiwells.replay.chunk.ChunkRecorder;
import me.senseiwells.replay.ducks.ServerReplay$ChunkRecordable;
import me.senseiwells.replay.ducks.ChunkRecordable;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ChunkResult;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.*;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
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.Unique;
Expand All @@ -25,14 +22,16 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

@Mixin(ChunkHolder.class)
public abstract class ChunkHolderMixin implements ServerReplay$ChunkRecordable {
@Shadow @Final public static ChunkResult<LevelChunk> UNLOADED_LEVEL_CHUNK;

@Shadow private volatile CompletableFuture<ChunkResult<LevelChunk>> fullChunkFuture;
import static net.minecraft.server.level.ChunkHolder.UNLOADED_LEVEL_CHUNK;

@Mixin(ChunkHolder.class)
public abstract class ChunkHolderMixin extends GenerationChunkHolder implements ChunkRecordable {
@Unique private final Set<ChunkRecorder> replay$recorders = new HashSet<>();

public ChunkHolderMixin(ChunkPos pos) {
super(pos);
}

@Shadow public abstract CompletableFuture<ChunkResult<LevelChunk>> getFullChunkFuture();

@Inject(
Expand Down Expand Up @@ -67,7 +66,7 @@ private boolean shouldSkipBroadcasting(boolean noPlayers) {
)
)
private void onChunkLoad(ChunkMap chunkMap, Executor executor, CallbackInfo ci) {
this.fullChunkFuture.thenAccept(result -> {
this.getFullChunkFuture().thenAccept(result -> {
result.ifSuccess(chunk -> {
for (ChunkRecorder recorder : this.getRecorders()) {
recorder.onChunkLoaded(chunk);
Expand All @@ -88,7 +87,7 @@ private void onChunkUnload(ChunkMap chunkMap, Executor executor, CallbackInfo ci
LevelChunk chunk = this.getFullChunk();
if (chunk != null) {
for (ChunkRecorder recorder : this.getRecorders()) {
recorder.onChunkUnloaded(chunk);
recorder.onChunkUnloaded(this.pos);
}
}
}
Expand All @@ -101,7 +100,7 @@ private void onChunkUnload(ChunkMap chunkMap, Executor executor, CallbackInfo ci
@Override
public void replay$addRecorder(ChunkRecorder recorder) {
if (this.replay$recorders.add(recorder)) {
this.fullChunkFuture.thenAccept(result -> {
this.getFullChunkFuture().thenAccept(result -> {
result.ifSuccess(recorder::onChunkLoaded);
});

Expand All @@ -114,7 +113,7 @@ private void onChunkUnload(ChunkMap chunkMap, Executor executor, CallbackInfo ci
if (this.replay$recorders.remove(recorder)) {
LevelChunk chunk = this.getFullChunk();
if (chunk != null) {
recorder.onChunkUnloaded(chunk);
recorder.onChunkUnloaded(this.pos);
}

recorder.removeRecordable(this);
Expand All @@ -126,7 +125,7 @@ private void onChunkUnload(ChunkMap chunkMap, Executor executor, CallbackInfo ci
LevelChunk chunk = this.getFullChunk();
for (ChunkRecorder recorder : this.replay$recorders) {
if (chunk != null) {
recorder.onChunkUnloaded(chunk);
recorder.onChunkUnloaded(this.pos);
}
recorder.removeRecordable(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ChunkMapMixin {
remap = false
)
)
private void onUpdateChunkMap(
private void onLoadChunk(
long chunkPos,
int newLevel,
ChunkHolder holder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.llamalad7.mixinextras.sugar.Local;
import me.senseiwells.replay.chunk.ChunkRecorder;
import me.senseiwells.replay.ducks.ServerReplay$ChunkRecordable;
import me.senseiwells.replay.ducks.ChunkRecordable;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
import net.minecraft.server.level.ServerBossEvent;
Expand All @@ -22,7 +22,7 @@
import java.util.function.Function;

@Mixin(ServerBossEvent.class)
public abstract class ServerBossEventMixin extends BossEvent implements ServerReplay$ChunkRecordable {
public abstract class ServerBossEventMixin extends BossEvent implements ChunkRecordable {
@Shadow private boolean visible;
@Unique private final Set<ChunkRecorder> replay$recorders = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.senseiwells.replay.chunk.ChunkRecorder;
import me.senseiwells.replay.chunk.ChunkRecorders;
import me.senseiwells.replay.ducks.ServerReplay$ChunkRecordable;
import me.senseiwells.replay.ducks.ChunkRecordable;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
Expand All @@ -25,7 +25,7 @@
import java.util.*;

@Mixin(ChunkMap.TrackedEntity.class)
public class TrackedEntityMixin implements ServerReplay$ChunkRecordable {
public class TrackedEntityMixin implements ChunkRecordable {
@Unique private final Set<ChunkRecorder> replay$chunks = new HashSet<>();

@Shadow @Final Entity entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package me.senseiwells.replay.mixin.compat.c2me;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.senseiwells.replay.chunk.ChunkRecorder;
import me.senseiwells.replay.ducks.ChunkRecordable;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.*;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

@Mixin(ChunkHolder.class)
public abstract class ChunkHolderMixin extends GenerationChunkHolder implements ChunkRecordable {
@Unique private final Set<ChunkRecorder> replay$recorders = new HashSet<>();

public ChunkHolderMixin(ChunkPos pos) {
super(pos);
}

@Shadow public abstract CompletableFuture<ChunkResult<LevelChunk>> getFullChunkFuture();

@Inject(
method = "broadcast",
at = @At("HEAD")
)
private void onBroadcast(List<ServerPlayer> players, Packet<?> packet, CallbackInfo ci) {
for (ChunkRecorder recorder : this.replay$recorders) {
recorder.record(packet);
}
}

@ModifyExpressionValue(
method = "broadcastChanges",
at = @At(
value = "INVOKE",
target = "Ljava/util/List;isEmpty()Z",
remap = false
)
)
private boolean shouldSkipBroadcasting(boolean noPlayers) {
return noPlayers && this.replay$recorders.isEmpty();
}

@Override
public Collection<ChunkRecorder> replay$getRecorders() {
return this.replay$recorders;
}

@Override
public void replay$addRecorder(ChunkRecorder recorder) {
CompletableFuture<ChunkResult<LevelChunk>> future = this.getFullChunkFuture();
if (future.isDone() && !future.getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK).isSuccess()) {
return;
}

if (this.replay$recorders.add(recorder)) {
this.getFullChunkFuture().thenAccept(result -> {
result.ifSuccess(recorder::onChunkLoaded);
});

recorder.addRecordable(this);
}
}

@Override
public void replay$removeRecorder(ChunkRecorder recorder) {
if (this.replay$recorders.remove(recorder)) {
recorder.onChunkUnloaded(this.pos);
recorder.removeRecordable(this);
}
}

@Override
public void replay$removeAllRecorders() {
for (ChunkRecorder recorder : this.replay$recorders) {
recorder.onChunkUnloaded(this.pos);
recorder.removeRecordable(this);
}
this.replay$recorders.clear();
}
}
Loading

0 comments on commit 3b73bb8

Please sign in to comment.