⬆️ Update to Minecraft 1.15.

This commit is contained in:
LambdAurora
2019-12-11 22:43:23 +01:00
parent 6b78d32e6f
commit b232ccc3a1
15 changed files with 221 additions and 100 deletions

View File

@@ -1,6 +1,6 @@
# LambdaControls # 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) [![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. A Fabric Minecraft mod which add better controls.

View File

@@ -31,7 +31,7 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" 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.jetbrains:annotations:17.0.0"
implementation "org.aperlambda:lambdajcommon:1.7.2" implementation "org.aperlambda:lambdajcommon:1.7.2"

View File

@@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
minecraft_version=1.14.4 minecraft_version=1.15
yarn_mappings=1.14.4+build.15:v2 yarn_mappings=1.15+build.1:v2
loader_version=0.7.1+build.173 loader_version=0.7.2+build.174
# Mod Properties # Mod Properties
mod_version = 1.0.0-SNAPSHOT mod_version = 1.0.0-SNAPSHOT1
maven_group = me.lambdaurora maven_group = me.lambdaurora
archives_base_name = lambdacontrols archives_base_name = lambdacontrols
# Dependencies # Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api # 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

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -15,12 +15,14 @@ import net.minecraft.client.options.GameOptions;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.ScreenshotUtils; 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.Nameable;
import org.aperlambda.lambdacommon.utils.Pair;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.util.*; import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@@ -30,37 +32,37 @@ import java.util.stream.Stream;
*/ */
public class ButtonBinding implements Nameable public class ButtonBinding implements Nameable
{ {
private static final List<ButtonBinding> BINDINGS = new ArrayList<>(); private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
private static final Map<Pair<String, Integer>, List<ButtonBinding>> CATEGORIES = new HashMap<>(); private static final List<Category> CATEGORIES = new ArrayList<>();
public static final String MOVEMENT_CATEGORY = "key.categories.movement"; public static final Category MOVEMENT_CATEGORY;
public static final String GAMEPLAY_CATEGORY = "key.categories.gameplay"; public static final Category GAMEPLAY_CATEGORY;
public static final String INVENTORY_CATEGORY = "key.categories.inventory"; public static final Category INVENTORY_CATEGORY;
public static final String MULTIPLAYER_CATEGORY = "key.categories.multiplayer"; public static final Category MULTIPLAYER_CATEGORY;
public static final String MISC_CATEGORY = "key.categories.misc"; public static final Category MISC_CATEGORY;
public static final ButtonBinding ATTACK = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true), "attack"); 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(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y, false), "back"); 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(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "chat"); public static final ButtonBinding CHAT = new ButtonBinding("chat", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT);
public static final ButtonBinding DROP_ITEM = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_B, "drop_item"); public static final ButtonBinding DROP_ITEM = new ButtonBinding("drop_item", GLFW.GLFW_GAMEPAD_BUTTON_B);
public static final ButtonBinding FORWARD = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y, true), "forward"); 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(GLFW.GLFW_GAMEPAD_BUTTON_Y, "inventory"); public static final ButtonBinding INVENTORY = new ButtonBinding("inventory", GLFW.GLFW_GAMEPAD_BUTTON_Y);
public static final ButtonBinding JUMP = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_A, "jump"); public static final ButtonBinding JUMP = new ButtonBinding("jump", GLFW.GLFW_GAMEPAD_BUTTON_A);
public static final ButtonBinding LEFT = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, false), "left"); 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(GLFW.GLFW_GAMEPAD_BUTTON_START, "pause_game"); public static final ButtonBinding PAUSE_GAME = new ButtonBinding("pause_game", GLFW.GLFW_GAMEPAD_BUTTON_START);
public static final ButtonBinding PICK_BLOCK = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "pick_block"); public static final ButtonBinding PICK_BLOCK = new ButtonBinding("pick_block", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT);
public static final ButtonBinding PLAYER_LIST = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_BACK, "player_list"); public static final ButtonBinding PLAYER_LIST = new ButtonBinding("player_list", GLFW.GLFW_GAMEPAD_BUTTON_BACK);
public static final ButtonBinding RIGHT = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, true), "right"); 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(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "screenshot", public static final ButtonBinding SCREENSHOT = new ButtonBinding("screenshot", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
Collections.singletonList((client, action) -> { 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))); text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text)));
return true; return true;
})); }));
public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding(-1, "toggle_smooth_camera"); public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding("toggle_smooth_camera", -1);
public static final ButtonBinding SNEAK = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "sneak"); public static final ButtonBinding SNEAK = new ButtonBinding("sneak", GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB);
public static final ButtonBinding SPRINT = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "sprint"); public static final ButtonBinding SPRINT = new ButtonBinding("sprint", GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB);
public static final ButtonBinding SWAP_HANDS = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_X, "swap_hands"); public static final ButtonBinding SWAP_HANDS = new ButtonBinding("swap_hands", GLFW.GLFW_GAMEPAD_BUTTON_X);
public static final ButtonBinding TOGGLE_PERSPECTIVE = new ButtonBinding(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, "toggle_perspective"); public static final ButtonBinding TOGGLE_PERSPECTIVE = new ButtonBinding("toggle_perspective", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP);
public static final ButtonBinding USE = new ButtonBinding(axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true), "use"); public static final ButtonBinding USE = new ButtonBinding("use", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true));
private int button; private int button;
private int default_button; private int default_button;
@@ -72,17 +74,17 @@ public class ButtonBinding implements Nameable
})); }));
private boolean pressed = false; private boolean pressed = false;
public ButtonBinding(int button, @NotNull String key, @NotNull List<PressAction> actions) protected ButtonBinding(@NotNull String key, int default_button, @NotNull List<PressAction> actions)
{ {
this.default_button = this.button = button; this.default_button = this.button = default_button;
this.key = key; this.key = key;
this.actions.addAll(actions); this.actions.addAll(actions);
BINDINGS.add(this); 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(); return BINDINGS.stream();
} }
public static @NotNull Stream<Map.Entry<Pair<String, Integer>, List<ButtonBinding>>> stream_categories() public static @NotNull Stream<Category> stream_categories()
{ {
return CATEGORIES.entrySet().stream(); return CATEGORIES.stream();
} }
static { static {
CATEGORIES.put(Pair.of(MOVEMENT_CATEGORY, 0), Arrays.asList( MOVEMENT_CATEGORY = register_default_category("key.categories.movement", category -> category.register_all_bindings(
FORWARD, FORWARD,
BACK, BACK,
LEFT, LEFT,
RIGHT, RIGHT,
JUMP, JUMP,
SNEAK, SNEAK,
SPRINT SPRINT));
)); GAMEPLAY_CATEGORY = register_default_category("key.categories.gameplay", category -> category.register_all_bindings(
CATEGORIES.put(Pair.of(GAMEPLAY_CATEGORY, 1), Arrays.asList(
ATTACK, ATTACK,
PICK_BLOCK, PICK_BLOCK,
USE 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, DROP_ITEM,
INVENTORY, INVENTORY,
SWAP_HANDS SWAP_HANDS
)); ));
CATEGORIES.put(Pair.of(MULTIPLAYER_CATEGORY, 2), Arrays.asList( MULTIPLAYER_CATEGORY = register_default_category("key.categories.multiplayer",
CHAT, category -> category.register_all_bindings(CHAT, PLAYER_LIST));
PLAYER_LIST MISC_CATEGORY = register_default_category("key.categories.misc", category -> category.register_all_bindings(
));
CATEGORIES.put(Pair.of(MISC_CATEGORY, 3), Arrays.asList(
SCREENSHOT, SCREENSHOT,
//SMOOTH_CAMERA, //SMOOTH_CAMERA,
TOGGLE_PERSPECTIVE TOGGLE_PERSPECTIVE
)); ));
} }
public static ButtonBinding register(@NotNull Identifier binding_id, int default_button, @NotNull List<PressAction> 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<PressAction> 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<Category> 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<ButtonBinding> 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<ButtonBinding> bindings)
{
bindings.forEach(this::register_binding);
}
/**
* Gets the bindings assigned to this category.
*
* @return The bindings assigned to this category.
*/
public @NotNull List<ButtonBinding> get_bindings()
{
return Collections.unmodifiableList(this.bindings);
}
/**
* Gets the translated name of this category.
* <p>
* 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 @FunctionalInterface
public static interface PressAction public static interface PressAction
{ {

View File

@@ -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) { 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_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; 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); GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouse_x, mouse_y);
((MouseAccessor) client.mouse).on_cursor_pos(client.window.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) { if (client.currentScreen instanceof AbstractContainerScreen && client.interactionManager != null && client.player != null) {
double pos_x = client.mouse.getX() * (double) client.window.getScaledWidth() / (double) client.window.getWidth(); double pos_x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth();
double pos_y = client.mouse.getY() * (double) client.window.getScaledHeight() / (double) client.window.getHeight(); 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); Slot slot = ((AbstractContainerScreenAccessor) client.currentScreen).get_slot_at(pos_x, pos_y);
if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && slot != null) { 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; this.action_gui_cooldown = 5;
return; return;
} else if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) { } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) {
client.player.closeContainer(); client.player.closeContainer();
return; return;
} else if (button == GLFW.GLFW_GAMEPAD_BUTTON_X && slot != null) { } 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; return;
} else if (button == GLFW.GLFW_GAMEPAD_BUTTON_Y && slot != null) { } 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; return;
} }
} else if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) { } 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) { 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_x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth();
double mouse_y = client.mouse.getY() * (double) client.window.getScaledHeight() / (double) client.window.getHeight(); double mouse_y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
if (action == 0) { if (action == 0) {
client.currentScreen.mouseClicked(mouse_x, mouse_y, GLFW.GLFW_MOUSE_BUTTON_1); client.currentScreen.mouseClicked(mouse_x, mouse_y, GLFW.GLFW_MOUSE_BUTTON_1);
} else if (action == 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) { 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 += 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 += 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); this.move_mouse_to_closest_slot(client, client.currentScreen);
@@ -469,13 +469,13 @@ public class ControllerInput
return true; return true;
} else if (focused instanceof WorldListWidget) { } else if (focused instanceof WorldListWidget) {
WorldListWidget list = (WorldListWidget) focused; WorldListWidget list = (WorldListWidget) focused;
list.method_20159().ifPresent(WorldListWidget.LevelItem::play); list.method_20159().ifPresent(WorldListWidget.Entry::play);
return true; return true;
} else if (focused instanceof MultiplayerServerListWidget) { } else if (focused instanceof MultiplayerServerListWidget) {
MultiplayerServerListWidget list = (MultiplayerServerListWidget) focused; MultiplayerServerListWidget list = (MultiplayerServerListWidget) focused;
MultiplayerServerListWidget.Entry entry = list.getSelected(); MultiplayerServerListWidget.Entry entry = list.getSelected();
if (entry instanceof MultiplayerServerListWidget.LanServerListEntry || entry instanceof MultiplayerServerListWidget.ServerItem) { if (entry instanceof MultiplayerServerListWidget.LanServerEntry || entry instanceof MultiplayerServerListWidget.ServerEntry) {
((MultiplayerScreen) screen).selectEntry(entry); ((MultiplayerScreen) screen).select(entry);
((MultiplayerScreen) screen).connect(); ((MultiplayerScreen) screen).connect();
} }
} else if (focused instanceof ParentElement) { } else if (focused instanceof ParentElement) {
@@ -556,10 +556,10 @@ public class ControllerInput
if (screen instanceof AbstractContainerScreen) { if (screen instanceof AbstractContainerScreen) {
AbstractContainerScreen inventory_screen = (AbstractContainerScreen) screen; AbstractContainerScreen inventory_screen = (AbstractContainerScreen) screen;
AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) inventory_screen; AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) inventory_screen;
int gui_left = accessor.get_left(); int gui_left = accessor.get_x();
int gui_top = accessor.get_top(); int gui_top = accessor.get_y();
int mouse_x = (int) (target_mouse_x * (double) client.window.getScaledWidth() / (double) client.window.getWidth()); int mouse_x = (int) (target_mouse_x * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth());
int mouse_y = (int) (target_mouse_y * (double) client.window.getScaledHeight() / (double) client.window.getHeight()); 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. // Finds the closest slot in the GUI within 14 pixels.
Optional<Pair<Slot, Double>> closest_slot = inventory_screen.getContainer().slotList.parallelStream() Optional<Pair<Slot, Double>> closest_slot = inventory_screen.getContainer().slotList.parallelStream()
@@ -578,8 +578,8 @@ public class ControllerInput
if (slot.hasStack() || !client.player.inventory.getMainHandStack().isEmpty()) { if (slot.hasStack() || !client.player.inventory.getMainHandStack().isEmpty()) {
int slot_center_x_scaled = gui_left + slot.xPosition + 8; int slot_center_x_scaled = gui_left + slot.xPosition + 8;
int slot_center_y_scaled = gui_top + slot.yPosition + 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_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.window.getScaledHeight() / (double) client.window.getHeight())); 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_x = slot_center_x - target_mouse_x;
double delta_y = slot_center_y - target_mouse_y; double delta_y = slot_center_y - target_mouse_y;

View File

@@ -19,7 +19,6 @@ import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import org.aperlambda.lambdacommon.utils.Pair;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
@@ -41,12 +40,11 @@ public class ControlsListWidget extends ElementListWidget<ControlsListWidget.Ent
this.gui = gui; this.gui = gui;
ButtonBinding.stream_categories() ButtonBinding.stream_categories()
.sorted(Comparator.comparingInt(e -> e.getKey().get_value())) .sorted(Comparator.comparingInt(ButtonBinding.Category::get_priority))
.map(category -> Pair.of(category.getKey().get_key(), category.getValue()))
.forEach(category -> { .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())); int i = client.textRenderer.getStringWidth(I18n.translate(binding.get_translation_key()));
if (i > this.field_2733) { if (i > this.field_2733) {
this.field_2733 = i; this.field_2733 = i;
@@ -150,9 +148,9 @@ public class ControlsListWidget extends ElementListWidget<ControlsListWidget.Ent
private final String name; private final String name;
private final int name_width; private final int name_width;
public CategoryEntry(String string) public CategoryEntry(@NotNull ButtonBinding.Category category)
{ {
this.name = I18n.translate(string); this.name = category.get_translated_name();
this.name_width = ControlsListWidget.this.minecraft.textRenderer.getStringWidth(this.name); this.name_width = ControlsListWidget.this.minecraft.textRenderer.getStringWidth(this.name);
} }

View File

@@ -43,14 +43,14 @@ public class LambdaControlsHud extends DrawableHelper
x = 10; x = 10;
x += this.draw_button_tip(x, (y -= 20), ButtonBinding.DROP_ITEM, !client.player.getMainHandStack().isEmpty()) + 10; x += this.draw_button_tip(x, (y -= 20), ButtonBinding.DROP_ITEM, !client.player.getMainHandStack().isEmpty()) + 10;
this.draw_button_tip(x, y, ButtonBinding.ATTACK.get_button(), this.draw_button_tip(x, y, ButtonBinding.ATTACK.get_button(),
client.hitResult.getType() == HitResult.Type.BLOCK ? "lambdacontrols.action.hit" : ButtonBinding.ATTACK.get_translation_key(), client.crosshairTarget.getType() == HitResult.Type.BLOCK ? "lambdacontrols.action.hit" : ButtonBinding.ATTACK.get_translation_key(),
client.hitResult.getType() != HitResult.Type.MISS); client.crosshairTarget.getType() != HitResult.Type.MISS);
} }
} }
private int bottom(int y) private int bottom(int y)
{ {
return this.client.window.getScaledHeight() - y - 15; return this.client.getWindow().getScaledHeight() - y - 15;
} }
private int draw_button_tip(int x, int y, @NotNull ButtonBinding button, boolean display) private int draw_button_tip(int x, int y, @NotNull ButtonBinding button, boolean display)

View File

@@ -13,7 +13,7 @@ import me.lambdaurora.lambdacontrols.Controller;
import me.lambdaurora.lambdacontrols.ControlsMode; import me.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.LambdaControls; import me.lambdaurora.lambdacontrols.LambdaControls;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.controls.ControlsOptionsScreen; import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
import net.minecraft.client.gui.widget.ButtonListWidget; import net.minecraft.client.gui.widget.ButtonListWidget;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.options.*; import net.minecraft.client.options.*;

View File

@@ -143,8 +143,8 @@ public class TouchscreenOverlay extends Screen
protected void init() protected void init()
{ {
super.init(); super.init();
int scaled_width = this.minecraft.window.getScaledWidth(); int scaled_width = this.minecraft.getWindow().getScaledWidth();
int scaled_height = this.minecraft.window.getScaledHeight(); int scaled_height = this.minecraft.getWindow().getScaledHeight();
this.addButton(new TexturedButtonWidget(scaled_width / 2 - 20, 0, 20, 20, 0, 106, 20, ButtonWidget.WIDGETS_LOCATION, 256, 256, this.addButton(new TexturedButtonWidget(scaled_width / 2 - 20, 0, 20, 20, 0, 106, 20, ButtonWidget.WIDGETS_LOCATION, 256, 256,
btn -> this.minecraft.openScreen(new ChatScreen("")), "")); btn -> this.minecraft.openScreen(new ChatScreen("")), ""));
this.addButton(new TexturedButtonWidget(scaled_width / 2, 0, 20, 20, 0, 0, 20, WIDGETS_LOCATION, 256, 256, this.addButton(new TexturedButtonWidget(scaled_width / 2, 0, 20, 20, 0, 0, 20, WIDGETS_LOCATION, 256, 256,

View File

@@ -28,25 +28,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(AbstractContainerScreen.class) @Mixin(AbstractContainerScreen.class)
public abstract class AbstractContainerScreenMixin implements AbstractContainerScreenAccessor public abstract class AbstractContainerScreenMixin implements AbstractContainerScreenAccessor
{ {
@Shadow protected int x;
protected int left;
@Shadow protected int y;
protected int top;
@Shadow @Shadow
protected abstract Slot getSlotAt(double xPosition, double yPosition); protected abstract Slot getSlotAt(double xPosition, double yPosition);
@Override @Override
public int get_left() public int get_x()
{ {
return this.left; return this.x;
} }
@Override @Override
public int get_top() public int get_y()
{ {
return this.top; return this.y;
} }
@Override @Override
@@ -60,7 +58,7 @@ public abstract class AbstractContainerScreenMixin implements AbstractContainerS
{ {
if (LambdaControls.get().config.get_controls_mode() == ControlsMode.CONTROLLER) { if (LambdaControls.get().config.get_controls_mode() == ControlsMode.CONTROLLER) {
MinecraftClient client = MinecraftClient.getInstance(); 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_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; x += LambdaControls.draw_button_tip(x, y, GLFW.GLFW_GAMEPAD_BUTTON_B, "lambdacontrols.action.exit", true, client) + 10;

View File

@@ -34,7 +34,7 @@ public abstract class MinecraftClientMixin
@Shadow @Shadow
public Screen currentScreen; public Screen currentScreen;
@Inject(method = "init", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
private void on_init(CallbackInfo ci) private void on_init(CallbackInfo ci)
{ {
LambdaControls.get().on_mc_init((MinecraftClient) (Object) this); LambdaControls.get().on_mc_init((MinecraftClient) (Object) this);

View File

@@ -21,14 +21,14 @@ public interface AbstractContainerScreenAccessor
* *
* @return The left coordinate of the GUI. * @return The left coordinate of the GUI.
*/ */
int get_left(); int get_x();
/** /**
* Gets the top coordinate of the GUI. * Gets the top coordinate of the GUI.
* *
* @return The top coordinate of the GUI. * @return The top coordinate of the GUI.
*/ */
int get_top(); int get_y();
/** /**
* Gets the slot at position. * Gets the slot at position.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -3,7 +3,7 @@
"id": "lambdacontrols", "id": "lambdacontrols",
"name": "LambdaControls", "name": "LambdaControls",
"version": "${version}", "version": "${version}",
"description": "Add better controls: controller and touchscreen support.", "description": "Adds better controls: controller and touchscreen support.",
"authors": [ "authors": [
"LambdAurora" "LambdAurora"
], ],
@@ -26,8 +26,7 @@
"depends": { "depends": {
"fabricloader": ">=0.4.0", "fabricloader": ">=0.4.0",
"fabric": "*", "fabric": "*",
"minecraft": "1.14.x", "minecraft": "1.15.x"
"cotton-client-commands": ">=0.4.2+1.14.3-SNAPSHOT"
}, },
"suggests": { "suggests": {
"flamingo": "*" "flamingo": "*"