Skip to content

Commit 1431931

Browse files
committed
3.1.0: fast reset like button location
1 parent 801c589 commit 1431931

10 files changed

Lines changed: 176 additions & 144 deletions

File tree

build.gradle

Lines changed: 22 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,49 @@
11
plugins {
2-
id 'fabric-loom' version "0.7-SNAPSHOT" // To use chocoloom, change the version to a commit hash
3-
id 'maven-publish'
4-
id 'org.ajoberstar.grgit' version '4.1.0'
2+
id "fabric-loom" version "1.10-SNAPSHOT"
3+
id "legacy-looming" version "1.10-SNAPSHOT"
4+
id "maven-publish"
55
}
66

7-
sourceCompatibility = JavaVersion.VERSION_1_8
8-
targetCompatibility = JavaVersion.VERSION_1_8
7+
version = "$mod_version+$target_version"
8+
group = maven_group
99

10-
def getVersionMetadata() {
11-
// CI builds version numbers
12-
def build_id = System.getenv("RELEASE_NUMBER")
13-
if (build_id != null) {
14-
return build_id + ".0.0"
15-
}
16-
17-
// Development builds
18-
if (grgit == null) {
19-
return "dev"
20-
}
21-
22-
// Named development builds
23-
def id = grgit.head().abbreviatedId
24-
if (!grgit.status().clean) {
25-
id += "-dirty"
26-
}
27-
28-
return "rev.${id}"
10+
base {
11+
archivesName = archives_name
2912
}
3013

31-
archivesBaseName = "${project.mod_id}-${project.minecraft_version}"
32-
version = "${getVersionMetadata()}"
33-
group = project.maven_group
34-
35-
repositories {
36-
maven {
37-
name = "legacy-fabric"
38-
url = "https://maven.legacyfabric.net"
14+
loom {
15+
decompilers {
16+
vineflower {
17+
options.putAll(["mark-corresponding-synthetics": "1", "indent-string": " "])
18+
}
3919
}
40-
}
41-
42-
// Comment out this block if you're using Chocoloom
43-
// Comment when using loom 0.10
44-
minecraft {
45-
intermediaryUrl = {
46-
return "https://maven.legacyfabric.net/net/fabricmc/intermediary/" + it + "/intermediary-" + it + "-v2.jar";
20+
mixin {
21+
useLegacyMixinAp = false
4722
}
4823
}
4924

5025
dependencies {
51-
minecraft "com.mojang:minecraft:${project.minecraft_version}"
52-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
53-
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
54-
55-
// Fabric API provides hooks for events, item registration, and more. As most mods will need this, it's included by default.
56-
// If you know for a fact you don't, it's not required and can be safely removed.
57-
//modImplementation ("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${fabric_version}") {
58-
// exclude module: "fabric-loader-1.8.9"
59-
//}
60-
61-
// Hacks that make mac os work
62-
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
63-
implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'
64-
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
65-
implementation 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
66-
}
67-
}
68-
69-
// More hacks that make mac os work
70-
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
71-
configurations.all {
72-
resolutionStrategy {
73-
dependencySubstitution {
74-
substitute module('org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209')
75-
substitute module('org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209')
76-
}
77-
force 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
78-
}
79-
}
26+
minecraft "com.mojang:minecraft:$minecraft_version"
27+
mappings legacy.yarn(minecraft_version, yarn_build)
28+
modImplementation "net.fabricmc:fabric-loader:$loader_version"
8029
}
8130

8231
processResources {
83-
inputs.property "mod_id", project.mod_id
84-
inputs.property "version", project.version
85-
86-
filesMatching("fabric.mod.json") {
87-
expand "mod_id": project.mod_id, "version": project.version
32+
filesMatching "fabric.mod.json", {
33+
expand "version": version
8834
}
8935
}
9036

91-
// ensure that the encoding is set to UTF-8, no matter what the system default is
92-
// this fixes some edge cases with special characters not displaying correctly
93-
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
9437
tasks.withType(JavaCompile).configureEach {
9538
it.options.encoding = "UTF-8"
96-
if (JavaVersion.current().isJava9Compatible()) it.options.release = 8
39+
it.options.release.set(8)
9740
}
9841

9942
java {
100-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
101-
// if it is present.
102-
// If you remove this line, sources will not be generated.
43+
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
10344
withSourcesJar()
10445
}
10546

10647
jar {
107-
from("LICENSE") {
108-
rename { "${it}_${project.archivesBaseName}"}
109-
}
48+
from "LICENSE"
11049
}
111-
112-
// configure the maven publication
113-
publishing {
114-
publications {
115-
mavenJava(MavenPublication) {
116-
from components.java
117-
}
118-
}
119-
120-
// select the repositories you want to publish to
121-
repositories {
122-
// uncomment to publish to the local maven
123-
// mavenLocal()
124-
}
125-
}

gradle.properties

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# suppress inspection "UnusedProperty" for whole file
2-
# Done to increase the memory available to gradle.
3-
org.gradle.jvmargs=-Xmx2G
1+
org.gradle.jvmargs = -Xmx2G
2+
org.gradle.parallel = true
3+
org.gradle.caching = true
44

5-
# Fabric Properties
6-
minecraft_version = 1.8.9
7-
yarn_mappings = 1.8.9+build.202201091851
8-
loader_version = 0.12.12
5+
mod_version = 3.1.0
96

10-
# Mod Properties
11-
mod_version = 1.0.2
7+
target_version = 1.8-1.12.2
8+
archives_name = anchiale
129
maven_group = me.voidxwalker
13-
mod_id = anchiale
10+
11+
minecraft_version = 1.8.9
12+
yarn_build = 571
13+
loader_version = 0.16.14
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pluginManagement {
22
repositories {
3-
maven {
4-
name = 'Fabric'
5-
url = 'https://maven.fabricmc.net/'
6-
}
3+
maven { url "https://maven.fabricmc.net" }
4+
maven { url "https://maven.legacyfabric.net" }
5+
mavenCentral()
76
gradlePluginPortal()
7+
mavenLocal()
88
}
99
}
Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
package me.voidxwalker.anchiale;
22

3-
import org.apache.logging.log4j.LogManager;
4-
import org.apache.logging.log4j.Logger;
3+
import net.fabricmc.loader.api.FabricLoader;
4+
import org.apache.logging.log4j.*;
5+
6+
import java.io.IOException;
7+
import java.nio.file.*;
58

69
public class Anchiale {
710
public static final Logger LOGGER = LogManager.getLogger();
811
public static boolean fastReset = false;
12+
public static ButtonLocation buttonLocation = ButtonLocation.BOTTOM_RIGHT;
13+
public static Path config = FabricLoader.getInstance().getConfigDir().resolve("anchiale.txt");
14+
15+
static {
16+
try {
17+
if (Files.notExists(config)) {
18+
Files.createFile(config);
19+
saveConfig();
20+
}
21+
buttonLocation = ButtonLocation.values()[Integer.parseInt(new String(Files.readAllBytes(config)))];
22+
} catch (Exception e) {
23+
LOGGER.error("Failed to create/read Anchiale config");
24+
e.printStackTrace();
25+
}
26+
}
27+
28+
public static void saveConfig() {
29+
try {
30+
Files.write(config, ("" + buttonLocation.ordinal()).getBytes());
31+
} catch (IOException e) {
32+
LOGGER.error("Failed to write Anchiale config");
33+
e.printStackTrace();
34+
}
35+
}
36+
37+
public enum ButtonLocation {
38+
BOTTOM_RIGHT("Bottom Right"),
39+
CENTER("Center"),
40+
REPLACE_SQ("Replace Save and Quit");
41+
42+
private final String name;
43+
44+
ButtonLocation(String name) {
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return this.name;
51+
}
52+
}
953
}
Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,69 @@
11
package me.voidxwalker.anchiale.mixin;
22

3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import com.llamalad7.mixinextras.sugar.Share;
5+
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
36
import me.voidxwalker.anchiale.Anchiale;
4-
import net.minecraft.client.gui.screen.GameMenuScreen;
5-
import net.minecraft.client.gui.screen.Screen;
7+
import net.minecraft.client.gui.screen.*;
68
import net.minecraft.client.gui.widget.ButtonWidget;
7-
import net.minecraft.client.resource.language.I18n;
89
import org.spongepowered.asm.mixin.Mixin;
9-
import org.spongepowered.asm.mixin.injection.At;
10-
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.*;
1111
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1212

1313
@Mixin(GameMenuScreen.class)
1414
public abstract class GameMenuScreenMixin extends Screen {
15+
@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;<init>(IIILjava/lang/String;)V", ordinal = 0), index = 1)
16+
private int titleScreenX(int x, @Share("originalX") LocalIntRef originalX) {
17+
originalX.set(x);
18+
return Anchiale.buttonLocation == Anchiale.ButtonLocation.REPLACE_SQ ? this.width - 153 - 4 : x;
19+
}
20+
21+
@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;<init>(IIILjava/lang/String;)V", ordinal = 0), index = 2)
22+
private int titleScreenY(int y, @Share("originalY") LocalIntRef originalY) {
23+
originalY.set(y);
24+
return Anchiale.buttonLocation == Anchiale.ButtonLocation.REPLACE_SQ ? this.height - 24 : y;
25+
}
26+
27+
@ModifyExpressionValue(method = "init", at = @At(value = "NEW", target = "(IIILjava/lang/String;)Lnet/minecraft/client/gui/widget/ButtonWidget;", ordinal = 0))
28+
private ButtonWidget titleScreenWidth(ButtonWidget button) {
29+
if (Anchiale.buttonLocation == Anchiale.ButtonLocation.REPLACE_SQ) {
30+
button.setWidth(150); // from fast reset
31+
}
32+
return button;
33+
}
1534

1635
@Inject(method = "init", at = @At("TAIL"))
17-
private void anchiale_addMenuQuitWorldButton(CallbackInfo ci) {
36+
private void addAnchialeButton(CallbackInfo ci, @Share("originalX") LocalIntRef originalX, @Share("originalY") LocalIntRef originalY) {
37+
int x, y, width;
38+
switch (Anchiale.buttonLocation) {
39+
case BOTTOM_RIGHT:
40+
x = this.width - 104;
41+
y = this.height - 24;
42+
break;
43+
case CENTER:
44+
x = originalX.get();
45+
y = originalY.get() + 24;
46+
break;
47+
case REPLACE_SQ:
48+
default:
49+
x = originalX.get();
50+
y = originalY.get();
51+
}
1852
if (this.client.isInSingleplayer()) {
19-
this.buttons.add(new ButtonWidget(1507, this.width - 106, this.height - 24, 102, 20, I18n.translate("menu.quitWorld")));
53+
this.buttons.add(new ButtonWidget(1507, x, y, Anchiale.buttonLocation == Anchiale.ButtonLocation.BOTTOM_RIGHT ? 100 : 200, 20, "Quit to Title"));
2054
}
2155
}
2256

2357
@Inject(method = "buttonClicked", at = @At("HEAD"))
24-
private void anchiale_onMenuQuitWorldClicked(ButtonWidget button, CallbackInfo ci) {
58+
private void onMenuQuitWorldClicked(ButtonWidget button, CallbackInfo ci) {
2559
if (button.id == 1507) {
2660
Anchiale.fastReset = true;
2761
button.id = 1;
2862
}
2963
}
3064

3165
@Inject(method = "buttonClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/TitleScreen;<init>()V"))
32-
private void anchiale_fastResetFalse(CallbackInfo ci) {
66+
private void fastResetFalse(CallbackInfo ci) {
3367
Anchiale.fastReset = false;
3468
}
35-
}
69+
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
package me.voidxwalker.anchiale.mixin;
22

3-
import com.google.common.util.concurrent.Futures;
3+
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
44
import me.voidxwalker.anchiale.Anchiale;
55
import net.minecraft.server.integrated.IntegratedServer;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.injection.At;
8-
import org.spongepowered.asm.mixin.injection.Redirect;
98

109
import java.util.concurrent.Future;
1110

1211
@Mixin(IntegratedServer.class)
1312
public abstract class IntegratedServerMixin {
14-
15-
@Redirect(method = "stopRunning", at = @At(value = "INVOKE", target = "Lcom/google/common/util/concurrent/Futures;getUnchecked(Ljava/util/concurrent/Future;)Ljava/lang/Object;"))
16-
public Object anchiale_fastReset(Future<?> e){
13+
@WrapWithCondition(method = "stopRunning", at = @At(value = "INVOKE", target = "Lcom/google/common/util/concurrent/Futures;getUnchecked(Ljava/util/concurrent/Future;)Ljava/lang/Object;"))
14+
public boolean fastReset(Future<?> e) {
1715
if (Anchiale.fastReset) {
18-
Anchiale.LOGGER.info("Exiting world without waiting for server tasks to finish.");
19-
return null;
20-
} else {
21-
Anchiale.LOGGER.info("Exiting world normally.");
22-
return Futures.getUnchecked(e);
16+
Anchiale.LOGGER.info("Exiting world without waiting for server tasks to finish");
17+
return false;
2318
}
19+
return true;
2420
}
25-
}
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.voidxwalker.anchiale.mixin;
2+
3+
import me.voidxwalker.anchiale.Anchiale;
4+
import net.minecraft.client.gui.screen.Screen;
5+
import net.minecraft.client.gui.screen.options.SkinOptionsScreen;
6+
import net.minecraft.client.gui.widget.ButtonWidget;
7+
import org.spongepowered.asm.mixin.*;
8+
import org.spongepowered.asm.mixin.injection.*;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
10+
11+
@Mixin(SkinOptionsScreen.class)
12+
public abstract class SkinOptionsScreenMixin extends Screen {
13+
@Unique
14+
private ButtonWidget locationButton;
15+
16+
@Inject(method = "init", at = @At("TAIL"))
17+
private void addLocationButton(CallbackInfo ci) {
18+
this.buttons.add(this.locationButton = new ButtonWidget(1541, this.width / 2 - 155, this.height / 6 + 120, 150, 20, Anchiale.buttonLocation.toString()));
19+
}
20+
21+
@Inject(method = "buttonClicked", at = @At("TAIL"))
22+
private void locationButtonClicked(ButtonWidget button, CallbackInfo ci) {
23+
if (button.active && button.id == 1541) {
24+
Anchiale.ButtonLocation[] locations = Anchiale.ButtonLocation.values();
25+
Anchiale.buttonLocation = locations[(Anchiale.buttonLocation.ordinal() + 1) % locations.length];
26+
locationButton.message = Anchiale.buttonLocation.toString();
27+
Anchiale.saveConfig();
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)