mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-02 14:38:50 +00:00
Public Release
This commit is contained in:
1 parent
666398e480
commit
61bb497a22
126 files changed
+8435
-1240
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(AttributeInstance.class)
|
||||
public abstract class MixinAttributeInstance {
|
||||
|
||||
@Shadow
|
||||
public abstract boolean removeModifier(ResourceLocation resourceLocation);
|
||||
|
||||
@Inject(method = "addModifier", at = @At(value = "HEAD"))
|
||||
public void addModifier(AttributeModifier attributeModifier, CallbackInfo ci) {
|
||||
// Some mods (e.g. HorseBuff) may end up adding a duplicate modifier while inside a replay
|
||||
// Remove the modifier first in order to ensure no exceptions are thrown
|
||||
if (Flashback.isInReplay()) {
|
||||
try {
|
||||
this.removeModifier(attributeModifier.id());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||
import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
@Mixin(value = ChunkHolder.class, priority = 1100)
|
||||
public class MixinChunkHolder {
|
||||
|
||||
@Shadow
|
||||
private boolean hasChangedSections;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private BitSet skyChangedLightSectionFilter;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private BitSet blockChangedLightSectionFilter;
|
||||
|
||||
@Inject(method = "broadcastChanges", at = @At("HEAD"))
|
||||
public void broadcastChanges(LevelChunk levelChunk, CallbackInfo ci) {
|
||||
if (levelChunk instanceof LevelChunkExt levelChunkExt) {
|
||||
if (this.hasChangedSections || !this.skyChangedLightSectionFilter.isEmpty() || !this.blockChangedLightSectionFilter.isEmpty()) {
|
||||
levelChunkExt.flashback$setCachedChunkId(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,12 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.ReplayVisuals;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
import com.moulberry.flashback.ext.ItemInHandRendererExt;
|
||||
import com.moulberry.flashback.ext.MinecraftExt;
|
||||
import com.moulberry.flashback.visuals.CameraRotation;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
@@ -20,6 +22,7 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import org.joml.Quaternionf;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -29,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class MixinGameRenderer {
|
||||
public abstract class MixinGameRenderer {
|
||||
|
||||
|
||||
@WrapOperation(method = "render", at=@At(value = "FIELD", target = "Lnet/minecraft/client/Options;pauseOnLostFocus:Z"))
|
||||
@@ -48,6 +51,9 @@ public class MixinGameRenderer {
|
||||
@Final
|
||||
private Minecraft minecraft;
|
||||
|
||||
@Shadow
|
||||
public abstract float getDepthFar();
|
||||
|
||||
@WrapOperation(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"))
|
||||
public GameType getPlayerMode(MultiPlayerGameMode instance, Operation<GameType> original) {
|
||||
if (Flashback.getSpectatingPlayer() != null) {
|
||||
@@ -60,8 +66,9 @@ public class MixinGameRenderer {
|
||||
public void renderItemInHand_renderHandsWithItems(ItemInHandRenderer instance, float f, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, LocalPlayer localPlayer, int i, Operation<Void> original) {
|
||||
AbstractClientPlayer spectatingPlayer = Flashback.getSpectatingPlayer();
|
||||
if (spectatingPlayer != null) {
|
||||
f = ((MinecraftExt)this.minecraft).flashback$getLocalPlayerPartialTick();
|
||||
((ItemInHandRendererExt)instance).flashback$renderHandsWithItems(f, poseStack, bufferSource, spectatingPlayer, i);
|
||||
Entity entity = this.minecraft.getCameraEntity() == null ? this.minecraft.player : this.minecraft.getCameraEntity();
|
||||
float frozenPartialTick = this.minecraft.level.tickRateManager().isEntityFrozen(entity) ? 1.0f : f;
|
||||
((ItemInHandRendererExt)instance).flashback$renderHandsWithItems(frozenPartialTick, poseStack, bufferSource, spectatingPlayer, i);
|
||||
} else {
|
||||
original.call(instance, f, poseStack, bufferSource, localPlayer, i);
|
||||
}
|
||||
@@ -70,11 +77,34 @@ public class MixinGameRenderer {
|
||||
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V"))
|
||||
public void renderLevel_setupCamera(Camera instance, BlockGetter blockGetter, Entity entity, boolean bl, boolean bl2, float f, Operation<Void> original) {
|
||||
if (Flashback.isInReplay()) {
|
||||
f = ((MinecraftExt)this.minecraft).flashback$getLocalPlayerPartialTick();
|
||||
f = ((MinecraftExt)this.minecraft).flashback$getLocalPlayerPartialTick(f);
|
||||
}
|
||||
original.call(instance, blockGetter, entity, bl, bl2, f);
|
||||
}
|
||||
|
||||
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;rotation()Lorg/joml/Quaternionf;"))
|
||||
public Quaternionf renderLevel(Camera instance, Operation<Quaternionf> original) {
|
||||
return CameraRotation.modifyViewQuaternion(original.call(instance));
|
||||
}
|
||||
|
||||
// @Inject(method = "getProjectionMatrix", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;perspective(FFFF)Lorg/joml/Matrix4f;", shift = At.Shift.BEFORE))
|
||||
// @Inject(method = "getProjectionMatrix", at = @At(value = "RETURN"))
|
||||
// public void getProjectionMatrix(double d, CallbackInfoReturnable<Matrix4f> cir) {
|
||||
// if (ReplayVisuals.overrideZoom) {
|
||||
// cir.getReturnValue().scaleLocal(ReplayVisuals.overrideZoomAmount, ReplayVisuals.overrideZoomAmount, 1.0f);
|
||||
// }
|
||||
// }
|
||||
|
||||
// @Inject(method = "getProjectionMatrix", at = @At(value = "RETURN"), cancellable = true)
|
||||
// public void getProjectionMatrix(double d, CallbackInfoReturnable<Matrix4f> cir) {
|
||||
// if (ReplayVisuals.overrideZoom) {
|
||||
// Window window = Minecraft.getInstance().getWindow();
|
||||
// Matrix4f matrix4f = new Matrix4f().setOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 0.05f, this.getDepthFar());
|
||||
// cir.setReturnValue(matrix4f);
|
||||
//// cir.setReturnValue(new Matrix4f().ortho());
|
||||
// }
|
||||
// }
|
||||
|
||||
@Inject(method = "tryTakeScreenshotIfNeeded", at = @At("HEAD"), cancellable = true)
|
||||
public void tryTakeScreenshotIfNeeded(CallbackInfo ci) {
|
||||
if (Flashback.isInReplay()) {
|
||||
@@ -89,13 +119,13 @@ public class MixinGameRenderer {
|
||||
cir.setReturnValue(70.0);
|
||||
return;
|
||||
}
|
||||
|
||||
int fov = this.minecraft.options.fov().get().intValue();
|
||||
if (ReplayVisuals.overrideFov) {
|
||||
cir.setReturnValue((double) ReplayVisuals.overrideFovAmount);
|
||||
return;
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.replayVisuals.overrideFov) {
|
||||
cir.setReturnValue((double) editorState.replayVisuals.overrideFovAmount);
|
||||
} else {
|
||||
int fov = this.minecraft.options.fov().get().intValue();
|
||||
cir.setReturnValue((double) fov);
|
||||
}
|
||||
cir.setReturnValue((double) fov);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.chunk.UpgradeData;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.blending.BlendingData;
|
||||
import net.minecraft.world.level.lighting.LightEngine;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
||||
@Mixin(LevelChunk.class)
|
||||
public abstract class MixinLevelChunk extends ChunkAccess implements LevelChunkExt {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Level level;
|
||||
|
||||
@Shadow
|
||||
public abstract void addAndRegisterBlockEntity(BlockEntity blockEntity);
|
||||
|
||||
@Shadow
|
||||
protected abstract <T extends BlockEntity> void updateBlockEntityTicker(T blockEntity);
|
||||
|
||||
@Shadow
|
||||
public abstract @Nullable BlockEntity getBlockEntity(BlockPos blockPos, LevelChunk.EntityCreationType entityCreationType);
|
||||
|
||||
public MixinLevelChunk(ChunkPos chunkPos, UpgradeData upgradeData, LevelHeightAccessor levelHeightAccessor, Registry<Biome> registry, long l, @Nullable LevelChunkSection[] levelChunkSections, @Nullable BlendingData blendingData) {
|
||||
super(chunkPos, upgradeData, levelHeightAccessor, registry, l, levelChunkSections, blendingData);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private int cachedChunkId = -1;
|
||||
|
||||
@Override
|
||||
public int flashback$getCachedChunkId() {
|
||||
return this.cachedChunkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$setCachedChunkId(int id) {
|
||||
this.cachedChunkId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$setBlockStateWithoutUpdates(BlockPos blockPos, BlockState blockState) {
|
||||
int y = blockPos.getY();
|
||||
LevelChunkSection levelChunkSection = this.getSection(this.getSectionIndex(y));
|
||||
boolean oldHasOnlyAir = levelChunkSection.hasOnlyAir();
|
||||
if (oldHasOnlyAir && blockState.isAir()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set block
|
||||
int localX = blockPos.getX() & 0xF;
|
||||
int localY = y & 0xF;
|
||||
int localZ = blockPos.getZ() & 0xF;
|
||||
BlockState oldBlockState = levelChunkSection.setBlockState(localX, localY, localZ, blockState);
|
||||
if (oldBlockState == blockState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update heightmaps
|
||||
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).update(localX, y, localZ, blockState);
|
||||
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES).update(localX, y, localZ, blockState);
|
||||
this.heightmaps.get(Heightmap.Types.OCEAN_FLOOR).update(localX, y, localZ, blockState);
|
||||
this.heightmaps.get(Heightmap.Types.WORLD_SURFACE).update(localX, y, localZ, blockState);
|
||||
|
||||
// Update air status
|
||||
boolean newHasOnlyAir = levelChunkSection.hasOnlyAir();
|
||||
if (oldHasOnlyAir != newHasOnlyAir) {
|
||||
this.level.getChunkSource().getLightEngine().updateSectionStatus(blockPos, newHasOnlyAir);
|
||||
}
|
||||
|
||||
// Update light
|
||||
if (LightEngine.hasDifferentLightProperties(this, blockPos, oldBlockState, blockState)) {
|
||||
if (this.skyLightSources != null) {
|
||||
this.skyLightSources.update(this, localX, y, localZ);
|
||||
}
|
||||
this.level.getChunkSource().getLightEngine().checkBlock(blockPos);
|
||||
}
|
||||
|
||||
// Update block entity
|
||||
Block block = blockState.getBlock();
|
||||
if (!oldBlockState.is(block) && oldBlockState.hasBlockEntity()) {
|
||||
this.removeBlockEntity(blockPos);
|
||||
}
|
||||
if (!levelChunkSection.getBlockState(localX, localY, localZ).is(block)) {
|
||||
return;
|
||||
}
|
||||
if (blockState.hasBlockEntity()) {
|
||||
BlockEntity blockEntity = this.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
|
||||
if (blockEntity == null) {
|
||||
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
|
||||
if (blockEntity != null) {
|
||||
this.addAndRegisterBlockEntity(blockEntity);
|
||||
}
|
||||
} else {
|
||||
blockEntity.setBlockState(blockState);
|
||||
this.updateBlockEntityTicker(blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
this.unsaved = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.ext.LevelChunkSectionExt;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.chunk.PalettedContainer;
|
||||
import net.minecraft.world.level.chunk.PalettedContainerRO;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(LevelChunkSection.class)
|
||||
public class MixinLevelChunkSection implements LevelChunkSectionExt {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private PalettedContainer<BlockState> states;
|
||||
|
||||
@Shadow
|
||||
private short nonEmptyBlockCount;
|
||||
|
||||
@Shadow
|
||||
private PalettedContainerRO<Holder<Biome>> biomes;
|
||||
|
||||
@Unique
|
||||
private int cachedChunkId = -1;
|
||||
|
||||
@Override
|
||||
public int flashback$getCachedChunkId() {
|
||||
return this.cachedChunkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashback$setCachedChunkId(int cachedChunkId) {
|
||||
this.cachedChunkId = cachedChunkId;
|
||||
}
|
||||
|
||||
@Inject(method = "read", at = @At("RETURN"))
|
||||
public void read(FriendlyByteBuf friendlyByteBuf, CallbackInfo ci) {
|
||||
this.cachedChunkId = -1;
|
||||
}
|
||||
|
||||
@Inject(method = "setBlockState(IIILnet/minecraft/world/level/block/state/BlockState;Z)Lnet/minecraft/world/level/block/state/BlockState;", at = @At("RETURN"))
|
||||
public void setBlockState(int i, int j, int k, BlockState blockState, boolean bl, CallbackInfoReturnable<BlockState> cir) {
|
||||
this.cachedChunkId = -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.playback.ReplayPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.ServerTickRateManager;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
@@ -10,6 +11,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(TickRateManager.class)
|
||||
@@ -18,16 +20,34 @@ public abstract class MixinTickRateManager {
|
||||
@Shadow
|
||||
public abstract boolean runsNormally();
|
||||
|
||||
@Shadow
|
||||
protected boolean runGameElements;
|
||||
|
||||
/*
|
||||
* Freeze the replay server, preventing game elements from running normally
|
||||
*/
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
public void tick(CallbackInfo ci) {
|
||||
if (Flashback.isInReplay() && this.isServerTickRateManager) {
|
||||
this.runGameElements = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private final boolean isClientTickRateManager = !((Object)this instanceof ServerTickRateManager);
|
||||
private final boolean isServerTickRateManager = ((Object)this instanceof ServerTickRateManager);
|
||||
|
||||
@Inject(method = "isEntityFrozen", at = @At("HEAD"), cancellable = true)
|
||||
public void isEntityFrozen(Entity entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (this.isClientTickRateManager && Flashback.isInReplay()) {
|
||||
if (Flashback.EXPORT_JOB != null && Flashback.EXPORT_JOB.isRunning()) {
|
||||
cir.setReturnValue(false);
|
||||
if (Flashback.isInReplay()) {
|
||||
if (this.isServerTickRateManager) {
|
||||
cir.setReturnValue(!(entity instanceof ReplayPlayer));
|
||||
} else {
|
||||
cir.setReturnValue(!this.runsNormally() || entity == Minecraft.getInstance().player);
|
||||
if (Flashback.isExporting()) {
|
||||
cir.setReturnValue(false);
|
||||
} else {
|
||||
cir.setReturnValue(!this.runsNormally() || entity == Minecraft.getInstance().player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user