This commit is contained in:
Moulberry committed 2024-09-30 20:00:24 +08:00
1 parent be99313e81
commit 63535e6b3d
79 files changed
+2007 -529

No files matched your search

@@ -0,0 +1,45 @@
package com.moulberry.flashback.mixin;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.ProfileResult;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
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.CallbackInfoReturnable;
@Mixin(AbstractClientPlayer.class)
public abstract class MixinAbstractClientPlayer extends Player {
public MixinAbstractClientPlayer(Level level, BlockPos blockPos, float f, GameProfile gameProfile) {
super(level, blockPos, f, gameProfile);
}
@Unique
private PlayerInfo skinOverridePlayerInfo = null;
@Inject(method = "getSkin", at = @At("HEAD"), cancellable = true, require = 0)
public void getSkin(CallbackInfoReturnable<PlayerSkin> cir) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null) {
GameProfile skinOverride = editorState.skinOverride.get(this.uuid);
if (skinOverride != null) {
if (skinOverridePlayerInfo == null || skinOverridePlayerInfo.getProfile() != skinOverride) {
skinOverridePlayerInfo = new PlayerInfo(skinOverride, false);
}
cir.setReturnValue(skinOverridePlayerInfo.getSkin());
}
}
}
}
@@ -73,7 +73,7 @@ public abstract class MixinLevelRenderer {
ReplayUI.lastViewQuaternion = camera.rotation();
}
@Inject(method = "renderSectionLayer", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderSectionLayer", at = @At("HEAD"), cancellable = true, require = 0)
public void renderSectionLayer(RenderType renderType, double d, double e, double f, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null) {
@@ -83,7 +83,7 @@ public abstract class MixinLevelRenderer {
}
}
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSectionLayer(Lnet/minecraft/client/renderer/RenderType;DDDLorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V", ordinal = 2, shift = At.Shift.AFTER))
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSectionLayer(Lnet/minecraft/client/renderer/RenderType;DDDLorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V", ordinal = 2, shift = At.Shift.AFTER), require = 0)
public void renderLevel_renderCutoutLayer(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
if (Flashback.isExporting() && Flashback.EXPORT_JOB.getSettings().transparent()) {
RenderTarget main = Minecraft.getInstance().mainRenderTarget;
@@ -109,7 +109,7 @@ public abstract class MixinLevelRenderer {
}
}
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V", shift = At.Shift.AFTER))
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V", shift = At.Shift.AFTER), require = 0)
public void renderLevel_levelFogColor(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null) {
@@ -137,13 +137,13 @@ public abstract class MixinLevelRenderer {
}
}
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;render(Lnet/minecraft/world/level/block/entity/BlockEntity;FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V"))
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;render(Lnet/minecraft/world/level/block/entity/BlockEntity;FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V"), require = 0)
public boolean renderLevel_renderBlockEntity(BlockEntityRenderDispatcher instance, BlockEntity blockEntity, float f, PoseStack poseStack, MultiBufferSource multiBufferSource) {
EditorState editorState = EditorStateManager.getCurrent();
return editorState == null || editorState.replayVisuals.renderBlocks;
}
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderEntity(Lnet/minecraft/world/entity/Entity;DDDFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V"))
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderEntity(Lnet/minecraft/world/entity/Entity;DDDFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V"), require = 0)
public boolean renderLevel_renderEntity(LevelRenderer instance, Entity entity, double d, double e, double f, float g, PoseStack poseStack, MultiBufferSource multiBufferSource) {
EditorState editorState = EditorStateManager.getCurrent();
if (entity instanceof Player) {
@@ -153,7 +153,7 @@ public abstract class MixinLevelRenderer {
}
}
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getCloudsType()Lnet/minecraft/client/CloudStatus;"))
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getCloudsType()Lnet/minecraft/client/CloudStatus;"), require = 0)
public CloudStatus renderLevel_getCloudsType(Options instance, Operation<CloudStatus> original) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.renderSky) {
@@ -163,19 +163,19 @@ public abstract class MixinLevelRenderer {
}
}
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V"))
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V"), require = 0)
public boolean renderLevel_renderParticles(ParticleEngine instance, LightTexture lightTexture, Camera camera, float f) {
EditorState editorState = EditorStateManager.getCurrent();
return editorState == null || editorState.replayVisuals.renderParticles;
}
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSky(Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;FLnet/minecraft/client/Camera;ZLjava/lang/Runnable;)V"))
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSky(Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;FLnet/minecraft/client/Camera;ZLjava/lang/Runnable;)V"), require = 0)
public boolean renderLevel_renderSky(LevelRenderer instance, Matrix4f matrix4f, Matrix4f matrix4f2, float f, Camera camera, boolean bl, Runnable runnable) {
EditorState editorState = EditorStateManager.getCurrent();
return editorState == null || editorState.replayVisuals.renderSky;
}
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;setupRender(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;ZZ)V"))
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;setupRender(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;ZZ)V"), require = 0)
public void setupRender(LevelRenderer instance, Camera camera, Frustum frustum, boolean capturedFrustum, boolean isSpectator, Operation<Void> original) {
if (PerfectFrames.isEnabled()) {
boolean doCompile = true;
@@ -8,7 +8,9 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.MeshData;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.moulberry.flashback.WindowSizeTracker;
import com.moulberry.flashback.editor.ui.ReplayUI;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ShaderInstance;
@@ -27,24 +29,42 @@ import java.util.Objects;
public abstract class MixinRenderTarget {
@Shadow
public int frameBufferId;
@Shadow
public abstract int getColorTextureId();
public int colorTextureId;
@Inject(method = "blitToScreen(IIZ)V", at = @At("HEAD"), cancellable = true)
public void blitToScreenSodium(int width, int height, boolean noBlend, CallbackInfo ci) {
if ((Object)this == Minecraft.getInstance().getMainRenderTarget() && ReplayUI.isActive()) {
var window = Minecraft.getInstance().getWindow();
int frameBottom = (ReplayUI.viewportSizeY - (ReplayUI.frameY + ReplayUI.frameHeight)) * window.framebufferHeight / ReplayUI.viewportSizeY;
int frameLeft = ReplayUI.frameX * window.framebufferWidth / ReplayUI.viewportSizeX;
int frameWidth = Math.max(1, ReplayUI.frameWidth) * window.framebufferWidth / ReplayUI.viewportSizeX;
int frameHeight = Math.max(1, ReplayUI.frameHeight) * window.framebufferHeight / ReplayUI.viewportSizeY;
float frameLeft = (float) ReplayUI.frameX / ReplayUI.viewportSizeX;
float frameTop = (float) ReplayUI.frameY / ReplayUI.viewportSizeY;
float frameWidth = (float) Math.max(1, ReplayUI.frameWidth) / ReplayUI.viewportSizeX;
float frameHeight = (float) Math.max(1, ReplayUI.frameHeight) / ReplayUI.viewportSizeY;
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, this.frameBufferId);
GL30.glBlitFramebuffer(0, 0, width, height, frameLeft, frameBottom, frameLeft+frameWidth, frameBottom+frameHeight,
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_LINEAR);
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, 0);
int realWidth = WindowSizeTracker.getWidth(window);
int realHeight = WindowSizeTracker.getHeight(window);
RenderSystem.assertOnRenderThread();
GlStateManager._colorMask(true, true, true, false);
GlStateManager._disableDepthTest();
GlStateManager._depthMask(false);
GlStateManager._viewport((int)(realWidth * frameLeft), (int)(realHeight * (1 - (frameTop+frameHeight))),
Math.max(1, (int)(realWidth * frameWidth)), Math.max(1, (int)(realHeight * frameHeight)));
if (noBlend) {
GlStateManager._disableBlend();
}
Minecraft minecraft = Minecraft.getInstance();
ShaderInstance shaderInstance = Objects.requireNonNull(minecraft.gameRenderer.blitShader, "Blit shader not loaded");
shaderInstance.setSampler("DiffuseSampler", this.colorTextureId);
shaderInstance.apply();
BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN);
bufferBuilder.addVertex(0.0f, 0.0f, 0.0f);
bufferBuilder.addVertex(1.0f, 0.0f, 0.0f);
bufferBuilder.addVertex(1.0f, 1.0f, 0.0f);
bufferBuilder.addVertex(0.0f, 1.0f, 0.0f);
BufferUploader.draw(bufferBuilder.buildOrThrow());
shaderInstance.clear();
GlStateManager._depthMask(true);
GlStateManager._colorMask(true, true, true, true);
ci.cancel();
}
}
@@ -21,9 +21,8 @@ import java.util.SortedSet;
@Mixin(targets = {"net.caffeinemc.mods.sodium.client.render.SodiumWorldRenderer", "me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer"})
public class MixinSodiumWorldRenderer {
@Inject(method = "renderBlockEntities(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/RenderBuffers;Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;Lnet/minecraft/client/Camera;F)V",
at = @At("HEAD"), cancellable = true)
public void renderBlockEntities(PoseStack matrices, RenderBuffers bufferBuilders, Long2ObjectMap<SortedSet<BlockDestructionProgress>> blockBreakingProgressions, Camera camera, float tickDelta, CallbackInfo ci) {
@Inject(method = "renderBlockEntities", at = @At("HEAD"), cancellable = true, require = 0, remap = false)
public void renderBlockEntities(CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.renderBlocks) {
ci.cancel();
@@ -1,4 +1,4 @@
package com.moulberry.flashback.mixin.compat;
package com.moulberry.flashback.mixin.compat.axiom;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.editor.ui.ReplayUI;
@@ -0,0 +1,23 @@
package com.moulberry.flashback.mixin.compat.axiom;
import com.moulberry.flashback.Flashback;
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@IfModLoaded("axiom")
@Pseudo
@Mixin(targets = "com.moulberry.axiom.integration.ServerIntegration", remap = false)
public class MixinAxiomServerIntegration {
@Inject(method = "changeGameMode", at = @At("HEAD"), cancellable = true, require = 0)
private static void changeGameMode(CallbackInfo ci) {
if (Flashback.isInReplay()) {
ci.cancel();
}
}
}
@@ -1,23 +0,0 @@
package com.moulberry.flashback.mixin.compat.distanthorizons;
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import org.spongepowered.asm.mixin.Mixin;
@IfModLoaded("distanthorizons")
@Mixin(value = SharedApi.class, remap = false)
public abstract class MixinSharedApi {
/*
* Override any changes to the DhWorld, changing it to our proxy world
*/
// @Inject(method = "setDhWorld", at = @At("HEAD"), cancellable = true)
// private static void setDhWorld(AbstractDhWorld newWorld, CallbackInfo ci) {
// if (Flashback.isInReplay() && newWorld != null && !(newWorld instanceof ProxyDhWorld)) {
// SharedApi.setDhWorld(new ProxyDhWorld());
// ci.cancel();
// }
// }
}
@@ -1,4 +1,4 @@
package com.moulberry.flashback.mixin.compat;
package com.moulberry.flashback.mixin.compat.fabric;
import com.bawnorton.mixinsquared.TargetHandler;
import com.moulberry.flashback.playback.ReplayServer;
@@ -21,7 +21,7 @@ public class MixinFabricMinecraftServer {
mixin = "net.fabricmc.fabric.mixin.biome.modification.MinecraftServerMixin",
name = "finalizeWorldGen"
)
@Inject(method = "@MixinSquared:Handler", at = @At("HEAD"), cancellable = true)
@Inject(method = "@MixinSquared:Handler", at = @At("HEAD"), cancellable = true, require = 0)
private void preventWorldGenChanges(CallbackInfo ci) {
if ((Object) this instanceof ReplayServer) {
ci.cancel();
@@ -0,0 +1,39 @@
package com.moulberry.flashback.mixin.compat.fabric;
import com.moulberry.flashback.playback.FakePlayer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = ServerPlayNetworking.class, remap = false)
public class MixinFabricServerPlayNetworking {
@Inject(method = "canSend(Lnet/minecraft/server/network/ServerGamePacketListenerImpl;Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload$Type;)Z", at = @At("HEAD"), cancellable = true, require = 0)
private static void canSend1(ServerGamePacketListenerImpl handler, CustomPacketPayload.Type<?> type, CallbackInfoReturnable<Boolean> cir) {
if (handler.player instanceof FakePlayer) {
cir.setReturnValue(true);
}
}
@Inject(method = "canSend(Lnet/minecraft/server/network/ServerGamePacketListenerImpl;Lnet/minecraft/resources/ResourceLocation;)Z", at = @At("HEAD"), cancellable = true, require = 0)
private static void canSend2(ServerGamePacketListenerImpl handler, ResourceLocation channelName, CallbackInfoReturnable<Boolean> cir) {
if (handler.player instanceof FakePlayer) {
cir.setReturnValue(true);
}
}
@Inject(method = "send", at = @At("HEAD"), cancellable = true, require = 0)
private static void send(ServerPlayer player, CustomPacketPayload payload, CallbackInfo ci) {
if (player instanceof FakePlayer) {
ci.cancel();
}
}
}
@@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = SystemTimeUniforms.Timer.class, remap = false)
public class MixinIrisSystemTimeUniforms {
@Inject(method = "getFrameTimeCounter", at = @At("HEAD"), cancellable = true)
@Inject(method = "getFrameTimeCounter", at = @At("HEAD"), require = 0, cancellable = true)
public void getFrameTimeCounter(CallbackInfoReturnable<Float> cir) {
if (Flashback.isExporting()) {
double currentTick = Flashback.EXPORT_JOB.getCurrentTickDouble();
@@ -22,7 +22,7 @@ public class MixinIrisSystemTimeUniforms {
}
}
@Inject(method = "getLastFrameTime", at = @At("HEAD"), cancellable = true)
@Inject(method = "getLastFrameTime", at = @At("HEAD"), require = 0, cancellable = true)
public void getLastFrameTime(CallbackInfoReturnable<Float> cir) {
if (Flashback.isExporting()) {
cir.setReturnValue((float)(1 / Flashback.EXPORT_JOB.getSettings().framerate()));
@@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = ReplayModRecording.class, remap = false)
public class MixinReplayModRecording {
@Inject(method = "initiateRecording", at = @At("HEAD"), cancellable = true)
@Inject(method = "initiateRecording", at = @At("HEAD"), require = 0, cancellable = true)
public void initiateRecording(Connection networkManager, CallbackInfo ci) {
if (Flashback.isInReplay()) {
ci.cancel();
@@ -5,7 +5,10 @@ import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.configuration.FlashbackConfig;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
@@ -54,4 +57,17 @@ public abstract class MixinPlayerEntity extends LivingEntity {
}
}
@Inject(method = "getName", at = @At("HEAD"), cancellable = true)
public void getName(CallbackInfoReturnable<Component> cir) {
if ((Object)this instanceof RemotePlayer) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null) {
String nameOverride = editorState.nameOverride.get(this.uuid);
if (nameOverride != null) {
cir.setReturnValue(Component.literal(nameOverride));
}
}
}
}
}
@@ -7,14 +7,17 @@ import com.moulberry.flashback.visuals.AccurateEntityPositionHandler;
import net.minecraft.client.Camera;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import org.joml.Vector2f;
import org.joml.Vector3d;
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;
@Mixin(Camera.class)
public class MixinCamera {
public abstract class MixinCamera {
@Shadow
private float eyeHeightOld;
@@ -22,28 +25,22 @@ public class MixinCamera {
@Shadow
public float eyeHeight;
@WrapOperation(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 0))
public void setRotation(Camera instance, float yaw, float pitch, Operation<Void> original,
@Local(argsOnly = true) Entity entity, @Local(argsOnly = true) float partialTick) {
@Shadow
protected abstract void setRotation(float f, float g);
@Shadow
protected abstract void setPosition(double d, double e, double f);
@Inject(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setPosition(DDD)V", ordinal = 0, shift = At.Shift.AFTER))
public void afterSetPosition(BlockGetter blockGetter, Entity entity, boolean bl, boolean bl2, float partialTick, CallbackInfo ci) {
Vector2f rotation = AccurateEntityPositionHandler.getAccurateRotation(entity, partialTick);
if (rotation != null) {
pitch = rotation.x;
yaw = rotation.y;
this.setRotation(rotation.y, rotation.x);
}
original.call(instance, yaw, pitch);
}
@WrapOperation(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setPosition(DDD)V", ordinal = 0))
public void setPosition(Camera instance, double x, double y, double z, Operation<Void> original,
@Local(argsOnly = true) Entity entity, @Local(argsOnly = true) float partialTick) {
Vector3d position = AccurateEntityPositionHandler.getAccuratePosition(entity, partialTick);
if (position != null) {
x = position.x;
y = position.y + Mth.lerp(partialTick, this.eyeHeightOld, this.eyeHeight);
z = position.z;
this.setPosition(position.x, position.y + Mth.lerp(partialTick, this.eyeHeightOld, this.eyeHeight), position.z);
}
original.call(instance, x, y, z);
}
}
@@ -12,6 +12,7 @@ import com.moulberry.flashback.ext.ItemInHandRendererExt;
import com.moulberry.flashback.ext.MinecraftExt;
import com.moulberry.flashback.visuals.AccurateEntityPositionHandler;
import com.moulberry.flashback.visuals.CameraRotation;
import com.moulberry.flashback.visuals.ReplayVisuals;
import com.moulberry.flashback.visuals.ShaderManager;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
@@ -26,6 +27,7 @@ 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.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.GameType;
import org.jetbrains.annotations.Nullable;
@@ -105,6 +107,14 @@ public abstract class MixinGameRenderer {
original.call(instance, blockGetter, entity, bl, bl2, f);
}
@Inject(method = "getNightVisionScale", at = @At("HEAD"), cancellable = true)
private static void getNightVisionScale(LivingEntity livingEntity, float f, CallbackInfoReturnable<Float> cir) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && editorState.replayVisuals.overrideNightVision) {
cir.setReturnValue(1.0f);
}
}
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;rotation()Lorg/joml/Quaternionf;"))
public Quaternionf renderLevel(Camera instance, Operation<Quaternionf> original) {
return CameraRotation.modifyViewQuaternion(original.call(instance));
@@ -4,6 +4,7 @@ import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.record.Recorder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.prediction.BlockStatePredictionHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.network.ConnectionProtocol;
@@ -31,11 +32,17 @@ public class MixinClientLevel {
@Final
private Minecraft minecraft;
@Shadow
@Final
private BlockStatePredictionHandler blockStatePredictionHandler;
@Inject(method = "setBlock", at = @At("HEAD"))
public void setBlock(BlockPos blockPos, BlockState blockState, int i, int j, CallbackInfoReturnable<Boolean> cir) {
Recorder recorder = Flashback.RECORDER;
if (recorder != null && !recorder.isPaused()) {
recorder.writePacketAsync(new ClientboundBlockUpdatePacket(blockPos.immutable(), blockState), ConnectionProtocol.PLAY);
if (this.blockStatePredictionHandler.isPredicting()) {
Recorder recorder = Flashback.RECORDER;
if (recorder != null && !recorder.isPaused()) {
recorder.writePacketAsync(new ClientboundBlockUpdatePacket(blockPos.immutable(), blockState), ConnectionProtocol.PLAY);
}
}
}
@@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(BossHealthOverlay.class)
public class MixinBossHealthOverlay {
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
@Inject(method = "render", at = @At("HEAD"), cancellable = true, require = 0)
public void render(GuiGraphics guiGraphics, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.showBossBar) {
@@ -17,7 +17,7 @@ public class MixinClientLevel {
* This code here ensures that the interpolation of yRotO -> yRot will always be the shortest path
*/
@Inject(method = "tickNonPassenger", at = @At("RETURN"))
@Inject(method = "tickNonPassenger", at = @At("RETURN"), require = 0)
public void tickNonPassengerEnd(Entity entity, CallbackInfo ci) {
if (Flashback.isInReplay()) {
entity.xRotO = Mth.wrapDegrees(entity.xRotO - entity.getXRot()) + entity.getXRot();
@@ -25,7 +25,7 @@ public class MixinClientLevel {
}
}
@Inject(method = "tickPassenger", at = @At("RETURN"))
@Inject(method = "tickPassenger", at = @At("RETURN"), require = 0)
public void tickPassengerEnd(Entity vehicle, Entity entity, CallbackInfo ci) {
if (Flashback.isInReplay()) {
entity.xRotO = Mth.wrapDegrees(entity.xRotO - entity.getXRot()) + entity.getXRot();
@@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ClientLevel.ClientLevelData.class)
public class MixinClientLevelData {
@Inject(method = "getDayTime", at = @At("HEAD"), cancellable = true)
@Inject(method = "getDayTime", at = @At("HEAD"), cancellable = true, require = 0)
public void getDayTime(CallbackInfoReturnable<Long> cir) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && editorState.replayVisuals.overrideTimeOfDay >= 0) {
@@ -36,7 +36,7 @@ public abstract class MixinEntityRenderDispatcher {
}
// Add a yellow outline to selected entity
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = At.Shift.BEFORE))
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = At.Shift.BEFORE), require = 0)
public void renderAfter(Entity entity, double d, double e, double f, float g, float h, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) {
if (Flashback.isInReplay()) {
if (ReplayUI.isEntitySelected(entity.getUUID())) {
@@ -51,7 +51,7 @@ public abstract class MixinEntityRenderDispatcher {
}
// Prevent rendering shadows when blocks are turned off
@WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderDispatcher;renderShadow(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/Entity;FFLnet/minecraft/world/level/LevelReader;F)V"))
@WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderDispatcher;renderShadow(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/Entity;FFLnet/minecraft/world/level/LevelReader;F)V"), require = 0)
public boolean renderShadow(PoseStack poseStack, MultiBufferSource multiBufferSource, Entity entity, float f, float g, LevelReader levelReader, float h) {
EditorState editorState = EditorStateManager.getCurrent();
return editorState == null || editorState.replayVisuals.renderBlocks;
@@ -15,11 +15,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(EntityRenderer.class)
public class MixinEntityRenderer {
@Inject(method = "renderNameTag", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderNameTag", at = @At("HEAD"), cancellable = true, require = 0)
public void renderNameTag(Entity entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, float f, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.renderNametags) {
ci.cancel();
if (editorState != null) {
if (!editorState.replayVisuals.renderNametags) {
ci.cancel();
} else if (editorState.hideNametags.contains(entity.getUUID())) {
ci.cancel();
} else if (editorState.hideDuringExport.contains(entity.getUUID())) {
ci.cancel();
}
}
}
@@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(FogRenderer.class)
public class MixinFogRenderer {
@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true, require = 0)
private static void setupFog(Camera camera, FogRenderer.FogMode fogMode, float f, boolean bl, float g, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && editorState.replayVisuals.overrideFog) {
@@ -54,7 +54,7 @@ public abstract class MixinGui {
}
}
@Inject(method = "renderChat", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderChat", at = @At("HEAD"), cancellable = true, require = 0)
public void renderChat(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.showChat) {
@@ -62,7 +62,7 @@ public abstract class MixinGui {
}
}
@Inject(method = "renderTitle", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderTitle", at = @At("HEAD"), cancellable = true, require = 0)
public void renderTitle(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.showTitleText) {
@@ -70,7 +70,7 @@ public abstract class MixinGui {
}
}
@Inject(method = "renderScoreboardSidebar", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderScoreboardSidebar", at = @At("HEAD"), cancellable = true, require = 0)
public void renderScoreboardSidebar(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.showScoreboard) {
@@ -78,7 +78,7 @@ public abstract class MixinGui {
}
}
@Inject(method = "renderOverlayMessage", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderOverlayMessage", at = @At("HEAD"), cancellable = true, require = 0)
public void renderOverlayMessage(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.showActionBar) {
@@ -86,7 +86,7 @@ public abstract class MixinGui {
}
}
@Inject(method = "renderHotbarAndDecorations", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderHotbarAndDecorations", at = @At("HEAD"), cancellable = true, require = 0)
public void renderHotbarAndDecorations(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && !editorState.replayVisuals.showHotbar) {
@@ -94,7 +94,7 @@ public abstract class MixinGui {
}
}
@WrapOperation(method = "renderHotbarAndDecorations", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"))
@WrapOperation(method = "renderHotbarAndDecorations", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"), require = 0)
public GameType renderHotbarAndDecorations_getPlayerMode(MultiPlayerGameMode instance, Operation<GameType> original) {
if (Flashback.isInReplay()) {
return this.cameraGameType;
@@ -102,7 +102,7 @@ public abstract class MixinGui {
return original.call(instance);
}
@WrapOperation(method = "renderHotbarAndDecorations", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;canHurtPlayer()Z"))
@WrapOperation(method = "renderHotbarAndDecorations", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;canHurtPlayer()Z"), require = 0)
public boolean renderHotbarAndDecorations_canHurtPlayer(MultiPlayerGameMode instance, Operation<Boolean> original) {
if (Flashback.isInReplay()) {
return this.cameraGameType.isSurvival();
@@ -110,14 +110,14 @@ public abstract class MixinGui {
return original.call(instance);
}
@Inject(method = "isExperienceBarVisible", at = @At("HEAD"), cancellable = true)
@Inject(method = "isExperienceBarVisible", at = @At("HEAD"), cancellable = true, require = 0)
public void isExperienceBarVisible(CallbackInfoReturnable<Boolean> cir) {
if (Flashback.isInReplay()) {
cir.setReturnValue(this.cameraGameType.isSurvival());
}
}
@WrapOperation(method = "renderExperienceBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getXpNeededForNextLevel()I"))
@WrapOperation(method = "renderExperienceBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getXpNeededForNextLevel()I"), require = 0)
public int renderExperienceBar_getXpNeededForNextLevel(LocalPlayer instance, Operation<Integer> original) {
if (Flashback.isInReplay()) {
Player player = this.getCameraPlayer();
@@ -128,7 +128,7 @@ public abstract class MixinGui {
return original.call(instance);
}
@WrapOperation(method = "renderExperienceBar", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;experienceProgress:F"))
@WrapOperation(method = "renderExperienceBar", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;experienceProgress:F"), require = 0)
public float renderExperienceBar_experienceProgress(LocalPlayer instance, Operation<Float> original) {
if (Flashback.isInReplay()) {
Player player = this.getCameraPlayer();
@@ -139,7 +139,7 @@ public abstract class MixinGui {
return original.call(instance);
}
@WrapOperation(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getAttackStrengthScale(F)F"))
@WrapOperation(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getAttackStrengthScale(F)F"), require = 0)
public float renderCrosshair_getAttackStrengthScale(LocalPlayer instance, float partialTick, Operation<Float> original) {
if (Flashback.isInReplay()) {
Player player = this.getCameraPlayer();
@@ -150,7 +150,7 @@ public abstract class MixinGui {
return original.call(instance, partialTick);
}
@WrapOperation(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getCurrentItemAttackStrengthDelay()F"))
@WrapOperation(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getCurrentItemAttackStrengthDelay()F"), require = 0)
public float renderCrosshair_getCurrentItemAttackStrengthDelay(LocalPlayer instance, Operation<Float> original) {
if (Flashback.isInReplay()) {
Player player = this.getCameraPlayer();
@@ -161,7 +161,7 @@ public abstract class MixinGui {
return original.call(instance);
}
@WrapOperation(method = "renderExperienceLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;experienceLevel:I"))
@WrapOperation(method = "renderExperienceLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;experienceLevel:I"), require = 0)
public int renderExperienceLevel_experienceLevel(LocalPlayer instance, Operation<Integer> original) {
if (Flashback.isInReplay()) {
Player player = this.getCameraPlayer();
@@ -181,7 +181,7 @@ public abstract class MixinGui {
}
}
@Inject(method = "canRenderCrosshairForSpectator", at = @At("HEAD"), cancellable = true)
@Inject(method = "canRenderCrosshairForSpectator", at = @At("HEAD"), cancellable = true, require = 0)
public void canRenderCrosshairForSpectator(HitResult hitResult, CallbackInfoReturnable<Boolean> cir) {
if (Flashback.isInReplay()) {
if (!Flashback.isExporting() && ReplayUI.isActive() && ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME) {
@@ -0,0 +1,28 @@
package com.moulberry.flashback.mixin.visuals;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffects;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(LightTexture.class)
public class MixinLightTexture {
@WrapOperation(method = "updateLightTexture", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;hasEffect(Lnet/minecraft/core/Holder;)Z"), require = 0)
public boolean updateLightTexture_hasEffect(LocalPlayer instance, Holder holder, Operation<Boolean> original) {
if (holder == MobEffects.NIGHT_VISION) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && editorState.replayVisuals.overrideNightVision) {
return true;
}
}
return original.call(instance, holder);
}
}
@@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntityRenderer.class)
public class MixinLivingEntityRenderer {
@Inject(method = "isBodyVisible", at = @At("HEAD"), cancellable = true)
@Inject(method = "isBodyVisible", at = @At("HEAD"), cancellable = true, require = 0)
public void isBodyVisible(LivingEntity livingEntity, CallbackInfoReturnable<Boolean> cir) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && editorState.hideDuringExport.contains(livingEntity.getUUID())) {
@@ -19,7 +19,7 @@ public class MixinLoadingOverlay {
@Shadow @Final private Minecraft minecraft;
// Make overlay disappear instantly if inside replay
@Inject(method = "render", at = @At("RETURN"))
@Inject(method = "render", at = @At("RETURN"), require = 0)
public void render(GuiGraphics guiGraphics, int i, int j, float f, CallbackInfo ci) {
if (this.fadeOutStart != -1 && Flashback.isInReplay()) {
this.minecraft.setOverlay(null);
@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.At;
@Mixin(RenderStateShard.class)
public class MixinRenderStateShard {
@WrapOperation(method = "setupGlintTexturing", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getMillis()J"))
@WrapOperation(method = "setupGlintTexturing", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getMillis()J"), require = 0)
private static long setupGlintTexturing(Operation<Long> original) {
if (Flashback.isExporting()) {
double currentTick = Flashback.EXPORT_JOB.getCurrentTickDouble();