Skip to content

Commit

Permalink
Merge pull request #20 from KabanFriends/dev/1.21.2
Browse files Browse the repository at this point in the history
Update to 1.21.2
  • Loading branch information
KabanFriends authored Oct 23, 2024
2 parents 279df8b + 453259b commit 30df162
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
}

architectury {
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
}

loom {
accessWidenerPath = file("src/main/resources/craftgr.accesswidener")
accessWidenerPath = file("src/main/resources/craftgr-common.accesswidener")
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return false;
}

return _keyPressed(keyCode);
}

public boolean _keyPressed(int keyCode) {
if (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_SPACE || keyCode == InputConstants.KEY_NUMPADENTER) {
toggleSetting();
return true;
Expand All @@ -95,7 +99,15 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!isMouseOver(mouseX, mouseY) || !isAvailable()) {
if (!isMouseOver(mouseX, mouseY)) {
return false;
}

return _mouseClicked();
}

public boolean _mouseClicked() {
if (!isAvailable()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package io.github.kabanfriends.craftgr.mixin;

import net.minecraft.client.gui.Font;
import com.mojang.blaze3d.platform.Window;
import io.github.kabanfriends.craftgr.util.ThreadLocals;
import io.github.kabanfriends.craftgr.util.render.UnscaledScreenRectangle;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
import net.minecraft.client.gui.navigation.ScreenRectangle;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

// The purpose of this Mixin is to fix a client bug where the
// batch text rendering in tooltips are never correctly flushed.
@Mixin(GuiGraphics.class)
public abstract class MixinGuiGraphics {
public class MixinGuiGraphics {

@Shadow
protected abstract void flushIfUnmanaged();
@Inject(method = "applyScissor", at = @At("HEAD"))
private void craftgr$getScissorRectangle(ScreenRectangle rectangle, CallbackInfo ci) {
if (rectangle instanceof UnscaledScreenRectangle) {
ThreadLocals.SCISSOR_CURRENT_RECTANGLE.set(rectangle);
}
}

@Inject(method = "renderTooltipInternal", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V",shift = At.Shift.AFTER))
private void craftgr$fixTooltip(Font font, List<ClientTooltipComponent> tooltips, int mouseX, int mouseY, ClientTooltipPositioner positioner, CallbackInfo ci) {
flushIfUnmanaged();
@Redirect(method = "applyScissor", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/Window;getGuiScale()D"))
private double craftgr$patchScissorScale(Window window) {
if (ThreadLocals.SCISSOR_CURRENT_RECTANGLE.get() instanceof UnscaledScreenRectangle) {
ThreadLocals.SCISSOR_CURRENT_RECTANGLE.remove();
return 1.0;
}
return window.getGuiScale();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.List;

@Mixin(OptionsList.OptionEntry.class)
public class MixinOptionEntry {
public class MixinOptionsListOptionEntry {

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/OptionsList$Entry;<init>(Ljava/util/List;Lnet/minecraft/client/gui/screens/Screen;)V"))
private static List<AbstractWidget> craftgr$initOptionEntry(List<AbstractWidget> list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import io.github.kabanfriends.craftgr.overlay.widget.impl.ScrollingText;
import io.github.kabanfriends.craftgr.song.Song;
import io.github.kabanfriends.craftgr.util.*;
import io.github.kabanfriends.craftgr.util.render.RenderUtil;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -128,7 +130,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);

if (!ModConfig.<Boolean>get("hideAlbumArt")) {
graphics.blit(shouldRenderAlbumArt() ? ALBUM_ART_LOCATION : ALBUM_ART_PLACEHOLDER_LOCATION, x + ART_LEFT_PADDING, y + ART_TOP_PADDING, 0f, 0f, ART_SIZE, ART_SIZE, ART_SIZE, ART_SIZE);
graphics.blit(RenderType::guiTextured, shouldRenderAlbumArt() ? ALBUM_ART_LOCATION : ALBUM_ART_PLACEHOLDER_LOCATION, x + ART_LEFT_PADDING, y + ART_TOP_PADDING, 0f, 0f, ART_SIZE, ART_SIZE, ART_SIZE, ART_SIZE);
}

poseStack.pushPose();
Expand All @@ -140,10 +142,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY) {
if (!song.metadata().intermission()) {
int dotWidth = font.width("...");

String year = null;
if (song.metadata().year() != null) {
year = "(" + song.metadata().year() + ")";
}
String year = song.metadata().year() == null ? null : "(" + song.metadata().year() + ")";

String[] strings = {year, song.metadata().artist(), song.metadata().album(), song.metadata().circle()};
for (int i = 0; i < 4; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.kabanfriends.craftgr.overlay.widget.impl;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import io.github.kabanfriends.craftgr.CraftGR;
import io.github.kabanfriends.craftgr.config.ModConfig;
import io.github.kabanfriends.craftgr.overlay.widget.UIWidget;
import io.github.kabanfriends.craftgr.util.render.RenderUtil;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;

Expand Down Expand Up @@ -87,17 +87,17 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY) {

PoseStack poseStack = graphics.pose();

RenderSystem.enableScissor(scissorX, (CraftGR.getInstance().getMinecraft().getWindow().getHeight() - scissorY - scissorH), scissorW, scissorH);
RenderUtil.enableUnscaledScissor(graphics, scissorX, scissorY, scissorX + scissorW, scissorY + scissorH);

// Uncomment to debug
//io.github.kabanfriends.craftgr.util.RenderUtil.fill(poseStack, 0, 0, CraftGR.MC.getWindow().getWidth(), CraftGR.MC.getWindow().getHeight(), 0x8F00FF00, 0.6f);
//RenderUtil.fill(poseStack, 0, 0, CraftGR.getInstance().getMinecraft().getWindow().getWidth(), CraftGR.getInstance().getMinecraft().getWindow().getHeight(), 0x8F00FF00, 0.6f);

poseStack.pushPose();
poseStack.scale(2, 2, 2);
graphics.drawString(CraftGR.getInstance().getMinecraft().font, component, fontX, fontY, Color.WHITE.getRGB());
poseStack.popPose();

RenderSystem.disableScissor();
graphics.disableScissor();
}

private float getMovingX(float x) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.github.kabanfriends.craftgr.util;

import net.minecraft.client.gui.navigation.ScreenRectangle;

public class ThreadLocals {

public static final ThreadLocal<Boolean> PNG_INFO_BYPASS_VALIDATION = new ThreadLocal<>();
public static final ThreadLocal<Boolean> RADIO_OPTION_CONTAINER_ADDED = new ThreadLocal<>();
public static final ThreadLocal<ScreenRectangle> SCISSOR_CURRENT_RECTANGLE = new ThreadLocal<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class TitleFixer {
}

public static String fixJapaneseString(String input) {
if (input == null) {
return null;
}

//Replace or remove special characters that are visible only in Minecraft font
input = input.replaceAll(" ", " ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.kabanfriends.craftgr.util;
package io.github.kabanfriends.craftgr.util.render;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import io.github.kabanfriends.craftgr.CraftGR;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.CoreShaders;
import org.joml.Matrix4f;

public class RenderUtil {
Expand Down Expand Up @@ -45,7 +45,7 @@ public static void fill(PoseStack poseStack, float minX, float minY, float maxX,

RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShader(CoreShaders.POSITION_COLOR);
BufferBuilder bb = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
bb.addVertex(matrix4f, minX, maxY, 0.0F).setColor(r, g, b, a);
bb.addVertex(matrix4f, maxX, maxY, 0.0F).setColor(r, g, b, a);
Expand All @@ -60,4 +60,8 @@ public static float getUIScale(float uiScale) {

return (float) ((((double) UI_BASE_SCALE) * (((double) UI_BASE_SCALE) / mcScale)) * uiScale);
}

public static void enableUnscaledScissor(GuiGraphics graphics, int x, int y, int width, int height) {
graphics.applyScissor(graphics.scissorStack.push(new UnscaledScreenRectangle(x, y, width - x, height -y)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.kabanfriends.craftgr.util.render;

import net.minecraft.client.gui.navigation.ScreenRectangle;

public class UnscaledScreenRectangle extends ScreenRectangle {

public UnscaledScreenRectangle(int x, int y, int width, int height) {
super(x, y, width, height);
}
}
10 changes: 10 additions & 0 deletions common/src/main/resources/craftgr-common.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
accessWidener v2 named

extendable class net/minecraft/client/gui/navigation/ScreenRectangle

accessible class net/minecraft/client/gui/GuiGraphics$ScissorStack
accessible class net/minecraft/client/gui/components/OptionsList$Entry
accessible class net/minecraft/client/gui/components/OptionsList$OptionEntry
accessible class net/minecraft/client/gui/components/AbstractSelectionList$Entry
accessible field net/minecraft/client/gui/GuiGraphics scissorStack Lnet/minecraft/client/gui/GuiGraphics$ScissorStack;
accessible method net/minecraft/client/gui/GuiGraphics applyScissor (Lnet/minecraft/client/gui/navigation/ScreenRectangle;)V
2 changes: 1 addition & 1 deletion common/src/main/resources/craftgr-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mixins": [
"MixinAccessorAbstractSelectionList",
"MixinGuiGraphics",
"MixinOptionEntry",
"MixinOptionsListOptionEntry",
"MixinOptionsSubScreen",
"MixinPngInfo",
"MixinSoundEngine",
Expand Down
4 changes: 0 additions & 4 deletions common/src/main/resources/craftgr.accesswidener

This file was deleted.

5 changes: 5 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }

modApi("com.terraformersmc:modmenu:${rootProject.mod_menu_version}") { transitive(false) }
modApi "dev.isxander:yet-another-config-lib:${rootProject.yacl_version}-fabric"

include "com.github.umjammer:jlayer:${rootProject.jlayer_version}"
include("org.java-websocket:Java-WebSocket:${rootProject.java_websocket_version}") {
Expand All @@ -35,6 +36,10 @@ dependencies {
localRuntime "org.java-websocket:Java-WebSocket:${rootProject.java_websocket_version}"
}

loom {
accessWidenerPath = file("src/main/resources/craftgr-fabric.accesswidener")
}

processResources {
inputs.property "version", rootProject.version

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.kabanfriends.craftgr.fabric.mixin;

import dev.isxander.yacl3.gui.OptionListWidget;
import io.github.kabanfriends.craftgr.config.controller.RadioStateController;
import net.minecraft.client.gui.components.AbstractSelectionList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(AbstractSelectionList.class)
public class MixinAbstractSelectionList {

@Redirect(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;mouseClicked(DDI)Z"))
private boolean craftgr$fixMouseClicked(AbstractSelectionList.Entry<?> entry, double mouseX, double mouseY, int button) {
if (entry instanceof OptionListWidget.OptionEntry optionEntry) {
if (optionEntry.widget instanceof RadioStateController.Element radioElement) {
return radioElement._mouseClicked();
}
}
return entry.mouseClicked(mouseX, mouseY, button);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.kabanfriends.craftgr.fabric.mixin;

import net.minecraft.client.gui.components.AbstractSelectionList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(AbstractSelectionList.Entry.class)
public interface MixinAccessorAbstractSelectionListEntry<E extends AbstractSelectionList.Entry<E>> {

@Accessor
AbstractSelectionList<E> getList();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.kabanfriends.craftgr.fabric.mixin;

import dev.isxander.yacl3.gui.OptionListWidget;
import io.github.kabanfriends.craftgr.config.controller.RadioStateController;
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(OptionListWidget.OptionEntry.class)
public class MixinOptionListWidgetOptionEntry {

@Inject(method = "keyPressed", at = @At(value = "INVOKE", target = "Ldev/isxander/yacl3/gui/AbstractWidget;keyPressed(III)Z"), cancellable = true)
private void craftgr$fixKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (!((MixinAccessorAbstractSelectionListEntry<?>)this).getList().getFocused().equals(this)) {
return;
}
if (((OptionListWidget.OptionEntry)(Object)this).widget instanceof RadioStateController.Element radioElement) {
cir.setReturnValue(radioElement._keyPressed(keyCode));
cir.cancel();
}
}
}
3 changes: 3 additions & 0 deletions fabric/src/main/resources/craftgr-fabric.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v2 named

accessible class net/minecraft/client/gui/components/AbstractSelectionList$Entry
14 changes: 14 additions & 0 deletions fabric/src/main/resources/craftgr-fabric.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "io.github.kabanfriends.craftgr.fabric.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"MixinAbstractSelectionList",
"MixinAccessorAbstractSelectionListEntry",
"MixinOptionListWidgetOptionEntry"
],
"server": [],
"injectors": {
"defaultRequire": 1
}
}
10 changes: 6 additions & 4 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@
"server": []
},
"mixins": [
"craftgr-common.mixins.json"
"craftgr-common.mixins.json",
"craftgr-fabric.mixins.json"
],
"accessWidener": "craftgr-common.accesswidener",
"depends": {
"minecraft": ">=1.21-",
"minecraft": ">=1.21.2-",
"fabricloader": "*",
"fabric-key-binding-api-v1": "*",
"fabric-lifecycle-events-v1": "*",
"fabric-rendering-v1": "*",
"fabric-screen-api-v1": "*"
},
"recommends": {
"yet_another_config_lib_v3": ">=3.5.0"
"yet_another_config_lib_v3": ">=3.6.0"
},
"suggests": {
"modmenu": ">=11.0.0-beta.1"
"modmenu": ">=12.0.0-"
},
"custom": {
"modmenu:clientsideOnly": true
Expand Down
Loading

0 comments on commit 30df162

Please sign in to comment.