Skip to content

Commit

Permalink
Review and update mixins.
Browse files Browse the repository at this point in the history
- Improve mixin compatibility
* Review and update mixins where needed
* Use MixinExtras mixins where beneficial
* Restore the outline "feature"
  • Loading branch information
gniftygnome committed Feb 8, 2024
1 parent e9be937 commit 975fc31
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,4 @@ private void takeScreenshot(Path folder, int id, Framebuffer buffer) {

@Shadow
public abstract void setRenderHand(boolean renderHand);

}
63 changes: 41 additions & 22 deletions src/main/java/com/terraformersmc/vistas/mixin/LogoDrawerMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.terraformersmc.vistas.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.terraformersmc.vistas.Vistas;
import com.terraformersmc.vistas.panorama.LogoControl;
import com.terraformersmc.vistas.panorama.Panorama;
Expand All @@ -17,7 +21,8 @@
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.Redirect;

import java.util.function.BiConsumer;

@Environment(EnvType.CLIENT)
@Mixin(LogoDrawer.class)
Expand All @@ -29,15 +34,16 @@ public abstract class LogoDrawerMixin implements LogoDrawerAccessor {
@Unique
private boolean isVistas = false;

@Redirect(
@WrapOperation(
method = "draw(Lnet/minecraft/client/gui/DrawContext;IFI)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIFFIIII)V",
ordinal = 0
)
)
private void vistas$render$drawOutline(DrawContext context, Identifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, DrawContext _context, int screenWidth) {
@SuppressWarnings("unused")
private void vistas$render$drawOutline(DrawContext instance, Identifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, Operation<Void> operation, DrawContext context, int screenWidth) {
Panorama panorama = VistasTitle.CURRENT.getValue();
LogoControl logo = panorama.getLogoControl();
MatrixStack matrices = context.getMatrices();
Expand All @@ -50,43 +56,45 @@ public abstract class LogoDrawerMixin implements LogoDrawerAccessor {
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((float) logo.getLogoRot()));
matrices.translate(-(screenWidth / 2.0D), -(y * 2.0D) + (y / 2.0D), 0.0D);

// TODO: Outline rendering no longer works
if (!logo.getLogoId().equals(LOGO_TEXTURE) || this.isVistas) {
Identifier logoTexture = this.isVistas ? Vistas.id("textures/vistas_logo.png") : logo.getLogoId();
int rx = (screenWidth / 2) - 256;
int ry = 52 - 256;

// BiConsumer<Integer, Integer> render = (ix, iy) -> Screen.drawTexture(matrices, ix, iy, 0, 0, 0, 512, 512, 512, 512);
// if (logo.isOutlined()) {
// DrawableHelper.drawWithOutline(rx, ry, render);
// } else {
// render.accept(rx, ry);
// }
BiConsumer<Integer, Integer> render = (ix, iy) -> context.drawTexture(logoTexture, ix, iy, 0, 0, 0, 512, 512, 512, 512);

if (logo.isOutlined()) {
vistas$drawWithOutline(rx, ry, render);
} else {
render.accept(rx, ry);
}

context.drawTexture(logoTexture, rx, ry, 0, 0, 512, 512, 512, 512, 512);
operation.call(instance, logoTexture, rx, ry, 0, 0, 512, 512, 512, 512, 512);
} else {
// if (logo.isOutlined()) {
// DrawableHelper.drawWithOutline(x, y, renderAction);
// } else {
// renderAction.accept(x, y);
// }

// TODO: This mixin would be better as a WrapOperation
context.drawTexture(logo.getLogoId(), x, y, u, v, width, height, textureWidth, textureHeight);
BiConsumer<Integer, Integer> render = (ix, iy) -> context.drawTexture(logo.getLogoId(), ix, iy, u, v, width, height, textureWidth, textureHeight);

if (logo.isOutlined()) {
vistas$drawWithOutline(x, y, render);
} else {
render.accept(x, y);
}

operation.call(instance, logo.getLogoId(), x, y, u, v, width, height, textureWidth, textureHeight);
}

matrices.pop();
}

@Redirect(
@WrapOperation(
method = "draw(Lnet/minecraft/client/gui/DrawContext;IFI)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIFFIIII)V",
ordinal = 1
)
)
private void vistas$render(DrawContext context, Identifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, DrawContext _context, int screenWidth) {
@SuppressWarnings("unused")
private void vistas$render(DrawContext instance, Identifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, Operation<Void> operation, DrawContext context, int screenWidth) {
Panorama panorama = VistasTitle.CURRENT.getValue();
LogoControl logo = panorama.getLogoControl();
MatrixStack matrices = context.getMatrices();
Expand All @@ -103,7 +111,7 @@ public abstract class LogoDrawerMixin implements LogoDrawerAccessor {
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((float) logo.getLogoRot()));
matrices.translate(-(screenWidth / 2.0D), -45, 0.0D);

context.drawTexture(texture, x, y, u, v, width, height, textureWidth, textureHeight);
operation.call(instance, texture, x, y, u, v, width, height, textureWidth, textureHeight);

matrices.pop();
}
Expand All @@ -112,4 +120,15 @@ public abstract class LogoDrawerMixin implements LogoDrawerAccessor {
public void vistas$setIsVistas(boolean value) {
this.isVistas = value;
}

@Unique
private static void vistas$drawWithOutline(int x, int y, BiConsumer<Integer, Integer> renderAction) {
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
renderAction.accept(x + 1, y);
renderAction.accept(x - 1, y);
renderAction.accept(x, y + 1);
renderAction.accept(x, y - 1);
RenderSystem.defaultBlendFunc();
renderAction.accept(x, y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ public class MinecraftClientMixin implements MinecraftClientAccess {
@Shadow
public ClientPlayerEntity player;

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ReloadableResourceManagerImpl;registerReloader(Lnet/minecraft/resource/ResourceReloader;)V", ordinal = 2, shift = Shift.AFTER))
@Inject(
method = "<init>",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/resource/ReloadableResourceManagerImpl;registerReloader(Lnet/minecraft/resource/ResourceReloader;)V",
ordinal = 2,
shift = Shift.AFTER
)
)
private void vistas$init$registerPanoramaReloader(RunArgs args, CallbackInfo ci) {
this.panoramaResourceReloader = new PanoramaResourceReloader();
this.resourceManager.registerReloader(panoramaResourceReloader);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
package com.terraformersmc.vistas.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.terraformersmc.vistas.panorama.LogoControl;
import com.terraformersmc.vistas.panorama.Panorama;
import com.terraformersmc.vistas.title.VistasTitle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.SplashTextRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.RotationAxis;
import org.joml.Quaternionf;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin(SplashTextRenderer.class)
public abstract class SplashTextRendererMixin {
@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/RotationAxis;rotationDegrees(F)Lorg/joml/Quaternionf;"))
private float vistas$render$changeAngle(float in) {
return (float) VistasTitle.CURRENT.getValue().getLogoControl().getSplashRot();
}

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V", shift = At.Shift.BEFORE))
private void vistas$render(DrawContext context, int screenWidth, TextRenderer textRenderer, int alpha, CallbackInfo ci) {
@WrapOperation(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V"
)
)
@SuppressWarnings("unused")
private void vistas$render(MatrixStack instance, Quaternionf quaternion, Operation<Void> operation) {
Panorama panorama = VistasTitle.CURRENT.getValue();
LogoControl logo = panorama.getLogoControl();

context.getMatrices().translate(logo.getSplashX(), logo.getSplashY(), 0.0D);
float rotation = (float) VistasTitle.CURRENT.getValue().getLogoControl().getSplashRot();

instance.translate(logo.getSplashX(), logo.getSplashY(), 0.0D);
operation.call(instance, RotationAxis.POSITIVE_Z.rotationDegrees(rotation));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.terraformersmc.vistas.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.terraformersmc.vistas.access.MinecraftClientAccess;
import com.terraformersmc.vistas.resource.PanoramaResourceReloader;
import com.terraformersmc.vistas.title.VistasTitle;
Expand All @@ -11,29 +12,29 @@
import net.minecraft.util.Identifier;
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 org.spongepowered.asm.mixin.injection.Slice;

@Environment(EnvType.CLIENT)
@Mixin(SplashTextResourceSupplier.class)
public class SplashTextResourceSupplierMixin {
@Inject(method = "get", at = @At(value = "RETURN", ordinal = 4), cancellable = true)
private void vistas$get$4(CallbackInfoReturnable<SplashTextRenderer> ci) {
vistas$get(ci);
}

@Inject(method = "get", at = @At(value = "RETURN", ordinal = 5), cancellable = true)
private void vistas$get$5(CallbackInfoReturnable<SplashTextRenderer> ci) {
vistas$get(ci);
}

private void vistas$get(CallbackInfoReturnable<SplashTextRenderer> ci) {
@ModifyReturnValue(
method = "get",
at = @At(value = "RETURN"),
slice = @Slice(
from = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"),
to = @At(value = "TAIL")
)
)
@SuppressWarnings("unused")
private SplashTextRenderer vistas$getRenderer(SplashTextRenderer original) {
MinecraftClient client = MinecraftClient.getInstance();
PanoramaResourceReloader resourceReloader = ((MinecraftClientAccess) client).getPanoramaResourceReloader();
Identifier panoramaId = VistasTitle.PANORAMAS_INVERT.get(VistasTitle.CURRENT.getValue());

if (resourceReloader != null && panoramaId != null) {
ci.setReturnValue(new SplashTextRenderer(resourceReloader.get()));
return new SplashTextRenderer(resourceReloader.get());
}

return original;
}
}
24 changes: 11 additions & 13 deletions src/main/java/com/terraformersmc/vistas/mixin/TitleScreenMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.terraformersmc.vistas.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.terraformersmc.vistas.Vistas;
Expand All @@ -26,10 +28,8 @@
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
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.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Random;

Expand Down Expand Up @@ -74,31 +74,29 @@ protected TitleScreenMixin(Text title) {
}
}

@Inject(
@WrapOperation(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V",
shift = Shift.BEFORE
),
locals = LocalCapture.CAPTURE_FAILHARD
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
)
)
private void vistas$render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci, float f) {
@SuppressWarnings("unused")
private void vistas$render(RotatingCubeMapRenderer instance, float delta, float fade, Operation<Void> operation, DrawContext context) {
assert this.client != null;
PanoramaRenderer.time += delta;
VistasTitle.CURRENT.getValue().getCubemaps().forEach((cubemap) -> {
PanoramaRenderer panoramaRenderer = new PanoramaRenderer(cubemap);
panoramaRenderer.render(delta, MathHelper.clamp(f, 0.0F, 1.0F));
panoramaRenderer.render(delta, fade);
Identifier overlayId = new Identifier(panoramaRenderer.getCubemap().getCubemapId() + "_overlay.png");
if (this.client.getResourceManager().getResource(overlayId).isPresent()) {
// TODO: Some of these functions may be redundant.
// RenderSystem.setShader(GameRenderer::getPositionTexProgram);
// RenderSystem.setShaderTexture(0, overlayId);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.doBackgroundFade ? (float) MathHelper.ceil(MathHelper.clamp(f, 0.0F, 1.0F)) : 1.0F);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.doBackgroundFade ? (float) MathHelper.ceil(fade) : 1.0F);
context.drawTexture(overlayId, 0, 0, this.width, this.height, 0.0F, 0.0F, 16, 128, 16, 128);
}
});

operation.call(instance, delta, fade);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/vistas/panoramas.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"logoX": 0.0,
"logoY": 0.0,
"logoRot": 0.0,
"outlined": true,
"outlined": false,
"splashX": 0.0,
"splashY": 0.0,
"splashRot": -20.0,
Expand Down

0 comments on commit 975fc31

Please sign in to comment.