Skip to content

Commit

Permalink
remap modern to mojmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolij committed May 13, 2024
1 parent 5d3c9b2 commit b705d4b
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ unimined.minecraft {

mappings {
intermediary()
yarn("modern_mappings_version"())
mojmap()
devFallbackNamespace("intermediary")
}

Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fabric_version = 0.15.10
## Modern Fabric
# https://modmuss50.me/fabric.html
modern_minecraft_version = 1.20.1
modern_mappings_version = 10
modern_fabric_api_version = 0.92.0+1.20.1

## Legacy Fabric
Expand Down
2 changes: 1 addition & 1 deletion modern/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ unimined.minecraft {

mappings {
intermediary()
yarn("modern_mappings_version"())
mojmap()
devFallbackNamespace("intermediary")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package dev.nolij.zume.mixin.modern;

import dev.nolij.zume.api.platform.v0.ZumeAPI;
import net.minecraft.client.render.Camera;
import net.minecraft.client.Camera;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(value = Camera.class, priority = 1500)
public class CameraMixin {

@ModifyArg(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;clipToSpace(D)D"))
@ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;getMaxZoom(D)D"))
public double zume$update$clipToSpace(double original) {
return ZumeAPI.thirdPersonCameraHook(original);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.nolij.zume.api.platform.v0.ZumeAPI;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.renderer.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import dev.nolij.zume.api.platform.v0.ZumeAPI;
import net.minecraft.client.Mouse;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.client.MouseHandler;
import net.minecraft.world.entity.player.Inventory;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Group;

@Mixin(value = Mouse.class, priority = 500)
public class MouseMixin {
@Mixin(value = MouseHandler.class, priority = 500)
public class MouseHandlerMixin {

@Dynamic
@ModifyExpressionValue(method = {
"updateMouse",
"turnPlayer",
"method_1606(D)V" // 20.5+ compat
}, at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;smoothCameraEnabled:Z"))
}, at = @At(value = "FIELD", target = "Lnet/minecraft/client/Options;smoothCamera:Z"))
public boolean zume$updateMouse$smoothCameraEnabled(boolean original) {
return ZumeAPI.cinematicCameraEnabledHook(original);
}
Expand All @@ -26,30 +26,30 @@ public class MouseMixin {
@Dynamic
@Group(name = "zume$getMouseSensitivity", min = 1, max = 1)
@ModifyExpressionValue(method = {
"updateMouse",
"turnPlayer",
"method_1606(D)V" // 20.5+ compat
}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;", ordinal = 0), require = 0)
}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/OptionInstance;get()Ljava/lang/Object;", ordinal = 0), require = 0)
public <T> T zume$updateMouse$getMouseSensitivity$getValue(T original) {
return (T) (Object) ZumeAPI.mouseSensitivityHook((Double) original);
}

@Dynamic
@Group(name = "zume$getMouseSensitivity", min = 1, max = 1)
@ModifyExpressionValue(method = "updateMouse", at = @At(value = "FIELD", target = "Lnet/minecraft/class_315;field_1843:D", remap = false), require = 0)
@ModifyExpressionValue(method = "turnPlayer", at = @At(value = "FIELD", target = "Lnet/minecraft/class_315;field_1843:D", remap = false), require = 0)
public double zume$updateMouse$mouseSensitivity(double original) {
return ZumeAPI.mouseSensitivityHook(original);
}

@ModifyExpressionValue(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSpectator()Z"))
@ModifyExpressionValue(method = "onScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isSpectator()Z"))
public boolean onMouseScroll$isSpectator(boolean original) {
if (ZumeAPI.isMouseScrollHookActive())
return false;

return original;
}

@WrapWithCondition(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;scrollInHotbar(D)V"))
public boolean onMouseScroll$scrollInHotbar(PlayerInventory instance, double scrollAmount) {
@WrapWithCondition(method = "onScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;swapPaint(D)V"))
public boolean onMouseScroll$scrollInHotbar(Inventory instance, double scrollAmount) {
return !ZumeAPI.mouseScrollHook((int) scrollAmount);
}

Expand Down
16 changes: 8 additions & 8 deletions modern/src/main/java/dev/nolij/zume/modern/ModernZume.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import org.jetbrains.annotations.NotNull;

import java.lang.invoke.MethodHandle;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void onInitializeClient() {

@Override
public boolean isZoomPressed() {
return MinecraftClient.getInstance().currentScreen == null && ZumeKeyBind.ZOOM.isPressed();
return Minecraft.getInstance().screen == null && ZumeKeyBind.ZOOM.isPressed();
}

@Override
Expand All @@ -59,22 +59,22 @@ public boolean isZoomOutPressed() {
}

private static final MethodHandle GET_PERSPECTIVE = MethodHandleHelper.PUBLIC.getMethodOrNull(
GameOptions.class,
Options.class,
FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary",
"net.minecraft.class_315", "method_31044", "()Lnet/minecraft/class_5498;"),
MethodType.methodType(Enum.class, GameOptions.class));
MethodType.methodType(Enum.class, Options.class));
private static final MethodHandle PERSPECTIVE =
MethodHandleHelper.PUBLIC.getGetterOrNull(GameOptions.class, "field_1850", int.class);
MethodHandleHelper.PUBLIC.getGetterOrNull(Options.class, "field_1850", int.class);

@Override
public @NotNull CameraPerspective getCameraPerspective() {
int ordinal;
try {
if (GET_PERSPECTIVE != null)
ordinal = ((Enum<?>) GET_PERSPECTIVE.invokeExact(MinecraftClient.getInstance().options)).ordinal();
ordinal = ((Enum<?>) GET_PERSPECTIVE.invokeExact(Minecraft.getInstance().options)).ordinal();
else
//noinspection DataFlowIssue
ordinal = (int) PERSPECTIVE.invokeExact(MinecraftClient.getInstance().options);
ordinal = (int) PERSPECTIVE.invokeExact(Minecraft.getInstance().options);
} catch (Throwable e) {
throw new AssertionError(e);
}
Expand Down
14 changes: 7 additions & 7 deletions modern/src/main/java/dev/nolij/zume/modern/ZumeKeyBind.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.nolij.zume.modern;

import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;

public enum ZumeKeyBind {
Expand All @@ -12,18 +12,18 @@ public enum ZumeKeyBind {

;

public final KeyBinding value;
public final KeyMapping value;

public boolean isPressed() {
return value.isPressed();
return value.isDown();
}

ZumeKeyBind(String translationKey, InputUtil.Type type, int code, String category) {
this.value = new KeyBinding(translationKey, type, code, category);
ZumeKeyBind(String translationKey, InputConstants.Type type, int code, String category) {
this.value = new KeyMapping(translationKey, type, code, category);
}

ZumeKeyBind(String translationKey, int code) {
this(translationKey, InputUtil.Type.KEYSYM, code, "zume");
this(translationKey, InputConstants.Type.KEYSYM, code, "zume");
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package dev.nolij.zume.modern.integration;

import dev.nolij.zume.api.platform.v0.ZumeAPI;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

public class ModernZumeConfigScreen extends Screen {

private final Screen parent;

public ModernZumeConfigScreen(Text arg, Screen parent) {
public ModernZumeConfigScreen(Component arg, Screen parent) {
super(arg);
this.parent = parent;
}
Expand All @@ -18,7 +18,7 @@ public ModernZumeConfigScreen(Text arg, Screen parent) {
public void init() {
ZumeAPI.openConfigFile();

MinecraftClient.getInstance().setScreen(parent);
Minecraft.getInstance().setScreen(parent);
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import me.jellysquid.mods.sodium.client.gui.options.control.SliderControl;
import me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import net.minecraft.text.Text;
import net.minecraft.network.chat.Component;
import org.embeddedt.embeddium.api.OptionGUIConstructionEvent;
import org.embeddedt.embeddium.api.eventbus.EventHandlerRegistrar;
import org.embeddedt.embeddium.client.gui.options.OptionIdentifier;
Expand Down Expand Up @@ -98,12 +98,12 @@ private Control<Integer> percentageControl(final Option<Integer> option) {

private Control<Integer> exponentControl(final Option<Integer> option) {
return new SliderControl(option, 100, 500, 25, v -> switch (v) {
case 100 -> Text.translatable("zume.linear");
case 200 -> Text.translatable("zume.quad");
case 300 -> Text.translatable("zume.cubic");
case 400 -> Text.translatable("zume.quart");
case 500 -> Text.translatable("zume.quint");
default -> Text.literal("x^" + (v / 100D));
case 100 -> Component.translatable("zume.linear");
case 200 -> Component.translatable("zume.quad");
case 300 -> Component.translatable("zume.cubic");
case 400 -> Component.translatable("zume.quart");
case 500 -> Component.translatable("zume.quint");
default -> Component.literal("x^" + (v / 100D));
});
}

Expand Down Expand Up @@ -177,8 +177,8 @@ public void acceptEvent(OptionGUIConstructionEvent event) {
.setControl(option ->
new SliderControl(option, 0, 500, 25,
v -> v > 0
? Text.literal(v + "ms")
: Text.translatable("zume.instant")))
? Component.literal(v + "ms")
: Component.translatable("zume.instant")))
.setBinding(
(config, value) -> config.zoomSmoothnessMilliseconds = value.shortValue(),
config -> (int) config.zoomSmoothnessMilliseconds)
Expand All @@ -191,8 +191,8 @@ public void acceptEvent(OptionGUIConstructionEvent event) {
.setControl(option ->
new SliderControl(option, 0, 30, 1,
v -> v > 0
? Text.translatable("zume.blocks", v)
: Text.translatable("zume.disabled")))
? Component.translatable("zume.blocks", v)
: Component.translatable("zume.disabled")))
.setBinding(
(config, value) -> config.maximumThirdPersonZoomBlocks = value,
config -> (int) config.maximumThirdPersonZoomBlocks)
Expand All @@ -202,8 +202,8 @@ public void acceptEvent(OptionGUIConstructionEvent event) {
.setControl(option ->
new SliderControl(option, 0, 10, 1,
v -> v > 0
? Text.translatable("zume.blocks", v)
: Text.translatable("zume.blocks", 0.5)))
? Component.translatable("zume.blocks", v)
: Component.translatable("zume.blocks", 0.5)))
.setBinding(
(config, value) -> config.minimumThirdPersonZoomBlocks = value > 0 ? value : 0.5,
config -> (int) config.minimumThirdPersonZoomBlocks)
Expand Down Expand Up @@ -233,7 +233,7 @@ public void acceptEvent(OptionGUIConstructionEvent event) {
.setId(MIN_FOV)
.setControl(option ->
new SliderControl(option, -2, 1, 1,
v -> Text.literal(String.valueOf(Math.pow(10, v)))))
v -> Component.literal(String.valueOf(Math.pow(10, v)))))
.setBinding(
(config, value) -> config.minimumFOV = Math.pow(10, value),
config -> (int) Math.log10(config.minimumFOV))
Expand All @@ -249,12 +249,12 @@ public void acceptEvent(OptionGUIConstructionEvent event) {
.build());

event.getPages().add(new OptionPage(
GENERAL,
Text.translatable("zume.options.pages.general"),
GENERAL,
Component.translatable("zume.options.pages.general"),
ImmutableList.copyOf(generalGroups)));
event.getPages().add(new OptionPage(
ADVANCED,
Text.translatable("zume.options.pages.advanced"),
ADVANCED,
Component.translatable("zume.options.pages.advanced"),
ImmutableList.copyOf(advancedGroups)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import dev.nolij.zume.api.platform.v0.ZumeAPI;
import dev.nolij.zume.api.util.v0.MethodHandleHelper;
import io.github.prospector.modmenu.api.ModMenuApi;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.*;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
Expand All @@ -17,7 +17,7 @@ public class ZumeModMenuIntegration implements ModMenuApi {

private static final MethodHandle LITERALTEXT_INIT = MethodHandleHelper.PUBLIC.getConstructorOrNull(
MethodHandleHelper.PUBLIC.getClassOrNull("net.minecraft.class_2585"),
MethodType.methodType(Text.class, String.class),
MethodType.methodType(Component.class, String.class),
String.class);

@Override
Expand All @@ -30,7 +30,7 @@ public String getModId() {
return (parent) -> {
try {
//noinspection DataFlowIssue
return new ModernZumeConfigScreen((Text) LITERALTEXT_INIT.invokeExact(""), parent);
return new ModernZumeConfigScreen((Component) LITERALTEXT_INIT.invokeExact(""), parent);
} catch (Throwable e) {
ZumeAPI.getLogger().error("Error opening config screen: ", e);
return null;
Expand All @@ -40,7 +40,7 @@ public String getModId() {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return (parent) -> new ModernZumeConfigScreen(Text.literal(""), parent);
return (parent) -> new ModernZumeConfigScreen(Component.literal(""), parent);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.prospector.modmenu.api;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screens.Screen;

import java.util.function.Function;

Expand Down
2 changes: 1 addition & 1 deletion modern/src/main/resources/zume-modern.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"client": [
"modern.CameraMixin",
"modern.GameRendererMixin",
"modern.MouseMixin"
"modern.MouseHandlerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b705d4b

Please sign in to comment.