Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 22 additions & 98 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,125 +1,49 @@
plugins {
id 'fabric-loom' version "0.7-SNAPSHOT" // To use chocoloom, change the version to a commit hash
id 'maven-publish'
id 'org.ajoberstar.grgit' version '4.1.0'
id "fabric-loom" version "1.10-SNAPSHOT"
id "legacy-looming" version "1.10-SNAPSHOT"
id "maven-publish"
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
version = "$mod_version+$target_version"
group = maven_group

def getVersionMetadata() {
// CI builds version numbers
def build_id = System.getenv("RELEASE_NUMBER")
if (build_id != null) {
return build_id + ".0.0"
}

// Development builds
if (grgit == null) {
return "dev"
}

// Named development builds
def id = grgit.head().abbreviatedId
if (!grgit.status().clean) {
id += "-dirty"
}

return "rev.${id}"
base {
archivesName = archives_name
}

archivesBaseName = "${project.mod_id}-${project.minecraft_version}"
version = "${getVersionMetadata()}"
group = project.maven_group

repositories {
maven {
name = "legacy-fabric"
url = "https://maven.legacyfabric.net"
loom {
decompilers {
vineflower {
options.putAll(["mark-corresponding-synthetics": "1", "indent-string": " "])
}
}
}

// Comment out this block if you're using Chocoloom
// Comment when using loom 0.10
minecraft {
intermediaryUrl = {
return "https://maven.legacyfabric.net/net/fabricmc/intermediary/" + it + "/intermediary-" + it + "-v2.jar";
mixin {
useLegacyMixinAp = false
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API provides hooks for events, item registration, and more. As most mods will need this, it's included by default.
// If you know for a fact you don't, it's not required and can be safely removed.
//modImplementation ("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${fabric_version}") {
// exclude module: "fabric-loader-1.8.9"
//}

// Hacks that make mac os work
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}

// More hacks that make mac os work
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module('org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209')
substitute module('org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209')
}
force 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
minecraft "com.mojang:minecraft:$minecraft_version"
mappings legacy.yarn(minecraft_version, yarn_build)
modImplementation "net.fabricmc:fabric-loader:$loader_version"
}

processResources {
inputs.property "mod_id", project.mod_id
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "mod_id": project.mod_id, "version": project.version
filesMatching "fabric.mod.json", {
expand "version": version
}
}

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

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

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
from "LICENSE"
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# suppress inspection "UnusedProperty" for whole file
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs = -Xmx2G
org.gradle.parallel = true
org.gradle.caching = true

# Fabric Properties
minecraft_version = 1.8.9
yarn_mappings = 1.8.9+build.202201091851
loader_version = 0.12.12
mod_version = 3.1.0

# Mod Properties
mod_version = 1.0.2
target_version = 1.8.x
archives_name = anchiale
maven_group = me.voidxwalker
mod_id = anchiale

minecraft_version = 1.8.9
yarn_build = 571
loader_version = 0.16.14
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 4 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven { url "https://maven.fabricmc.net" }
maven { url "https://maven.legacyfabric.net" }
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
}
48 changes: 46 additions & 2 deletions src/main/java/me/voidxwalker/anchiale/Anchiale.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
package me.voidxwalker.anchiale;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.fabricmc.loader.api.FabricLoader;
import org.apache.logging.log4j.*;

import java.io.IOException;
import java.nio.file.*;

public class Anchiale {
public static final Logger LOGGER = LogManager.getLogger();
public static boolean fastReset = false;
public static ButtonLocation buttonLocation = ButtonLocation.BOTTOM_RIGHT;
public static Path config = FabricLoader.getInstance().getConfigDir().resolve("anchiale.txt");

static {
try {
if (Files.notExists(config)) {
Files.createFile(config);
saveConfig();
}
buttonLocation = ButtonLocation.values()[Integer.parseInt(new String(Files.readAllBytes(config)))];
} catch (Exception e) {
LOGGER.error("Failed to create/read Anchiale config");
e.printStackTrace();
}
}

public static void saveConfig() {
try {
Files.write(config, ("" + buttonLocation.ordinal()).getBytes());
} catch (IOException e) {
LOGGER.error("Failed to write Anchiale config");
e.printStackTrace();
}
}

public enum ButtonLocation {
BOTTOM_RIGHT("Bottom Right"),
CENTER("Center"),
REPLACE_SQ("Replace Save and Quit");

private final String name;

ButtonLocation(String name) {
this.name = name;
}

@Override
public String toString() {
return this.name;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,69 @@
package me.voidxwalker.anchiale.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import me.voidxwalker.anchiale.Anchiale;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.*;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.resource.language.I18n;
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.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GameMenuScreen.class)
public abstract class GameMenuScreenMixin extends Screen {
@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;<init>(IIILjava/lang/String;)V", ordinal = 0), index = 1)
private int titleScreenX(int x, @Share("originalX") LocalIntRef originalX) {
originalX.set(x);
return Anchiale.buttonLocation == Anchiale.ButtonLocation.REPLACE_SQ ? this.width - 153 - 4 : x;
}

@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;<init>(IIILjava/lang/String;)V", ordinal = 0), index = 2)
private int titleScreenY(int y, @Share("originalY") LocalIntRef originalY) {
originalY.set(y);
return Anchiale.buttonLocation == Anchiale.ButtonLocation.REPLACE_SQ ? this.height - 24 : y;
}

@ModifyExpressionValue(method = "init", at = @At(value = "NEW", target = "(IIILjava/lang/String;)Lnet/minecraft/client/gui/widget/ButtonWidget;", ordinal = 0))
private ButtonWidget titleScreenWidth(ButtonWidget button) {
if (Anchiale.buttonLocation == Anchiale.ButtonLocation.REPLACE_SQ) {
button.setWidth(150); // from fast reset
}
return button;
}

@Inject(method = "init", at = @At("TAIL"))
private void anchiale_addMenuQuitWorldButton(CallbackInfo ci) {
private void addAnchialeButton(CallbackInfo ci, @Share("originalX") LocalIntRef originalX, @Share("originalY") LocalIntRef originalY) {
int x, y;
switch (Anchiale.buttonLocation) {
case BOTTOM_RIGHT:
x = this.width - 104;
y = this.height - 24;
break;
case CENTER:
x = originalX.get();
y = originalY.get() + 24;
break;
case REPLACE_SQ:
default:
x = originalX.get();
y = originalY.get();
}
if (this.client.isInSingleplayer()) {
this.buttons.add(new ButtonWidget(1507, this.width - 106, this.height - 24, 102, 20, I18n.translate("menu.quitWorld")));
this.buttons.add(new ButtonWidget(1507, x, y, Anchiale.buttonLocation == Anchiale.ButtonLocation.BOTTOM_RIGHT ? 100 : 200, 20, "Quit to Title"));
}
}

@Inject(method = "buttonClicked", at = @At("HEAD"))
private void anchiale_onMenuQuitWorldClicked(ButtonWidget button, CallbackInfo ci) {
private void onMenuQuitWorldClicked(ButtonWidget button, CallbackInfo ci) {
if (button.id == 1507) {
Anchiale.fastReset = true;
button.id = 1;
}
}

@Inject(method = "buttonClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/TitleScreen;<init>()V"))
private void anchiale_fastResetFalse(CallbackInfo ci) {
private void fastResetFalse(CallbackInfo ci) {
Anchiale.fastReset = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package me.voidxwalker.anchiale.mixin;

import com.google.common.util.concurrent.Futures;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import me.voidxwalker.anchiale.Anchiale;
import net.minecraft.server.integrated.IntegratedServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.concurrent.Future;

@Mixin(IntegratedServer.class)
public abstract class IntegratedServerMixin {

@Redirect(method = "stopRunning", at = @At(value = "INVOKE", target = "Lcom/google/common/util/concurrent/Futures;getUnchecked(Ljava/util/concurrent/Future;)Ljava/lang/Object;"))
public Object anchiale_fastReset(Future<?> e){
@WrapWithCondition(method = "stopRunning", at = @At(value = "INVOKE", target = "Lcom/google/common/util/concurrent/Futures;getUnchecked(Ljava/util/concurrent/Future;)Ljava/lang/Object;"))
public boolean fastReset(Future<?> e) {
if (Anchiale.fastReset) {
Anchiale.LOGGER.info("Exiting world without waiting for server tasks to finish.");
return null;
} else {
Anchiale.LOGGER.info("Exiting world normally.");
return Futures.getUnchecked(e);
Anchiale.LOGGER.info("Exiting world without waiting for server tasks to finish");
return false;
}
return true;
}
}
}
Loading