mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-02 06:28:48 +00:00
Public Release
This commit is contained in:
1 parent
666398e480
commit
61bb497a22
126 files changed
+8435
-1240
No files matched your search
@@ -16,7 +16,7 @@ public class MixinDebugScreenOverlay {
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||
public void render(GuiGraphics guiGraphics, CallbackInfo ci) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.isRunning()) {
|
||||
if (Flashback.isExporting()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ 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.ReplayVisuals;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import com.moulberry.flashback.exporting.PerfectFrames;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@@ -40,6 +43,18 @@ public abstract class MixinLevelRenderer {
|
||||
|
||||
@Shadow @Final public SectionOcclusionGraph sectionOcclusionGraph;
|
||||
|
||||
@Shadow
|
||||
private int ticks;
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||
public void tick(CallbackInfo ci) {
|
||||
ReplayServer replayServer = Flashback.getReplayServer();
|
||||
if (replayServer != null) {
|
||||
this.ticks = replayServer.getReplayTick();
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderLevel", at = @At("HEAD"))
|
||||
public void renderLevel(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f projection, CallbackInfo ci) {
|
||||
ReplayUI.lastProjectionMatrix = projection;
|
||||
@@ -48,49 +63,56 @@ public abstract class MixinLevelRenderer {
|
||||
|
||||
@Inject(method = "renderSectionLayer", at = @At("HEAD"), cancellable = true)
|
||||
public void renderSectionLayer(RenderType renderType, double d, double e, double f, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.renderBlocks) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.renderBlocks) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V", shift = At.Shift.AFTER))
|
||||
public void renderLevel_levelFogColor(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.renderSky) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.renderSky) {
|
||||
RenderSystem.clearColor(0.0f, 1.0f, 0.0f, 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@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"))
|
||||
public boolean renderLevel_renderBlockEntity(BlockEntityRenderDispatcher instance, BlockEntity blockEntity, float f, PoseStack poseStack, MultiBufferSource multiBufferSource) {
|
||||
return ReplayVisuals.renderBlocks;
|
||||
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"))
|
||||
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) {
|
||||
return ReplayVisuals.renderPlayers;
|
||||
return editorState == null || editorState.replayVisuals.renderPlayers;
|
||||
} else {
|
||||
return ReplayVisuals.renderEntities;
|
||||
return editorState == null || editorState.replayVisuals.renderEntities;
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getCloudsType()Lnet/minecraft/client/CloudStatus;"))
|
||||
public CloudStatus renderLevel_getCloudsType(Options instance, Operation<CloudStatus> original) {
|
||||
if (ReplayVisuals.renderSky) {
|
||||
return original.call(instance);
|
||||
} else {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.renderSky) {
|
||||
return CloudStatus.OFF;
|
||||
} else {
|
||||
return original.call(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@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"))
|
||||
public boolean renderLevel_renderParticles(ParticleEngine instance, LightTexture lightTexture, Camera camera, float f) {
|
||||
return ReplayVisuals.renderParticles;
|
||||
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"))
|
||||
public boolean renderLevel_renderSky(LevelRenderer instance, Matrix4f matrix4f, Matrix4f matrix4f2, float f, Camera camera, boolean bl, Runnable runnable) {
|
||||
return ReplayVisuals.renderSky;
|
||||
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"))
|
||||
|
||||
@@ -5,9 +5,12 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.configuration.FlashbackConfig;
|
||||
import com.moulberry.flashback.exporting.ExportJob;
|
||||
import com.moulberry.flashback.exporting.ExportJobQueue;
|
||||
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateCache;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.exporting.PerfectFrames;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import com.moulberry.flashback.ext.MinecraftExt;
|
||||
@@ -63,6 +66,8 @@ import java.time.Instant;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
@@ -129,7 +134,9 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
@Final
|
||||
public ParticleEngine particleEngine;
|
||||
|
||||
@Shadow @Final public DeltaTracker.Timer timer;
|
||||
@Shadow
|
||||
@Nullable
|
||||
public Entity cameraEntity;
|
||||
|
||||
@Inject(method="<init>", at=@At("RETURN"))
|
||||
public void init(GameConfig gameConfig, CallbackInfo ci) {
|
||||
@@ -145,7 +152,8 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
|
||||
@Inject(method = "renderNames", at = @At("HEAD"), cancellable = true)
|
||||
private static void renderNames(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!ReplayVisuals.renderNametags) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.renderNametags) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +173,7 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
Flashback.RECORDER.endTick(false);
|
||||
}
|
||||
|
||||
EditorStateCache.saveIfNeeded();
|
||||
EditorStateManager.saveIfNeeded();
|
||||
|
||||
ReplayServer replayServer = Flashback.getReplayServer();
|
||||
|
||||
@@ -173,63 +181,11 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
if (inReplay != inReplayLast) {
|
||||
inReplayLast = inReplay;
|
||||
if (inReplay) {
|
||||
ReplayVisuals.setupReplay();
|
||||
Minecraft.getInstance().options.hideGui = false;
|
||||
} else {
|
||||
ReplayVisuals.disable();
|
||||
EditorStateCache.reset();
|
||||
EditorStateManager.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if (inReplay && ReplayVisuals.forceEntityLerpTicks > 0) {
|
||||
ReplayVisuals.forceEntityLerpTicks -= 1;
|
||||
if (replayServer.replayPaused && this.level != null && !this.level.tickRateManager().runsNormally()) {
|
||||
for (Entity entity : this.level.entitiesForRendering()) {
|
||||
if (entity == this.player) {
|
||||
continue;
|
||||
}
|
||||
if (entity instanceof LivingEntity livingEntity) {
|
||||
if (livingEntity.lerpSteps > 0) {
|
||||
livingEntity.lerpPositionAndRotationStep(livingEntity.lerpSteps, livingEntity.lerpTargetX(),
|
||||
livingEntity.lerpTargetY(), livingEntity.lerpTargetZ(), livingEntity.lerpTargetYRot(), livingEntity.lerpTargetXRot());
|
||||
--livingEntity.lerpSteps;
|
||||
}
|
||||
if (livingEntity.lerpHeadSteps > 0) {
|
||||
livingEntity.lerpHeadRotationStep(livingEntity.lerpHeadSteps, livingEntity.lerpYHeadRot);
|
||||
--livingEntity.lerpHeadSteps;
|
||||
}
|
||||
livingEntity.setOldPosAndRot();
|
||||
livingEntity.tickHeadTurn(livingEntity.yBodyRot, 0.0f);
|
||||
} else {
|
||||
entity.moveTo(entity.lerpTargetX(), entity.lerpTargetY(), entity.lerpTargetZ(),
|
||||
entity.lerpTargetYRot(), entity.lerpTargetXRot());
|
||||
}
|
||||
if (entity.isPassenger()) {
|
||||
entity.setDeltaMovement(Vec3.ZERO);
|
||||
entity.getVehicle().positionRider(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private volatile boolean forceClientTick = false;
|
||||
|
||||
@Override
|
||||
public void flashback$forceClientTick() {
|
||||
this.forceClientTick = true;
|
||||
}
|
||||
|
||||
@WrapOperation(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/DeltaTracker$Timer;advanceTime(JZ)I"))
|
||||
public int runTick_advanceTime(DeltaTracker.Timer instance, long l, boolean runTick, Operation<Integer> original) {
|
||||
int ticks = original.call(instance, l, runTick);
|
||||
if (this.forceClientTick) {
|
||||
this.forceClientTick = false;
|
||||
this.particleEngine.clearParticles();
|
||||
return Math.max(1, ticks);
|
||||
}
|
||||
return ticks;
|
||||
}
|
||||
|
||||
@Inject(method = "getTickTargetMillis", at = @At("HEAD"), cancellable = true)
|
||||
@@ -249,8 +205,27 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
@Unique
|
||||
private final DeltaTracker.Timer localPlayerTimer = new DeltaTracker.Timer(20.0f, 0, FloatUnaryOperator.identity());
|
||||
|
||||
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V", at = @At("HEAD"))
|
||||
public void disconnect(Screen screen, boolean isTransferring, CallbackInfo ci) {
|
||||
try {
|
||||
if (Flashback.getConfig().automaticallyFinish && Flashback.RECORDER != null && !isTransferring) {
|
||||
Flashback.finishRecordingReplay();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Flashback.LOGGER.error("Failed to finish replay on disconnect", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;runAllTasks()V", shift = At.Shift.AFTER))
|
||||
public void runTick_runAllTasks(boolean runTick, CallbackInfo ci) {
|
||||
if (ExportJobQueue.drainingQueue) {
|
||||
if (ExportJobQueue.queuedJobs.isEmpty()) {
|
||||
ExportJobQueue.drainingQueue = false;
|
||||
} else if (Flashback.EXPORT_JOB == null) {
|
||||
Flashback.EXPORT_JOB = new ExportJob(ExportJobQueue.queuedJobs.removeFirst());
|
||||
}
|
||||
}
|
||||
|
||||
if (Flashback.EXPORT_JOB != null && !ReplayUI.isActive()) {
|
||||
try {
|
||||
PerfectFrames.enable();
|
||||
@@ -266,18 +241,26 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
if (this.level != null && this.player != null && !this.player.isPassenger() && !this.player.isRemoved()) {
|
||||
localPlayerTicks = Math.min(10, localPlayerTicks);
|
||||
for (int i = 0; i < localPlayerTicks; i++) {
|
||||
this.level.tickNonPassenger(this.player);
|
||||
this.level.guardEntityTick(this.level::tickNonPassenger, this.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float flashback$getLocalPlayerPartialTick() {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.isRunning()) {
|
||||
return this.timer.getGameTimeDeltaPartialTick(true);
|
||||
public float flashback$getLocalPlayerPartialTick(float originalPartialTick) {
|
||||
if (Flashback.isExporting() || this.cameraEntity != this.player) {
|
||||
return originalPartialTick;
|
||||
}
|
||||
return localPlayerTimer.getGameTimeDeltaPartialTick(true);
|
||||
return this.localPlayerTimer.getGameTimeDeltaPartialTick(true);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private final AtomicBoolean applyKeyframes = new AtomicBoolean(false);
|
||||
|
||||
@Override
|
||||
public void flashback$applyKeyframes() {
|
||||
this.applyKeyframes.set(true);
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/Window;setErrorSection(Ljava/lang/String;)V", ordinal = 1), cancellable = true)
|
||||
@@ -287,9 +270,10 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!replayServer.replayPaused) {
|
||||
EditorState editorState = EditorStateCache.get(replayServer.getMetadata().replayIdentifier);
|
||||
editorState.applyKeyframes((Minecraft) (Object) this, replayServer.getPartialReplayTick());
|
||||
boolean forceApplyKeyframes = this.applyKeyframes.compareAndSet(true, false);
|
||||
if (!replayServer.replayPaused || forceApplyKeyframes) {
|
||||
EditorState editorState = EditorStateManager.get(replayServer.getMetadata().replayIdentifier);
|
||||
editorState.applyKeyframes(new MinecraftKeyframeHandler((Minecraft) (Object) this), replayServer.getPartialReplayTick());
|
||||
}
|
||||
if (!replayServer.doClientRendering()) {
|
||||
ci.cancel();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.editor.ui.CustomImGuiImplGlfw;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
@@ -16,17 +17,23 @@ public class MixinMouseHandler {
|
||||
public void isMouseGrabbed(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ReplayUI.isActive()) {
|
||||
cir.setReturnValue(ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME);
|
||||
} else if (Flashback.isExporting()) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "grabMouse", at=@At("HEAD"), cancellable = true)
|
||||
public void grabMouse(CallbackInfo ci) {
|
||||
if (ReplayUI.isActive()) ci.cancel();
|
||||
if (ReplayUI.isActive() || Flashback.isExporting()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "releaseMouse", at=@At("HEAD"), cancellable = true)
|
||||
public void releaseMouse(CallbackInfo ci) {
|
||||
if (ReplayUI.isActive()) ci.cancel();
|
||||
if (ReplayUI.isActive()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,26 +3,22 @@ package com.moulberry.flashback.mixin;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.combo_options.Sizing;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = RenderTarget.class, priority = 1100)
|
||||
public class MixinRenderTarget {
|
||||
|
||||
@WrapOperation(method = "_blitToScreen", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_viewport(IIII)V", remap = false))
|
||||
public void blitToScreenViewport(int left, int bottom, int width, int height, Operation<Void> original) {
|
||||
if ((Object)this == Minecraft.getInstance().getMainRenderTarget() && ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
if ((Object)this == Minecraft.getInstance().getMainRenderTarget() && ReplayUI.shouldModifyViewport()) {
|
||||
ReplayUI.setupMainViewport();
|
||||
} else {
|
||||
original.call(left, bottom, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ext.ThreadedLevelLightEngineExt;
|
||||
import net.minecraft.server.level.ThreadedLevelLightEngine;
|
||||
import net.minecraft.world.level.chunk.LightChunkGetter;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@Mixin(ThreadedLevelLightEngine.class)
|
||||
public abstract class MixinThreadedLevelLightEngine extends LevelLightEngine implements ThreadedLevelLightEngineExt {
|
||||
@@ -21,4 +25,19 @@ public abstract class MixinThreadedLevelLightEngine extends LevelLightEngine imp
|
||||
public void flashback$submitPost(int x, int z, Runnable runnable) {
|
||||
this.addTask(x, z, ThreadedLevelLightEngine.TaskType.POST_UPDATE, runnable);
|
||||
}
|
||||
|
||||
@WrapOperation(method = "runUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"))
|
||||
public int runUpdate_runLightUpdates(ThreadedLevelLightEngine instance, Operation<Integer> original) {
|
||||
if (Flashback.isInReplay()) {
|
||||
try {
|
||||
return original.call(instance);
|
||||
} catch (Exception e) {
|
||||
Flashback.LOGGER.error("Exception occurred while processing light updates", e);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return original.call(instance);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,14 @@ package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.visuals.ReplayVisuals;
|
||||
import com.moulberry.flashback.combo_options.Sizing;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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;
|
||||
@@ -36,12 +37,22 @@ public abstract class MixinWindow {
|
||||
@Final
|
||||
private long window;
|
||||
|
||||
@Unique
|
||||
private float calculateWidthScaleFactor() {
|
||||
return Math.max(1/8f, Math.min(8f, (float) this.framebufferWidth / this.width));
|
||||
}
|
||||
|
||||
@Unique
|
||||
private float calculateHeightScaleFactor() {
|
||||
return Math.max(1/8f, Math.min(8f, (float) this.framebufferHeight / this.height));
|
||||
}
|
||||
|
||||
@Inject(method = "getWidth", at=@At("HEAD"), cancellable = true)
|
||||
public void getWidth(CallbackInfoReturnable<Integer> cir) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.shouldChangeFramebufferSize()) {
|
||||
cir.setReturnValue(Flashback.EXPORT_JOB.getWidth());
|
||||
} else if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
cir.setReturnValue(ReplayUI.getNewGameWidth((float) this.framebufferWidth / this.width));
|
||||
} else if (ReplayUI.shouldModifyViewport()) {
|
||||
cir.setReturnValue(ReplayUI.getNewGameWidth(this.calculateWidthScaleFactor()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,49 +60,29 @@ public abstract class MixinWindow {
|
||||
public void getHeight(CallbackInfoReturnable<Integer> cir) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.shouldChangeFramebufferSize()) {
|
||||
cir.setReturnValue(Flashback.EXPORT_JOB.getHeight());
|
||||
} else if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
cir.setReturnValue(ReplayUI.getNewGameHeight((float) this.framebufferHeight / this.height));
|
||||
} else if (ReplayUI.shouldModifyViewport()) {
|
||||
cir.setReturnValue(ReplayUI.getNewGameHeight(this.calculateHeightScaleFactor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getScreenWidth", at=@At("HEAD"), cancellable = true)
|
||||
public void getScreenWidth(CallbackInfoReturnable<Integer> cir) {
|
||||
if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
if (ReplayUI.shouldModifyViewport()) {
|
||||
cir.setReturnValue(ReplayUI.getNewGameWidth(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getScreenHeight", at=@At("HEAD"), cancellable = true)
|
||||
public void getScreenHeight(CallbackInfoReturnable<Integer> cir) {
|
||||
if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
if (ReplayUI.shouldModifyViewport()) {
|
||||
cir.setReturnValue(ReplayUI.getNewGameHeight(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onFramebufferResize", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/WindowEventHandler;resizeDisplay()V", shift = At.Shift.BEFORE))
|
||||
public void onFramebufferResize(long l, int i, int j, CallbackInfo ci) {
|
||||
int[] widthB = new int[1];
|
||||
int[] heightB = new int[1];
|
||||
GLFW.glfwGetWindowSize(this.window, widthB, heightB);
|
||||
if (widthB[0] > 0 && heightB[0] > 0) {
|
||||
this.width = widthB[0];
|
||||
this.height = heightB[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onResize", at=@At("HEAD"), cancellable = true)
|
||||
public void onResize(long l, int i, int j, CallbackInfo ci) {
|
||||
if (l != this.window) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
int[] widthB = new int[1];
|
||||
int[] heightB = new int[1];
|
||||
GLFW.glfwGetFramebufferSize(this.window, widthB, heightB);
|
||||
if (widthB[0] > 0 && heightB[0] > 0) {
|
||||
this.framebufferWidth = widthB[0];
|
||||
this.framebufferHeight = heightB[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +100,9 @@ public abstract class MixinWindow {
|
||||
j++;
|
||||
}
|
||||
cir.setReturnValue(j);
|
||||
} else if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
int fbw = ReplayUI.getNewGameWidth((float) this.framebufferWidth / this.width);
|
||||
int fbh = ReplayUI.getNewGameHeight((float) this.framebufferHeight / this.height);
|
||||
} else if (ReplayUI.shouldModifyViewport()) {
|
||||
int fbw = ReplayUI.getNewGameWidth(this.calculateWidthScaleFactor());
|
||||
int fbh = ReplayUI.getNewGameHeight(this.calculateHeightScaleFactor());
|
||||
|
||||
int j = 1;
|
||||
while (j != scale && j < fbw && j < fbh && fbw / (j + 1) >= 320 && fbh / (j + 1) >= 240) {
|
||||
@@ -137,9 +128,9 @@ public abstract class MixinWindow {
|
||||
this.guiScaledHeight = (double)fbh / d > (double)j ? j + 1 : j;
|
||||
|
||||
ci.cancel();
|
||||
} else if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
int fbw = ReplayUI.getNewGameWidth((float) this.framebufferWidth / this.width);
|
||||
int fbh = ReplayUI.getNewGameHeight((float) this.framebufferHeight / this.height);
|
||||
} else if (ReplayUI.shouldModifyViewport()) {
|
||||
int fbw = ReplayUI.getNewGameWidth(this.calculateWidthScaleFactor());
|
||||
int fbh = ReplayUI.getNewGameHeight(this.calculateHeightScaleFactor());
|
||||
|
||||
this.guiScale = d;
|
||||
int i = (int)((double)fbw / d);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.moulberry.flashback.mixin.audio;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.blaze3d.audio.Library;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import org.lwjgl.openal.ALC10;
|
||||
import org.lwjgl.openal.ALC11;
|
||||
import org.lwjgl.openal.SOFTLoopback;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
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.nio.IntBuffer;
|
||||
|
||||
@Mixin(Library.class)
|
||||
public class MixinAudioLibrary {
|
||||
|
||||
@Shadow
|
||||
public long currentDevice;
|
||||
|
||||
@Unique
|
||||
private boolean usingLoopbackDevice = false;
|
||||
|
||||
@Inject(method = "init", at = @At("HEAD"))
|
||||
public void init(String string, boolean bl, CallbackInfo ci) {
|
||||
this.usingLoopbackDevice = Flashback.isExporting() && Flashback.EXPORT_JOB.getSettings().recordAudio();
|
||||
if (this.usingLoopbackDevice) {
|
||||
Flashback.LOGGER.info("Enabling loopback device for recording audio");
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "init", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/audio/Library;openDeviceOrFallback(Ljava/lang/String;)J"))
|
||||
public long init_openDevice(String string, Operation<Long> original) {
|
||||
if (this.usingLoopbackDevice) {
|
||||
return SOFTLoopback.alcLoopbackOpenDeviceSOFT((CharSequence) null);
|
||||
} else {
|
||||
return original.call(string);
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "init", at = @At(value = "INVOKE", target = "Lorg/lwjgl/openal/ALC10;alcCreateContext(JLjava/nio/IntBuffer;)J", remap = false))
|
||||
public long init_createContext(long deviceHandle, IntBuffer attrList, Operation<Long> original) {
|
||||
if (this.usingLoopbackDevice) {
|
||||
try (MemoryStack memoryStack = MemoryStack.stackPush()) {
|
||||
IntBuffer intBuffer = memoryStack.callocInt(7)
|
||||
.put(SOFTLoopback.ALC_FORMAT_TYPE_SOFT).put(SOFTLoopback.ALC_FLOAT_SOFT)
|
||||
.put(SOFTLoopback.ALC_FORMAT_CHANNELS_SOFT).put(SOFTLoopback.ALC_MONO_SOFT)
|
||||
.put(ALC10.ALC_FREQUENCY).put(44100)
|
||||
.put(0).flip();
|
||||
return ALC10.alcCreateContext(this.currentDevice, intBuffer);
|
||||
}
|
||||
} else {
|
||||
return original.call(deviceHandle, attrList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.moulberry.flashback.mixin.audio;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
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(SoundEngine.class)
|
||||
public class MixinSoundEngine {
|
||||
|
||||
@Unique
|
||||
private boolean wasExportingAudio = false;
|
||||
|
||||
@Inject(method = "shouldChangeDevice", at = @At("HEAD"), cancellable = true)
|
||||
public void shouldChangeDevice(CallbackInfoReturnable<Boolean> cir) {
|
||||
boolean isExportingAudio = Flashback.isExporting() && Flashback.EXPORT_JOB.getSettings().recordAudio();
|
||||
|
||||
if (wasExportingAudio != isExportingAudio) {
|
||||
wasExportingAudio = isExportingAudio;
|
||||
cir.setReturnValue(true);
|
||||
} else if (isExportingAudio) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.moulberry.flashback.mixin.compat;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import net.minecraft.client.Camera;
|
||||
@@ -23,9 +24,10 @@ 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) {
|
||||
if (!ReplayVisuals.renderBlocks) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.renderBlocks) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.moulberry.flashback.mixin.norandom;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.util.RandomSource;
|
||||
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.Random;
|
||||
|
||||
@Mixin(Particle.class)
|
||||
public class MixinParticle {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
protected RandomSource random;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/client/multiplayer/ClientLevel;DDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/Particle;setSize(FF)V"))
|
||||
private void newParticle(ClientLevel clientLevel, double d, double e, double f, CallbackInfo ci) {
|
||||
if (Flashback.isExporting()) {
|
||||
Random random = Flashback.EXPORT_JOB.getParticleRandom();
|
||||
if (random != null) {
|
||||
this.random.setSeed(random.nextLong());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
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(AttributeInstance.class)
|
||||
public abstract class MixinAttributeInstance {
|
||||
|
||||
@Shadow
|
||||
public abstract boolean removeModifier(ResourceLocation resourceLocation);
|
||||
|
||||
@Inject(method = "addModifier", at = @At(value = "HEAD"))
|
||||
public void addModifier(AttributeModifier attributeModifier, CallbackInfo ci) {
|
||||
// Some mods (e.g. HorseBuff) may end up adding a duplicate modifier while inside a replay
|
||||
// Remove the modifier first in order to ensure no exceptions are thrown
|
||||
if (Flashback.isInReplay()) {
|
||||
try {
|
||||
this.removeModifier(attributeModifier.id());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||
import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
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.BitSet;
|
||||
|
||||
@Mixin(value = ChunkHolder.class, priority = 1100)
|
||||
public class MixinChunkHolder {
|
||||
|
||||
@Shadow
|
||||
private boolean hasChangedSections;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private BitSet skyChangedLightSectionFilter;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private BitSet blockChangedLightSectionFilter;
|
||||
|
||||
@Inject(method = "broadcastChanges", at = @At("HEAD"))
|
||||
public void broadcastChanges(LevelChunk levelChunk, CallbackInfo ci) {
|
||||
if (levelChunk instanceof LevelChunkExt levelChunkExt) {
|
||||
if (this.hasChangedSections || !this.skyChangedLightSectionFilter.isEmpty() || !this.blockChangedLightSectionFilter.isEmpty()) {
|
||||
levelChunkExt.flashback$setCachedChunkId(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,12 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
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 net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
@@ -20,6 +22,7 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import org.joml.Quaternionf;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -29,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class MixinGameRenderer {
|
||||
public abstract class MixinGameRenderer {
|
||||
|
||||
|
||||
@WrapOperation(method = "render", at=@At(value = "FIELD", target = "Lnet/minecraft/client/Options;pauseOnLostFocus:Z"))
|
||||
@@ -48,6 +51,9 @@ public class MixinGameRenderer {
|
||||
@Final
|
||||
private Minecraft minecraft;
|
||||
|
||||
@Shadow
|
||||
public abstract float getDepthFar();
|
||||
|
||||
@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) {
|
||||
@@ -60,8 +66,9 @@ public class MixinGameRenderer {
|
||||
public void renderItemInHand_renderHandsWithItems(ItemInHandRenderer instance, float f, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, LocalPlayer localPlayer, int i, Operation<Void> original) {
|
||||
AbstractClientPlayer spectatingPlayer = Flashback.getSpectatingPlayer();
|
||||
if (spectatingPlayer != null) {
|
||||
f = ((MinecraftExt)this.minecraft).flashback$getLocalPlayerPartialTick();
|
||||
((ItemInHandRendererExt)instance).flashback$renderHandsWithItems(f, poseStack, bufferSource, spectatingPlayer, i);
|
||||
Entity entity = this.minecraft.getCameraEntity() == null ? this.minecraft.player : this.minecraft.getCameraEntity();
|
||||
float frozenPartialTick = this.minecraft.level.tickRateManager().isEntityFrozen(entity) ? 1.0f : f;
|
||||
((ItemInHandRendererExt)instance).flashback$renderHandsWithItems(frozenPartialTick, poseStack, bufferSource, spectatingPlayer, i);
|
||||
} else {
|
||||
original.call(instance, f, poseStack, bufferSource, localPlayer, i);
|
||||
}
|
||||
@@ -70,11 +77,34 @@ public class MixinGameRenderer {
|
||||
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V"))
|
||||
public void renderLevel_setupCamera(Camera instance, BlockGetter blockGetter, Entity entity, boolean bl, boolean bl2, float f, Operation<Void> original) {
|
||||
if (Flashback.isInReplay()) {
|
||||
f = ((MinecraftExt)this.minecraft).flashback$getLocalPlayerPartialTick();
|
||||
f = ((MinecraftExt)this.minecraft).flashback$getLocalPlayerPartialTick(f);
|
||||
}
|
||||
original.call(instance, blockGetter, entity, bl, bl2, f);
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
// @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()) {
|
||||
@@ -89,13 +119,13 @@ public class MixinGameRenderer {
|
||||
cir.setReturnValue(70.0);
|
||||
return;
|
||||
}
|
||||
|
||||
int fov = this.minecraft.options.fov().get().intValue();
|
||||
if (ReplayVisuals.overrideFov) {
|
||||
cir.setReturnValue((double) ReplayVisuals.overrideFovAmount);
|
||||
return;
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.replayVisuals.overrideFov) {
|
||||
cir.setReturnValue((double) editorState.replayVisuals.overrideFovAmount);
|
||||
} else {
|
||||
int fov = this.minecraft.options.fov().get().intValue();
|
||||
cir.setReturnValue((double) fov);
|
||||
}
|
||||
cir.setReturnValue((double) fov);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.chunk.UpgradeData;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.blending.BlendingData;
|
||||
import net.minecraft.world.level.lighting.LightEngine;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
||||
@Mixin(LevelChunk.class)
|
||||
public abstract class MixinLevelChunk extends ChunkAccess implements LevelChunkExt {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Level level;
|
||||
|
||||
@Shadow
|
||||
public abstract void addAndRegisterBlockEntity(BlockEntity blockEntity);
|
||||
|
||||
@Shadow
|
||||
protected abstract <T extends BlockEntity> void updateBlockEntityTicker(T blockEntity);
|
||||
|
||||
@Shadow
|
||||
public abstract @Nullable BlockEntity getBlockEntity(BlockPos blockPos, LevelChunk.EntityCreationType entityCreationType);
|
||||
|
||||
public MixinLevelChunk(ChunkPos chunkPos, UpgradeData upgradeData, LevelHeightAccessor levelHeightAccessor, Registry<Biome> registry, long l, @Nullable LevelChunkSection[] levelChunkSections, @Nullable BlendingData blendingData) {
|
||||
super(chunkPos, upgradeData, levelHeightAccessor, registry, l, levelChunkSections, blendingData);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private int cachedChunkId = -1;
|
||||
|
||||
@Override
|
||||
public int flashback$getCachedChunkId() {
|
||||
return this.cachedChunkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$setCachedChunkId(int id) {
|
||||
this.cachedChunkId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$setBlockStateWithoutUpdates(BlockPos blockPos, BlockState blockState) {
|
||||
int y = blockPos.getY();
|
||||
LevelChunkSection levelChunkSection = this.getSection(this.getSectionIndex(y));
|
||||
boolean oldHasOnlyAir = levelChunkSection.hasOnlyAir();
|
||||
if (oldHasOnlyAir && blockState.isAir()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set block
|
||||
int localX = blockPos.getX() & 0xF;
|
||||
int localY = y & 0xF;
|
||||
int localZ = blockPos.getZ() & 0xF;
|
||||
BlockState oldBlockState = levelChunkSection.setBlockState(localX, localY, localZ, blockState);
|
||||
if (oldBlockState == blockState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
this.heightmaps.get(Heightmap.Types.OCEAN_FLOOR).update(localX, y, localZ, blockState);
|
||||
this.heightmaps.get(Heightmap.Types.WORLD_SURFACE).update(localX, y, localZ, blockState);
|
||||
|
||||
// Update air status
|
||||
boolean newHasOnlyAir = levelChunkSection.hasOnlyAir();
|
||||
if (oldHasOnlyAir != newHasOnlyAir) {
|
||||
this.level.getChunkSource().getLightEngine().updateSectionStatus(blockPos, newHasOnlyAir);
|
||||
}
|
||||
|
||||
// Update light
|
||||
if (LightEngine.hasDifferentLightProperties(this, blockPos, oldBlockState, blockState)) {
|
||||
if (this.skyLightSources != null) {
|
||||
this.skyLightSources.update(this, localX, y, localZ);
|
||||
}
|
||||
this.level.getChunkSource().getLightEngine().checkBlock(blockPos);
|
||||
}
|
||||
|
||||
// Update block entity
|
||||
Block block = blockState.getBlock();
|
||||
if (!oldBlockState.is(block) && oldBlockState.hasBlockEntity()) {
|
||||
this.removeBlockEntity(blockPos);
|
||||
}
|
||||
if (!levelChunkSection.getBlockState(localX, localY, localZ).is(block)) {
|
||||
return;
|
||||
}
|
||||
if (blockState.hasBlockEntity()) {
|
||||
BlockEntity blockEntity = this.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
|
||||
if (blockEntity == null) {
|
||||
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
|
||||
if (blockEntity != null) {
|
||||
this.addAndRegisterBlockEntity(blockEntity);
|
||||
}
|
||||
} else {
|
||||
blockEntity.setBlockState(blockState);
|
||||
this.updateBlockEntityTicker(blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
this.unsaved = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.ext.LevelChunkSectionExt;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.chunk.PalettedContainer;
|
||||
import net.minecraft.world.level.chunk.PalettedContainerRO;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(LevelChunkSection.class)
|
||||
public class MixinLevelChunkSection implements LevelChunkSectionExt {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private PalettedContainer<BlockState> states;
|
||||
|
||||
@Shadow
|
||||
private short nonEmptyBlockCount;
|
||||
|
||||
@Shadow
|
||||
private PalettedContainerRO<Holder<Biome>> biomes;
|
||||
|
||||
@Unique
|
||||
private int cachedChunkId = -1;
|
||||
|
||||
@Override
|
||||
public int flashback$getCachedChunkId() {
|
||||
return this.cachedChunkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$setCachedChunkId(int cachedChunkId) {
|
||||
this.cachedChunkId = cachedChunkId;
|
||||
}
|
||||
|
||||
@Inject(method = "read", at = @At("RETURN"))
|
||||
public void read(FriendlyByteBuf friendlyByteBuf, CallbackInfo ci) {
|
||||
this.cachedChunkId = -1;
|
||||
}
|
||||
|
||||
@Inject(method = "setBlockState(IIILnet/minecraft/world/level/block/state/BlockState;Z)Lnet/minecraft/world/level/block/state/BlockState;", at = @At("RETURN"))
|
||||
public void setBlockState(int i, int j, int k, BlockState blockState, boolean bl, CallbackInfoReturnable<BlockState> cir) {
|
||||
this.cachedChunkId = -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.playback.ReplayPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.ServerTickRateManager;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
@@ -10,6 +11,7 @@ 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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(TickRateManager.class)
|
||||
@@ -18,16 +20,34 @@ public abstract class MixinTickRateManager {
|
||||
@Shadow
|
||||
public abstract boolean runsNormally();
|
||||
|
||||
@Shadow
|
||||
protected boolean runGameElements;
|
||||
|
||||
/*
|
||||
* Freeze the replay server, preventing game elements from running normally
|
||||
*/
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
public void tick(CallbackInfo ci) {
|
||||
if (Flashback.isInReplay() && this.isServerTickRateManager) {
|
||||
this.runGameElements = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private final boolean isClientTickRateManager = !((Object)this instanceof ServerTickRateManager);
|
||||
private final boolean isServerTickRateManager = ((Object)this instanceof ServerTickRateManager);
|
||||
|
||||
@Inject(method = "isEntityFrozen", at = @At("HEAD"), cancellable = true)
|
||||
public void isEntityFrozen(Entity entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (this.isClientTickRateManager && Flashback.isInReplay()) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.isRunning()) {
|
||||
cir.setReturnValue(false);
|
||||
if (Flashback.isInReplay()) {
|
||||
if (this.isServerTickRateManager) {
|
||||
cir.setReturnValue(!(entity instanceof ReplayPlayer));
|
||||
} else {
|
||||
cir.setReturnValue(!this.runsNormally() || entity == Minecraft.getInstance().player);
|
||||
if (Flashback.isExporting()) {
|
||||
cir.setReturnValue(false);
|
||||
} else {
|
||||
cir.setReturnValue(!this.runsNormally() || entity == Minecraft.getInstance().player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.moulberry.flashback.mixin.record;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.ConnectionProtocol;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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;
|
||||
|
||||
@Mixin(ClientLevel.class)
|
||||
public class MixinClientLevel {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft minecraft;
|
||||
|
||||
@Inject(method = "levelEvent", at = @At("HEAD"))
|
||||
public void levelEvent(Player player, int type, BlockPos blockPos, int data, CallbackInfo ci) {
|
||||
if (Flashback.RECORDER != null && !Flashback.RECORDER.isPaused()) {
|
||||
Flashback.RECORDER.writeLevelEvent(type, blockPos, data, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "globalLevelEvent", at = @At("HEAD"))
|
||||
public void globalLevelEvent(int type, BlockPos blockPos, int data, CallbackInfo ci) {
|
||||
if (Flashback.RECORDER != null && !Flashback.RECORDER.isPaused()) {
|
||||
Flashback.RECORDER.writeLevelEvent(type, blockPos, data, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "playSeededSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;FFJ)V", at = @At("RETURN"))
|
||||
public void playSeededSoundEntity(@Nullable Player player, Entity entity, Holder<SoundEvent> holder, SoundSource soundSource, float volume, float pitch, long seed, CallbackInfo ci) {
|
||||
if (player != null && player == this.minecraft.player && Flashback.RECORDER != null && !Flashback.RECORDER.isPaused()) {
|
||||
Flashback.RECORDER.writePacketAsync(new ClientboundSoundEntityPacket(holder, soundSource, entity, volume, pitch, seed), ConnectionProtocol.PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "playSeededSound(Lnet/minecraft/world/entity/player/Player;DDDLnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;FFJ)V", at = @At("RETURN"))
|
||||
public void playSeededSoundNormal(@Nullable Player player, double x, double y, double z, Holder<SoundEvent> holder, SoundSource soundSource, float volume, float pitch, long seed, CallbackInfo ci) {
|
||||
if (player != null && player == this.minecraft.player && Flashback.RECORDER != null && !Flashback.RECORDER.isPaused()) {
|
||||
Flashback.RECORDER.writePacketAsync(new ClientboundSoundPacket(holder, soundSource, x, y, z, volume, pitch, seed), ConnectionProtocol.PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
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.level.Level;
|
||||
import org.slf4j.Logger;
|
||||
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 java.util.Optional;
|
||||
@@ -21,6 +27,10 @@ public class MixinPlayerList {
|
||||
* Don't change the dimension of replay viewers when spawning them
|
||||
*/
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private MinecraftServer server;
|
||||
|
||||
@WrapOperation(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Ljava/util/Optional;flatMap(Ljava/util/function/Function;)Ljava/util/Optional;"))
|
||||
public Optional<ResourceKey<Level>> placeNewPlayer_flatMap(Optional instance, Function function, Operation<Optional<ResourceKey<Level>>> original,
|
||||
@Local(argsOnly = true) ServerPlayer serverPlayer) {
|
||||
@@ -30,4 +40,9 @@ public class MixinPlayerList {
|
||||
return original.call(instance, function);
|
||||
}
|
||||
|
||||
@WrapWithCondition(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;[Ljava/lang/Object;)V", remap = false))
|
||||
public boolean placeNewPlayer_logInfo(Logger instance, String s, Object[] objects) {
|
||||
return !(this.server instanceof ReplayServer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.server.level.ServerEntity;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
@@ -12,12 +14,12 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
public class MixinServerEntity {
|
||||
|
||||
/*
|
||||
* Force update interval to be 1 on a replay server
|
||||
* Force update interval to be 1 on a replay server, sending updates as soon as possible
|
||||
*/
|
||||
|
||||
@ModifyVariable(method = "<init>", at = @At("HEAD"), argsOnly = true)
|
||||
private static int init_modifyUpdateInterval(int updateInterval, @Local(argsOnly = true) ServerLevel level) {
|
||||
if (level.getServer() instanceof ReplayServer) {
|
||||
if (updateInterval <= 3 && level != null && level.getServer() instanceof ReplayServer) {
|
||||
return 1;
|
||||
}
|
||||
return updateInterval;
|
||||
|
||||
+7
-2
@@ -1,6 +1,7 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.network.protocol.login.ServerboundHelloPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -13,6 +14,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(ServerLoginPacketListenerImpl.class)
|
||||
@@ -32,8 +34,11 @@ public abstract class MixinServerLoginPacketListenerImpl {
|
||||
@Inject(method = "handleHello", at = @At("HEAD"), cancellable = true)
|
||||
public void handleHello(ServerboundHelloPacket serverboundHelloPacket, CallbackInfo ci) {
|
||||
if (this.server instanceof ReplayServer) {
|
||||
this.requestedUsername = "ReplayViewer";
|
||||
this.startClientVerification(new GameProfile(UUID.randomUUID(), "ReplayViewer"));
|
||||
this.requestedUsername = ReplayServer.REPLAY_VIEWER_NAME;
|
||||
UUID replayViewerUUID = UUID.nameUUIDFromBytes(serverboundHelloPacket.name().getBytes(StandardCharsets.UTF_8));
|
||||
GameProfile gameProfile = new GameProfile(replayViewerUUID, ReplayServer.REPLAY_VIEWER_NAME);
|
||||
gameProfile.getProperties().put("IsReplayViewer", new Property("IsReplayViewer", "True"));
|
||||
this.startClientVerification(gameProfile);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -3,27 +3,22 @@ package com.moulberry.flashback.mixin.replay_server;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.server.ServerTickRateManager;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(TickRateManager.class)
|
||||
public abstract class MixinTickRateManager {
|
||||
|
||||
@Shadow
|
||||
protected boolean runGameElements;
|
||||
|
||||
/*
|
||||
* Freeze the replay server, preventing game elements from running normally
|
||||
*/
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
public void tick(CallbackInfo ci) {
|
||||
if (Flashback.isInReplay() && (Object)this instanceof ServerTickRateManager) {
|
||||
this.runGameElements = false;
|
||||
}
|
||||
@Inject(method = "isEntityFrozen", at = @At("RETURN"))
|
||||
public void isEntityFrozen(Entity entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.moulberry.flashback.mixin.ui;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.screen.BottomTextWidget;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.layouts.GridLayout;
|
||||
import net.minecraft.client.gui.layouts.LayoutElement;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.PauseScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -19,8 +22,8 @@ public class MixinPauseScreen {
|
||||
|
||||
@Inject(method = "createPauseMenu", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/layouts/GridLayout;arrangeElements()V", shift = At.Shift.BEFORE))
|
||||
public void createPauseMenu(CallbackInfo ci, @Local GridLayout.RowHelper rowHelper) {
|
||||
if (!Flashback.isInReplay()) {
|
||||
rowHelper.addChild(new BottomTextWidget(204, 10, Component.literal("Flashback"), Minecraft.getInstance().font), 2);
|
||||
if (!Flashback.isInReplay() && !Flashback.getConfig().hidePauseMenuControls) {
|
||||
rowHelper.addChild(new BottomTextWidget(204, 30, Component.literal("Flashback"), Minecraft.getInstance().font), 2);
|
||||
if (Flashback.RECORDER == null) {
|
||||
rowHelper.addChild(Button.builder(Component.literal("Start Recording"), (button) -> {
|
||||
Flashback.startRecordingReplay();
|
||||
@@ -59,4 +62,12 @@ public class MixinPauseScreen {
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "createPauseMenu", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/layouts/FrameLayout;alignInRectangle(Lnet/minecraft/client/gui/layouts/LayoutElement;IIIIFF)V"))
|
||||
public void createPauseMenu_alignInRectangle(LayoutElement layoutElement, int i, int j, int k, int l, float f, float g, Operation<Void> original) {
|
||||
if (!Flashback.isInReplay() && !Flashback.getConfig().hidePauseMenuControls) {
|
||||
g += 0.05f;
|
||||
}
|
||||
original.call(layoutElement, i, j, k, l, f, g);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,14 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
|
||||
import com.moulberry.flashback.screen.FlashbackButton;
|
||||
import com.moulberry.flashback.screen.SelectReplayScreen;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.Screens;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ImageButton;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -33,8 +37,34 @@ public class MixinTitleScreen extends Screen {
|
||||
@Unique
|
||||
private final List<AbstractWidget> normalMenuWidgets = new ArrayList<>();
|
||||
|
||||
@Unique
|
||||
private AbstractWidget openSelectReplayScreenButton = null;
|
||||
|
||||
@Inject(method = "init", at = @At("RETURN"))
|
||||
public void init(CallbackInfo ci) {
|
||||
if (this.openSelectReplayScreenButton != null) {
|
||||
this.removeWidget(this.openSelectReplayScreenButton);
|
||||
this.openSelectReplayScreenButton = null;
|
||||
}
|
||||
}
|
||||
|
||||
// We do this on tick to ensure that our button is added after ever other mod's
|
||||
// Our button logic has automatic repositioning, whereas other mods (i.e. ModMenu)
|
||||
// might not implement repositioning logic, causing our button to render under theirs
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
public void tick(CallbackInfo ci) {
|
||||
if (this.openSelectReplayScreenButton == null) {
|
||||
this.createOpenSelectReplayScreenButton();
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private void createOpenSelectReplayScreenButton() {
|
||||
if (this.openSelectReplayScreenButton != null) {
|
||||
this.removeWidget(this.openSelectReplayScreenButton);
|
||||
this.openSelectReplayScreenButton = null;
|
||||
}
|
||||
|
||||
for (int offsetX = 0; offsetX < 5; offsetX++) {
|
||||
for (int i = this.normalMenuWidgets.size()-1; i >= 0; i--) {
|
||||
AbstractWidget widget = this.normalMenuWidgets.get(i);
|
||||
@@ -48,7 +78,7 @@ public class MixinTitleScreen extends Screen {
|
||||
for (Renderable renderable : this.renderables) {
|
||||
if (renderable instanceof AbstractWidget otherWidget) {
|
||||
if (x < otherWidget.getRight() && x+size > otherWidget.getX() &&
|
||||
y < otherWidget.getBottom() && y+size > otherWidget.getY()) {
|
||||
y < otherWidget.getBottom() && y+size > otherWidget.getY()) {
|
||||
overlapsWithExistingButton = true;
|
||||
break;
|
||||
}
|
||||
@@ -56,9 +86,10 @@ public class MixinTitleScreen extends Screen {
|
||||
}
|
||||
|
||||
if (!overlapsWithExistingButton) {
|
||||
this.addRenderableWidget(Button.builder(Component.literal("R"), button -> {
|
||||
this.openSelectReplayScreenButton = new FlashbackButton(x, y, size, size, Component.literal("Open Replays"), button -> {
|
||||
this.minecraft.setScreen(new SelectReplayScreen(this));
|
||||
}).bounds(x, y, size, size).build());
|
||||
});
|
||||
this.addRenderableWidget(this.openSelectReplayScreenButton);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.BossHealthOverlay;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -13,7 +14,8 @@ public class MixinBossHealthOverlay {
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||
public void render(GuiGraphics guiGraphics, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showBossBar) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.showBossBar) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.visuals.ReplayVisuals;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -12,8 +14,9 @@ public class MixinClientLevelData {
|
||||
|
||||
@Inject(method = "getDayTime", at = @At("HEAD"), cancellable = true)
|
||||
public void getDayTime(CallbackInfoReturnable<Long> cir) {
|
||||
if (ReplayVisuals.overrideTimeOfDay >= 0) {
|
||||
cir.setReturnValue(ReplayVisuals.overrideTimeOfDay);
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.replayVisuals.overrideTimeOfDay >= 0) {
|
||||
cir.setReturnValue(editorState.replayVisuals.overrideTimeOfDay);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -3,7 +3,8 @@ package com.moulberry.flashback.mixin.visuals;
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
@@ -34,7 +35,8 @@ 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"))
|
||||
public boolean renderShadow(PoseStack poseStack, MultiBufferSource multiBufferSource, Entity entity, float f, float g, LevelReader levelReader, float h) {
|
||||
return ReplayVisuals.renderBlocks;
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
return editorState == null || editorState.replayVisuals.renderBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.mojang.blaze3d.shaders.FogShape;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -15,9 +16,10 @@ public class MixinFogRenderer {
|
||||
|
||||
@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
|
||||
private static void setupFog(Camera camera, FogRenderer.FogMode fogMode, float f, boolean bl, float g, CallbackInfo ci) {
|
||||
if (ReplayVisuals.overrideFog) {
|
||||
RenderSystem.setShaderFogStart(ReplayVisuals.overrideFogStart);
|
||||
RenderSystem.setShaderFogEnd(ReplayVisuals.overrideFogEnd);
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.replayVisuals.overrideFog) {
|
||||
RenderSystem.setShaderFogStart(editorState.replayVisuals.overrideFogStart);
|
||||
RenderSystem.setShaderFogEnd(editorState.replayVisuals.overrideFogEnd);
|
||||
RenderSystem.setShaderFogShape(FogShape.SPHERE);
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.editor.ui.CustomImGuiImplGlfw;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
@@ -18,28 +20,32 @@ public class MixinGui {
|
||||
|
||||
@Inject(method = "renderChat", at = @At("HEAD"), cancellable = true)
|
||||
public void renderChat(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showChat) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.showChat) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderTitle", at = @At("HEAD"), cancellable = true)
|
||||
public void renderTitle(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showTitleText) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.showTitleText) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderScoreboardSidebar", at = @At("HEAD"), cancellable = true)
|
||||
public void renderScoreboardSidebar(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showScoreboard) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.showScoreboard) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderOverlayMessage", at = @At("HEAD"), cancellable = true)
|
||||
public void renderOverlayMessage(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showActionBar) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && !editorState.replayVisuals.showActionBar) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -49,6 +55,9 @@ public class MixinGui {
|
||||
if (ReplayUI.isActive() && ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
if (Flashback.getSpectatingPlayer() != null) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.visuals.WorldRenderHook;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.RenderBuffers;
|
||||
import org.joml.Matrix4f;
|
||||
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;
|
||||
|
||||
@Mixin(LevelRenderer.class)
|
||||
public class MixinLevelRenderer {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private RenderBuffers renderBuffers;
|
||||
|
||||
@Inject(method="renderLevel", at=@At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/Options;getCloudsType()Lnet/minecraft/client/CloudStatus;",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
public void renderLevelPost(net.minecraft.client.DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture,
|
||||
Matrix4f matrix4f, Matrix4f projection, CallbackInfo ci) {
|
||||
|
||||
if (!Flashback.isInReplay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.renderBuffers.bufferSource().endBatch();
|
||||
|
||||
PoseStack poseStack = new PoseStack();
|
||||
poseStack.mulPose(matrix4f);
|
||||
|
||||
// Set model view stack to identity
|
||||
var modelViewStack = RenderSystem.getModelViewStack();
|
||||
modelViewStack.pushMatrix();
|
||||
modelViewStack.identity();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
|
||||
float tickDelta = deltaTracker.getGameTimeDeltaPartialTick(true);
|
||||
WorldRenderHook.renderHook(poseStack, tickDelta, renderBlockOutline, camera, gameRenderer, lightTexture, projection);
|
||||
|
||||
this.renderBuffers.bufferSource().endBatch();
|
||||
|
||||
// Pop model view stack
|
||||
modelViewStack.popMatrix();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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 com.moulberry.flashback.Utils;
|
||||
import com.moulberry.flashback.ext.OptionsExt;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.client.OptionInstance;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@Mixin(MouseHandler.class)
|
||||
public class MixinMouseHandler {
|
||||
|
||||
// Reduces sensitivity when overriding fov to a lower value
|
||||
// This makes the camera much easier to control with low fov values
|
||||
|
||||
@WrapOperation(method = "turnPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;sensitivity()Lnet/minecraft/client/OptionInstance;"))
|
||||
public OptionInstance<Double> turnPlayer_sensitivity(Options instance, Operation<OptionInstance<Double>> original) {
|
||||
OptionInstance<Double> sensitivity = original.call(instance);
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.replayVisuals.overrideFov) {
|
||||
float newFov = editorState.replayVisuals.overrideFovAmount;
|
||||
if (newFov > 20.0) {
|
||||
return original.call(instance);
|
||||
}
|
||||
float oldFov = ((OptionsExt)instance).flashback$getOriginalFov();
|
||||
|
||||
if (newFov < oldFov) {
|
||||
float newFocalLength = Utils.fovToFocalLength(newFov);
|
||||
float oldFocalLength = Utils.fovToFocalLength(oldFov);
|
||||
|
||||
float sensitivityMultiplier = oldFocalLength / newFocalLength;
|
||||
double newSensitivity = sensitivity.get() * sensitivityMultiplier;
|
||||
|
||||
sensitivity = new OptionInstance<>("options.sensitivity", OptionInstance.noTooltip(), (component, double_) -> {
|
||||
if (double_ == 0.0) {
|
||||
return Options.genericValueLabel(component, Component.translatable("options.sensitivity.min"));
|
||||
}
|
||||
if (double_ == 1.0) {
|
||||
return Options.genericValueLabel(component, Component.translatable("options.sensitivity.max"));
|
||||
}
|
||||
return Component.translatable("options.percent_value", component, (int)(double_ * 200.0));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, newSensitivity, double_ -> {});
|
||||
}
|
||||
}
|
||||
return sensitivity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +1,46 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.ext.OptionsExt;
|
||||
import net.minecraft.client.OptionInstance;
|
||||
import net.minecraft.client.Options;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Options.class)
|
||||
public class MixinOptions {
|
||||
public class MixinOptions implements OptionsExt {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private OptionInstance<Integer> fov;
|
||||
@Unique
|
||||
private OptionInstance<Integer> cachedOptionInstance = null;
|
||||
private OptionInstance<Integer> cachedFovOptionInstance = null;
|
||||
|
||||
@Inject(method = "fov", at = @At("RETURN"), cancellable = true)
|
||||
public void fov(CallbackInfoReturnable<OptionInstance<Integer>> cir) {
|
||||
if (ReplayVisuals.overrideFov) {
|
||||
if (this.cachedOptionInstance == null || this.cachedOptionInstance.get() != Math.round(ReplayVisuals.overrideFovAmount)) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.replayVisuals.overrideFov) {
|
||||
if (this.cachedFovOptionInstance == null || this.cachedFovOptionInstance.get() != Math.round(editorState.replayVisuals.overrideFovAmount)) {
|
||||
OptionInstance<Integer> delegate = cir.getReturnValue();
|
||||
this.cachedOptionInstance = new OptionInstance<>("options.fov", OptionInstance.noTooltip(), Options::genericValueLabel,
|
||||
delegate.values(), delegate.codec(), Math.round(ReplayVisuals.overrideFovAmount), value -> {
|
||||
ReplayVisuals.overrideFov = false;
|
||||
this.cachedFovOptionInstance = new OptionInstance<>("options.fov", OptionInstance.noTooltip(), Options::genericValueLabel,
|
||||
delegate.values(), delegate.codec(), Math.round(editorState.replayVisuals.overrideFovAmount), value -> {
|
||||
editorState.replayVisuals.overrideFov = false;
|
||||
delegate.set(value);
|
||||
});
|
||||
}
|
||||
|
||||
cir.setReturnValue(this.cachedOptionInstance);
|
||||
cir.setReturnValue(this.cachedFovOptionInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int flashback$getOriginalFov() {
|
||||
return this.fov.get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user