-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67407a2
commit 3b73bb8
Showing
25 changed files
with
290 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...y/ducks/ServerReplay$ChunkRecordable.java → ...eiwells/replay/ducks/ChunkRecordable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...eplay/ducks/ServerReplay$PackTracker.java → ...senseiwells/replay/ducks/PackTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/me/senseiwells/replay/mixin/compat/c2me/ChunkHolderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.