This commit is contained in:
Moulberry committed 2024-08-29 10:34:49 +08:00
1 parent d2a217509f
commit 4d8f896cdf
90 files changed
+2345 -720

No files matched your search

@@ -2,6 +2,8 @@ package com.moulberry.flashback.mixin.playback;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.playback.ReplayServer;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
@@ -12,6 +14,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.UUID;
@Mixin(Entity.class)
public abstract class MixinEntity {
@@ -24,10 +28,18 @@ public abstract class MixinEntity {
@Shadow
public abstract boolean isInvisibleTo(Player player);
@Shadow
public abstract UUID getUUID();
@Inject(method = "isInvisibleTo", at = @At("HEAD"), cancellable = true)
public void isInvisibleTo(Player player, CallbackInfoReturnable<Boolean> cir) {
ReplayServer replayServer = Flashback.getReplayServer();
if (replayServer != null && player == Minecraft.getInstance().player) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && editorState.hideDuringExport.contains(this.getUUID())) {
cir.setReturnValue(true);
}
int localId = replayServer.getLocalPlayerId();
if (this.level.getEntity(localId) instanceof Player localPlayer) {
if ((Object)this == localPlayer) {
@@ -2,6 +2,7 @@ package com.moulberry.flashback.mixin.playback;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.state.EditorState;
@@ -10,7 +11,9 @@ import com.moulberry.flashback.editor.ui.ReplayUI;
import com.moulberry.flashback.ext.ItemInHandRendererExt;
import com.moulberry.flashback.ext.MinecraftExt;
import com.moulberry.flashback.visuals.CameraRotation;
import com.moulberry.flashback.visuals.ShaderManager;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
@@ -19,9 +22,12 @@ import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.PostChain;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.GameType;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -54,6 +60,39 @@ public abstract class MixinGameRenderer {
@Shadow
public abstract float getDepthFar();
@Shadow
public abstract void renderLevel(DeltaTracker deltaTracker);
@Shadow
private @Nullable PostChain postEffect;
@Shadow
private boolean effectActive;
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
public void render(DeltaTracker deltaTracker, boolean bl, CallbackInfo ci) {
if (Flashback.isExporting()) {
int i = (int)(this.minecraft.mouseHandler.xpos() * (double)this.minecraft.getWindow().getGuiScaledWidth() / (double)this.minecraft.getWindow().getScreenWidth());
int j = (int)(this.minecraft.mouseHandler.ypos() * (double)this.minecraft.getWindow().getGuiScaledHeight() / (double)this.minecraft.getWindow().getScreenHeight());
RenderSystem.viewport(0, 0, this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight());
boolean bl2 = this.minecraft.isGameLoadFinished();
if (bl2 && bl && this.minecraft.level != null) {
this.minecraft.getProfiler().push("level");
this.renderLevel(deltaTracker);
this.minecraft.levelRenderer.doEntityOutline();
if (this.postEffect != null && this.effectActive) {
RenderSystem.disableBlend();
RenderSystem.disableDepthTest();
RenderSystem.resetTextureMatrix();
this.postEffect.process(deltaTracker.getGameTimeDeltaTicks());
}
this.minecraft.getMainRenderTarget().bindWrite(true);
}
ci.cancel();
}
}
@WrapOperation(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"))
public GameType getPlayerMode(MultiPlayerGameMode instance, Operation<GameType> original) {
if (Flashback.getSpectatingPlayer() != null) {
@@ -87,24 +126,6 @@ public abstract class MixinGameRenderer {
return CameraRotation.modifyViewQuaternion(original.call(instance));
}
// @Inject(method = "getProjectionMatrix", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;perspective(FFFF)Lorg/joml/Matrix4f;", shift = At.Shift.BEFORE))
// @Inject(method = "getProjectionMatrix", at = @At(value = "RETURN"))
// public void getProjectionMatrix(double d, CallbackInfoReturnable<Matrix4f> cir) {
// if (ReplayVisuals.overrideZoom) {
// cir.getReturnValue().scaleLocal(ReplayVisuals.overrideZoomAmount, ReplayVisuals.overrideZoomAmount, 1.0f);
// }
// }
// @Inject(method = "getProjectionMatrix", at = @At(value = "RETURN"), cancellable = true)
// public void getProjectionMatrix(double d, CallbackInfoReturnable<Matrix4f> cir) {
// if (ReplayVisuals.overrideZoom) {
// Window window = Minecraft.getInstance().getWindow();
// Matrix4f matrix4f = new Matrix4f().setOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 0.05f, this.getDepthFar());
// cir.setReturnValue(matrix4f);
//// cir.setReturnValue(new Matrix4f().ortho());
// }
// }
@Inject(method = "tryTakeScreenshotIfNeeded", at = @At("HEAD"), cancellable = true)
public void tryTakeScreenshotIfNeeded(CallbackInfo ci) {
if (Flashback.isInReplay()) {
@@ -78,6 +78,8 @@ public abstract class MixinLevelChunk extends ChunkAccess implements LevelChunkE
return;
}
this.cachedChunkId = -1;
// Update heightmaps
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).update(localX, y, localZ, blockState);
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES).update(localX, y, localZ, blockState);
@@ -1,8 +1,11 @@
package com.moulberry.flashback.mixin.playback;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.ext.ServerLevelExt;
import com.moulberry.flashback.playback.ReplayServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.PlayerChunkSender;
import net.minecraft.world.level.chunk.LevelChunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -32,4 +35,14 @@ public class MixinPlayerChunkSender {
}
}
@Inject(method = "markChunkPendingToSend", at = @At("HEAD"), cancellable = true)
public void markChunkPendingToSend(LevelChunk levelChunk, CallbackInfo ci) {
ReplayServer replayServer = Flashback.getReplayServer();
if (replayServer != null) {
if (!((ServerLevelExt)levelChunk.getLevel()).flashback$shouldSendChunk(levelChunk.getPos().toLong())) {
ci.cancel();
}
}
}
}