Clean up mixins and fix changes from last commit

- Add FixNormalScalingMixin from Create
- Fix VisualizedRenderDispatcher#tryAddBlockEntity
- Fix flywheel.sodium.mixins.json using wrong plugin class name
This commit is contained in:
PepperCode1 2023-04-13 11:36:05 -07:00
parent b4cef0b5c9
commit 361cb5a1d9
19 changed files with 132 additions and 92 deletions

View file

@ -166,7 +166,7 @@ public class VisualizedRenderDispatcher {
public static <T extends BlockEntity> boolean tryAddBlockEntity(T blockEntity) {
Level level = blockEntity.getLevel();
if (FlwUtil.canUseVisualization(level)) {
if (!FlwUtil.canUseVisualization(level)) {
return false;
}

View file

@ -64,24 +64,24 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
}
@Override
public TransformedInstance scale(float pX, float pY, float pZ) {
public TransformedInstance scale(float x, float y, float z) {
setChanged();
model.multiply(Matrix4f.createScaleMatrix(pX, pY, pZ));
if (pX == pY && pY == pZ) {
if (pX > 0.0F) {
return this;
model.multiply(Matrix4f.createScaleMatrix(x, y, z));
if (x == y && y == z) {
if (x < 0.0f) {
normal.mul(-1.0f);
}
normal.mul(-1.0F);
return this;
}
float f = 1.0F / pX;
float f1 = 1.0F / pY;
float f2 = 1.0F / pZ;
float f3 = Mth.fastInvCubeRoot(Math.abs(f * f1 * f2));
normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2));
float invX = 1.0f / x;
float invY = 1.0f / y;
float invZ = 1.0f / z;
float f = Mth.fastInvCubeRoot(Math.abs(invX * invY * invZ));
normal.mul(Matrix3f.createScaleMatrix(f * invX, f * invY, f * invZ));
return this;
}

View file

@ -36,7 +36,7 @@ public final class AnimationTickHolder {
public static float getPartialTicks() {
Minecraft mc = Minecraft.getInstance();
return (mc.isPaused() ? ((PausedPartialTickAccessor) mc).flywheel$getPartialTicksPaused() : mc.getFrameTime());
return (mc.isPaused() ? ((PausedPartialTickAccessor) mc).flywheel$getPausePartialTick() : mc.getFrameTime());
}
// Unused but might be useful for debugging.

View file

@ -46,22 +46,22 @@ public abstract class BufferBuilderMixin implements BufferBuilderExtension {
@Override
public void flywheel$freeBuffer() {
if (this.buffer != null) {
MemoryUtil.memFree(this.buffer);
this.buffer = null;
if (buffer != null) {
MemoryUtil.memFree(buffer);
buffer = null;
}
}
@Override
public void flywheel$injectForRender(@NotNull ByteBuffer buffer, @NotNull VertexFormat format, int vertexCount) {
this.building = true;
this.mode = VertexFormat.Mode.QUADS;
building = true;
mode = VertexFormat.Mode.QUADS;
this.buffer = buffer;
this.format = format;
this.vertices = vertexCount;
vertices = vertexCount;
this.currentElement = this.format.getElements().get(0);
this.elementIndex = 0;
currentElement = format.getElements().get(0);
elementIndex = 0;
}
}

View file

@ -27,15 +27,17 @@ public abstract class ClientLevelMixin implements ClientLevelExtension {
return getEntities().getAll();
}
@Inject(method = "entitiesForRendering", at = @At("RETURN"), cancellable = true)
@Inject(method = "entitiesForRendering()Ljava/lang/Iterable;", at = @At("RETURN"), cancellable = true)
private void flywheel$filterEntities(CallbackInfoReturnable<Iterable<Entity>> cir) {
if (FlwUtil.canUseVisualization((ClientLevel) (Object) this)) {
Iterable<Entity> entities = cir.getReturnValue();
ArrayList<Entity> filtered = Lists.newArrayList(entities);
filtered.removeIf(VisualizationHelper::shouldSkipRender);
cir.setReturnValue(filtered);
if (!FlwUtil.canUseVisualization((ClientLevel) (Object) this)) {
return;
}
Iterable<Entity> entities = cir.getReturnValue();
ArrayList<Entity> filtered = Lists.newArrayList(entities);
filtered.removeIf(VisualizationHelper::shouldSkipRender);
cir.setReturnValue(filtered);
}
}

View file

@ -9,7 +9,7 @@ import net.minecraft.client.main.Main;
@Mixin(Main.class)
public class ClientMainMixin {
@Inject(method = "main", at = @At("HEAD"))
@Inject(method = "main([Ljava/lang/String;)V", at = @At("HEAD"))
private static void flywheel$injectRenderDoc(CallbackInfo ci) {
// Only try to load RenderDoc if a system property is set.
if (System.getProperty("flw.loadRenderDoc") == null) {

View file

@ -1,23 +0,0 @@
package com.jozufozu.flywheel.mixin;
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 com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
@Mixin(LevelRenderer.class)
public class FixFabulousDepthMixin {
@Inject(method = "renderLevel", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/renderer/PostChain;process(F)V"))
private void flywheel$disableTransparencyShaderDepth(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) {
GlStateManager._depthMask(false);
}
}

View file

@ -1,6 +1,7 @@
package com.jozufozu.flywheel.mixin;
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;
@ -11,21 +12,22 @@ import net.minecraft.client.renderer.FogRenderer;
@Mixin(FogRenderer.class)
public class FogUpdateMixin {
@Unique
private static void flywheel$updateFog() {
FlwShaderUniforms.FOG_UPDATE = true;
}
@Inject(method = "setupNoFog", at = @At("TAIL"))
@Inject(method = "setupNoFog()V", at = @At("RETURN"))
private static void flywheel$onNoFog(CallbackInfo ci) {
flywheel$updateFog();
}
@Inject(method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", remap = false, at = @At("TAIL"))
@Inject(method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", at = @At("RETURN"), remap = false)
private static void flywheel$onFog(CallbackInfo ci) {
flywheel$updateFog();
}
@Inject(method = "levelFogColor", at = @At("TAIL"))
@Inject(method = "levelFogColor()V", at = @At("RETURN"))
private static void flywheel$onFogColor(CallbackInfo ci) {
flywheel$updateFog();
}

View file

@ -11,18 +11,18 @@ import com.mojang.blaze3d.platform.GlStateManager;
@Mixin(GlStateManager.class)
public class GlStateManagerMixin {
@Inject(method = "_glBindBuffer", at = @At("TAIL"))
private static void flywheel$onBindBuffer(int pTarget, int pBuffer, CallbackInfo ci) {
GlStateTracker._setBuffer(GlBufferType.fromTarget(pTarget), pBuffer);
@Inject(method = "_glBindBuffer(II)V", at = @At("RETURN"))
private static void flywheel$onBindBuffer(int target, int buffer, CallbackInfo ci) {
GlStateTracker._setBuffer(GlBufferType.fromTarget(target), buffer);
}
@Inject(method = "_glBindVertexArray", at = @At("TAIL"))
private static void flywheel$onBindVertexArray(int pArray, CallbackInfo ci) {
GlStateTracker._setVertexArray(pArray);
@Inject(method = "_glBindVertexArray(I)V", at = @At("RETURN"))
private static void flywheel$onBindVertexArray(int array, CallbackInfo ci) {
GlStateTracker._setVertexArray(array);
}
@Inject(method = "_glUseProgram", at = @At("TAIL"))
private static void flywheel$onUseProgram(int pProgram, CallbackInfo ci) {
GlStateTracker._setProgram(pProgram);
@Inject(method = "_glUseProgram(I)V", at = @At("RETURN"))
private static void flywheel$onUseProgram(int program, CallbackInfo ci) {
GlStateTracker._setProgram(program);
}
}

View file

@ -38,26 +38,27 @@ public class LevelRendererMixin {
@Unique
private RenderContext flywheel$renderContext;
@Inject(at = @At("HEAD"), method = "renderLevel")
private void flywheel$beginRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) {
flywheel$renderContext = RenderContext.create((LevelRenderer) (Object) this, level, renderBuffers, pPoseStack, pProjectionMatrix, pCamera);
@Inject(method = "renderLevel", at = @At("HEAD"))
private void flywheel$beginRender(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) {
flywheel$renderContext = RenderContext.create((LevelRenderer) (Object) this, level, renderBuffers, poseStack, projectionMatrix, camera);
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(flywheel$renderContext));
}
@Inject(at = @At("TAIL"), method = "renderLevel")
private void flywheel$endRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) {
@Inject(method = "renderLevel", at = @At("RETURN"))
private void flywheel$endRender(CallbackInfo ci) {
flywheel$renderContext = null;
}
@Inject(at = @At("TAIL"), method = "allChanged")
@Inject(method = "allChanged", at = @At("RETURN"))
private void flywheel$refresh(CallbackInfo ci) {
MinecraftForge.EVENT_BUS.post(new ReloadRenderersEvent(level));
}
// @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;crumblingBufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 2, shift = Shift.BY, by = 2 // after the game renders the breaking overlay normally
// ), method = "renderLevel")
// private void flywheel$renderCrumbling(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) {
// // after the game renders the breaking overlay normally
// @Inject(method = "renderLevel",
// at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;crumblingBufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 2, shift = Shift.BY, by = 2))
// private void flywheel$renderCrumbling(CallbackInfo ci) {
// if (flywheel$renderContext != null) {
// // TODO: Crumbling
// }

View file

@ -8,5 +8,5 @@ import net.minecraft.client.Minecraft;
@Mixin(Minecraft.class)
public interface PausedPartialTickAccessor {
@Accessor("pausePartialTick")
float flywheel$getPartialTicksPaused();
float flywheel$getPausePartialTick();
}

View file

@ -0,0 +1,18 @@
package com.jozufozu.flywheel.mixin.fix;
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 com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.renderer.LevelRenderer;
@Mixin(LevelRenderer.class)
public class FixFabulousDepthMixin {
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/PostChain;process(F)V", ordinal = 1))
private void flywheel$disableTransparencyShaderDepth(CallbackInfo ci) {
GlStateManager._depthMask(false);
}
}

View file

@ -0,0 +1,36 @@
package com.jozufozu.flywheel.mixin.fix;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.vertex.PoseStack;
@Mixin(PoseStack.class)
public class FixNormalScalingMixin {
/**
* Minecraft negates the normal matrix if all scales are equal and negative, but
* does not return afterward. This allows the rest of the method's logic to be
* applied, which negates the matrix again, resulting in the matrix being the
* same as in the beginning.
*/
@Inject(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/math/Matrix3f;mul(F)V", shift = Shift.AFTER), cancellable = true)
private void flywheel$returnAfterNegate(float x, float y, float z, CallbackInfo ci) {
ci.cancel();
}
/**
* Minecraft takes the inverse cube root of the product of all scales to provide a
* rough estimate for normalization so that it does not need to be done later. It
* does not make sense for this "normalization factor" to be negative though, as
* that would invert all normals. Additionally, Minecraft's fastInvCubeRoot method
* does not work for negative numbers.
*/
@ModifyArg(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;fastInvCubeRoot(F)F"))
private float flywheel$absInvCbrtInput(float input) {
return Math.abs(input);
}
}

View file

@ -14,9 +14,9 @@ import net.minecraft.world.level.block.entity.BlockEntity;
@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask")
public class ChunkRebuildHooksMixin {
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
private <E extends BlockEntity> void flywheel$addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) {
if (VisualizedRenderDispatcher.tryAddBlockEntity(be)) {
@Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;Ljava/util/Set;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
private void flywheel$tryAddBlockEntity(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> globalBlockEntities, BlockEntity blockEntity, CallbackInfo ci) {
if (VisualizedRenderDispatcher.tryAddBlockEntity(blockEntity)) {
ci.cancel();
}
}

View file

@ -20,12 +20,14 @@ public class VisualAddMixin {
@Final
Level level;
@Inject(method = "setBlockEntity",
@Inject(method = "setBlockEntity(Lnet/minecraft/world/level/block/entity/BlockEntity;)V",
at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
private void flywheel$onBlockEntityAdded(BlockEntity blockEntity, CallbackInfo ci) {
if (level.isClientSide && FlwUtil.canUseVisualization(level)) {
VisualizedRenderDispatcher.getBlockEntities(level)
.add(blockEntity);
if (!FlwUtil.canUseVisualization(level)) {
return;
}
VisualizedRenderDispatcher.getBlockEntities(level)
.add(blockEntity);
}
}

View file

@ -10,7 +10,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.impl.visualization.VisualizedRenderDispatcher;
import com.jozufozu.flywheel.util.FlwUtil;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -20,11 +19,13 @@ public class VisualRemoveMixin {
@Nullable
protected Level level;
@Inject(at = @At("TAIL"), method = "setRemoved")
@Inject(method = "setRemoved()V", at = @At("TAIL"))
private void flywheel$removeVisual(CallbackInfo ci) {
if (level instanceof ClientLevel && FlwUtil.canUseVisualization(level)) {
VisualizedRenderDispatcher.getBlockEntities(level)
.remove((BlockEntity) (Object) this);
if (!FlwUtil.canUseVisualization(level)) {
return;
}
VisualizedRenderDispatcher.getBlockEntities(level)
.remove((BlockEntity) (Object) this);
}
}

View file

@ -23,13 +23,13 @@ public class VisualUpdateMixin {
/**
* This gets called when a block is marked for rerender by vanilla.
*/
@Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")
private void flywheel$checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) {
@Inject(method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V", at = @At("TAIL"))
private void flywheel$checkUpdate(BlockPos pos, BlockState oldState, BlockState newState, CallbackInfo ci) {
if (!FlwUtil.canUseVisualization(level)) {
return;
}
BlockEntity blockEntity = level.getBlockEntity(pos);
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity == null) {
return;
}

View file

@ -10,7 +10,6 @@
"ClientLevelMixin",
"ClientMainMixin",
"EntityTypeMixin",
"FixFabulousDepthMixin",
"FogUpdateMixin",
"GlStateManagerMixin",
"LevelRendererAccessor",
@ -19,6 +18,8 @@
"PausedPartialTickAccessor",
"RenderTypeMixin",
"VertexFormatMixin",
"fix.FixFabulousDepthMixin",
"fix.FixNormalScalingMixin",
"matrix.Matrix3fAccessor",
"matrix.Matrix4fAccessor",
"matrix.PoseStackMixin",

View file

@ -4,7 +4,7 @@
"package": "com.jozufozu.flywheel.mixin.sodium",
"compatibilityLevel": "JAVA_17",
"refmap": "flywheel.refmap.json",
"plugin": "com.jozufozu.flywheel.compat.SodiumMixinConfigPlugin",
"plugin": "com.jozufozu.flywheel.compat.SodiumMixinPlugin",
"client": [
"ChunkRenderRebuildTaskMixin",
"FlywheelCompatMixin"