Skip to content

Commit

Permalink
add Legacy Fabric 6.4 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolij committed Jul 2, 2024
1 parent fe1dacf commit c46fb76
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
- added Embeddium config screen integration on LexForge 20.1, Fabric 20.1-20.6, and NeoForge 20.1 and 21+
- applied more aggressive jar size reduction techniques (@rhysdh540)
- wrote much smaller custom config serializer from scratch to replace Jankson
- obfuscate/shrink more class and member names
- reduced jar size impact of mixins
- fixed Fabric and NeoForge 21 compatibility
- dropped LexForge 20.6+
- added support for Legacy Fabric 6.4 (requires Legacy Fabric API 1.10.2+)
- further improvements to overall system stability and other minor adjustments have been made to enhance the user experience
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A: Zume supports the following platforms:
- Fabric: Any version supported by Fabric Keybinding API v1 (currently 14.4+)
- NeoForge: 20.4+ (requires NeoForge 20.4.195+)
- LexForge: 14.4 - 20.5 (requires MixinBootstrap before 16.1) (there are currently no plans to support 20.6+)
- Legacy Fabric: Any version supported by Legacy Fabric Keybinding API v1 (currently 7.10 - 12.2)
- Legacy Fabric: Any version supported by Legacy Fabric Keybinding API v1 (currently 6.4 - 12.2)
- Babric (Fabric for Minecraft Beta): Any version supported by Station API (currently b7.3)
- Vintage Forge: 8.9 - 12.2 (requires MixinBooter or UniMixins)
- Archaic Forge: 7.10 (requires UniMixins)
Expand Down
6 changes: 2 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ afterEvaluate {
}

minecraftVersionRange {
start = "1.7.10"
start = "1.6.4"
end = "1.12.2"

includeSnapshots = true
Expand All @@ -521,7 +521,7 @@ afterEvaluate {
}

minecraftVersionRange {
start = "1.7.10"
start = "1.6.4"
end = "1.12.2"
}

Expand All @@ -547,8 +547,6 @@ afterEvaluate {
snapshots = HashSet()
}

snapshots.add("1.21-Snapshot")

minecraftVersions.addAll(snapshots)
}

Expand Down
25 changes: 25 additions & 0 deletions legacy/src/main/java/dev/nolij/zume/legacy/LegacyZume.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.SmoothUtil;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;

public class LegacyZume implements ClientModInitializer, IZumeImplementation {

@Override
Expand Down Expand Up @@ -61,4 +65,25 @@ public void onZoomActivate() {
}
}

private static final MethodHandle KEYBINDING_INIT_CATEGORY =
MethodHandleHelper.PUBLIC.getConstructorOrNull(
KeyBinding.class,
MethodType.methodType(KeyBinding.class, String.class, int.class, String.class),
String.class, int.class, String.class
);
private static final MethodHandle KEYBINDING_INIT_NO_CATEGORY =
MethodHandleHelper.PUBLIC.getConstructorOrNull(
KeyBinding.class,
MethodType.methodType(KeyBinding.class, String.class, int.class),
String.class, int.class
);

public static KeyBinding newKeyBinding(String translationKey, int keyCode, String category) {
if (KEYBINDING_INIT_CATEGORY != null)
return (KeyBinding) KEYBINDING_INIT_CATEGORY.invokeExact(translationKey, keyCode, category);
else
//noinspection DataFlowIssue
return (KeyBinding) KEYBINDING_INIT_NO_CATEGORY.invokeExact(translationKey, keyCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public boolean isPressed() {
}

ZumeKeyBind(String translationKey, int code) {
this.value = new KeyBinding(translationKey, code, "zume");
this.value = LegacyZume.newKeyBinding(translationKey, code, "zume");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.nolij.zume.impl.Zume;
import dev.nolij.zumegradle.proguard.ProGuardKeep;
import net.minecraft.client.option.KeyBinding;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -16,20 +15,32 @@
@Mixin(KeyBinding.class)
public abstract class KeyBindingMixin {

@Shadow private boolean pressed;

@SuppressWarnings({"MissingUnique", "unused", "MismatchedQueryAndUpdateOfCollection"})
@ProGuardKeep
private static Map<String, Integer> field_15867; // vintage intermediary

@Shadow @Final private static Set<String> categories;
@SuppressWarnings({"MissingUnique", "unused", "MismatchedQueryAndUpdateOfCollection"})
@ProGuardKeep
private static Set<String> field_7614; // archaic intermediary

@Inject(method = "<clinit>", at = @At("TAIL"))
private static void static$TAIL(CallbackInfo ci) {
if (Zume.disabled)
return;

categories.add("zume");
if (field_7614 != null)
field_7614.add("zume");
if (field_15867 != null)
field_15867.put("zume", 8);
}

// ugly hack for <=6.4 compat
@SuppressWarnings({"MissingUnique", "unused"})
@ProGuardKeep
public boolean method_6619() {
return this.pressed;
}

}
2 changes: 1 addition & 1 deletion src/main/java/dev/nolij/zume/FabricZumeBootstrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FabricZumeBootstrapper implements ClientModInitializer, PreLaunchEn
private static final String MISSING_DEPENDENCY_MESSAGE = """
Failed to detect which variant of Zume to load! Ensure all dependencies are installed:
Fabric (14.4+): Fabric API (fabric-key-binding-api-v1)
Legacy Fabric (7.10-12.2): Legacy Fabric API (legacy-fabric-keybinding-api-v1-common)
Legacy Fabric (6.4-12.2): Legacy Fabric API (legacy-fabric-keybinding-api-v1-common)
Babric (b7.3): Station API (station-keybindings-v0)""";

@Override
Expand Down

0 comments on commit c46fb76

Please sign in to comment.