mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-02 06:28:48 +00:00
Stuff
This commit is contained in:
1 parent
9c4a30d224
commit
666398e480
174 files changed
+8694
-2942
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.DebugScreenOverlay;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = DebugScreenOverlay.class, priority = 1100)
|
||||
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()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getGameInformation", at = @At("RETURN"))
|
||||
public void getGameInformation(CallbackInfoReturnable<List<String>> info) {
|
||||
if (Flashback.RECORDER != null) {
|
||||
info.getReturnValue().add(Flashback.RECORDER.getDebugString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
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.editor.ui.ReplayUI;
|
||||
import com.moulberry.flashback.exporting.PerfectFrames;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.CloudStatus;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.chunk.RenderRegionCache;
|
||||
import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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(value = LevelRenderer.class, priority = 1100)
|
||||
public abstract class MixinLevelRenderer {
|
||||
|
||||
@Shadow @Final public ObjectArrayList<SectionRenderDispatcher.RenderSection> visibleSections;
|
||||
|
||||
@Shadow private @Nullable SectionRenderDispatcher sectionRenderDispatcher;
|
||||
|
||||
@Shadow @Final public SectionOcclusionGraph sectionOcclusionGraph;
|
||||
|
||||
@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;
|
||||
ReplayUI.lastViewQuaternion = camera.rotation();
|
||||
}
|
||||
|
||||
@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) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (entity instanceof Player) {
|
||||
return ReplayVisuals.renderPlayers;
|
||||
} else {
|
||||
return 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 {
|
||||
return CloudStatus.OFF;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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"))
|
||||
public void setupRender(LevelRenderer instance, Camera camera, Frustum frustum, boolean capturedFrustum, boolean isSpectator, Operation<Void> original) {
|
||||
if (PerfectFrames.isEnabled()) {
|
||||
boolean doCompile = true;
|
||||
while (doCompile) {
|
||||
doCompile = false;
|
||||
|
||||
int before = this.visibleSections.size();
|
||||
original.call(instance, camera, frustum, capturedFrustum, isSpectator);
|
||||
if (this.visibleSections.size() != before) {
|
||||
doCompile = true;
|
||||
}
|
||||
|
||||
RenderRegionCache renderRegionCache = new RenderRegionCache();
|
||||
for (SectionRenderDispatcher.RenderSection renderSection : this.visibleSections) {
|
||||
if (renderSection.isDirty()) {
|
||||
this.sectionRenderDispatcher.rebuildSectionSync(renderSection, renderRegionCache);
|
||||
renderSection.setNotDirty();
|
||||
doCompile = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.sectionRenderDispatcher.uploadAllPendingUploads();
|
||||
}
|
||||
} else {
|
||||
original.call(instance, camera, frustum, capturedFrustum, isSpectator);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
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.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateCache;
|
||||
import com.moulberry.flashback.exporting.PerfectFrames;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import com.moulberry.flashback.ext.MinecraftExt;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import it.unimi.dsi.fastutil.floats.FloatUnaryOperator;
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.ReportedException;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.User;
|
||||
import net.minecraft.client.gui.screens.LevelLoadingScreen;
|
||||
import net.minecraft.client.gui.screens.Overlay;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.chat.report.ReportEnvironment;
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.server.IntegratedServer;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.login.ServerboundHelloPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.server.WorldStem;
|
||||
import net.minecraft.server.level.progress.ProcessorChunkProgressListener;
|
||||
import net.minecraft.server.level.progress.StoringChunkProgressListener;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.players.GameProfileCache;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
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.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MixinMinecraft implements MinecraftExt {
|
||||
|
||||
@Shadow
|
||||
public abstract void disconnect();
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private AtomicReference<StoringChunkProgressListener> progressListener;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private YggdrasilAuthenticationService authenticationService;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
public File gameDirectory;
|
||||
|
||||
@Shadow
|
||||
private @Nullable IntegratedServer singleplayerServer;
|
||||
|
||||
@Shadow
|
||||
private boolean isLocalServer;
|
||||
|
||||
@Shadow
|
||||
public abstract void updateReportEnvironment(ReportEnvironment reportEnvironment);
|
||||
|
||||
@Shadow
|
||||
public abstract void setScreen(@Nullable Screen screen);
|
||||
|
||||
@Shadow
|
||||
private ProfilerFiller profiler;
|
||||
|
||||
@Shadow
|
||||
private @Nullable Overlay overlay;
|
||||
|
||||
@Shadow
|
||||
protected abstract void runTick(boolean bl);
|
||||
|
||||
@Shadow
|
||||
protected abstract void handleDelayedCrash();
|
||||
|
||||
@Shadow
|
||||
public abstract User getUser();
|
||||
|
||||
@Shadow
|
||||
private @Nullable Connection pendingConnection;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Queue<Runnable> progressTasks;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public ClientLevel level;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public LocalPlayer player;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
public ParticleEngine particleEngine;
|
||||
|
||||
@Shadow @Final public DeltaTracker.Timer timer;
|
||||
|
||||
@Inject(method="<init>", at=@At("RETURN"))
|
||||
public void init(GameConfig gameConfig, CallbackInfo ci) {
|
||||
ReplayUI.init();
|
||||
}
|
||||
|
||||
@Inject(method = "pauseGame", at = @At("HEAD"), cancellable = true)
|
||||
public void pauseGame(boolean bl, CallbackInfo ci) {
|
||||
if (Flashback.EXPORT_JOB != null) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderNames", at = @At("HEAD"), cancellable = true)
|
||||
private static void renderNames(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!ReplayVisuals.renderNametags) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;blitToScreen(II)V", shift = At.Shift.AFTER))
|
||||
public void afterMainBlit(boolean bl, CallbackInfo ci) {
|
||||
if (!RenderSystem.isOnRenderThread()) return;
|
||||
ReplayUI.drawOverlay();
|
||||
}
|
||||
|
||||
@Unique
|
||||
private boolean inReplayLast = false;
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
public void tick(CallbackInfo ci) {
|
||||
if (Flashback.RECORDER != null) {
|
||||
Flashback.RECORDER.endTick(false);
|
||||
}
|
||||
|
||||
EditorStateCache.saveIfNeeded();
|
||||
|
||||
ReplayServer replayServer = Flashback.getReplayServer();
|
||||
|
||||
boolean inReplay = replayServer != null;
|
||||
if (inReplay != inReplayLast) {
|
||||
inReplayLast = inReplay;
|
||||
if (inReplay) {
|
||||
ReplayVisuals.setupReplay();
|
||||
Minecraft.getInstance().options.hideGui = false;
|
||||
} else {
|
||||
ReplayVisuals.disable();
|
||||
EditorStateCache.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)
|
||||
public void getTickTargetMillis(float f, CallbackInfoReturnable<Float> cir) {
|
||||
if (Flashback.isInReplay()) {
|
||||
if (this.level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TickRateManager tickRateManager = this.level.tickRateManager();
|
||||
if (tickRateManager.runsNormally()) {
|
||||
cir.setReturnValue(tickRateManager.millisecondsPerTick());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private final DeltaTracker.Timer localPlayerTimer = new DeltaTracker.Timer(20.0f, 0, FloatUnaryOperator.identity());
|
||||
|
||||
@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 (Flashback.EXPORT_JOB != null && !ReplayUI.isActive()) {
|
||||
try {
|
||||
PerfectFrames.enable();
|
||||
Flashback.EXPORT_JOB.run();
|
||||
} finally {
|
||||
PerfectFrames.disable();
|
||||
Flashback.EXPORT_JOB = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (Flashback.isInReplay()) {
|
||||
int localPlayerTicks = localPlayerTimer.advanceTime(Util.getMillis(), runTick);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float flashback$getLocalPlayerPartialTick() {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.isRunning()) {
|
||||
return this.timer.getGameTimeDeltaPartialTick(true);
|
||||
}
|
||||
return localPlayerTimer.getGameTimeDeltaPartialTick(true);
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/Window;setErrorSection(Ljava/lang/String;)V", ordinal = 1), cancellable = true)
|
||||
public void runTick_setErrorSection(boolean bl, CallbackInfo ci) {
|
||||
ReplayServer replayServer = Flashback.getReplayServer();
|
||||
if (replayServer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!replayServer.replayPaused) {
|
||||
EditorState editorState = EditorStateCache.get(replayServer.getMetadata().replayIdentifier);
|
||||
editorState.applyKeyframes((Minecraft) (Object) this, replayServer.getPartialReplayTick());
|
||||
}
|
||||
if (!replayServer.doClientRendering()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$startReplayServer(LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem stem,
|
||||
UUID playbackUUID, Path path) {
|
||||
this.disconnect();
|
||||
this.progressListener.set(null);
|
||||
Instant instant = Instant.now();
|
||||
try {
|
||||
// levelStorageAccess.saveDataTag((RegistryAccess)worldStem.registries().compositeAccess(), worldStem.worldData());
|
||||
Services services = Services.create(this.authenticationService, this.gameDirectory);
|
||||
services.profileCache().setExecutor((Executor)this);
|
||||
SkullBlockEntity.setup(services, (Executor)this);
|
||||
GameProfileCache.setUsesAuthentication(false);
|
||||
this.singleplayerServer = MinecraftServer.spin(thread -> new ReplayServer(thread, (Minecraft) (Object) this,
|
||||
levelStorageAccess, packRepository, stem, services, i -> {
|
||||
StoringChunkProgressListener storingChunkProgressListener = StoringChunkProgressListener.createFromGameruleRadius(i);
|
||||
this.progressListener.set(storingChunkProgressListener);
|
||||
return ProcessorChunkProgressListener.createStarted(storingChunkProgressListener, this.progressTasks::add);
|
||||
}, playbackUUID, path));
|
||||
this.isLocalServer = true;
|
||||
this.updateReportEnvironment(ReportEnvironment.local());
|
||||
// this.quickPlayLog.setWorldData(QuickPlayLog.Type.SINGLEPLAYER, levelStorageAccess.getLevelId(), worldStem.worldData().getLevelName());
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashReport = CrashReport.forThrowable(throwable, "Starting replay server");
|
||||
// CrashReportCategory crashReportCategory = crashReport.addCategory("Starting integrated server");
|
||||
// crashReportCategory.setDetail("Level ID", (Object)levelStorageAccess.getLevelId());
|
||||
// crashReportCategory.setDetail("Level Name", () -> worldStem.worldData().getLevelName());
|
||||
throw new ReportedException(crashReport);
|
||||
}
|
||||
while (this.progressListener.get() == null) {
|
||||
Thread.yield();
|
||||
}
|
||||
LevelLoadingScreen levelLoadingScreen = new LevelLoadingScreen(this.progressListener.get());
|
||||
this.setScreen(levelLoadingScreen);
|
||||
this.profiler.push("waitForServer");
|
||||
while (!this.singleplayerServer.isReady() || this.overlay != null) {
|
||||
levelLoadingScreen.tick();
|
||||
this.runTick(false);
|
||||
try {
|
||||
Thread.sleep(16L);
|
||||
} catch (InterruptedException crashReport) {
|
||||
// empty catch block
|
||||
}
|
||||
this.handleDelayedCrash();
|
||||
}
|
||||
this.profiler.pop();
|
||||
Duration duration = Duration.between(instant, Instant.now());
|
||||
SocketAddress socketAddress = this.singleplayerServer.getConnection().startMemoryChannel();
|
||||
Connection connection = Connection.connectToLocalServer(socketAddress);
|
||||
connection.initiateServerboundPlayConnection(socketAddress.toString(), 0, new ClientHandshakePacketListenerImpl(connection,
|
||||
(Minecraft) (Object) this, null, null, false, duration, component -> {}, null));
|
||||
connection.send(new ServerboundHelloPacket(this.getUser().getName(), this.getUser().getProfileId()));
|
||||
this.pendingConnection = connection;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
import com.moulberry.flashback.editor.ui.CustomImGuiImplGlfw;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
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(MouseHandler.class)
|
||||
public class MixinMouseHandler {
|
||||
|
||||
@Inject(method = "isMouseGrabbed", at=@At("HEAD"), cancellable = true)
|
||||
public void isMouseGrabbed(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ReplayUI.isActive()) {
|
||||
cir.setReturnValue(ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "grabMouse", at=@At("HEAD"), cancellable = true)
|
||||
public void grabMouse(CallbackInfo ci) {
|
||||
if (ReplayUI.isActive()) ci.cancel();
|
||||
}
|
||||
|
||||
@Inject(method = "releaseMouse", at=@At("HEAD"), cancellable = true)
|
||||
public void releaseMouse(CallbackInfo ci) {
|
||||
if (ReplayUI.isActive()) ci.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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.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) {
|
||||
ReplayUI.setupMainViewport();
|
||||
} else {
|
||||
original.call(left, bottom, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.moulberry.flashback.mixin;
|
||||
|
||||
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;
|
||||
|
||||
@Mixin(ThreadedLevelLightEngine.class)
|
||||
public abstract class MixinThreadedLevelLightEngine extends LevelLightEngine implements ThreadedLevelLightEngineExt {
|
||||
|
||||
@Shadow
|
||||
protected abstract void addTask(int i, int j, ThreadedLevelLightEngine.TaskType taskType, Runnable runnable);
|
||||
|
||||
public MixinThreadedLevelLightEngine(LightChunkGetter lightChunkGetter, boolean bl, boolean bl2) {
|
||||
super(lightChunkGetter, bl, bl2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$submitPost(int x, int z, Runnable runnable) {
|
||||
this.addTask(x, z, ThreadedLevelLightEngine.TaskType.POST_UPDATE, runnable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
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.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.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(Window.class)
|
||||
public abstract class MixinWindow {
|
||||
|
||||
@Shadow private int framebufferWidth;
|
||||
@Shadow private int framebufferHeight;
|
||||
|
||||
@Shadow private int width;
|
||||
@Shadow private int height;
|
||||
|
||||
@Shadow private double guiScale;
|
||||
|
||||
@Shadow private int guiScaledWidth;
|
||||
|
||||
@Shadow private int guiScaledHeight;
|
||||
|
||||
@Shadow
|
||||
private int windowedWidth;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private long window;
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getHeight", at=@At("HEAD"), cancellable = true)
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getScreenWidth", at=@At("HEAD"), cancellable = true)
|
||||
public void getScreenWidth(CallbackInfoReturnable<Integer> cir) {
|
||||
if (ReplayUI.isActive() && ReplayVisuals.sizing != Sizing.UNDERLAY) {
|
||||
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) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "calculateScale", at=@At("HEAD"), cancellable = true)
|
||||
public void calculateScale(int scale, boolean forceEven, CallbackInfoReturnable<Integer> cir) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.shouldChangeFramebufferSize()) {
|
||||
int fbw = Flashback.EXPORT_JOB.getWidth();
|
||||
int fbh = Flashback.EXPORT_JOB.getHeight();
|
||||
|
||||
int j = 1;
|
||||
while (j != scale && j < fbw && j < fbh && fbw / (j + 1) >= 320 && fbh / (j + 1) >= 240) {
|
||||
j++;
|
||||
}
|
||||
if (forceEven && j % 2 != 0) {
|
||||
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);
|
||||
|
||||
int j = 1;
|
||||
while (j != scale && j < fbw && j < fbh && fbw / (j + 1) >= 320 && fbh / (j + 1) >= 240) {
|
||||
j++;
|
||||
}
|
||||
if (forceEven && j % 2 != 0) {
|
||||
j++;
|
||||
}
|
||||
cir.setReturnValue(j);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setGuiScale", at=@At("HEAD"), cancellable = true)
|
||||
public void setGuiScale(double d, CallbackInfo ci) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.shouldChangeFramebufferSize()) {
|
||||
int fbw = Flashback.EXPORT_JOB.getWidth();
|
||||
int fbh = Flashback.EXPORT_JOB.getHeight();
|
||||
|
||||
this.guiScale = d;
|
||||
int i = (int)((double)fbw / d);
|
||||
this.guiScaledWidth = (double)fbw / d > (double)i ? i + 1 : i;
|
||||
int j = (int)((double)fbh / d);
|
||||
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);
|
||||
|
||||
this.guiScale = d;
|
||||
int i = (int)((double)fbw / d);
|
||||
this.guiScaledWidth = (double)fbw / d > (double)i ? i + 1 : i;
|
||||
int j = (int)((double)fbh / d);
|
||||
this.guiScaledHeight = (double)fbh / d > (double)j ? j + 1 : j;
|
||||
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.moulberry.flashback.mixin.compat;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Pseudo;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@IfModLoaded("axiom")
|
||||
@Pseudo
|
||||
@Mixin(targets = "com.moulberry.axiom.editor.EditorUI", remap = false)
|
||||
public class MixinAxiomEditorUI {
|
||||
|
||||
@Shadow
|
||||
private static boolean enabled;
|
||||
|
||||
@Inject(method = "isActiveInternal", at = @At("HEAD"), cancellable = true)
|
||||
private static void isActiveInternal(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ReplayUI.isActive() || Flashback.isInReplay()) {
|
||||
enabled = false;
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.moulberry.flashback.mixin.compat;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.RenderBuffers;
|
||||
import net.minecraft.server.level.BlockDestructionProgress;
|
||||
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;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
@IfModLoaded(value = "sodium", aliases = "embeddium")
|
||||
@Pseudo
|
||||
@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) {
|
||||
if (!ReplayVisuals.renderBlocks) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.moulberry.flashback.mixin.packet_fix;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.gui.components.BossHealthOverlay;
|
||||
import net.minecraft.client.gui.components.LerpingBossEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
|
||||
import net.minecraft.world.BossEvent;
|
||||
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.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(BossHealthOverlay.class)
|
||||
public class MixinBossHealthOverlay {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
Map<UUID, LerpingBossEvent> events;
|
||||
|
||||
/**
|
||||
* Prevent disconnection if boss state is incorrect
|
||||
*/
|
||||
@Inject(method = "update", at = @At("HEAD"), cancellable = true)
|
||||
public void update(ClientboundBossEventPacket clientboundBossEventPacket, CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
clientboundBossEventPacket.dispatch(new ClientboundBossEventPacket.Handler() {
|
||||
@Override
|
||||
public void updateProgress(UUID uuid, float f) {
|
||||
if (!events.containsKey(uuid)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(UUID uuid, Component component) {
|
||||
if (!events.containsKey(uuid)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStyle(UUID uuid, BossEvent.BossBarColor bossBarColor, BossEvent.BossBarOverlay bossBarOverlay) {
|
||||
if (!events.containsKey(uuid)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProperties(UUID uuid, boolean bl, boolean bl2, boolean bl3) {
|
||||
if (!events.containsKey(uuid)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.renderer.entity.ArmorStandRenderer;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
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;
|
||||
|
||||
@Mixin(ArmorStandRenderer.class)
|
||||
public class MixinArmorStandRenderer {
|
||||
|
||||
/*
|
||||
* Disable armor stand hit animation
|
||||
* If the game time isn't updated, it'll just keep on playing it (even if it wasn't hit)
|
||||
*/
|
||||
|
||||
@Inject(method = "setupRotations(Lnet/minecraft/world/entity/decoration/ArmorStand;Lcom/mojang/blaze3d/vertex/PoseStack;FFFF)V", at = @At("HEAD"), cancellable = true)
|
||||
public void setupRotations(ArmorStand armorStand, PoseStack poseStack, float f, float g, float h, float i, CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(180.0F - g));
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.packet.FinishedServerTick;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
||||
import net.minecraft.network.protocol.PacketUtils;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket;
|
||||
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;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(ClientCommonPacketListenerImpl.class)
|
||||
public abstract class MixinClientCommonPacketListenerImpl {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
protected Minecraft minecraft;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
private static URL parseResourcePackUrl(String string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the resource pack prompt screen in replays
|
||||
*/
|
||||
@Inject(method = "handleResourcePackPush", at = @At("HEAD"), cancellable = true)
|
||||
public void handleResourcePackPush(ClientboundResourcePackPushPacket clientboundResourcePackPushPacket, CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
PacketUtils.ensureRunningOnSameThread(clientboundResourcePackPushPacket, (ClientCommonPacketListenerImpl)(Object)this, this.minecraft);
|
||||
|
||||
UUID uuid = clientboundResourcePackPushPacket.id();
|
||||
URL uRL = parseResourcePackUrl(clientboundResourcePackPushPacket.url());
|
||||
if (uRL != null) {
|
||||
String string = clientboundResourcePackPushPacket.hash();
|
||||
this.minecraft.getDownloadedPackSource().allowServerPacks();
|
||||
this.minecraft.getDownloadedPackSource().pushPack(uuid, uRL, string);
|
||||
}
|
||||
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V", at = @At("HEAD"), cancellable = true)
|
||||
public void handleCustomPayload(ClientboundCustomPayloadPacket clientboundCustomPayloadPacket, CallbackInfo ci) {
|
||||
if (clientboundCustomPayloadPacket.payload() == FinishedServerTick.INSTANCE) {
|
||||
if (Flashback.EXPORT_JOB != null) {
|
||||
Flashback.EXPORT_JOB.onFinishedServerTick();
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public abstract class MixinEntity {
|
||||
|
||||
@Shadow
|
||||
public abstract boolean isInvisible();
|
||||
|
||||
@Shadow
|
||||
private Level level;
|
||||
|
||||
@Shadow
|
||||
public abstract boolean isInvisibleTo(Player player);
|
||||
|
||||
@Inject(method = "isInvisibleTo", at = @At("HEAD"), cancellable = true)
|
||||
public void isInvisibleTo(Player player, CallbackInfoReturnable<Boolean> cir) {
|
||||
ReplayServer replayServer = Flashback.getReplayServer();
|
||||
if (replayServer != null && player == Minecraft.getInstance().player) {
|
||||
int localId = replayServer.getLocalPlayerId();
|
||||
if (this.level.getEntity(localId) instanceof Player localPlayer) {
|
||||
if ((Object)this == localPlayer) {
|
||||
cir.setReturnValue(false);
|
||||
} else {
|
||||
cir.setReturnValue(this.isInvisibleTo(localPlayer));
|
||||
}
|
||||
} else {
|
||||
cir.setReturnValue(this.isInvisible());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
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.editor.ui.ReplayUI;
|
||||
import com.moulberry.flashback.ext.ItemInHandRendererExt;
|
||||
import com.moulberry.flashback.ext.MinecraftExt;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.GameType;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class MixinGameRenderer {
|
||||
|
||||
|
||||
@WrapOperation(method = "render", at=@At(value = "FIELD", target = "Lnet/minecraft/client/Options;pauseOnLostFocus:Z"))
|
||||
public boolean getPauseOnLostFocus(Options instance, Operation<Boolean> original) {
|
||||
if (ReplayUI.isActive() || Flashback.EXPORT_JOB != null) {
|
||||
return false;
|
||||
}
|
||||
return original.call(instance);
|
||||
}
|
||||
|
||||
/*
|
||||
* Render item in hand for spectators in a replay
|
||||
*/
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft minecraft;
|
||||
|
||||
@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) {
|
||||
return GameType.SURVIVAL;
|
||||
}
|
||||
return original.call(instance);
|
||||
}
|
||||
|
||||
@WrapOperation(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;renderHandsWithItems(FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/player/LocalPlayer;I)V"))
|
||||
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);
|
||||
} else {
|
||||
original.call(instance, f, poseStack, bufferSource, localPlayer, i);
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
original.call(instance, blockGetter, entity, bl, bl2, f);
|
||||
}
|
||||
|
||||
@Inject(method = "tryTakeScreenshotIfNeeded", at = @At("HEAD"), cancellable = true)
|
||||
public void tryTakeScreenshotIfNeeded(CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getFov", at = @At("HEAD"), cancellable = true)
|
||||
public void getFov(Camera camera, float f, boolean bl, CallbackInfoReturnable<Double> cir) {
|
||||
if (Flashback.isInReplay()) {
|
||||
if (!bl) {
|
||||
cir.setReturnValue(70.0);
|
||||
return;
|
||||
}
|
||||
|
||||
int fov = this.minecraft.options.fov().get().intValue();
|
||||
if (ReplayVisuals.overrideFov) {
|
||||
cir.setReturnValue((double) ReplayVisuals.overrideFovAmount);
|
||||
return;
|
||||
}
|
||||
cir.setReturnValue((double) fov);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ext.ItemInHandRendererExt;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(ItemInHandRenderer.class)
|
||||
public abstract class MixinItemInHandRenderer implements ItemInHandRendererExt {
|
||||
|
||||
@Shadow
|
||||
private float oMainHandHeight;
|
||||
|
||||
@Shadow
|
||||
private float mainHandHeight;
|
||||
|
||||
@Shadow
|
||||
private float oOffHandHeight;
|
||||
|
||||
@Shadow
|
||||
private float offHandHeight;
|
||||
|
||||
@Shadow
|
||||
protected abstract void renderArmWithItem(AbstractClientPlayer abstractClientPlayer, float f, float g, InteractionHand interactionHand, float h, ItemStack itemStack, float i, PoseStack poseStack, MultiBufferSource multiBufferSource, int j);
|
||||
|
||||
@Shadow
|
||||
private ItemStack mainHandItem;
|
||||
|
||||
@Shadow
|
||||
private ItemStack offHandItem;
|
||||
|
||||
@Override
|
||||
public void flashback$renderHandsWithItems(float partialTick, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, AbstractClientPlayer clientPlayer, int i) {
|
||||
float m;
|
||||
float l;
|
||||
float g = clientPlayer.getAttackAnim(partialTick);
|
||||
InteractionHand interactionHand = MoreObjects.firstNonNull(clientPlayer.swingingArm, InteractionHand.MAIN_HAND);
|
||||
float h = Mth.lerp(partialTick, clientPlayer.xRotO, clientPlayer.getXRot());
|
||||
// todo: hand selection
|
||||
// ItemInHandRenderer.HandRenderSelection handRenderSelection = evaluateWhichHandsToRender(clientPlayer);
|
||||
// todo: bob
|
||||
// float j = Mth.lerp((float)f, (float)clientPlayer.xBobO, (float)clientPlayer.xBob);
|
||||
// float k = Mth.lerp((float)f, (float)clientPlayer.yBobO, (float)clientPlayer.yBob);
|
||||
// poseStack.mulPose(Axis.XP.rotationDegrees((clientPlayer.getViewXRot(f) - j) * 0.1f));
|
||||
// poseStack.mulPose(Axis.YP.rotationDegrees((clientPlayer.getViewYRot(f) - k) * 0.1f));
|
||||
if (true) {
|
||||
l = interactionHand == InteractionHand.MAIN_HAND ? g : 0.0f;
|
||||
m = 1.0f - Mth.lerp(partialTick, this.oMainHandHeight, this.mainHandHeight);
|
||||
renderArmWithItem(clientPlayer, partialTick, h, InteractionHand.MAIN_HAND, l, this.mainHandItem, m, poseStack, bufferSource, i);
|
||||
}
|
||||
if (true) {
|
||||
l = interactionHand == InteractionHand.OFF_HAND ? g : 0.0f;
|
||||
m = 1.0f - Mth.lerp(partialTick, this.oOffHandHeight, this.offHandHeight);
|
||||
renderArmWithItem(clientPlayer, partialTick, h, InteractionHand.OFF_HAND, l, this.offHandItem, m, poseStack, bufferSource, i);
|
||||
}
|
||||
bufferSource.endBatch();
|
||||
}
|
||||
|
||||
// todo: change first person FOV when pulling bows, etc.
|
||||
|
||||
// todo: show arm (need to replace usage of LocalPlayer in renderPlayerArm
|
||||
|
||||
@Unique
|
||||
private UUID lastSpectatingPlayer = null;
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||
public void tick(CallbackInfo ci) {
|
||||
AbstractClientPlayer spectatingPlayer = Flashback.getSpectatingPlayer();
|
||||
if (spectatingPlayer == null) {
|
||||
this.lastSpectatingPlayer = null;
|
||||
} else {
|
||||
ItemStack newMainHandItem = spectatingPlayer.getMainHandItem();
|
||||
ItemStack newOffHandItem = spectatingPlayer.getOffhandItem();
|
||||
|
||||
if (!spectatingPlayer.getUUID().equals(lastSpectatingPlayer)) {
|
||||
this.lastSpectatingPlayer = spectatingPlayer.getUUID();
|
||||
this.mainHandItem = newMainHandItem;
|
||||
this.offHandItem = newOffHandItem;
|
||||
this.oMainHandHeight = this.mainHandHeight = 1.0f;
|
||||
this.oOffHandHeight = this.offHandHeight = 1.0f;
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
this.oMainHandHeight = this.mainHandHeight;
|
||||
this.oOffHandHeight = this.offHandHeight;
|
||||
if (ItemStack.matches(this.mainHandItem, newMainHandItem)) {
|
||||
this.mainHandItem = newMainHandItem;
|
||||
}
|
||||
if (ItemStack.matches(this.offHandItem, newOffHandItem)) {
|
||||
this.offHandItem = newOffHandItem;
|
||||
}
|
||||
if (false /*clientPlayer.isHandsBusy()*/) {
|
||||
this.mainHandHeight = Mth.clamp((float)(this.mainHandHeight - 0.4f), (float)0.0f, (float)1.0f);
|
||||
this.offHandHeight = Mth.clamp((float)(this.offHandHeight - 0.4f), (float)0.0f, (float)1.0f);
|
||||
} else {
|
||||
// todo: attack strength
|
||||
float f = 1.0f;//spectatingPlayer.getAttackStrengthScale(1.0f);
|
||||
this.mainHandHeight += Mth.clamp((this.mainHandItem == newMainHandItem ? f * f * f : 0.0f) - this.mainHandHeight, -0.4f, 0.4f);
|
||||
this.offHandHeight += Mth.clamp((float)(this.offHandItem == newOffHandItem ? 1 : 0) - this.offHandHeight, -0.4f, 0.4f);
|
||||
}
|
||||
if (this.mainHandHeight < 0.1f) {
|
||||
this.mainHandItem = newMainHandItem;
|
||||
}
|
||||
if (this.offHandHeight < 0.1f) {
|
||||
this.offHandItem = newOffHandItem;
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public abstract class MixinLivingEntity extends Entity {
|
||||
|
||||
@Shadow
|
||||
public abstract void lerpTo(double d, double e, double f, float g, float h, int i);
|
||||
|
||||
@Shadow
|
||||
public abstract void lerpHeadTo(float f, int i);
|
||||
|
||||
public MixinLivingEntity(EntityType<?> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
// todo: maybe reintroduce this lerpTo code?
|
||||
// @Inject(method = "lerpTo", at = @At("HEAD"), cancellable = true)
|
||||
// public void lerpTo(double d, double e, double f, float g, float h, int i, CallbackInfo ci) {
|
||||
// if (FlashbackClient.isInReplay() && i > 1 && FlashbackClient.getReplayServer().getLocalPlayerId() == this.getId() && Minecraft.getInstance().getCameraEntity() == this) {
|
||||
// this.lerpTo(d, e, f, g, h, 1);
|
||||
// ci.cancel();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Inject(method = "lerpHeadTo", at = @At("HEAD"), cancellable = true)
|
||||
// public void lerpHeadTo(float f, int i, CallbackInfo ci) {
|
||||
// if (FlashbackClient.isInReplay() && i > 1 && FlashbackClient.getReplayServer().getLocalPlayerId() == this.getId() && Minecraft.getInstance().getCameraEntity() == this) {
|
||||
// this.lerpHeadTo(f, 1);
|
||||
// ci.cancel();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.PlayerChunkSender;
|
||||
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(PlayerChunkSender.class)
|
||||
public class MixinPlayerChunkSender {
|
||||
|
||||
// Make chunks send faster on replay servers
|
||||
|
||||
@Shadow
|
||||
private float desiredChunksPerTick;
|
||||
|
||||
@Shadow
|
||||
private int unacknowledgedBatches;
|
||||
|
||||
@Shadow
|
||||
private float batchQuota;
|
||||
|
||||
@Inject(method = "sendNextChunks", at = @At("HEAD"))
|
||||
public void sendNextChunks(ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
this.unacknowledgedBatches = 0;
|
||||
this.batchQuota = 0.0f;
|
||||
this.desiredChunksPerTick = Math.max(this.desiredChunksPerTick, 256.0f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.numbers.NumberFormat;
|
||||
import net.minecraft.world.scores.Objective;
|
||||
import net.minecraft.world.scores.Scoreboard;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Scoreboard.class)
|
||||
public abstract class MixinScoreboard {
|
||||
|
||||
@Shadow @Final private Object2ObjectMap<String, Objective> objectivesByName;
|
||||
|
||||
@Shadow public abstract void removeObjective(Objective objective);
|
||||
|
||||
@Inject(method = "addObjective", at = @At("HEAD"))
|
||||
public void addObjective(String string, ObjectiveCriteria objectiveCriteria, Component component, ObjectiveCriteria.RenderType renderType, boolean bl, NumberFormat numberFormat, CallbackInfoReturnable<Objective> cir) {
|
||||
if (Flashback.isInReplay() && this.objectivesByName.containsKey(string)) {
|
||||
this.removeObjective(this.objectivesByName.get(string));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(TickRateManager.class)
|
||||
public abstract class MixinTickRateManager {
|
||||
|
||||
@Shadow
|
||||
public abstract boolean runsNormally();
|
||||
|
||||
@Unique
|
||||
private final boolean isClientTickRateManager = !((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);
|
||||
} else {
|
||||
cir.setReturnValue(!this.runsNormally() || entity == Minecraft.getInstance().player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.moulberry.flashback.mixin.record;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
||||
import net.minecraft.client.multiplayer.ClientConfigurationPacketListenerImpl;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.multiplayer.CommonListenerCookie;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.configuration.ClientboundFinishConfigurationPacket;
|
||||
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;
|
||||
|
||||
@Mixin(ClientConfigurationPacketListenerImpl.class)
|
||||
public abstract class MixinClientConfigurationPacketListenerImpl extends ClientCommonPacketListenerImpl {
|
||||
|
||||
protected MixinClientConfigurationPacketListenerImpl(Minecraft minecraft, Connection connection, CommonListenerCookie commonListenerCookie) {
|
||||
super(minecraft, connection, commonListenerCookie);
|
||||
}
|
||||
|
||||
@Inject(method = "handleConfigurationFinished", at = @At("RETURN"))
|
||||
public void handleConfigurationFinished(ClientboundFinishConfigurationPacket clientboundFinishConfigurationPacket, CallbackInfo ci) {
|
||||
if (Flashback.RECORDER != null) {
|
||||
Flashback.RECORDER.setRegistryAccess(((ClientPacketListener)this.connection.getPacketListener()).registryAccess());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.moulberry.flashback.mixin.record;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.record.Recorder;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.ConnectionProtocol;
|
||||
import net.minecraft.network.PacketListener;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.configuration.ClientConfigurationPacketListener;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
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;
|
||||
|
||||
@Mixin(Connection.class)
|
||||
public class MixinConnection {
|
||||
|
||||
@Inject(method = "genericsFtw", at = @At("HEAD"))
|
||||
private static void genericsFtw(Packet<?> packet, PacketListener packetListener, CallbackInfo ci) {
|
||||
Recorder recorder = Flashback.RECORDER;
|
||||
if (recorder != null) {
|
||||
if (packetListener instanceof ClientGamePacketListener) {
|
||||
recorder.writePacketAsync(packet, ConnectionProtocol.PLAY);
|
||||
} else if (packetListener instanceof ClientConfigurationPacketListener) {
|
||||
recorder.writePacketAsync(packet, ConnectionProtocol.CONFIGURATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.moulberry.flashback.mixin.record;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import org.bytedeco.ffmpeg.avutil.AVFrame;
|
||||
import org.bytedeco.javacv.FFmpegFrameRecorder;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@Mixin(value = FFmpegFrameRecorder.class, remap = false)
|
||||
public class MixinFFmpegFrameRecorder {
|
||||
|
||||
// Don't change linesize, let it be calculated automatically
|
||||
|
||||
@WrapOperation(method = "recordImage", remap = false, at = @At(value = "INVOKE", remap = false, target = "Lorg/bytedeco/ffmpeg/avutil/AVFrame;linesize(II)Lorg/bytedeco/ffmpeg/avutil/AVFrame;"))
|
||||
private AVFrame changeLinesize(AVFrame instance, int i, int setter, Operation<AVFrame> original) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.moulberry.flashback.playback.EmptyLevelSource;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerators;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ChunkGenerators.class)
|
||||
public class MixinChunkGenerators {
|
||||
|
||||
@Inject(method = "bootstrap", at = @At("HEAD"))
|
||||
private static void bootstrap(Registry<MapCodec<? extends ChunkGenerator>> registry, CallbackInfoReturnable<MapCodec<? extends ChunkGenerator>> cir) {
|
||||
Registry.register(registry, "flashback/empty", EmptyLevelSource.CODEC);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.server.level.GenerationChunkHolder;
|
||||
import net.minecraft.util.StaticCache2D;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatusTasks;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStep;
|
||||
import net.minecraft.world.level.chunk.status.WorldGenContext;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Mixin(ChunkStatusTasks.class)
|
||||
public class MixinChunkStatusTasks {
|
||||
|
||||
@Inject(method = "initializeLight", at = @At("HEAD"), cancellable = true)
|
||||
private static void initializeLight(WorldGenContext worldGenContext, ChunkStep chunkStep, StaticCache2D<GenerationChunkHolder> staticCache2D, ChunkAccess chunkAccess, CallbackInfoReturnable<CompletableFuture<ChunkAccess>> cir) {
|
||||
if (Flashback.isInReplay()) {
|
||||
cir.setReturnValue(CompletableFuture.completedFuture(chunkAccess));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "light", at = @At("HEAD"), cancellable = true)
|
||||
private static void light(WorldGenContext worldGenContext, ChunkStep chunkStep, StaticCache2D<GenerationChunkHolder> staticCache2D, ChunkAccess chunkAccess, CallbackInfoReturnable<CompletableFuture<ChunkAccess>> cir) {
|
||||
if (Flashback.isInReplay()) {
|
||||
cir.setReturnValue(CompletableFuture.completedFuture(chunkAccess));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
|
||||
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;
|
||||
|
||||
@Mixin(PersistentEntitySectionManager.class)
|
||||
public class MixinPersistentEntitySectionManager {
|
||||
|
||||
@Inject(method = "saveAll", at = @At("HEAD"), cancellable = true)
|
||||
public void saveAll(CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public class MixinPlayerList {
|
||||
|
||||
/*
|
||||
* Don't change the dimension of replay viewers when spawning them
|
||||
*/
|
||||
|
||||
@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) {
|
||||
if (serverPlayer.server instanceof ReplayServer) {
|
||||
return Optional.of(serverPlayer.level().dimension());
|
||||
}
|
||||
return original.call(instance, function);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
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(ServerChunkCache.class)
|
||||
public class MixinServerChunkCache {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
ServerLevel level;
|
||||
|
||||
@Inject(method = "save", at = @At("HEAD"), cancellable = true)
|
||||
public void save(boolean bl, CallbackInfo ci) {
|
||||
if (this.level.getServer() instanceof ReplayServer) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.moulberry.flashback.ext.ServerConfigurationPacketListenerImplExt;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.configuration.ClientConfigurationPacketListener;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
|
||||
import net.minecraft.server.network.config.SynchronizeRegistriesTask;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
@Mixin(ServerConfigurationPacketListenerImpl.class)
|
||||
public abstract class MixinServerConfigurationPacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerConfigurationPacketListenerImplExt {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Queue<ConfigurationTask> configurationTasks;
|
||||
|
||||
@Shadow
|
||||
protected abstract void startNextTask();
|
||||
|
||||
@Shadow
|
||||
private @Nullable SynchronizeRegistriesTask synchronizeRegistriesTask;
|
||||
|
||||
public MixinServerConfigurationPacketListenerImpl(MinecraftServer minecraftServer, Connection connection, CommonListenerCookie commonListenerCookie) {
|
||||
super(minecraftServer, connection, commonListenerCookie);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$startConfiguration(List<Packet<? super ClientConfigurationPacketListener>> initialPackets, List<ConfigurationTask> tasks) {
|
||||
for (Packet<? super ClientConfigurationPacketListener> initialPacket : initialPackets) {
|
||||
this.send(initialPacket);
|
||||
}
|
||||
|
||||
for (ConfigurationTask task : tasks) {
|
||||
if (task instanceof SynchronizeRegistriesTask synchronizeRegistriesTask) {
|
||||
if (this.synchronizeRegistriesTask != null) {
|
||||
throw new IllegalStateException("Duplicate SynchronizeRegistriesTask");
|
||||
}
|
||||
this.synchronizeRegistriesTask = synchronizeRegistriesTask;
|
||||
}
|
||||
}
|
||||
|
||||
this.configurationTasks.addAll(tasks);
|
||||
this.startNextTask();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
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 org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
@Mixin(ServerEntity.class)
|
||||
public class MixinServerEntity {
|
||||
|
||||
/*
|
||||
* Force update interval to be 1 on a replay server
|
||||
*/
|
||||
|
||||
@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) {
|
||||
return 1;
|
||||
}
|
||||
return updateInterval;
|
||||
}
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ext.ServerConfigurationPacketListenerImplExt;
|
||||
import com.moulberry.flashback.ext.ServerGamePacketListenerImplExt;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.configuration.ClientConfigurationPacketListener;
|
||||
import net.minecraft.network.protocol.configuration.ConfigurationProtocols;
|
||||
import net.minecraft.network.protocol.game.ServerboundConfigurationAcknowledgedPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public abstract class MixinServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListenerImplExt {
|
||||
|
||||
@Shadow
|
||||
public ServerPlayer player;
|
||||
|
||||
@Shadow
|
||||
public abstract void switchToConfig();
|
||||
|
||||
public MixinServerGamePacketListenerImpl(MinecraftServer minecraftServer, Connection connection, CommonListenerCookie commonListenerCookie) {
|
||||
super(minecraftServer, connection, commonListenerCookie);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private List<Packet<? super ClientConfigurationPacketListener>> pendingConfigurationPackets = null;
|
||||
@Unique
|
||||
private List<ConfigurationTask> pendingTasks = null;
|
||||
|
||||
@Override
|
||||
public void flashback$switchToConfigWithTasks(List<Packet<? super ClientConfigurationPacketListener>> initialPackets, List<ConfigurationTask> tasks) {
|
||||
this.switchToConfig();
|
||||
this.pendingConfigurationPackets = initialPackets;
|
||||
this.pendingTasks = tasks;
|
||||
}
|
||||
|
||||
@Inject(method = "switchToConfig", at = @At("HEAD"))
|
||||
public void switchToConfig(CallbackInfo ci) {
|
||||
this.pendingConfigurationPackets = null;
|
||||
this.pendingTasks = null;
|
||||
}
|
||||
|
||||
@Inject(method = "handleConfigurationAcknowledged", at = @At("HEAD"), cancellable = true)
|
||||
public void handleConfigurationAcknowledged(ServerboundConfigurationAcknowledgedPacket serverboundConfigurationAcknowledgedPacket, CallbackInfo ci) {
|
||||
if (this.pendingTasks != null) {
|
||||
var configurationHandler = new ServerConfigurationPacketListenerImpl(this.server, this.connection,
|
||||
this.createCookie(this.player.clientInformation()));
|
||||
((ServerConfigurationPacketListenerImplExt)configurationHandler).flashback$startConfiguration(this.pendingConfigurationPackets, this.pendingTasks);
|
||||
this.pendingTasks = null;
|
||||
this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, configurationHandler);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove player disconnect logging in replays
|
||||
@WrapWithCondition(method = "onDisconnect", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", remap = false))
|
||||
public boolean onDisconnect_info(Logger instance, String s, Object o1, Object o2) {
|
||||
return !Flashback.isInReplay();
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.network.protocol.login.ServerboundHelloPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||
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;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(ServerLoginPacketListenerImpl.class)
|
||||
public abstract class MixinServerLoginPacketListenerImpl {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
MinecraftServer server;
|
||||
|
||||
@Shadow
|
||||
abstract void startClientVerification(GameProfile gameProfile);
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
String requestedUsername;
|
||||
|
||||
@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"));
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.moulberry.flashback.mixin.replay_server;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.server.ServerTickRateManager;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
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(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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.moulberry.flashback.mixin.ui;
|
||||
|
||||
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.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.PauseScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
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;
|
||||
|
||||
@Mixin(PauseScreen.class)
|
||||
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.RECORDER == null) {
|
||||
rowHelper.addChild(Button.builder(Component.literal("Start Recording"), (button) -> {
|
||||
Flashback.startRecordingReplay();
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
}).width(204).build(), 2);
|
||||
} else {
|
||||
rowHelper.addChild(Button.builder(Component.literal("Finish Recording"), (button) -> {
|
||||
Flashback.finishRecordingReplay();
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
}).width(204).build(), 2);
|
||||
|
||||
if (Flashback.RECORDER.isPaused()) {
|
||||
rowHelper.addChild(Button.builder(Component.literal("Unpause Recording"), (button) -> {
|
||||
Flashback.pauseRecordingReplay(false);
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
}).width(98).build());
|
||||
} else {
|
||||
rowHelper.addChild(Button.builder(Component.literal("Pause Recording"), (button) -> {
|
||||
Flashback.pauseRecordingReplay(true);
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
}).width(98).build());
|
||||
}
|
||||
|
||||
rowHelper.addChild(Button.builder(Component.literal("Cancel Recording"), (button) -> {
|
||||
Minecraft.getInstance().setScreen(new ConfirmScreen(value -> {
|
||||
if (value) {
|
||||
Flashback.cancelRecordingReplay();
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
} else {
|
||||
Minecraft.getInstance().setScreen(new PauseScreen(true));
|
||||
}
|
||||
}, Component.literal("Confirm Cancel Recording"),
|
||||
Component.literal("Are you sure you want to cancel the recording? You won't be able to recover it")));
|
||||
}).width(98).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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.llamalad7.mixinextras.sugar.ref.LocalIntRef;
|
||||
import com.moulberry.flashback.screen.SelectReplayScreen;
|
||||
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.Renderable;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
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.CallbackInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = TitleScreen.class, priority = 1300)
|
||||
public class MixinTitleScreen extends Screen {
|
||||
|
||||
private MixinTitleScreen() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private final List<AbstractWidget> normalMenuWidgets = new ArrayList<>();
|
||||
|
||||
@Inject(method = "init", at = @At("RETURN"))
|
||||
public void init(CallbackInfo ci) {
|
||||
for (int offsetX = 0; offsetX < 5; offsetX++) {
|
||||
for (int i = this.normalMenuWidgets.size()-1; i >= 0; i--) {
|
||||
AbstractWidget widget = this.normalMenuWidgets.get(i);
|
||||
int size = widget.getHeight();
|
||||
int x = widget.getRight() + 4 + size * offsetX;
|
||||
int y = widget.getY();
|
||||
|
||||
boolean overlapsWithExistingButton = false;
|
||||
|
||||
// Check for overlaps with any existing buttons
|
||||
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()) {
|
||||
overlapsWithExistingButton = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!overlapsWithExistingButton) {
|
||||
this.addRenderableWidget(Button.builder(Component.literal("R"), button -> {
|
||||
this.minecraft.setScreen(new SelectReplayScreen(this));
|
||||
}).bounds(x, y, size, size).build());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "createNormalMenuOptions", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/TitleScreen;addRenderableWidget(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;"))
|
||||
public GuiEventListener addNormalMenuOption(TitleScreen instance, GuiEventListener guiEventListener, Operation<GuiEventListener> original) {
|
||||
GuiEventListener option = original.call(instance, guiEventListener);
|
||||
if (option instanceof AbstractWidget widget) {
|
||||
this.normalMenuWidgets.add(widget);
|
||||
}
|
||||
return option;
|
||||
}
|
||||
|
||||
@Inject(method = "createNormalMenuOptions", at = @At("HEAD"))
|
||||
public void createNormalMenuOptions(int y, int buttonHeight, CallbackInfo ci) {
|
||||
this.normalMenuWidgets.clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.BossHealthOverlay;
|
||||
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;
|
||||
|
||||
@Mixin(BossHealthOverlay.class)
|
||||
public class MixinBossHealthOverlay {
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||
public void render(GuiGraphics guiGraphics, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showBossBar) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
public class MixinClientLevel {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientLevel.ClientLevelData.class)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
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(value = EntityRenderDispatcher.class, priority = 990)
|
||||
public abstract class MixinEntityRenderDispatcher {
|
||||
|
||||
@Shadow
|
||||
private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, float g, float h, float i) {
|
||||
}
|
||||
|
||||
// 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))
|
||||
public void render(Entity entity, double d, double e, double f, float g, float h, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) {
|
||||
if (ReplayUI.isEntitySelected(entity.getId())) {
|
||||
renderHitbox(poseStack, multiBufferSource.getBuffer(RenderType.lines()), entity, h, 1.0f, 1.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.mojang.blaze3d.shaders.FogShape;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
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;
|
||||
|
||||
@Mixin(FogRenderer.class)
|
||||
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);
|
||||
RenderSystem.setShaderFogShape(FogShape.SPHERE);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.editor.ui.CustomImGuiImplGlfw;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
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(Gui.class)
|
||||
public class MixinGui {
|
||||
|
||||
@Inject(method = "renderChat", at = @At("HEAD"), cancellable = true)
|
||||
public void renderChat(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showChat) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderTitle", at = @At("HEAD"), cancellable = true)
|
||||
public void renderTitle(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showTitleText) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderScoreboardSidebar", at = @At("HEAD"), cancellable = true)
|
||||
public void renderScoreboardSidebar(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showScoreboard) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderOverlayMessage", at = @At("HEAD"), cancellable = true)
|
||||
public void renderOverlayMessage(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
|
||||
if (!ReplayVisuals.showActionBar) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "canRenderCrosshairForSpectator", at = @At("HEAD"), cancellable = true)
|
||||
public void canRenderCrosshairForSpectator(HitResult hitResult, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ReplayUI.isActive() && ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.LoadingOverlay;
|
||||
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(LoadingOverlay.class)
|
||||
public class MixinLoadingOverlay {
|
||||
|
||||
@Shadow private long fadeOutStart;
|
||||
|
||||
@Shadow @Final private Minecraft minecraft;
|
||||
|
||||
// Make overlay disappear instantly if inside replay
|
||||
@Inject(method = "render", at = @At("RETURN"))
|
||||
public void render(GuiGraphics guiGraphics, int i, int j, float f, CallbackInfo ci) {
|
||||
if (this.fadeOutStart != -1 && Flashback.isInReplay()) {
|
||||
this.minecraft.setOverlay(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.moulberry.flashback.mixin.visuals;
|
||||
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import net.minecraft.client.OptionInstance;
|
||||
import net.minecraft.client.Options;
|
||||
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(Options.class)
|
||||
public class MixinOptions {
|
||||
|
||||
@Unique
|
||||
private OptionInstance<Integer> cachedOptionInstance = 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)) {
|
||||
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;
|
||||
delegate.set(value);
|
||||
});
|
||||
}
|
||||
|
||||
cir.setReturnValue(this.cachedOptionInstance);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user