Skip to content

Commit

Permalink
added support for Minecraft 1.19
Browse files Browse the repository at this point in the history
fixed bug: toggle key bindings for auto jump and skin layers now also
works with alternative key bindings from NMUK
  • Loading branch information
Klotzi111 committed Jul 1, 2022
1 parent 868e3e0 commit 4f121ec
Show file tree
Hide file tree
Showing 33 changed files with 739 additions and 201 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# Amecs

[![curseforge downloads](http://cf.way2muchnoise.eu/full_amecs_downloads.svg)](https://minecraft.curseforge.com/projects/amecs)
[![curseforge mc versions](http://cf.way2muchnoise.eu/versions/amecs.svg)](https://minecraft.curseforge.com/projects/amecs)
# Note
This is a fork of [Siphalor/amecs](https://github.com/Siphalor/amecs)

# Amecs
![logo](src/main/resources/assets/amecs/logo.png?raw=true)

## API
If you want to use the api provided by this mod you'll want to implement and include this mod:

[See here 😜](https://github.com/Siphalor/amecs-api)
[See here 😜](https://github.com/Klotzi111/amecs-api)

## DEV Runtime

If you're a modder and you want Amecs in you development build you can do so by including it like this in the `build.gradle`:

```groovy
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
modRuntimeOnly("com.github.Klotzi111:amecs:multiversion-SNAPSHOT")
}
```

## License

Expand Down
54 changes: 31 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
ext {
jdk_version = 8

klotzi111_localDeps = "true".equals(System.getenv("klotzi111_localDeps"))
}

sourceCompatibility = jdk_version
targetCompatibility = jdk_version

archivesBaseName = project.archives_base_name
version = "$mod_version+mc$minecraft_version".toString()
group = project.maven_group

loom {
}

sourceSets {
testmod {
compileClasspath += main.compileClasspath
Expand All @@ -21,14 +24,14 @@ sourceSets {
}

repositories {
mavenLocal()
maven {
name "Siphalor's Maven"
url "https://maven.siphalor.de"
}
maven {
url "https://jitpack.io"
}
mavenLocal()
}

dependencies {
Expand All @@ -37,6 +40,22 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// FabricMultiVersionHelper
include(modApi(klotzi111_localDeps ? "de.klotzi111:FabricMultiVersionHelper:1+" : "com.github.Klotzi111:FabricMultiVersionHelper:main-SNAPSHOT"))

// Amecs API
def amecs_api = modApi(klotzi111_localDeps ? "de.siphalor:amecsapi-${project.target_minecraft_major_version}:1+" : "com.github.Klotzi111:amecs-api:main-SNAPSHOT") {
exclude(group: "*")
}
include(amecs_api)

// NMUK
modCompileOnly(klotzi111_localDeps ? "de.siphalor:nmuk-${project.target_minecraft_major_version}:1+" : "com.github.Klotzi111:nmuk:main-SNAPSHOT") {
exclude(group: "*")
}

testmodRuntimeOnly("com.github.astei:lazydfu:master-SNAPSHOT")

// we need those old api versions because newer versions require java 16 and that is not available on older minecraft versions
// these old fabric apis are required because we want to support down to minecraft 1.14
def fabric_deps = [
Expand All @@ -48,19 +67,6 @@ dependencies {
include(modApi("net.fabricmc.fabric-api:" + dep.getKey() + ":" + dep.getValue()))
}

def amecs_api = modApi("de.siphalor:amecsapi-${project.target_minecraft_major_version}:1.3.5+mc1.18.1") {
exclude group: "net.fabricmc.fabric-api"
exclude module: "nmuk-${project.target_minecraft_major_version}"
}
include(amecs_api)

modApi("de.siphalor:nmuk-${project.target_minecraft_major_version}:1.1+") {
exclude group: "net.fabricmc.fabric-api"
exclude module: "amecsapi-${project.target_minecraft_major_version}"
}

modRuntimeOnly("com.github.astei:lazydfu:master-SNAPSHOT")

testmodImplementation sourceSets.main.output
}

Expand All @@ -76,11 +82,13 @@ processResources {
}
}

// 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) {
// 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
// If Javadoc is generated, this must be specified in that task too.
options.encoding = "UTF-8"
options.release = jdk_version
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
org.gradle.jvmargs = -Xmx1G

#Fabric properties
minecraft_version = 1.18.2
yarn_mappings = 1.18.2+build.3
loader_version = 0.14.5
minecraft_version = 1.19
yarn_mappings = 1.19+build.2
loader_version = 0.14.7

#Mod properties
mod_version = 1.4.4
mod_version = 1.4.5
maven_group = de.siphalor.amecs
archives_base_name = amecs
target_minecraft_major_version = multiversion
3 changes: 3 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
before_install:
- sdk install java 17.0.1-open
- sdk use java 17.0.1-open
27 changes: 19 additions & 8 deletions src/main/java/de/siphalor/amecs/Amecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

import de.klotzi111.fabricmultiversionhelper.api.text.TextWrapper;
import de.siphalor.amecs.api.AmecsKeyBinding;
import de.siphalor.amecs.api.KeyBindingUtils;
import de.siphalor.amecs.api.KeyModifiers;
import de.siphalor.amecs.api.input.InputEventHandler;
Expand All @@ -33,7 +35,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;

/**
Expand All @@ -47,7 +48,7 @@ public class Amecs implements ClientModInitializer {
public static final String MOD_ID = "amecs";
public static final String MOD_NAME_SHORT = "Amecs";

private static final String LOGGER_PREFIX = "[" + MOD_NAME_SHORT + "] ";
private static final String LOG_PREFIX = "[" + MOD_NAME_SHORT + "] ";
private static final Logger LOGGER = LogManager.getLogger();

private static final String SKIN_LAYER_CATEGORY = MOD_ID + ".key.categories.skin_layers";
Expand All @@ -61,6 +62,7 @@ public class Amecs implements ClientModInitializer {
public static List<KeyBinding> ALL_KEYBINDINGS = new ArrayList<>();

public static DropEntireStackKeyBinding KEYBINDING_DROP_STACK;
public static KeyBinding ESCAPE_KEYBINDING;
// -keybindings

private static String makeKeyID(String keyName) {
Expand All @@ -69,7 +71,7 @@ private static String makeKeyID(String keyName) {

@Override
public void onInitializeClient() {
VersionedLogicMethodHelper.initLogicMethodsForClasses(Arrays.asList(HotbarScrollKeyBinding.class, DropEntireStackKeyBinding.class));
VersionedLogicMethodHelper.initLogicMethodsForClasses(Arrays.asList(HotbarScrollKeyBinding.class, DropEntireStackKeyBinding.class, ToggleAutoJumpKeyBinding.class));

createKeyBindings();
}
Expand All @@ -91,13 +93,13 @@ private static <K extends KeyBinding & InputEventHandler> void registerKeyBindin

private static void createKeyBindings() {
// auto jump
registerKeyBinding(new ToggleAutoJumpKeyBinding(makeKeyID("toggle_auto_jump"), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B, MOVEMENT_CATEGORY, new KeyModifiers()));
registerKeyBindingWithHandler(new ToggleAutoJumpKeyBinding(makeKeyID("toggle_auto_jump"), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B, MOVEMENT_CATEGORY, new KeyModifiers()));

// skin layers
Arrays.stream(PlayerModelPart.values())
.map(playerModelPart -> new SkinLayerKeyBinding(makeKeyID("toggle_" + playerModelPart.getName().toLowerCase(Locale.ENGLISH)), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, SKIN_LAYER_CATEGORY,
playerModelPart))
.forEach(Amecs::registerKeyBinding);
.forEach(Amecs::registerKeyBindingWithHandler);

// hotbar scroll
registerKeyBindingWithHandler(new HotbarScrollKeyBinding(makeKeyID("hotbar.scroll.up"), InputUtil.Type.MOUSE, KeyBindingUtils.MOUSE_SCROLL_UP, INVENTORY_CATEGORY, new KeyModifiers(), true));
Expand All @@ -107,10 +109,15 @@ private static void createKeyBindings() {
// we intentionally do not register the drop stack keybinding for input handling because it is called from MixinMinecraftClient
KEYBINDING_DROP_STACK = new DropEntireStackKeyBinding(makeKeyID("drop.stack"), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_Q, INVENTORY_CATEGORY, new KeyModifiers().setControl(true));
registerKeyBinding(KEYBINDING_DROP_STACK);

// we intentionally do not register the escape keybinding for input handling because it is checked before normal input checking and is translated to GLFW_KEY_ESCAPE
ESCAPE_KEYBINDING = new AmecsKeyBinding(makeKeyID("alternative_escape"), InputUtil.Type.KEYSYM, -1, "key.categories.ui", new KeyModifiers());
registerKeyBinding(ESCAPE_KEYBINDING);
}
// -keybindings

public static void sendToggleMessage(PlayerEntity playerEntity, boolean value, Text option) {
playerEntity.sendMessage(new TranslatableText("amecs.toggled." + (value ? "on" : "off"), option), true);
playerEntity.sendMessage(TextWrapper.translatable("amecs.toggled." + (value ? "on" : "off"), option), true);
}

// controls gui search
Expand Down Expand Up @@ -138,7 +145,7 @@ public static boolean entryMatches(ControlsListWidget.KeyBindingEntry entry, Key
// because checking the quality is not really cheaper and check both if they are not equal is overhead
boolean categoryContains = StringUtils.containsIgnoreCase(I18n.translate(binding.getCategory()), filterSettings.searchText);

String entryName = ((ControlsListWidgetKeyBindingEntryAccessor) entry).getBindingName().asString();
String entryName = TextWrapper.getAsString(((de.siphalor.amecs.duck.IKeyBindingEntry) entry).amecs$getBindingName());
// this fixes alternative keybindings from nmuk
// without this they are searched by their untranslateable translation key
// we could also search alternatives by thei parent but this way you can search for only alternatives
Expand All @@ -152,6 +159,10 @@ public static boolean entryMatches(ControlsListWidget.KeyBindingEntry entry, Key
}

public static void log(Level level, String message) {
LOGGER.log(level, LOGGER_PREFIX + message);
LOGGER.log(level, LOG_PREFIX + message);
}

public static void logException(Level level, Throwable e) {
LOGGER.catching(level, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.apache.logging.log4j.Level;

import de.siphalor.amecs.impl.version.MinecraftVersionHelper;
import de.klotzi111.fabricmultiversionhelper.api.version.MinecraftVersionHelper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.SemanticVersion;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static List<MethodFieldAndName> getMethodFieldAndNamesForClass(Class<?> c
ret.add(new MethodFieldAndName(f, logicMethodPrefix));
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
Amecs.log(Level.WARN, "Found logic method search method in class \"" + clazz.getName() + "\" but no associated logic method name prefix");
e.printStackTrace();
Amecs.logException(Level.ERROR, e);
continue;
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public Object invoke(Object instance, Object... args) {
return method.invoke(instance, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Amecs.log(Level.ERROR, "Error while executing: \"" + method.getName() + "\" in class: \"" + method.getDeclaringClass().getName() + "\"");
e.printStackTrace();
Amecs.logException(Level.ERROR, e);
}
return null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/de/siphalor/amecs/duck/IKeyBindingEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.siphalor.amecs.duck;

import net.minecraft.text.Text;

public interface IKeyBindingEntry {
Text amecs$getBindingName();

void amecs$setBindingName(Text bindingName);
}
Loading

0 comments on commit 4f121ec

Please sign in to comment.