Skip to content

Commit

Permalink
Add build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Apr 2, 2024
1 parent 4a735e3 commit 8879375
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 139 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Build mod jar

on:
[workflow_dispatch, push]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- uses: gradle/[email protected]
with:
gradle-version: 8.6
name: Set up Gradle
- name: Add permission
run: chmod +x ./gradlew
- name: Execute Gradle build
run: ./gradlew build

- name: Upload a Build Artifact
uses: actions/[email protected]
with:
path: build/libs
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'org.spongepowered.mixin'


version "1.3.0-beta"
version "1.3.2-beta"
group "gkappa.wrapfix"
archivesBaseName = "WrapFix"

Expand All @@ -44,6 +44,7 @@ minecraft {
jvmArg "-Dfml.coreMods.load=gkappa.wrapfix.WrapFixLoadingPlugin"
jvmArg "-Dmixin.hotSwap=true"
jvmArg "-Dmixin.checks.interfaces=true"
jvmArg "-Dmixin.debug=true"

workingDirectory project.file('run')

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
2 changes: 1 addition & 1 deletion src/main/java/gkappa/wrapfix/WrapFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class WrapFix {
public static final String MODID = "wrapfix";
public static final String NAME = "WrapFix";
public static final String VERSION = "1.3.0-beta";
public static final String VERSION = "1.3.2-beta";

public static final BreakIterator BREAK_ITERATOR = BreakIterator.getLineInstance();
public static Logger logger;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gkappa/wrapfix/WrapFixLoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<String> getMixinConfigs() {
@Override
public boolean shouldMixinConfigQueue(String mixinConfig) {
if(mixinConfig.equals("wrapfix.mixins.json")) {
return WrapFixConfig.patchVanilla && System.getProperty("java.version").startsWith("1.8");
return WrapFixConfig.patchVanilla;
}
return IEarlyMixinLoader.super.shouldMixinConfigQueue(mixinConfig);
}
Expand Down
68 changes: 33 additions & 35 deletions src/main/java/gkappa/wrapfix/mixin/MixinFontRenderer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package gkappa.wrapfix.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import gkappa.wrapfix.WrapFix;
import net.minecraft.client.gui.FontRenderer;
import org.apache.commons.lang3.tuple.Pair;
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.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -21,15 +19,25 @@
@Mixin({FontRenderer.class})
public abstract class MixinFontRenderer {

@Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;setColor(FFFF)V", ordinal = 1, shift = At.Shift.BY, by = 2))
private void hackSeg(String text, boolean shadow, CallbackInfo ci, @Local(ordinal = 0)LocalIntRef i) {
if (text.charAt(i.get() + 1) == '§')
i.set(i.get() - 1);
@Shadow
private static boolean isFormatSpecial(char formatChar) {
return false;
}

@ModifyConstant(method = "renderStringAtPos", constant = @Constant(stringValue = "0123456789abcdefklmnor"))
private String hackConst(String origin) {
return "0123456789abcdefklmnor§";
@Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Ljava/lang/String;length()I", ordinal = 1))
private void captureLocal(String text, boolean shadow, CallbackInfo ci, @Share("i") LocalIntRef intRef, @Local(ordinal = 0) int index) {
intRef.set(index);
}
@Redirect(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Ljava/lang/String;length()I", ordinal = 1))
private int hackSeg(String instance, @Share("i") LocalIntRef intRef) {
int i = intRef.get() + 1;
if (i < instance.length()) {
char c = instance.charAt(i);
if (!isFormatSpecial(c) && !isFormatColor(c)) {
return -1;
}
}
return instance.length();
}

@Inject(at = @At("HEAD"), method = "listFormattedStringToWidth", cancellable = true)
Expand All @@ -42,8 +50,8 @@ private void wrapStringToWidthICU4J(String str, int wrapWidth, CallbackInfoRetur
List<String> list = new ArrayList<>();
int lineWidth = 0, fed = 0, icui, d, prevFormat = 0;
StringBuilder format = new StringBuilder(); // For next line's format since it should use format of previous line
int[] widths = new int[wrapWidth/4];
String[] formats = new String[wrapWidth/4];
int[] widths = new int[str.length()];
String[] formats = new String[str.length()];
StringBuilder line = new StringBuilder();
String temp;
char[] chars = str.toCharArray();
Expand All @@ -54,7 +62,7 @@ private void wrapStringToWidthICU4J(String str, int wrapWidth, CallbackInfoRetur
switch (current) {
case '\n':
list.add(line.toString());
fed += line.length() + 1;
fed = i;
line.delete(0, line.length()).append(format);
lineWidth = 0;
widths[i - fed] = lineWidth;
Expand All @@ -63,33 +71,23 @@ private void wrapStringToWidthICU4J(String str, int wrapWidth, CallbackInfoRetur
case '§':
if (i + 1 < chars.length) { // Prevent out of bound
f = chars[i + 1];
if (f != 'l' && f != 'L') { // Check start of bold style
if (f == 'r' || f == 'R' || isFormatColor(f)) { // Not Bold, check end of style
bold = false;
if (f == 'r' || f == 'R') {
boolean isC = isFormatColor(f);
if (isC || isFormatSpecial(f)) {
if (f != 'l' && f != 'L') { // Check start of bold style
if (f == 'r' || f == 'R') { // Not Bold, check end of style
bold = false;
format.delete(0, format.length()); // Clear the format
} else {
format.append('§').append(f); // Add to current format code
} else if (isC) {
bold = false;
}
line.append('§').append(f);
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
i++;
continue;
}
if (f >= 'k' && f <= 'o' || f >= 'K' && f <= 'O') {
format.append('§').append(f); // Add to current format code
line.append('§').append(f);
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
continue;
} else {
bold = true;
}
} else {
bold = true;
format.append('§').append(f); // Add to current format code
line.append('§').append(f);
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
i++;
continue;
}
}
Expand All @@ -111,13 +109,13 @@ private void wrapStringToWidthICU4J(String str, int wrapWidth, CallbackInfoRetur
}
if (icui <= fed || i == icui) {
list.add(line.substring(0,line.length() - 1));
fed += line.length() - 1;
fed = i - 1;
line.delete(0, line.length()).append(format).append(current);
prevFormat = format.length();
lineWidth = getCharWidth(current);
} else {
d = icui - fed;
list.add(line.substring(prevFormat, d + prevFormat));
list.add(line.substring(0, d + prevFormat));
temp = line.substring(d + prevFormat);
fed = icui;
line.delete(0, line.length()).append(formats[d]).append(temp);
Expand Down
110 changes: 11 additions & 99 deletions src/main/java/gkappa/wrapfix/mixin/MixinRenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

@Mixin({RenderUtils.class})
public abstract class MixinRenderUtils {
@Shadow(remap = false)
public static List<String> splitString(String str, int wrapWidth, FontRenderer font) {
return null;
}

@Inject(at = {@At("HEAD")}, method = {"splitString"}, cancellable = true, remap = false)
private static void splitString(String str, int wrapWidth, FontRenderer font, CallbackInfoReturnable<List<String>> callback) {
if (str.isEmpty()){
Expand All @@ -29,8 +34,8 @@ private static void splitString(String str, int wrapWidth, FontRenderer font, Ca
List<String> list = new ArrayList<>();
int lineWidth = 0, fed = 0, icui, d, prevFormat = 0;
StringBuilder format = new StringBuilder(); // For next line's format since it should use format of previous line
int[] widths = new int[wrapWidth/4];
String[] formats = new String[wrapWidth/4];
int[] widths = new int[str.length()];
String[] formats = new String[str.length()];
StringBuilder line = new StringBuilder();
String temp;
char[] chars = str.toCharArray();
Expand All @@ -41,7 +46,7 @@ private static void splitString(String str, int wrapWidth, FontRenderer font, Ca
switch (current) {
case '\n':
list.add(line.toString());
fed += line.length() + 1;
fed = i;
line.delete(0, line.length()).append(format);
lineWidth = 0;
widths[i - fed] = lineWidth;
Expand Down Expand Up @@ -98,13 +103,13 @@ private static void splitString(String str, int wrapWidth, FontRenderer font, Ca
}
if (icui <= fed || i == icui) {
list.add(line.substring(0,line.length() - 1));
fed += line.length() - 1;
fed = i - 1;
line.delete(0, line.length()).append(format).append(current);
prevFormat = format.length();
lineWidth = font.getCharWidth(current);
} else {
d = icui - fed;
list.add(line.substring(prevFormat, d + prevFormat));
list.add(line.substring(0, d + prevFormat));
temp = line.substring(d + prevFormat);
fed = icui;
line.delete(0, line.length()).append(formats[d]).append(temp);
Expand All @@ -119,100 +124,7 @@ private static void splitString(String str, int wrapWidth, FontRenderer font, Ca

@Inject(at = {@At("HEAD")}, method = {"splitStringWithoutFormat"}, cancellable = true, remap = false)
private static void splitStringWithoutFormat(String str, int wrapWidth, FontRenderer font, CallbackInfoReturnable<List<String>> callback) {
if (str.isEmpty()){
callback.setReturnValue(Collections.singletonList(""));
return;
}
WrapFix.BREAK_ITERATOR.setText(str);
List<String> list = new ArrayList<>();
int lineWidth = 0, fed = 0, icui, d, prevFormat = 0;
StringBuilder format = new StringBuilder(); // For next line's format since it should use format of previous line
int[] widths = new int[wrapWidth/4];
String[] formats = new String[wrapWidth/4];
StringBuilder line = new StringBuilder();
String temp;
char[] chars = str.toCharArray();
char f;
boolean bold = false;
for (int i = 0; i < chars.length; i++) {
char current = chars[i];
switch (current) {
case '\n':
list.add(line.toString());
fed += line.length() + 1;
line.delete(0, line.length()).append(format);
lineWidth = 0;
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
continue;
case '§':
if (i + 1 < chars.length) { // Prevent out of bound
f = chars[i + 1];
if (f != 'l' && f != 'L') { // Check start of bold style
if (f == 'r' || f == 'R' || isFormatColor(f)) { // Not Bold, check end of style
bold = false;
if (f == 'r' || f == 'R') {
format.delete(0, format.length()); // Clear the format
} else {
format.append('§').append(f); // Add to current format code
}
line.append('§').append(f);
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
i++;
continue;
}
if (f >= 'k' && f <= 'o' || f >= 'K' && f <= 'O') {
format.append('§').append(f); // Add to current format code
line.append('§').append(f);
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
continue;
}
} else {
bold = true;
format.append('§').append(f); // Add to current format code
line.append('§').append(f);
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
continue;
}
}
default:
line.append(current);
lineWidth += font.getCharWidth(current);
if (bold) {
lineWidth++; // Bold style is one pixel wider
}
break;
}
widths[i - fed] = lineWidth;
formats[i - fed] = format.toString();
if (lineWidth >= wrapWidth) {
if (WrapFix.BREAK_ITERATOR.isBoundary(i)) {
icui = i;
} else {
icui = WrapFix.BREAK_ITERATOR.preceding(i);
}
if (icui <= fed || i == icui) {
list.add(line.substring(0,line.length() - 1));
fed += line.length() - 1;
line.delete(0, line.length()).append(format).append(current);
prevFormat = format.length();
lineWidth = font.getCharWidth(current);
} else {
d = icui - fed;
list.add(line.substring(prevFormat, d + prevFormat));
temp = line.substring(d + prevFormat);
fed = icui;
line.delete(0, line.length()).append(formats[d]).append(temp);
prevFormat = formats[d].length();
lineWidth = lineWidth - widths[d - 1];
}
}
}
list.add(line.toString());
callback.setReturnValue(list);
callback.setReturnValue(splitString(str, wrapWidth, font));
}

@Shadow(remap = false)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "wrapfix",
"name": "WrapFix",
"description": "Fix line wrapping",
"version": "1.3.0-beta",
"version": "1.3.2-beta",
"mcversion": "1.12.2",
"url": "",
"updateUrl": "",
Expand Down

0 comments on commit 8879375

Please sign in to comment.