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 0000000..20da8ee Binary files /dev/null and b/icon.png differ 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 0000000..c6168d5 Binary files /dev/null and b/src/main/resources/assets/lambdacontrols/icon.png differ 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": "*"