From b232ccc3a1a54ed3986cdfed28d39129beac5f7c Mon Sep 17 00:00:00 2001 From: LambdAurora Date: Wed, 11 Dec 2019 22:43:23 +0100 Subject: [PATCH] :arrow_up: Update to Minecraft 1.15. --- README.md | 2 +- build.gradle | 2 +- gradle.properties | 10 +- icon.png | Bin 0 -> 7987 bytes .../lambdacontrols/ButtonBinding.java | 214 ++++++++++++++---- .../lambdacontrols/ControllerInput.java | 42 ++-- .../gui/ControlsListWidget.java | 12 +- .../lambdacontrols/gui/LambdaControlsHud.java | 6 +- .../gui/LambdaControlsSettingsScreen.java | 2 +- .../gui/TouchscreenOverlay.java | 4 +- .../mixin/AbstractContainerScreenMixin.java | 16 +- .../mixin/MinecraftClientMixin.java | 2 +- .../util/AbstractContainerScreenAccessor.java | 4 +- .../resources/assets/lambdacontrols/icon.png | Bin 0 -> 1618 bytes src/main/resources/fabric.mod.json | 5 +- 15 files changed, 221 insertions(+), 100 deletions(-) create mode 100644 icon.png create mode 100644 src/main/resources/assets/lambdacontrols/icon.png diff --git a/README.md b/README.md index 0ab3089..a6099b9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LambdaControls -![JS and HTML/CSS](https://img.shields.io/badge/language-Java%208-9B599A.svg?style=flat-square) +![Java 8](https://img.shields.io/badge/language-Java%208-9B599A.svg?style=flat-square) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/LambdAurora/LambdaControls/master/LICENSE) A Fabric Minecraft mod which add better controls. diff --git a/build.gradle b/build.gradle index 1f805ac..661e18f 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modCompile "io.github.cottonmc:cotton-client-commands:0.4.2+1.14.3-SNAPSHOT" + //modCompile "io.github.cottonmc:cotton-client-commands:0.4.2+1.14.3-SNAPSHOT" implementation "org.jetbrains:annotations:17.0.0" implementation "org.aperlambda:lambdajcommon:1.7.2" diff --git a/gradle.properties b/gradle.properties index 5cb7827..7460226 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.14.4 - yarn_mappings=1.14.4+build.15:v2 - loader_version=0.7.1+build.173 + minecraft_version=1.15 + yarn_mappings=1.15+build.1:v2 + loader_version=0.7.2+build.174 # Mod Properties - mod_version = 1.0.0-SNAPSHOT + mod_version = 1.0.0-SNAPSHOT1 maven_group = me.lambdaurora archives_base_name = lambdacontrols # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.4.1+build.245-1.14 + fabric_version=0.4.23+build.276-1.15 diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..20da8ee3e124f59de9dfed745ee600f8b9bc475e GIT binary patch literal 7987 zcmeHs`8$;D-#=rNrNRiMWF)tJi6q&kMYb$i22J)5V~dd86v`6H)?z6PS%yiL?3yBt zt&*{CFEVTC5k-@%=xf3|Dh-0ff3wV3a95$g*8qm48*=<^@~vZB@FcS)_J<;ILbdl((pt%{>QLWI?u)E2 zBy|+8AS{(@Q7oiHO=OWAeBqcB0+Ibh-aOOCR5+u?%FL?ADlGIp|8GAt^WBDvyZRwj z^dT+J#;qyteNH4QoB?+or$Me8p~6|f*RhOnxV;c`AN4dGZu~iqixCEA(MD1jpub01 zwUL@`{9NGQ;IYI1_t^hLK!Q0K8DSjks)4I_lBQ{cRj+zKgg3dt{E+W8e+Gjy_DT$g zdvlf#g444-&&Yba^6^U!aJWYhiKrtF{7!&lZvP93Yv;Z3M+g<(bP0xNz4XoF3gAgU z{7hp1X;*bXlndG@m@>H*0XG{+$ZstuFAEOniA1m^Z*KW>=x)_b3{^^D8*p_9fYaQ6+IW;v!&n(@Ws; z%ezWgVB0*e5otjG?ZbZNWP(!yaVv$b50^}K(E?~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q zCakA{JSqR0*M{8)Tc*6b*&Gm`ie+sV9kZ+yFi}Z_q8OSC4uiy2_HSYXgOb=}0f(Uhl>z3~S! zU!xa+B*vpGI&bb;Ivp(QtWh!nUYmltUg$jwHBECYC()#sr!AEagDRumA$stJ_(EUa z4=)fGbZzG>Q!yo@f$_s#bMww1>TeXag@90$djZmfB}yOiS&KE@nxy+;nnGFnq~19~ z!MA@^1pSDJ+=Ng2k=q1CH)zIw3x2LJ&G`xaQbj==%Z{i(YqvvVnF9-GqPRqJz$O&s u4}!^G=qwUg7bgUUl>fW^zaEo)j>TW~_`LMQgN~-b)soA$5B?vLEqlxW literal 0 HcmV?d00001 diff --git a/src/main/java/me/lambdaurora/lambdacontrols/ButtonBinding.java b/src/main/java/me/lambdaurora/lambdacontrols/ButtonBinding.java index 6021ad8..f110834 100644 --- a/src/main/java/me/lambdaurora/lambdacontrols/ButtonBinding.java +++ b/src/main/java/me/lambdaurora/lambdacontrols/ButtonBinding.java @@ -15,12 +15,14 @@ import net.minecraft.client.options.GameOptions; import net.minecraft.client.options.KeyBinding; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.util.ScreenshotUtils; +import org.aperlambda.lambdacommon.Identifier; +import org.aperlambda.lambdacommon.utils.Identifiable; import org.aperlambda.lambdacommon.utils.Nameable; -import org.aperlambda.lambdacommon.utils.Pair; import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; import java.util.*; +import java.util.function.Consumer; import java.util.stream.Stream; /** @@ -30,37 +32,37 @@ import java.util.stream.Stream; */ public class ButtonBinding implements Nameable { - private static final List BINDINGS = new ArrayList<>(); - private static final Map, List> CATEGORIES = new HashMap<>(); - public static final String MOVEMENT_CATEGORY = "key.categories.movement"; - public static final String GAMEPLAY_CATEGORY = "key.categories.gameplay"; - public static final String INVENTORY_CATEGORY = "key.categories.inventory"; - public static final String MULTIPLAYER_CATEGORY = "key.categories.multiplayer"; - public static final String MISC_CATEGORY = "key.categories.misc"; - public static final ButtonBinding ATTACK = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true), "attack"); - public static final ButtonBinding BACK = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y, false), "back"); - public static final ButtonBinding CHAT = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "chat"); - public static final ButtonBinding DROP_ITEM = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_B, "drop_item"); - public static final ButtonBinding FORWARD = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y, true), "forward"); - public static final ButtonBinding INVENTORY = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_Y, "inventory"); - public static final ButtonBinding JUMP = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_A, "jump"); - public static final ButtonBinding LEFT = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, false), "left"); - public static final ButtonBinding PAUSE_GAME = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_START, "pause_game"); - public static final ButtonBinding PICK_BLOCK = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "pick_block"); - public static final ButtonBinding PLAYER_LIST = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_BACK, "player_list"); - public static final ButtonBinding RIGHT = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, true), "right"); - public static final ButtonBinding SCREENSHOT = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "screenshot", + private static final List BINDINGS = new ArrayList<>(); + private static final List CATEGORIES = new ArrayList<>(); + public static final Category MOVEMENT_CATEGORY; + public static final Category GAMEPLAY_CATEGORY; + public static final Category INVENTORY_CATEGORY; + public static final Category MULTIPLAYER_CATEGORY; + public static final Category MISC_CATEGORY; + public static final ButtonBinding ATTACK = new ButtonBinding("attack", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true)); + public static final ButtonBinding BACK = new ButtonBinding("back", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y, false)); + public static final ButtonBinding CHAT = new ButtonBinding("chat", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT); + public static final ButtonBinding DROP_ITEM = new ButtonBinding("drop_item", GLFW.GLFW_GAMEPAD_BUTTON_B); + public static final ButtonBinding FORWARD = new ButtonBinding("forward", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y, true)); + public static final ButtonBinding INVENTORY = new ButtonBinding("inventory", GLFW.GLFW_GAMEPAD_BUTTON_Y); + public static final ButtonBinding JUMP = new ButtonBinding("jump", GLFW.GLFW_GAMEPAD_BUTTON_A); + public static final ButtonBinding LEFT = new ButtonBinding("left", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, false)); + public static final ButtonBinding PAUSE_GAME = new ButtonBinding("pause_game", GLFW.GLFW_GAMEPAD_BUTTON_START); + public static final ButtonBinding PICK_BLOCK = new ButtonBinding("pick_block", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT); + public static final ButtonBinding PLAYER_LIST = new ButtonBinding("player_list", GLFW.GLFW_GAMEPAD_BUTTON_BACK); + public static final ButtonBinding RIGHT = new ButtonBinding("right", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, true)); + public static final ButtonBinding SCREENSHOT = new ButtonBinding("screenshot", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN, Collections.singletonList((client, action) -> { - ScreenshotUtils.method_1659(client.runDirectory, client.window.getFramebufferWidth(), client.window.getFramebufferHeight(), client.getFramebuffer(), + ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(), text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text))); return true; })); - public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding(-1, "toggle_smooth_camera"); - public static final ButtonBinding SNEAK = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "sneak"); - public static final ButtonBinding SPRINT = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "sprint"); - public static final ButtonBinding SWAP_HANDS = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_X, "swap_hands"); - public static final ButtonBinding TOGGLE_PERSPECTIVE = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, "toggle_perspective"); - public static final ButtonBinding USE = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true), "use"); + public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding("toggle_smooth_camera", -1); + public static final ButtonBinding SNEAK = new ButtonBinding("sneak", GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB); + public static final ButtonBinding SPRINT = new ButtonBinding("sprint", GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB); + public static final ButtonBinding SWAP_HANDS = new ButtonBinding("swap_hands", GLFW.GLFW_GAMEPAD_BUTTON_X); + public static final ButtonBinding TOGGLE_PERSPECTIVE = new ButtonBinding("toggle_perspective", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP); + public static final ButtonBinding USE = new ButtonBinding("use", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true)); private int button; private int default_button; @@ -72,17 +74,17 @@ public class ButtonBinding implements Nameable })); private boolean pressed = false; - public ButtonBinding(int button, @NotNull String key, @NotNull List actions) + protected ButtonBinding(@NotNull String key, int default_button, @NotNull List actions) { - this.default_button = this.button = button; + this.default_button = this.button = default_button; this.key = key; this.actions.addAll(actions); BINDINGS.add(this); } - public ButtonBinding(int button, @NotNull String key) + protected ButtonBinding(@NotNull String key, int default_button) { - this(button, key, Collections.emptyList()); + this(key, default_button, Collections.emptyList()); } /** @@ -331,42 +333,166 @@ public class ButtonBinding implements Nameable return BINDINGS.stream(); } - public static @NotNull Stream, List>> stream_categories() + public static @NotNull Stream stream_categories() { - return CATEGORIES.entrySet().stream(); + return CATEGORIES.stream(); } static { - CATEGORIES.put(Pair.of(MOVEMENT_CATEGORY, 0), Arrays.asList( + MOVEMENT_CATEGORY = register_default_category("key.categories.movement", category -> category.register_all_bindings( FORWARD, BACK, LEFT, RIGHT, JUMP, SNEAK, - SPRINT - )); - CATEGORIES.put(Pair.of(GAMEPLAY_CATEGORY, 1), Arrays.asList( + SPRINT)); + GAMEPLAY_CATEGORY = register_default_category("key.categories.gameplay", category -> category.register_all_bindings( ATTACK, PICK_BLOCK, USE )); - CATEGORIES.put(Pair.of(INVENTORY_CATEGORY, 2), Arrays.asList( + INVENTORY_CATEGORY = register_default_category("key.categories.inventory", category -> category.register_all_bindings( DROP_ITEM, INVENTORY, SWAP_HANDS )); - CATEGORIES.put(Pair.of(MULTIPLAYER_CATEGORY, 2), Arrays.asList( - CHAT, - PLAYER_LIST - )); - CATEGORIES.put(Pair.of(MISC_CATEGORY, 3), Arrays.asList( + MULTIPLAYER_CATEGORY = register_default_category("key.categories.multiplayer", + category -> category.register_all_bindings(CHAT, PLAYER_LIST)); + MISC_CATEGORY = register_default_category("key.categories.misc", category -> category.register_all_bindings( SCREENSHOT, //SMOOTH_CAMERA, TOGGLE_PERSPECTIVE )); } + public static ButtonBinding register(@NotNull Identifier binding_id, int default_button, @NotNull List actions) + { + return new ButtonBinding(binding_id.get_namespace() + "." + binding_id.get_name(), default_button, actions); + } + + public static ButtonBinding register(@NotNull Identifier binding_id, int default_button) + { + return register(binding_id, default_button, Collections.emptyList()); + } + + public static ButtonBinding register(@NotNull net.minecraft.util.Identifier binding_id, int default_button, @NotNull List actions) + { + return register(new Identifier(binding_id.getNamespace(), binding_id.getPath()), default_button, actions); + } + + public static ButtonBinding register(@NotNull net.minecraft.util.Identifier binding_id, int default_button) + { + return register(binding_id, default_button, Collections.emptyList()); + } + + /** + * Registers a category of button bindings. + * + * @param category The category to register. + * @return The registered category. + */ + public static Category register_category(@NotNull Category category) + { + CATEGORIES.add(category); + return category; + } + + public static Category register_category(@NotNull Identifier identifier, int priority) + { + return register_category(new Category(identifier, priority)); + } + + public static Category register_category(@NotNull Identifier identifier) + { + return register_category(new Category(identifier)); + } + + private static Category register_default_category(@NotNull String key, @NotNull Consumer key_adder) + { + Category category = register_category(new Identifier("minecraft", key), CATEGORIES.size()); + key_adder.accept(category); + return category; + } + + public static class Category implements Identifiable + { + private final List bindings = new ArrayList<>(); + private final Identifier id; + private int priority; + + public Category(@NotNull Identifier id, int priority) + { + this.id = id; + this.priority = priority; + } + + public Category(@NotNull Identifier id) + { + this(id, 100); + } + + public void register_binding(@NotNull ButtonBinding binding) + { + if (this.bindings.contains(binding)) + throw new IllegalStateException("Cannot register twice a button binding in the same category."); + this.bindings.add(binding); + } + + public void register_all_bindings(@NotNull ButtonBinding... bindings) + { + this.register_all_bindings(Arrays.asList(bindings)); + } + + public void register_all_bindings(@NotNull List bindings) + { + bindings.forEach(this::register_binding); + } + + /** + * Gets the bindings assigned to this category. + * + * @return The bindings assigned to this category. + */ + public @NotNull List get_bindings() + { + return Collections.unmodifiableList(this.bindings); + } + + /** + * Gets the translated name of this category. + *

+ * The translation key should be `modid.identifier_name`. + * + * @return The translated name. + */ + public @NotNull String get_translated_name() + { + System.out.println(id.toString()); + if (this.id.get_namespace().equals("minecraft")) + return I18n.translate(this.id.get_name()); + else + return I18n.translate(this.id.get_namespace() + "." + this.id.get_name()); + } + + /** + * Gets the priority display of this category. + * It will defines in which order the categories will display on the controls screen. + * + * @return The priority of this category. + */ + public int get_priority() + { + return this.priority; + } + + @Override + public @NotNull Identifier get_identifier() + { + return this.id; + } + } + @FunctionalInterface public static interface PressAction { diff --git a/src/main/java/me/lambdaurora/lambdacontrols/ControllerInput.java b/src/main/java/me/lambdaurora/lambdacontrols/ControllerInput.java index 16dfa15..f102245 100644 --- a/src/main/java/me/lambdaurora/lambdacontrols/ControllerInput.java +++ b/src/main/java/me/lambdaurora/lambdacontrols/ControllerInput.java @@ -117,8 +117,8 @@ public class ControllerInput if (this.prev_target_mouse_x != this.target_mouse_x || this.prev_target_mouse_y != this.target_mouse_y) { double mouse_x = this.prev_target_mouse_x + (this.target_mouse_x - this.prev_target_mouse_x) * client.getTickDelta() + 0.5; double mouse_y = this.prev_target_mouse_y + (this.target_mouse_y - this.prev_target_mouse_y) * client.getTickDelta() + 0.5; - GLFW.glfwSetCursorPos(client.window.getHandle(), mouse_x, mouse_y); - ((MouseAccessor) client.mouse).on_cursor_pos(client.window.getHandle(), mouse_x, mouse_y); + GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouse_x, mouse_y); + ((MouseAccessor) client.mouse).on_cursor_pos(client.getWindow().getHandle(), mouse_x, mouse_y); } } } @@ -248,22 +248,22 @@ public class ControllerInput } } - if (client.currentScreen instanceof AbstractContainerScreen) { - double pos_x = client.mouse.getX() * (double) client.window.getScaledWidth() / (double) client.window.getWidth(); - double pos_y = client.mouse.getY() * (double) client.window.getScaledHeight() / (double) client.window.getHeight(); + if (client.currentScreen instanceof AbstractContainerScreen && client.interactionManager != null && client.player != null) { + double pos_x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth(); + double pos_y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight(); Slot slot = ((AbstractContainerScreenAccessor) client.currentScreen).get_slot_at(pos_x, pos_y); if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && slot != null) { - client.interactionManager.method_2906(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, client.player); + client.interactionManager.clickSlot(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, client.player); this.action_gui_cooldown = 5; return; } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) { client.player.closeContainer(); return; } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_X && slot != null) { - client.interactionManager.method_2906(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_2, SlotActionType.PICKUP, client.player); + client.interactionManager.clickSlot(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_2, SlotActionType.PICKUP, client.player); return; } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_Y && slot != null) { - client.interactionManager.method_2906(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.QUICK_MOVE, client.player); + client.interactionManager.clickSlot(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.QUICK_MOVE, client.player); return; } } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) { @@ -280,8 +280,8 @@ public class ControllerInput } if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.currentScreen != null && !is_screen_interactive(client.currentScreen) && this.action_gui_cooldown == 0 && this.ignore_next_a == 0) { - double mouse_x = client.mouse.getX() * (double) client.window.getScaledWidth() / (double) client.window.getWidth(); - double mouse_y = client.mouse.getY() * (double) client.window.getScaledHeight() / (double) client.window.getHeight(); + double mouse_x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth(); + double mouse_y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight(); if (action == 0) { client.currentScreen.mouseClicked(mouse_x, mouse_y, GLFW.GLFW_MOUSE_BUTTON_1); } else if (action == 1) { @@ -421,9 +421,9 @@ public class ControllerInput if (Math.abs(this.mouse_speed_x) > .05F || Math.abs(this.mouse_speed_y) > .05F) { this.target_mouse_x += this.mouse_speed_x * this.config.get_mouse_speed(); - this.target_mouse_x = MathHelper.clamp(this.target_mouse_x, 0, client.window.getWidth()); + this.target_mouse_x = MathHelper.clamp(this.target_mouse_x, 0, client.getWindow().getWidth()); this.target_mouse_y += this.mouse_speed_y * this.config.get_mouse_speed(); - this.target_mouse_y = MathHelper.clamp(this.target_mouse_y, 0, client.window.getHeight()); + this.target_mouse_y = MathHelper.clamp(this.target_mouse_y, 0, client.getWindow().getHeight()); } this.move_mouse_to_closest_slot(client, client.currentScreen); @@ -469,13 +469,13 @@ public class ControllerInput return true; } else if (focused instanceof WorldListWidget) { WorldListWidget list = (WorldListWidget) focused; - list.method_20159().ifPresent(WorldListWidget.LevelItem::play); + list.method_20159().ifPresent(WorldListWidget.Entry::play); return true; } else if (focused instanceof MultiplayerServerListWidget) { MultiplayerServerListWidget list = (MultiplayerServerListWidget) focused; MultiplayerServerListWidget.Entry entry = list.getSelected(); - if (entry instanceof MultiplayerServerListWidget.LanServerListEntry || entry instanceof MultiplayerServerListWidget.ServerItem) { - ((MultiplayerScreen) screen).selectEntry(entry); + if (entry instanceof MultiplayerServerListWidget.LanServerEntry || entry instanceof MultiplayerServerListWidget.ServerEntry) { + ((MultiplayerScreen) screen).select(entry); ((MultiplayerScreen) screen).connect(); } } else if (focused instanceof ParentElement) { @@ -556,10 +556,10 @@ public class ControllerInput if (screen instanceof AbstractContainerScreen) { AbstractContainerScreen inventory_screen = (AbstractContainerScreen) screen; AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) inventory_screen; - int gui_left = accessor.get_left(); - int gui_top = accessor.get_top(); - int mouse_x = (int) (target_mouse_x * (double) client.window.getScaledWidth() / (double) client.window.getWidth()); - int mouse_y = (int) (target_mouse_y * (double) client.window.getScaledHeight() / (double) client.window.getHeight()); + int gui_left = accessor.get_x(); + int gui_top = accessor.get_y(); + int mouse_x = (int) (target_mouse_x * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth()); + int mouse_y = (int) (target_mouse_y * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight()); // Finds the closest slot in the GUI within 14 pixels. Optional> closest_slot = inventory_screen.getContainer().slotList.parallelStream() @@ -578,8 +578,8 @@ public class ControllerInput if (slot.hasStack() || !client.player.inventory.getMainHandStack().isEmpty()) { int slot_center_x_scaled = gui_left + slot.xPosition + 8; int slot_center_y_scaled = gui_top + slot.yPosition + 8; - int slot_center_x = (int) (slot_center_x_scaled / ((double) client.window.getScaledWidth() / (double) client.window.getWidth())); - int slot_center_y = (int) (slot_center_y_scaled / ((double) client.window.getScaledHeight() / (double) client.window.getHeight())); + int slot_center_x = (int) (slot_center_x_scaled / ((double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth())); + int slot_center_y = (int) (slot_center_y_scaled / ((double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight())); double delta_x = slot_center_x - target_mouse_x; double delta_y = slot_center_y - target_mouse_y; diff --git a/src/main/java/me/lambdaurora/lambdacontrols/gui/ControlsListWidget.java b/src/main/java/me/lambdaurora/lambdacontrols/gui/ControlsListWidget.java index d8c1592..309e28e 100644 --- a/src/main/java/me/lambdaurora/lambdacontrols/gui/ControlsListWidget.java +++ b/src/main/java/me/lambdaurora/lambdacontrols/gui/ControlsListWidget.java @@ -19,7 +19,6 @@ import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.resource.language.I18n; import net.minecraft.util.Formatting; -import org.aperlambda.lambdacommon.utils.Pair; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -41,12 +40,11 @@ public class ControlsListWidget extends ElementListWidget e.getKey().get_value())) - .map(category -> Pair.of(category.getKey().get_key(), category.getValue())) + .sorted(Comparator.comparingInt(ButtonBinding.Category::get_priority)) .forEach(category -> { - this.addEntry(new CategoryEntry(category.get_key())); + this.addEntry(new CategoryEntry(category)); - category.get_value().forEach(binding -> { + category.get_bindings().forEach(binding -> { int i = client.textRenderer.getStringWidth(I18n.translate(binding.get_translation_key())); if (i > this.field_2733) { this.field_2733 = i; @@ -150,9 +148,9 @@ public class ControlsListWidget extends ElementListWidget this.minecraft.openScreen(new ChatScreen("")), "")); this.addButton(new TexturedButtonWidget(scaled_width / 2, 0, 20, 20, 0, 0, 20, WIDGETS_LOCATION, 256, 256, diff --git a/src/main/java/me/lambdaurora/lambdacontrols/mixin/AbstractContainerScreenMixin.java b/src/main/java/me/lambdaurora/lambdacontrols/mixin/AbstractContainerScreenMixin.java index cf2ffca..c9e8333 100644 --- a/src/main/java/me/lambdaurora/lambdacontrols/mixin/AbstractContainerScreenMixin.java +++ b/src/main/java/me/lambdaurora/lambdacontrols/mixin/AbstractContainerScreenMixin.java @@ -28,25 +28,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(AbstractContainerScreen.class) public abstract class AbstractContainerScreenMixin implements AbstractContainerScreenAccessor { - @Shadow - protected int left; + protected int x; - @Shadow - protected int top; + protected int y; @Shadow protected abstract Slot getSlotAt(double xPosition, double yPosition); @Override - public int get_left() + public int get_x() { - return this.left; + return this.x; } @Override - public int get_top() + public int get_y() { - return this.top; + return this.y; } @Override @@ -60,7 +58,7 @@ public abstract class AbstractContainerScreenMixin implements AbstractContainerS { if (LambdaControls.get().config.get_controls_mode() == ControlsMode.CONTROLLER) { MinecraftClient client = MinecraftClient.getInstance(); - int x = 10, y = client.window.getScaledHeight() - 10 - 15; + int x = 10, y = client.getWindow().getScaledHeight() - 10 - 15; x += LambdaControls.draw_button_tip(x, y, GLFW.GLFW_GAMEPAD_BUTTON_A, "lambdacontrols.action.pickup_all", true, client) + 10; x += LambdaControls.draw_button_tip(x, y, GLFW.GLFW_GAMEPAD_BUTTON_B, "lambdacontrols.action.exit", true, client) + 10; diff --git a/src/main/java/me/lambdaurora/lambdacontrols/mixin/MinecraftClientMixin.java b/src/main/java/me/lambdaurora/lambdacontrols/mixin/MinecraftClientMixin.java index 27f8998..f3d463f 100644 --- a/src/main/java/me/lambdaurora/lambdacontrols/mixin/MinecraftClientMixin.java +++ b/src/main/java/me/lambdaurora/lambdacontrols/mixin/MinecraftClientMixin.java @@ -34,7 +34,7 @@ public abstract class MinecraftClientMixin @Shadow public Screen currentScreen; - @Inject(method = "init", at = @At("RETURN")) + @Inject(method = "", at = @At("RETURN")) private void on_init(CallbackInfo ci) { LambdaControls.get().on_mc_init((MinecraftClient) (Object) this); diff --git a/src/main/java/me/lambdaurora/lambdacontrols/util/AbstractContainerScreenAccessor.java b/src/main/java/me/lambdaurora/lambdacontrols/util/AbstractContainerScreenAccessor.java index 0caa082..e7b72d5 100644 --- a/src/main/java/me/lambdaurora/lambdacontrols/util/AbstractContainerScreenAccessor.java +++ b/src/main/java/me/lambdaurora/lambdacontrols/util/AbstractContainerScreenAccessor.java @@ -21,14 +21,14 @@ public interface AbstractContainerScreenAccessor * * @return The left coordinate of the GUI. */ - int get_left(); + int get_x(); /** * Gets the top coordinate of the GUI. * * @return The top coordinate of the GUI. */ - int get_top(); + int get_y(); /** * Gets the slot at position. diff --git a/src/main/resources/assets/lambdacontrols/icon.png b/src/main/resources/assets/lambdacontrols/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c6168d513d4e302e4a4b8c323b54e51b006e30df GIT binary patch literal 1618 zcmV-Y2CeytP)vjYr0Vso)r#l7InqD!UI|+ zzAk($>^J0q!Z%7!)cI9$y3U`9jc8;Z?5d|X{f85OSj!kW;W1%fE?d$X=TSFtCG$&* zQav(3XW&E$~XN5$!X?G^h#6n9f5lrF0Pwe zVjnJdVCYGY8}XXtkZDh);Qbu>V$gpFJ*)Ms8ta@rLUc=>=oStRVN~|J*M0%5t!LzN zrUa<~000SaNLh0L04^f{04^f|c%?sf000DuNkl zVuWlI!JE0PFX6?LFChCAo)%xgyJzp_5^sV?Hef^$50XoA$f79OOUyS(4Yf7>Q`MPa zcFi;_*`2Px@9V1S?#*UdJ6Z->23iJM23iJM23iK1W8mb}HC~O3D~))aA*Yv~fTq`? z(e!T`Jp4CS`viU#N}y2^7Gi18@Atg{Zf$Kv^*#1|Hk0gKB*vh_UazNGozZAy3H)Sr zb=Aqs{{B9mt8G;g-=d6!8-2358A}kFFA-%VCF;ioHYGk8SHU(pFc=L6{b76CIUlp1 zst0GJ8}dOiL_|&iz{diE+}FLm9MrwFwdjh)1Q1BK+s(xe4h}Mn|By|Jjbvgr;U6TZ zcLDA|I`ahvIsPI!4j#`y1Ydcdp3e{IzJGaEiTF$8#uh?NK+KSwr=SLdL53GkQ3{UF z(X)`AF9r^lNZ|fLu`g=V-%0?XXSN>vTHVa5yZU;~5{&vyP{)7xLA| z-`F@WxswGg0W$41ePFb+GZjZ~W24A~<>lp^1Pp*5kH`3181n(2XGGF zcX;A`0pN)UEY-+ zR_E1HVGi$czt9X*3DmjAyMpD{1k=~z6d0|343MRqQe~-htfgT7TAYJV4YqDQo|#%-#W}#D>}z~lr*+6# zV&YiU2O$J)A*l|K8k^P_O$6`&W}*IR_mI1ThA5IT6JSX-OCVLqro@&Lfb9i`f>8Qc zQ>zL*s0p z34ACEWEPh)AeK6_(*5O1%Rb=B1Q)h~fRKTCsC@}IbW7#sTe=KEQLAjNx4Px|jS{{> zSSXg#FA3;!G0%<9g2DMy3fE84=B?}h4;bpMnAU#FK+8bOK+8bOz-4FPABNMt=RzW~ Q>i_@%07*qoM6N<$f|>O7&j0`b literal 0 HcmV?d00001 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2f91a53..bda75b7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "lambdacontrols", "name": "LambdaControls", "version": "${version}", - "description": "Add better controls: controller and touchscreen support.", + "description": "Adds better controls: controller and touchscreen support.", "authors": [ "LambdAurora" ], @@ -26,8 +26,7 @@ "depends": { "fabricloader": ">=0.4.0", "fabric": "*", - "minecraft": "1.14.x", - "cotton-client-commands": ">=0.4.2+1.14.3-SNAPSHOT" + "minecraft": "1.15.x" }, "suggests": { "flamingo": "*"