Reformat code and update networking.

This commit is contained in:
LambdAurora
2021-03-17 00:51:34 +01:00
parent f89eebf0e7
commit 400b625716
60 changed files with 504 additions and 837 deletions

View File

@@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.5
loader_version=0.11.3 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version = 1.6.0 mod_version = 1.6.0-dev1
maven_group = dev.lambdaurora.lambdacontrols maven_group = dev.lambdaurora.lambdacontrols
archives_base_name = lambdacontrols archives_base_name = lambdacontrols

View File

@@ -22,8 +22,7 @@ import java.util.Optional;
* @version 1.1.0 * @version 1.1.0
* @since 1.0.0 * @since 1.0.0
*/ */
public enum ControlsMode implements Nameable public enum ControlsMode implements Nameable {
{
DEFAULT, DEFAULT,
CONTROLLER, CONTROLLER,
TOUCHSCREEN; TOUCHSCREEN;
@@ -33,8 +32,7 @@ public enum ControlsMode implements Nameable
* *
* @return The next available controls mode. * @return The next available controls mode.
*/ */
public ControlsMode next() public ControlsMode next() {
{
ControlsMode[] v = values(); ControlsMode[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -47,14 +45,12 @@ public enum ControlsMode implements Nameable
* @return The translated key of this controls mode. * @return The translated key of this controls mode.
* @since 1.1.0 * @since 1.1.0
*/ */
public String getTranslationKey() public String getTranslationKey() {
{
return "lambdacontrols.controls_mode." + this.getName(); return "lambdacontrols.controls_mode." + this.getName();
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
@@ -64,8 +60,7 @@ public enum ControlsMode implements Nameable
* @param id The identifier of the controls mode. * @param id The identifier of the controls mode.
* @return The controls mode if found, else empty. * @return The controls mode if found, else empty.
*/ */
public static Optional<ControlsMode> byId(@NotNull String id) public static Optional<ControlsMode> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -32,20 +32,18 @@ import java.util.Optional;
* @version 1.6.0 * @version 1.6.0
* @since 1.0.0 * @since 1.0.0
*/ */
public class LambdaControls implements ModInitializer public class LambdaControls implements ModInitializer {
{ private static LambdaControls INSTANCE;
private static LambdaControls INSTANCE; public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(LambdaControlsConstants.CONTROLS_MODE_CHANNEL.toString());
public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(LambdaControlsConstants.CONTROLS_MODE_CHANNEL.toString()); public static final Identifier FEATURE_CHANNEL = new Identifier(LambdaControlsConstants.FEATURE_CHANNEL.toString());
public static final Identifier FEATURE_CHANNEL = new Identifier(LambdaControlsConstants.FEATURE_CHANNEL.toString()); public static final Identifier HELLO_CHANNEL = new Identifier(LambdaControlsConstants.HELLO_CHANNEL.toString());
public static final Identifier HELLO_CHANNEL = new Identifier(LambdaControlsConstants.HELLO_CHANNEL.toString());
public static final TranslatableText NOT_BOUND_TEXT = new TranslatableText("lambdacontrols.not_bound"); public static final TranslatableText NOT_BOUND_TEXT = new TranslatableText("lambdacontrols.not_bound");
public final Logger logger = LogManager.getLogger("LambdaControls"); public final Logger logger = LogManager.getLogger("LambdaControls");
@Override @Override
public void onInitialize() public void onInitialize() {
{
INSTANCE = this; INSTANCE = this;
this.log("Initializing LambdaControls..."); this.log("Initializing LambdaControls...");
@@ -69,8 +67,7 @@ public class LambdaControls implements ModInitializer
* *
* @param info The message to print. * @param info The message to print.
*/ */
public void log(String info) public void log(String info) {
{
this.logger.info("[LambdaControls] " + info); this.logger.info("[LambdaControls] " + info);
} }
@@ -79,8 +76,7 @@ public class LambdaControls implements ModInitializer
* *
* @param warning The warning to print. * @param warning The warning to print.
*/ */
public void warn(String warning) public void warn(String warning) {
{
this.logger.info("[LambdaControls] " + warning); this.logger.info("[LambdaControls] " + warning);
} }
@@ -90,8 +86,7 @@ public class LambdaControls implements ModInitializer
* @param controlsMode The controls mode to send. * @param controlsMode The controls mode to send.
* @return The packet byte buffer. * @return The packet byte buffer.
*/ */
public PacketByteBuf makeControlsModeBuffer(@NotNull ControlsMode controlsMode) public PacketByteBuf makeControlsModeBuffer(@NotNull ControlsMode controlsMode) {
{
Objects.requireNonNull(controlsMode, "Controls mode cannot be null."); Objects.requireNonNull(controlsMode, "Controls mode cannot be null.");
return new PacketByteBuf(Unpooled.buffer()).writeString(controlsMode.getName(), 32); return new PacketByteBuf(Unpooled.buffer()).writeString(controlsMode.getName(), 32);
} }
@@ -102,16 +97,14 @@ public class LambdaControls implements ModInitializer
* @param feature The feature data to send. * @param feature The feature data to send.
* @return The packet byte buffer. * @return The packet byte buffer.
*/ */
public PacketByteBuf makeFeatureBuffer(@NotNull LambdaControlsFeature feature) public PacketByteBuf makeFeatureBuffer(@NotNull LambdaControlsFeature feature) {
{
Objects.requireNonNull(feature, "Feature cannot be null."); Objects.requireNonNull(feature, "Feature cannot be null.");
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()).writeString(feature.getName(), 64); PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()).writeString(feature.getName(), 64);
buffer.writeBoolean(feature.isAllowed()); buffer.writeBoolean(feature.isAllowed());
return buffer; return buffer;
} }
public PacketByteBuf makeHello(@NotNull ControlsMode controlsMode) public PacketByteBuf makeHello(@NotNull ControlsMode controlsMode) {
{
String version = ""; String version = "";
Optional<ModContainer> container; Optional<ModContainer> container;
if ((container = FabricLoader.getInstance().getModContainer(LambdaControlsConstants.NAMESPACE)).isPresent()) { if ((container = FabricLoader.getInstance().getModContainer(LambdaControlsConstants.NAMESPACE)).isPresent()) {
@@ -125,8 +118,7 @@ public class LambdaControls implements ModInitializer
* *
* @return The LambdaControls instance. * @return The LambdaControls instance.
*/ */
public static LambdaControls get() public static LambdaControls get() {
{
return INSTANCE; return INSTANCE;
} }
} }

View File

@@ -18,10 +18,9 @@ import org.aperlambda.lambdacommon.Identifier;
* @version 1.1.0 * @version 1.1.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsConstants public class LambdaControlsConstants {
{ public static final String NAMESPACE = "lambdacontrols";
public static final String NAMESPACE = "lambdacontrols";
public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(NAMESPACE, "controls_mode"); public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(NAMESPACE, "controls_mode");
public static final Identifier FEATURE_CHANNEL = new Identifier(NAMESPACE, "feature"); public static final Identifier FEATURE_CHANNEL = new Identifier(NAMESPACE, "feature");
public static final Identifier HELLO_CHANNEL = new Identifier(NAMESPACE, "hello"); public static final Identifier HELLO_CHANNEL = new Identifier(NAMESPACE, "hello");
} }

View File

@@ -24,37 +24,33 @@ import java.util.Optional;
* @version 1.5.0 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsFeature implements Nameable public class LambdaControlsFeature implements Nameable {
{ private static final List<LambdaControlsFeature> FEATURES = new ArrayList<>();
private static final List<LambdaControlsFeature> FEATURES = new ArrayList<>(); public static final LambdaControlsFeature FAST_BLOCK_PLACING = new LambdaControlsFeature("fast_block_placing", true, true);
public static final LambdaControlsFeature FAST_BLOCK_PLACING = new LambdaControlsFeature("fast_block_placing", true, true); public static final LambdaControlsFeature HORIZONTAL_REACHAROUND = new LambdaControlsFeature("horizontal_reacharound", true, false);
public static final LambdaControlsFeature HORIZONTAL_REACHAROUND = new LambdaControlsFeature("horizontal_reacharound", true, false); public static final LambdaControlsFeature VERTICAL_REACHAROUND = new LambdaControlsFeature("vertical_reacharound", true, false);
public static final LambdaControlsFeature VERTICAL_REACHAROUND = new LambdaControlsFeature("vertical_reacharound", true, false);
private final String key; private final String key;
private final boolean defaultAllowed; private final boolean defaultAllowed;
private boolean allowed; private boolean allowed;
private final boolean defaultEnabled; private final boolean defaultEnabled;
private boolean enabled; private boolean enabled;
public LambdaControlsFeature(@NotNull String key, boolean allowed, boolean enabled) public LambdaControlsFeature(@NotNull String key, boolean allowed, boolean enabled) {
{
Objects.requireNonNull(key, "Feature key cannot be null."); Objects.requireNonNull(key, "Feature key cannot be null.");
this.key = key; this.key = key;
this.setAllowed(this.defaultAllowed = allowed); this.setAllowed(this.defaultAllowed = allowed);
this.setEnabled(this.defaultEnabled = enabled); this.setEnabled(this.defaultEnabled = enabled);
} }
public LambdaControlsFeature(@NotNull String key) public LambdaControlsFeature(@NotNull String key) {
{
this(key, false, false); this(key, false, false);
} }
/** /**
* Allows the feature. * Allows the feature.
*/ */
public void allow() public void allow() {
{
this.setAllowed(true); this.setAllowed(true);
} }
@@ -63,8 +59,7 @@ public class LambdaControlsFeature implements Nameable
* *
* @return True if this feature is allowed, else false. * @return True if this feature is allowed, else false.
*/ */
public boolean isAllowed() public boolean isAllowed() {
{
return this.allowed; return this.allowed;
} }
@@ -73,16 +68,14 @@ public class LambdaControlsFeature implements Nameable
* *
* @param allowed True if this feature is allowed, else false. * @param allowed True if this feature is allowed, else false.
*/ */
public void setAllowed(boolean allowed) public void setAllowed(boolean allowed) {
{
this.allowed = allowed; this.allowed = allowed;
} }
/** /**
* Resets allowed state to default. * Resets allowed state to default.
*/ */
public void resetAllowed() public void resetAllowed() {
{
this.setAllowed(this.defaultAllowed); this.setAllowed(this.defaultAllowed);
} }
@@ -91,8 +84,7 @@ public class LambdaControlsFeature implements Nameable
* *
* @return True if this feature is enabled, else false. * @return True if this feature is enabled, else false.
*/ */
public boolean isEnabled() public boolean isEnabled() {
{
return this.enabled; return this.enabled;
} }
@@ -101,8 +93,7 @@ public class LambdaControlsFeature implements Nameable
* *
* @param enabled True if this feature is enabled, else false. * @param enabled True if this feature is enabled, else false.
*/ */
public void setEnabled(boolean enabled) public void setEnabled(boolean enabled) {
{
this.enabled = enabled; this.enabled = enabled;
} }
@@ -113,28 +104,24 @@ public class LambdaControlsFeature implements Nameable
* @see #isAllowed() * @see #isAllowed()
* @see #isEnabled() * @see #isEnabled()
*/ */
public boolean isAvailable() public boolean isAvailable() {
{
return this.isAllowed() && this.isEnabled(); return this.isAllowed() && this.isEnabled();
} }
/** /**
* Resets the feature to its default values. * Resets the feature to its default values.
*/ */
public void reset() public void reset() {
{
this.resetAllowed(); this.resetAllowed();
this.setEnabled(this.defaultEnabled); this.setEnabled(this.defaultEnabled);
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.key; return this.key;
} }
public static @NotNull Optional<LambdaControlsFeature> fromName(@NotNull String key) public static @NotNull Optional<LambdaControlsFeature> fromName(@NotNull String key) {
{
Objects.requireNonNull(key, "Cannot find features with a null name."); Objects.requireNonNull(key, "Cannot find features with a null name.");
return FEATURES.parallelStream().filter(feature -> feature.getName().equals(key)).findFirst(); return FEATURES.parallelStream().filter(feature -> feature.getName().equals(key)).findFirst();
} }
@@ -142,16 +129,14 @@ public class LambdaControlsFeature implements Nameable
/** /**
* Resets all features to their default values. * Resets all features to their default values.
*/ */
public static void resetAll() public static void resetAll() {
{
FEATURES.parallelStream().forEach(LambdaControlsFeature::reset); FEATURES.parallelStream().forEach(LambdaControlsFeature::reset);
} }
/** /**
* Resets all features to allow state. * Resets all features to allow state.
*/ */
public static void resetAllAllowed() public static void resetAllAllowed() {
{
FEATURES.parallelStream().forEach(LambdaControlsFeature::resetAllowed); FEATURES.parallelStream().forEach(LambdaControlsFeature::resetAllowed);
} }

View File

@@ -16,8 +16,7 @@ package dev.lambdaurora.lambdacontrols.client;
* @version 1.1.0 * @version 1.1.0
* @since 1.1.0 * @since 1.1.0
*/ */
public enum ButtonState public enum ButtonState {
{
NONE(0), NONE(0),
PRESS(1), PRESS(1),
RELEASE(2), RELEASE(2),
@@ -25,8 +24,7 @@ public enum ButtonState
public final int id; public final int id;
ButtonState(int id) ButtonState(int id) {
{
this.id = id; this.id = id;
} }
@@ -35,8 +33,7 @@ public enum ButtonState
* *
* @return True if this state is a pressed state, else false. * @return True if this state is a pressed state, else false.
*/ */
public boolean isPressed() public boolean isPressed() {
{
return this == PRESS || this == REPEAT; return this == PRESS || this == REPEAT;
} }
@@ -45,8 +42,7 @@ public enum ButtonState
* *
* @return True if this state is an unpressed state, else false. * @return True if this state is an unpressed state, else false.
*/ */
public boolean isUnpressed() public boolean isUnpressed() {
{
return this == RELEASE || this == NONE; return this == RELEASE || this == NONE;
} }
} }

View File

@@ -25,8 +25,7 @@ import java.util.Optional;
* @version 1.4.3 * @version 1.4.3
* @since 1.0.0 * @since 1.0.0
*/ */
public enum ControllerType implements Nameable public enum ControllerType implements Nameable {
{
DEFAULT(0), DEFAULT(0),
DUALSHOCK(1), DUALSHOCK(1),
SWITCH(2), SWITCH(2),
@@ -35,17 +34,15 @@ public enum ControllerType implements Nameable
STEAM(5), STEAM(5),
OUYA(6); OUYA(6);
private final int id; private final int id;
private final Text text; private final Text text;
ControllerType(int id) ControllerType(int id) {
{
this.id = id; this.id = id;
this.text = new TranslatableText("lambdacontrols.controller_type." + this.getName()); this.text = new TranslatableText("lambdacontrols.controller_type." + this.getName());
} }
ControllerType(int id, @NotNull Text text) ControllerType(int id, @NotNull Text text) {
{
this.id = id; this.id = id;
this.text = text; this.text = text;
} }
@@ -55,8 +52,7 @@ public enum ControllerType implements Nameable
* *
* @return The controller type's identifier. * @return The controller type's identifier.
*/ */
public int getId() public int getId() {
{
return this.id; return this.id;
} }
@@ -65,8 +61,7 @@ public enum ControllerType implements Nameable
* *
* @return The next available controller type. * @return The next available controller type.
*/ */
public @NotNull ControllerType next() public @NotNull ControllerType next() {
{
ControllerType[] v = values(); ControllerType[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -78,14 +73,12 @@ public enum ControllerType implements Nameable
* *
* @return The translated text of this controller type. * @return The translated text of this controller type.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
@@ -95,8 +88,7 @@ public enum ControllerType implements Nameable
* @param id The identifier of the controller type. * @param id The identifier of the controller type.
* @return The controller type if found, else empty. * @return The controller type if found, else empty.
*/ */
public static @NotNull Optional<ControllerType> byId(@NotNull String id) public static @NotNull Optional<ControllerType> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -24,15 +24,13 @@ import java.util.Optional;
* @version 1.4.0 * @version 1.4.0
* @since 1.0.0 * @since 1.0.0
*/ */
public enum HudSide implements Nameable public enum HudSide implements Nameable {
{
LEFT, LEFT,
RIGHT; RIGHT;
private final Text text; private final Text text;
HudSide() HudSide() {
{
this.text = new TranslatableText(this.getTranslationKey()); this.text = new TranslatableText(this.getTranslationKey());
} }
@@ -41,8 +39,7 @@ public enum HudSide implements Nameable
* *
* @return The next available side. * @return The next available side.
*/ */
public @NotNull HudSide next() public @NotNull HudSide next() {
{
HudSide[] v = values(); HudSide[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -54,8 +51,7 @@ public enum HudSide implements Nameable
* *
* @return The translation key of this hude side. * @return The translation key of this hude side.
*/ */
public @NotNull String getTranslationKey() public @NotNull String getTranslationKey() {
{
return "lambdacontrols.hud_side." + this.getName(); return "lambdacontrols.hud_side." + this.getName();
} }
@@ -64,14 +60,12 @@ public enum HudSide implements Nameable
* *
* @return The translated text of this hud side. * @return The translated text of this hud side.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
@@ -81,8 +75,7 @@ public enum HudSide implements Nameable
* @param id The identifier of the hud side. * @param id The identifier of the hud side.
* @return The hud side if found, else empty. * @return The hud side if found, else empty.
*/ */
public static @NotNull Optional<HudSide> byId(@NotNull String id) public static @NotNull Optional<HudSide> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -10,24 +10,26 @@
package dev.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import dev.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import dev.lambdaurora.lambdacontrols.LambdaControls;
import dev.lambdaurora.lambdacontrols.LambdaControlsConstants; import dev.lambdaurora.lambdacontrols.LambdaControlsConstants;
import dev.lambdaurora.lambdacontrols.LambdaControlsFeature; import dev.lambdaurora.lambdacontrols.LambdaControlsFeature;
import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsHud; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsHud;
import dev.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay; import dev.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay;
import dev.lambdaurora.lambdacontrols.client.ring.KeyBindingRingAction; import dev.lambdaurora.lambdacontrols.client.ring.KeyBindingRingAction;
import dev.lambdaurora.lambdacontrols.client.ring.LambdaRing; import dev.lambdaurora.lambdacontrols.client.ring.LambdaRing;
import dev.lambdaurora.lambdacontrols.LambdaControls;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.spruceui.event.OpenScreenCallback; import me.lambdaurora.spruceui.event.OpenScreenCallback;
import me.lambdaurora.spruceui.hud.HudManager; import me.lambdaurora.spruceui.hud.HudManager;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
@@ -43,36 +45,34 @@ import java.io.File;
* Represents the LambdaControls client mod. * Represents the LambdaControls client mod.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.5.0 * @version 1.6.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsClient extends LambdaControls implements ClientModInitializer public class LambdaControlsClient extends LambdaControls implements ClientModInitializer {
{ private static LambdaControlsClient INSTANCE;
private static LambdaControlsClient INSTANCE; public static final KeyBinding BINDING_LOOK_UP = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_up"),
public static final KeyBinding BINDING_LOOK_UP = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_up"),
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_8, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_8, "key.categories.movement");
public static final KeyBinding BINDING_LOOK_RIGHT = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_right"), public static final KeyBinding BINDING_LOOK_RIGHT = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_right"),
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_6, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_6, "key.categories.movement");
public static final KeyBinding BINDING_LOOK_DOWN = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_down"), public static final KeyBinding BINDING_LOOK_DOWN = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_down"),
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_2, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_2, "key.categories.movement");
public static final KeyBinding BINDING_LOOK_LEFT = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_left"), public static final KeyBinding BINDING_LOOK_LEFT = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_left"),
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_4, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_4, "key.categories.movement");
/*public static final KeyBinding BINDING_RING = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "ring"), /*public static final KeyBinding BINDING_RING = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "ring"),
InputUtil.Type.MOUSE, GLFW.GLFW_MOUSE_BUTTON_5, "key.categories.misc");*/ InputUtil.Type.MOUSE, GLFW.GLFW_MOUSE_BUTTON_5, "key.categories.misc");*/
public static final Identifier CONTROLLER_BUTTONS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_buttons.png"); public static final Identifier CONTROLLER_BUTTONS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_buttons.png");
public static final Identifier CONTROLLER_AXIS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_axis.png"); public static final Identifier CONTROLLER_AXIS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_axis.png");
public static final Identifier CURSOR_TEXTURE = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/cursor.png"); public static final Identifier CURSOR_TEXTURE = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/cursor.png");
public final static File MAPPINGS_FILE = new File("config/gamecontrollerdb.txt"); public final static File MAPPINGS_FILE = new File("config/gamecontrollerdb.txt");
public final LambdaControlsConfig config = new LambdaControlsConfig(this); public final LambdaControlsConfig config = new LambdaControlsConfig(this);
public final LambdaInput input = new LambdaInput(this); public final LambdaInput input = new LambdaInput(this);
public final LambdaRing ring = new LambdaRing(this); public final LambdaRing ring = new LambdaRing(this);
public final LambdaReacharound reacharound = new LambdaReacharound(); public final LambdaReacharound reacharound = new LambdaReacharound();
private LambdaControlsHud hud; private LambdaControlsHud hud;
private ControlsMode previousControlsMode; private ControlsMode previousControlsMode;
@Override @Override
public void onInitializeClient() public void onInitializeClient() {
{
INSTANCE = this; INSTANCE = this;
KeyBindingHelper.registerKeyBinding(BINDING_LOOK_UP); KeyBindingHelper.registerKeyBinding(BINDING_LOOK_UP);
KeyBindingHelper.registerKeyBinding(BINDING_LOOK_RIGHT); KeyBindingHelper.registerKeyBinding(BINDING_LOOK_RIGHT);
@@ -82,13 +82,19 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
this.ring.registerAction("keybinding", KeyBindingRingAction.FACTORY); this.ring.registerAction("keybinding", KeyBindingRingAction.FACTORY);
ClientSidePacketRegistry.INSTANCE.register(CONTROLS_MODE_CHANNEL, (context, attachedData) -> context.getTaskQueue() ClientPlayNetworking.registerGlobalReceiver(CONTROLS_MODE_CHANNEL, (client, handler, buf, responseSender) -> {
.execute(() -> ClientSidePacketRegistry.INSTANCE.sendToServer(CONTROLS_MODE_CHANNEL, this.makeControlsModeBuffer(this.config.getControlsMode())))); responseSender.sendPacket(CONTROLS_MODE_CHANNEL, this.makeControlsModeBuffer(this.config.getControlsMode()));
ClientSidePacketRegistry.INSTANCE.register(FEATURE_CHANNEL, (context, attachedData) -> {
String name = attachedData.readString(64);
boolean allowed = attachedData.readBoolean();
LambdaControlsFeature.fromName(name).ifPresent(feature -> context.getTaskQueue().execute(() -> feature.setAllowed(allowed)));
}); });
ClientPlayNetworking.registerGlobalReceiver(FEATURE_CHANNEL, (client, handler, buf, responseSender) -> {
String name = buf.readString(64);
boolean allowed = buf.readBoolean();
LambdaControlsFeature.fromName(name).ifPresent(feature -> client.execute(() -> feature.setAllowed(allowed)));
});
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
sender.sendPacket(HELLO_CHANNEL, this.makeHello(this.config.getControlsMode()));
sender.sendPacket(CONTROLS_MODE_CHANNEL, this.makeControlsModeBuffer(this.config.getControlsMode()));
});
ClientPlayConnectionEvents.DISCONNECT.register(this::onLeave);
ClientTickEvents.START_CLIENT_TICK.register(this.reacharound::tick); ClientTickEvents.START_CLIENT_TICK.register(this.reacharound::tick);
ClientTickEvents.END_CLIENT_TICK.register(this::onTick); ClientTickEvents.END_CLIENT_TICK.register(this::onTick);
@@ -110,8 +116,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
/** /**
* This method is called when Minecraft is initializing. * This method is called when Minecraft is initializing.
*/ */
public void onMcInit(@NotNull MinecraftClient client) public void onMcInit(@NotNull MinecraftClient client) {
{
ButtonBinding.init(client.options); ButtonBinding.init(client.options);
this.config.load(); this.config.load();
this.hud.setVisible(this.config.isHudEnabled()); this.hud.setVisible(this.config.isHudEnabled());
@@ -135,10 +140,9 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
/** /**
* This method is called every Minecraft tick. * This method is called every Minecraft tick.
* *
* @param client The client instance. * @param client the client instance
*/ */
public void onTick(@NotNull MinecraftClient client) public void onTick(@NotNull MinecraftClient client) {
{
this.input.tick(client); this.input.tick(client);
if (this.config.getControlsMode() == ControlsMode.CONTROLLER && (client.isWindowFocused() || this.config.hasUnfocusedInput())) if (this.config.getControlsMode() == ControlsMode.CONTROLLER && (client.isWindowFocused() || this.config.hasUnfocusedInput()))
this.input.tickController(client); this.input.tickController(client);
@@ -148,24 +152,21 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
}*/ }*/
} }
public void onRender(MinecraftClient client) public void onRender(MinecraftClient client) {
{
this.input.onRender(client.getTickDelta(), client); this.input.onRender(client.getTickDelta(), client);
} }
/** /**
* Called when leaving a server. * Called when leaving a server.
*/ */
public void onLeave() public void onLeave(ClientPlayNetworkHandler handler, MinecraftClient client) {
{
LambdaControlsFeature.resetAllAllowed(); LambdaControlsFeature.resetAllAllowed();
} }
/** /**
* Switches the controls mode if the auto switch is enabled. * Switches the controls mode if the auto switch is enabled.
*/ */
public void switchControlsMode() public void switchControlsMode() {
{
if (this.config.hasAutoSwitchMode()) { if (this.config.hasAutoSwitchMode()) {
if (this.config.getController().isGamepad()) { if (this.config.getController().isGamepad()) {
this.previousControlsMode = this.config.getControlsMode(); this.previousControlsMode = this.config.getControlsMode();
@@ -185,8 +186,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
* *
* @param enabled True if the HUD is enabled, else false. * @param enabled True if the HUD is enabled, else false.
*/ */
public void setHudEnabled(boolean enabled) public void setHudEnabled(boolean enabled) {
{
this.config.setHudEnabled(enabled); this.config.setHudEnabled(enabled);
this.hud.setVisible(enabled); this.hud.setVisible(enabled);
} }
@@ -196,8 +196,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
* *
* @return The LambdaControls client instance. * @return The LambdaControls client instance.
*/ */
public static LambdaControlsClient get() public static LambdaControlsClient get() {
{
return INSTANCE; return INSTANCE;
} }
} }

View File

@@ -20,11 +20,9 @@ import io.github.prospector.modmenu.api.ModMenuApi;
* @version 1.3.0 * @version 1.3.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsModMenu implements ModMenuApi public class LambdaControlsModMenu implements ModMenuApi {
{
@Override @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() public ConfigScreenFactory<?> getModConfigScreenFactory() {
{
return parent -> new LambdaControlsSettingsScreen(parent, false); return parent -> new LambdaControlsSettingsScreen(parent, false);
} }
} }

View File

@@ -217,7 +217,7 @@ public class LambdaInput {
this.mouseSpeedX = this.mouseSpeedY = 0.0F; this.mouseSpeedX = this.mouseSpeedY = 0.0F;
INPUT_MANAGER.resetMousePosition(windowWidth, windowHeight); INPUT_MANAGER.resetMousePosition(windowWidth, windowHeight);
} else if (isScreenInteractive(client.currentScreen) && this.config.hasVirtualMouse()) { } else if (isScreenInteractive(client.currentScreen) && this.config.hasVirtualMouse()) {
((MouseAccessor) client.mouse).lambdacontrols_onCursorPos(client.getWindow().getHandle(), 0, 0); ((MouseAccessor) client.mouse).lambdacontrols$onCursorPos(client.getWindow().getHandle(), 0, 0);
INPUT_MANAGER.resetMouseTarget(client); INPUT_MANAGER.resetMouseTarget(client);
} }
this.inventoryInteractionCooldown = 5; this.inventoryInteractionCooldown = 5;
@@ -378,13 +378,13 @@ public class LambdaInput {
HandledScreen screen = (HandledScreen) client.currentScreen; HandledScreen screen = (HandledScreen) client.currentScreen;
HandledScreenAccessor accessor = (HandledScreenAccessor) screen; HandledScreenAccessor accessor = (HandledScreenAccessor) screen;
Slot slot = ((HandledScreenAccessor) client.currentScreen).lambdacontrols_getSlotAt(x, y); Slot slot = ((HandledScreenAccessor) client.currentScreen).lambdacontrols$getSlotAt(x, y);
int slotId; int slotId;
if (slot == null) { if (slot == null) {
if (client.player.inventory.getCursorStack().isEmpty()) if (client.player.inventory.getCursorStack().isEmpty())
return false; return false;
slotId = accessor.lambdacontrols_isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1; slotId = accessor.lambdacontrols$isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1;
} else { } else {
slotId = slot.id; slotId = slot.id;
} }
@@ -394,7 +394,7 @@ public class LambdaInput {
switch (button) { switch (button) {
case GLFW_GAMEPAD_BUTTON_A: case GLFW_GAMEPAD_BUTTON_A:
if (screen instanceof CreativeInventoryScreen) if (screen instanceof CreativeInventoryScreen)
if (((CreativeInventoryScreenAccessor) screen).lambdacontrols_isCreativeInventorySlot(slot)) if (((CreativeInventoryScreenAccessor) screen).lambdacontrols$isCreativeInventorySlot(slot))
actionType = SlotActionType.CLONE; actionType = SlotActionType.CLONE;
if (slot != null && LambdaControlsCompat.streamCompatHandlers().anyMatch(handler -> handler.isCreativeSlot(screen, slot))) if (slot != null && LambdaControlsCompat.streamCompatHandlers().anyMatch(handler -> handler.isCreativeSlot(screen, slot)))
actionType = SlotActionType.CLONE; actionType = SlotActionType.CLONE;
@@ -409,7 +409,7 @@ public class LambdaInput {
return false; return false;
} }
accessor.lambdacontrols_onMouseClick(slot, slotId, clickData, actionType); accessor.lambdacontrols$onMouseClick(slot, slotId, clickData, actionType);
return true; return true;
} }
@@ -501,7 +501,7 @@ public class LambdaInput {
CreativeInventoryScreen screen = (CreativeInventoryScreen) client.currentScreen; CreativeInventoryScreen screen = (CreativeInventoryScreen) client.currentScreen;
CreativeInventoryScreenAccessor accessor = (CreativeInventoryScreenAccessor) screen; CreativeInventoryScreenAccessor accessor = (CreativeInventoryScreenAccessor) screen;
// @TODO allow rebinding to left stick // @TODO allow rebinding to left stick
if (accessor.lambdacontrols_hasScrollbar() && absValue >= deadZone) { if (accessor.lambdacontrols$hasScrollbar() && absValue >= deadZone) {
screen.mouseScrolled(0.0, 0.0, -value); screen.mouseScrolled(0.0, 0.0, -value);
} }
return; return;
@@ -655,7 +655,7 @@ public class LambdaInput {
this.actionGuiCooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks. this.actionGuiCooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks.
return false; return false;
} else if (element instanceof AlwaysSelectedEntryListWidget) { } else if (element instanceof AlwaysSelectedEntryListWidget) {
((EntryListWidgetAccessor) element).lambdacontrols_moveSelection(right ? EntryListWidget.MoveDirection.UP : EntryListWidget.MoveDirection.DOWN); ((EntryListWidgetAccessor) element).lambdacontrols$moveSelection(right ? EntryListWidget.MoveDirection.UP : EntryListWidget.MoveDirection.DOWN);
return false; return false;
} else if (element instanceof ParentElement) { } else if (element instanceof ParentElement) {
ParentElement entryList = (ParentElement) element; ParentElement entryList = (ParentElement) element;

View File

@@ -33,14 +33,12 @@ import org.jetbrains.annotations.Nullable;
* @version 1.5.0 * @version 1.5.0
* @since 1.3.2 * @since 1.3.2
*/ */
public class LambdaReacharound public class LambdaReacharound {
{ private BlockHitResult lastReacharoundResult = null;
private BlockHitResult lastReacharoundResult = null; private boolean lastReacharoundVertical = false;
private boolean lastReacharoundVertical = false; private boolean onSlab = false;
private boolean onSlab = false;
public void tick(@NotNull MinecraftClient client) public void tick(@NotNull MinecraftClient client) {
{
this.lastReacharoundResult = this.tryVerticalReachAround(client); this.lastReacharoundResult = this.tryVerticalReachAround(client);
if (this.lastReacharoundResult == null) { if (this.lastReacharoundResult == null) {
this.lastReacharoundResult = this.tryHorizontalReachAround(client); this.lastReacharoundResult = this.tryHorizontalReachAround(client);
@@ -53,8 +51,7 @@ public class LambdaReacharound
* *
* @return The last reach around result. * @return The last reach around result.
*/ */
public @Nullable BlockHitResult getLastReacharoundResult() public @Nullable BlockHitResult getLastReacharoundResult() {
{
return this.lastReacharoundResult; return this.lastReacharoundResult;
} }
@@ -63,8 +60,7 @@ public class LambdaReacharound
* *
* @return True if the reach around is vertical. * @return True if the reach around is vertical.
*/ */
public boolean isLastReacharoundVertical() public boolean isLastReacharoundVertical() {
{
return this.lastReacharoundVertical; return this.lastReacharoundVertical;
} }
@@ -73,13 +69,11 @@ public class LambdaReacharound
* *
* @return True if reacharound is available, else false. * @return True if reacharound is available, else false.
*/ */
public boolean isReacharoundAvailable() public boolean isReacharoundAvailable() {
{
return LambdaControlsFeature.HORIZONTAL_REACHAROUND.isAvailable() || LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable(); return LambdaControlsFeature.HORIZONTAL_REACHAROUND.isAvailable() || LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable();
} }
private float getPlayerRange(@NotNull MinecraftClient client) private float getPlayerRange(@NotNull MinecraftClient client) {
{
return client.interactionManager != null ? client.interactionManager.getReachDistance() : 0.f; return client.interactionManager != null ? client.interactionManager.getReachDistance() : 0.f;
} }
@@ -89,8 +83,7 @@ public class LambdaReacharound
* @param client The client instance. * @param client The client instance.
* @return A block hit result if vertical reach-around is possible, else null. * @return A block hit result if vertical reach-around is possible, else null.
*/ */
public @Nullable BlockHitResult tryVerticalReachAround(@NotNull MinecraftClient client) public @Nullable BlockHitResult tryVerticalReachAround(@NotNull MinecraftClient client) {
{
if (!LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable()) if (!LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable())
return null; return null;
if (client.player == null || client.world == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.MISS if (client.player == null || client.world == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.MISS
@@ -122,8 +115,7 @@ public class LambdaReacharound
* @param client The client instance. * @param client The client instance.
* @return A block hit result if horizontal reach-around is possible. * @return A block hit result if horizontal reach-around is possible.
*/ */
public @Nullable BlockHitResult tryHorizontalReachAround(@NotNull MinecraftClient client) public @Nullable BlockHitResult tryHorizontalReachAround(@NotNull MinecraftClient client) {
{
if (!LambdaControlsFeature.HORIZONTAL_REACHAROUND.isAvailable()) if (!LambdaControlsFeature.HORIZONTAL_REACHAROUND.isAvailable())
return null; return null;
@@ -156,15 +148,13 @@ public class LambdaReacharound
return null; return null;
} }
public @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @Nullable ItemStack stack) public @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @Nullable ItemStack stack) {
{
if (stack == null || stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) if (stack == null || stack.isEmpty() || !(stack.getItem() instanceof BlockItem))
return result; return result;
return withSideForReacharound(result, Block.getBlockFromItem(stack.getItem())); return withSideForReacharound(result, Block.getBlockFromItem(stack.getItem()));
} }
public @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @NotNull Block block) public @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @NotNull Block block) {
{
if (block instanceof SlabBlock) { if (block instanceof SlabBlock) {
if (this.onSlab) result = result.withSide(Direction.UP); if (this.onSlab) result = result.withSide(Direction.UP);
else result = result.withSide(Direction.DOWN); else result = result.withSide(Direction.DOWN);

View File

@@ -23,18 +23,16 @@ import java.util.Optional;
* @version 1.4.0 * @version 1.4.0
* @since 1.2.0 * @since 1.2.0
*/ */
public enum VirtualMouseSkin implements Nameable public enum VirtualMouseSkin implements Nameable {
{
DEFAULT_LIGHT("default_light"), DEFAULT_LIGHT("default_light"),
DEFAULT_DARK("default_dark"), DEFAULT_DARK("default_dark"),
SECOND_LIGHT("second_light"), SECOND_LIGHT("second_light"),
SECOND_DARK("second_dark"); SECOND_DARK("second_dark");
private final String name; private final String name;
private final Text text; private final Text text;
VirtualMouseSkin(String name) VirtualMouseSkin(String name) {
{
this.name = name; this.name = name;
this.text = new TranslatableText(this.getTranslationKey()); this.text = new TranslatableText(this.getTranslationKey());
} }
@@ -44,8 +42,7 @@ public enum VirtualMouseSkin implements Nameable
* *
* @return The next available virtual mouse skin. * @return The next available virtual mouse skin.
*/ */
public @NotNull VirtualMouseSkin next() public @NotNull VirtualMouseSkin next() {
{
VirtualMouseSkin[] v = values(); VirtualMouseSkin[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -57,8 +54,7 @@ public enum VirtualMouseSkin implements Nameable
* *
* @return The virtual mouse skin's translation key. * @return The virtual mouse skin's translation key.
*/ */
public @NotNull String getTranslationKey() public @NotNull String getTranslationKey() {
{
return "lambdacontrols.virtual_mouse.skin." + this.getName(); return "lambdacontrols.virtual_mouse.skin." + this.getName();
} }
@@ -67,14 +63,12 @@ public enum VirtualMouseSkin implements Nameable
* *
* @return The translated text of this virtual mouse skin. * @return The translated text of this virtual mouse skin.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name; return this.name;
} }
@@ -84,8 +78,7 @@ public enum VirtualMouseSkin implements Nameable
* @param id The identifier of the virtual mouse skin. * @param id The identifier of the virtual mouse skin.
* @return The virtual mouse skin if found, else empty. * @return The virtual mouse skin if found, else empty.
*/ */
public static @NotNull Optional<VirtualMouseSkin> byId(@NotNull String id) public static @NotNull Optional<VirtualMouseSkin> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -26,8 +26,7 @@ import org.jetbrains.annotations.Nullable;
* @version 1.5.0 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public interface CompatHandler public interface CompatHandler {
{
/** /**
* Handles compatibility of a mod. * Handles compatibility of a mod.
* *
@@ -41,8 +40,7 @@ public interface CompatHandler
* @param screen The screen. * @param screen The screen.
* @return True if the mouse is required on the specified screen, else false. * @return True if the mouse is required on the specified screen, else false.
*/ */
default boolean requireMouseOnScreen(Screen screen) default boolean requireMouseOnScreen(Screen screen) {
{
return false; return false;
} }
@@ -55,8 +53,7 @@ public interface CompatHandler
* @return A slot if present, else null. * @return A slot if present, else null.
* @since 1.5.0 * @since 1.5.0
*/ */
default @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) default @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) {
{
return null; return null;
} }
@@ -64,35 +61,32 @@ public interface CompatHandler
* Returns whether the current slot is a creative slot or not. * Returns whether the current slot is a creative slot or not.
* *
* @param screen The screen. * @param screen The screen.
* @param slot The slot to check. * @param slot The slot to check.
* @return True if the slot is a creative slot, else false. * @return True if the slot is a creative slot, else false.
*/ */
default boolean isCreativeSlot(@NotNull HandledScreen screen, @NotNull Slot slot) default boolean isCreativeSlot(@NotNull HandledScreen screen, @NotNull Slot slot) {
{
return false; return false;
} }
/** /**
* Returns a custom translation key to make custom attack action strings on the HUD. * Returns a custom translation key to make custom attack action strings on the HUD.
* *
* @param client The client instance. * @param client The client instance.
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
default String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) default String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
return null; return null;
} }
/** /**
* Returns a custom translation key to make custom use action strings on the HUD. * Returns a custom translation key to make custom use action strings on the HUD.
* *
* @param client The client instance. * @param client The client instance.
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
default String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) default String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
return null; return null;
} }
@@ -103,8 +97,7 @@ public interface CompatHandler
* @param screen The screen. * @param screen The screen.
* @return True if the handle was fired and succeed, else false. * @return True if the handle was fired and succeed, else false.
*/ */
default boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) default boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) {
{
return false; return false;
} }
} }

View File

@@ -25,20 +25,17 @@ import java.util.Optional;
* @version 1.3.2 * @version 1.3.2
* @since 1.3.2 * @since 1.3.2
*/ */
public class HQMCompat implements CompatHandler public class HQMCompat implements CompatHandler {
{ public static final String GUI_BASE_CLASS_PATH = "hardcorequesting.client.interfaces.GuiBase";
public static final String GUI_BASE_CLASS_PATH = "hardcorequesting.client.interfaces.GuiBase"; private Optional<Class<?>> guiBaseClass;
private Optional<Class<?>> guiBaseClass;
@Override @Override
public void handle(@NotNull LambdaControlsClient mod) public void handle(@NotNull LambdaControlsClient mod) {
{
this.guiBaseClass = LambdaReflection.getClass(GUI_BASE_CLASS_PATH); this.guiBaseClass = LambdaReflection.getClass(GUI_BASE_CLASS_PATH);
} }
@Override @Override
public boolean requireMouseOnScreen(Screen screen) public boolean requireMouseOnScreen(Screen screen) {
{
return this.guiBaseClass.map(clazz -> clazz.isInstance(screen)).orElse(false); return this.guiBaseClass.map(clazz -> clazz.isInstance(screen)).orElse(false);
} }
} }

View File

@@ -31,8 +31,7 @@ import java.util.stream.Stream;
* @version 1.5.0 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsCompat public class LambdaControlsCompat {
{
private static final List<CompatHandler> HANDLERS = new ArrayList<>(); private static final List<CompatHandler> HANDLERS = new ArrayList<>();
/** /**
@@ -40,8 +39,7 @@ public class LambdaControlsCompat
* *
* @param mod The mod instance. * @param mod The mod instance.
*/ */
public static void init(@NotNull LambdaControlsClient mod) public static void init(@NotNull LambdaControlsClient mod) {
{
if (FabricLoader.getInstance().isModLoaded("okzoomer")) { if (FabricLoader.getInstance().isModLoaded("okzoomer")) {
mod.log("Adding okzoomer compatibility..."); mod.log("Adding okzoomer compatibility...");
HANDLERS.add(new OkZoomerCompat()); HANDLERS.add(new OkZoomerCompat());
@@ -63,8 +61,7 @@ public class LambdaControlsCompat
* *
* @param handler The compatibility handler to register. * @param handler The compatibility handler to register.
*/ */
public static void registerCompatHandler(@NotNull CompatHandler handler) public static void registerCompatHandler(@NotNull CompatHandler handler) {
{
HANDLERS.add(handler); HANDLERS.add(handler);
} }
@@ -73,8 +70,7 @@ public class LambdaControlsCompat
* *
* @return A stream of compatibility handlers. * @return A stream of compatibility handlers.
*/ */
public static Stream<CompatHandler> streamCompatHandlers() public static Stream<CompatHandler> streamCompatHandlers() {
{
return HANDLERS.stream(); return HANDLERS.stream();
} }
@@ -84,8 +80,7 @@ public class LambdaControlsCompat
* @param screen The screen. * @param screen The screen.
* @return True if the mouse is requried on the specified screen, else false. * @return True if the mouse is requried on the specified screen, else false.
*/ */
public static boolean requireMouseOnScreen(Screen screen) public static boolean requireMouseOnScreen(Screen screen) {
{
return HANDLERS.stream().anyMatch(handler -> handler.requireMouseOnScreen(screen)); return HANDLERS.stream().anyMatch(handler -> handler.requireMouseOnScreen(screen));
} }
@@ -97,8 +92,7 @@ public class LambdaControlsCompat
* @param mouseY The mouse Y-coordinate. * @param mouseY The mouse Y-coordinate.
* @return A slot if present, else null. * @return A slot if present, else null.
*/ */
public static @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) public static @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
Pair<Integer, Integer> slot = handler.getSlotAt(screen, mouseX, mouseY); Pair<Integer, Integer> slot = handler.getSlotAt(screen, mouseX, mouseY);
if (slot != null) if (slot != null)
@@ -110,12 +104,11 @@ public class LambdaControlsCompat
/** /**
* Returns a custom translation key to make custom attack action strings on the HUD. * Returns a custom translation key to make custom attack action strings on the HUD.
* *
* @param client The client instance. * @param client The client instance.
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
public static String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) public static String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
String action = handler.getAttackActionAt(client, placeResult); String action = handler.getAttackActionAt(client, placeResult);
if (action != null) { if (action != null) {
@@ -128,12 +121,11 @@ public class LambdaControlsCompat
/** /**
* Returns a custom translation key to make custom use action strings on the HUD. * Returns a custom translation key to make custom use action strings on the HUD.
* *
* @param client The client instance. * @param client The client instance.
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
public static String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) public static String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
String action = handler.getUseActionAt(client, placeResult); String action = handler.getUseActionAt(client, placeResult);
if (action != null) { if (action != null) {
@@ -150,8 +142,7 @@ public class LambdaControlsCompat
* @param screen The screen. * @param screen The screen.
* @return True if the handle was fired and succeed, else false. * @return True if the handle was fired and succeed, else false.
*/ */
public static boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) public static boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
if (handler.handleMenuBack(client, screen)) if (handler.handleMenuBack(client, screen))
return true; return true;
@@ -164,8 +155,7 @@ public class LambdaControlsCompat
* *
* @return True if Roughly Enough Items is present, else false. * @return True if Roughly Enough Items is present, else false.
*/ */
public static boolean isReiPresent() public static boolean isReiPresent() {
{
return FabricLoader.getInstance().isModLoaded("roughlyenoughitems"); return FabricLoader.getInstance().isModLoaded("roughlyenoughitems");
} }
} }

View File

@@ -25,58 +25,48 @@ import java.util.Set;
* @version 1.5.0 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
public class LambdaControlsMixinPlugin implements IMixinConfigPlugin public class LambdaControlsMixinPlugin implements IMixinConfigPlugin {
{
private final HashMap<String, Boolean> conditionalMixins = new HashMap<>(); private final HashMap<String, Boolean> conditionalMixins = new HashMap<>();
public LambdaControlsMixinPlugin() public LambdaControlsMixinPlugin() {
{
this.putConditionalMixin("EntryListWidgetAccessor", LambdaControlsCompat.isReiPresent()); this.putConditionalMixin("EntryListWidgetAccessor", LambdaControlsCompat.isReiPresent());
this.putConditionalMixin("EntryWidgetAccessor", LambdaControlsCompat.isReiPresent()); this.putConditionalMixin("EntryWidgetAccessor", LambdaControlsCompat.isReiPresent());
this.putConditionalMixin("RecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent()); this.putConditionalMixin("RecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent());
this.putConditionalMixin("VillagerRecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent()); this.putConditionalMixin("VillagerRecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent());
} }
private void putConditionalMixin(@NotNull String path, boolean condition) private void putConditionalMixin(@NotNull String path, boolean condition) {
{
this.conditionalMixins.put("me.lambdaurora.lambdacontrols.client.compat.mixin." + path, condition); this.conditionalMixins.put("me.lambdaurora.lambdacontrols.client.compat.mixin." + path, condition);
} }
@Override @Override
public void onLoad(String mixinPackage) public void onLoad(String mixinPackage) {
{
} }
@Override @Override
public String getRefMapperConfig() public String getRefMapperConfig() {
{
return null; return null;
} }
@Override @Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
{
return this.conditionalMixins.getOrDefault(mixinClassName, Boolean.TRUE); return this.conditionalMixins.getOrDefault(mixinClassName, Boolean.TRUE);
} }
@Override @Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
{
} }
@Override @Override
public List<String> getMixins() public List<String> getMixins() {
{
return null; return null;
} }
@Override @Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
{
} }
@Override @Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
{
} }
} }

View File

@@ -9,9 +9,9 @@
package dev.lambdaurora.lambdacontrols.client.compat; package dev.lambdaurora.lambdacontrols.client.compat;
import io.github.joaoh1.okzoomer.client.keybinds.ZoomKeybinds;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import io.github.joaoh1.okzoomer.client.keybinds.ZoomKeybinds;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@@ -22,11 +22,9 @@ import org.lwjgl.glfw.GLFW;
* @version 1.4.3 * @version 1.4.3
* @since 1.1.0 * @since 1.1.0
*/ */
public class OkZoomerCompat implements CompatHandler public class OkZoomerCompat implements CompatHandler {
{
@Override @Override
public void handle(@NotNull LambdaControlsClient mod) public void handle(@NotNull LambdaControlsClient mod) {
{
new ButtonBinding.Builder("zoom") new ButtonBinding.Builder("zoom")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X) .buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X)
.onlyInGame() .onlyInGame()
@@ -36,26 +34,26 @@ public class OkZoomerCompat implements CompatHandler
.register(); .register();
if (ZoomKeybinds.areExtraKeybindsEnabled()) { if (ZoomKeybinds.areExtraKeybindsEnabled()) {
new ButtonBinding.Builder("zoom_in") new ButtonBinding.Builder("zoom_in")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true)) .buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true))
.onlyInGame() .onlyInGame()
.cooldown(true) .cooldown(true)
.category(ButtonBinding.MISC_CATEGORY) .category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.increaseZoomKey) .linkKeybind(ZoomKeybinds.increaseZoomKey)
.register(); .register();
new ButtonBinding.Builder("zoom_out") new ButtonBinding.Builder("zoom_out")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true)) .buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))
.onlyInGame() .onlyInGame()
.cooldown(true) .cooldown(true)
.category(ButtonBinding.MISC_CATEGORY) .category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.decreaseZoomKey) .linkKeybind(ZoomKeybinds.decreaseZoomKey)
.register(); .register();
new ButtonBinding.Builder("zoom_reset") new ButtonBinding.Builder("zoom_reset")
.onlyInGame() .onlyInGame()
.cooldown(true) .cooldown(true)
.category(ButtonBinding.MISC_CATEGORY) .category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.resetZoomKey) .linkKeybind(ZoomKeybinds.resetZoomKey)
.register(); .register();
} }
} }
} }

View File

@@ -50,14 +50,12 @@ import static org.lwjgl.glfw.GLFW.*;
* @version 1.5.0 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
public class ReiCompat implements CompatHandler public class ReiCompat implements CompatHandler {
{
private static final Pair<Integer, Integer> INVALID_SLOT = new Pair<>(-1, -1); private static final Pair<Integer, Integer> INVALID_SLOT = new Pair<>(-1, -1);
private static EntryListWidget ENTRY_LIST_WIDGET; private static EntryListWidget ENTRY_LIST_WIDGET;
@Override @Override
public void handle(@NotNull LambdaControlsClient mod) public void handle(@NotNull LambdaControlsClient mod) {
{
ButtonBinding.builder(new Identifier("rei", "category_back")) ButtonBinding.builder(new Identifier("rei", "category_back"))
.buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER) .buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
.filter((client, binding) -> isViewingScreen(client.currentScreen)) .filter((client, binding) -> isViewingScreen(client.currentScreen))
@@ -114,14 +112,12 @@ public class ReiCompat implements CompatHandler
} }
@Override @Override
public boolean requireMouseOnScreen(Screen screen) public boolean requireMouseOnScreen(Screen screen) {
{
return isViewingScreen(screen) || screen instanceof PreRecipeViewingScreen; return isViewingScreen(screen) || screen instanceof PreRecipeViewingScreen;
} }
@Override @Override
public @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) public @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) {
{
Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay(); Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay();
if (overlay.isPresent() && overlay.get().isInside(mouseX, mouseY)) { if (overlay.isPresent() && overlay.get().isInside(mouseX, mouseY)) {
EntryListWidget widget = getEntryListWidget(); EntryListWidget widget = getEntryListWidget();
@@ -141,8 +137,7 @@ public class ReiCompat implements CompatHandler
return null; return null;
} }
private @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Element element, int mouseX, int mouseY, boolean allowEmpty) private @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Element element, int mouseX, int mouseY, boolean allowEmpty) {
{
if (element instanceof EntryWidget) { if (element instanceof EntryWidget) {
EntryWidget entry = (EntryWidget) element; EntryWidget entry = (EntryWidget) element;
if (entry.containsMouse(mouseX, mouseY)) { if (entry.containsMouse(mouseX, mouseY)) {
@@ -167,14 +162,12 @@ public class ReiCompat implements CompatHandler
return null; return null;
} }
private static boolean isViewingScreen(Screen screen) private static boolean isViewingScreen(Screen screen) {
{
return screen instanceof RecipeViewingScreen || screen instanceof VillagerRecipeViewingScreen; return screen instanceof RecipeViewingScreen || screen instanceof VillagerRecipeViewingScreen;
} }
@Override @Override
public boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) public boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) {
{
if (!isViewingScreen(screen)) if (!isViewingScreen(screen))
return false; return false;
@@ -183,8 +176,7 @@ public class ReiCompat implements CompatHandler
return true; return true;
} }
private static EntryListWidget getEntryListWidget() private static EntryListWidget getEntryListWidget() {
{
if (ENTRY_LIST_WIDGET == null) { if (ENTRY_LIST_WIDGET == null) {
ENTRY_LIST_WIDGET = LambdaReflection.getFirstFieldOfType(ContainerScreenOverlay.class, EntryListWidget.class) ENTRY_LIST_WIDGET = LambdaReflection.getFirstFieldOfType(ContainerScreenOverlay.class, EntryListWidget.class)
.map(field -> (EntryListWidget) LambdaReflection.getFieldValue(null, field)) .map(field -> (EntryListWidget) LambdaReflection.getFieldValue(null, field))
@@ -193,8 +185,7 @@ public class ReiCompat implements CompatHandler
return ENTRY_LIST_WIDGET; return ENTRY_LIST_WIDGET;
} }
private static @Nullable EntryStack getCurrentStack(@NotNull MinecraftClient client) private static @Nullable EntryStack getCurrentStack(@NotNull MinecraftClient client) {
{
double x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth(); double x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth();
double y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight(); double y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
@@ -216,8 +207,7 @@ public class ReiCompat implements CompatHandler
return getCurrentStack(widget, x, y); return getCurrentStack(widget, x, y);
} }
private static @Nullable EntryStack getCurrentStack(@NotNull Element element, double mouseX, double mouseY) private static @Nullable EntryStack getCurrentStack(@NotNull Element element, double mouseX, double mouseY) {
{
if (element instanceof EntryWidget) { if (element instanceof EntryWidget) {
EntryWidget entry = (EntryWidget) element; EntryWidget entry = (EntryWidget) element;
if (entry.containsMouse(mouseX, mouseY)) if (entry.containsMouse(mouseX, mouseY))
@@ -239,8 +229,7 @@ public class ReiCompat implements CompatHandler
return null; return null;
} }
private static PressAction handleShowRecipeUsage(boolean usage) private static PressAction handleShowRecipeUsage(boolean usage) {
{
return (client, button, value, action) -> { return (client, button, value, action) -> {
if (action.isUnpressed()) if (action.isUnpressed())
return false; return false;
@@ -263,8 +252,7 @@ public class ReiCompat implements CompatHandler
}; };
} }
private static PressAction handlePage(boolean next) private static PressAction handlePage(boolean next) {
{
return (client, button, value, action) -> { return (client, button, value, action) -> {
if (action == ButtonState.RELEASE) if (action == ButtonState.RELEASE)
return false; return false;
@@ -293,8 +281,7 @@ public class ReiCompat implements CompatHandler
* @param next True if the action is to switch to the next tab. * @param next True if the action is to switch to the next tab.
* @return The handler. * @return The handler.
*/ */
private static PressAction handleTab(boolean next) private static PressAction handleTab(boolean next) {
{
return (client, button, value, action) -> { return (client, button, value, action) -> {
if (action != ButtonState.RELEASE) if (action != ButtonState.RELEASE)
return false; return false;
@@ -319,8 +306,7 @@ public class ReiCompat implements CompatHandler
}; };
} }
private static PressAction handleRecipe(boolean next) private static PressAction handleRecipe(boolean next) {
{
return (client, button, value, action) -> { return (client, button, value, action) -> {
if (action.isUnpressed()) if (action.isUnpressed())
return false; return false;
@@ -363,8 +349,7 @@ public class ReiCompat implements CompatHandler
}; };
} }
private static int getNextIndex(int currentIndex, int size, boolean next) private static int getNextIndex(int currentIndex, int size, boolean next) {
{
int nextIndex = currentIndex + (next ? 1 : -1); int nextIndex = currentIndex + (next ? 1 : -1);
if (nextIndex < 0) if (nextIndex < 0)
nextIndex = size - 1; nextIndex = size - 1;

View File

@@ -24,8 +24,7 @@ import java.util.List;
* @since 1.5.0 * @since 1.5.0
*/ */
@Mixin(value = EntryListWidget.class, remap = false) @Mixin(value = EntryListWidget.class, remap = false)
public interface EntryListWidgetAccessor public interface EntryListWidgetAccessor {
{
@Accessor(value = "entries") @Accessor(value = "entries")
List<EntryListEntryWidget> getEntries(); List<EntryListEntryWidget> getEntries();
} }

View File

@@ -22,8 +22,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
* @since 1.5.0 * @since 1.5.0
*/ */
@Mixin(value = EntryWidget.class, remap = false) @Mixin(value = EntryWidget.class, remap = false)
public interface EntryWidgetAccessor public interface EntryWidgetAccessor {
{
@Invoker("getCurrentEntry") @Invoker("getCurrentEntry")
EntryStack lambdacontrols_getCurrentEntry(); EntryStack lambdacontrols_getCurrentEntry();
} }

View File

@@ -22,8 +22,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
* @since 1.2.0 * @since 1.2.0
*/ */
@Mixin(value = RecipeViewingScreen.class, remap = false) @Mixin(value = RecipeViewingScreen.class, remap = false)
public interface RecipeViewingScreenAccessor public interface RecipeViewingScreenAccessor {
{
@Accessor("categoryBack") @Accessor("categoryBack")
Button getCategoryBack(); Button getCategoryBack();

View File

@@ -28,8 +28,7 @@ import java.util.Map;
* @since 1.2.0 * @since 1.2.0
*/ */
@Mixin(VillagerRecipeViewingScreen.class) @Mixin(VillagerRecipeViewingScreen.class)
public interface VillagerRecipeViewingScreenAccessor public interface VillagerRecipeViewingScreenAccessor {
{
@Accessor(value = "categoryMap", remap = false) @Accessor(value = "categoryMap", remap = false)
Map<RecipeCategory<?>, List<RecipeDisplay>> getCategoryMap(); Map<RecipeCategory<?>, List<RecipeDisplay>> getCategoryMap();

View File

@@ -26,37 +26,31 @@ import java.util.List;
* @version 1.1.0 * @version 1.1.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class ButtonCategory implements Identifiable public class ButtonCategory implements Identifiable {
{
private final List<ButtonBinding> bindings = new ArrayList<>(); private final List<ButtonBinding> bindings = new ArrayList<>();
private final Identifier id; private final Identifier id;
private int priority; private int priority;
public ButtonCategory(@NotNull Identifier id, int priority) public ButtonCategory(@NotNull Identifier id, int priority) {
{
this.id = id; this.id = id;
this.priority = priority; this.priority = priority;
} }
public ButtonCategory(@NotNull Identifier id) public ButtonCategory(@NotNull Identifier id) {
{
this(id, 100); this(id, 100);
} }
public void registerBinding(@NotNull ButtonBinding binding) public void registerBinding(@NotNull ButtonBinding binding) {
{
if (this.bindings.contains(binding)) if (this.bindings.contains(binding))
throw new IllegalStateException("Cannot register twice a button binding in the same category."); throw new IllegalStateException("Cannot register twice a button binding in the same category.");
this.bindings.add(binding); this.bindings.add(binding);
} }
public void registerAllBindings(@NotNull ButtonBinding... bindings) public void registerAllBindings(@NotNull ButtonBinding... bindings) {
{
this.registerAllBindings(Arrays.asList(bindings)); this.registerAllBindings(Arrays.asList(bindings));
} }
public void registerAllBindings(@NotNull List<ButtonBinding> bindings) public void registerAllBindings(@NotNull List<ButtonBinding> bindings) {
{
bindings.forEach(this::registerBinding); bindings.forEach(this::registerBinding);
} }
@@ -65,8 +59,7 @@ public class ButtonCategory implements Identifiable
* *
* @return The bindings assigned to this category. * @return The bindings assigned to this category.
*/ */
public @NotNull List<ButtonBinding> getBindings() public @NotNull List<ButtonBinding> getBindings() {
{
return Collections.unmodifiableList(this.bindings); return Collections.unmodifiableList(this.bindings);
} }
@@ -77,8 +70,7 @@ public class ButtonCategory implements Identifiable
* *
* @return The translated name. * @return The translated name.
*/ */
public @NotNull String getTranslatedName() public @NotNull String getTranslatedName() {
{
if (this.id.getNamespace().equals("minecraft")) if (this.id.getNamespace().equals("minecraft"))
return I18n.translate(this.id.getName()); return I18n.translate(this.id.getName());
else else
@@ -91,14 +83,12 @@ public class ButtonCategory implements Identifiable
* *
* @return The priority of this category. * @return The priority of this category.
*/ */
public int getPriority() public int getPriority() {
{
return this.priority; return this.priority;
} }
@Override @Override
public @NotNull Identifier getIdentifier() public @NotNull Identifier getIdentifier() {
{
return this.id; return this.id;
} }
} }

View File

@@ -44,13 +44,11 @@ import static org.lwjgl.BufferUtils.createByteBuffer;
* @version 1.4.3 * @version 1.4.3
* @since 1.0.0 * @since 1.0.0
*/ */
public class Controller implements Nameable public class Controller implements Nameable {
{
private static final Map<Integer, Controller> CONTROLLERS = new HashMap<>(); private static final Map<Integer, Controller> CONTROLLERS = new HashMap<>();
private final int id; private final int id;
public Controller(int id) public Controller(int id) {
{
this.id = id; this.id = id;
} }
@@ -59,8 +57,7 @@ public class Controller implements Nameable
* *
* @return The identifier of this controller. * @return The identifier of this controller.
*/ */
public int getId() public int getId() {
{
return this.id; return this.id;
} }
@@ -69,8 +66,7 @@ public class Controller implements Nameable
* *
* @return The controller's GUID. * @return The controller's GUID.
*/ */
public String getGuid() public String getGuid() {
{
String guid = GLFW.glfwGetJoystickGUID(this.id); String guid = GLFW.glfwGetJoystickGUID(this.id);
return guid == null ? "" : guid; return guid == null ? "" : guid;
} }
@@ -80,8 +76,7 @@ public class Controller implements Nameable
* *
* @return True if this controller is connected, else false. * @return True if this controller is connected, else false.
*/ */
public boolean isConnected() public boolean isConnected() {
{
return GLFW.glfwJoystickPresent(this.id); return GLFW.glfwJoystickPresent(this.id);
} }
@@ -90,8 +85,7 @@ public class Controller implements Nameable
* *
* @return True if this controller is a gamepad, else false. * @return True if this controller is a gamepad, else false.
*/ */
public boolean isGamepad() public boolean isGamepad() {
{
return this.isConnected() && GLFW.glfwJoystickIsGamepad(this.id); return this.isConnected() && GLFW.glfwJoystickIsGamepad(this.id);
} }
@@ -101,8 +95,7 @@ public class Controller implements Nameable
* @return The controller's name. * @return The controller's name.
*/ */
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
String name = this.isGamepad() ? GLFW.glfwGetGamepadName(this.id) : GLFW.glfwGetJoystickName(this.id); String name = this.isGamepad() ? GLFW.glfwGetGamepadName(this.id) : GLFW.glfwGetJoystickName(this.id);
return name == null ? String.valueOf(this.getId()) : name; return name == null ? String.valueOf(this.getId()) : name;
} }
@@ -112,16 +105,14 @@ public class Controller implements Nameable
* *
* @return The state of the controller input. * @return The state of the controller input.
*/ */
public GLFWGamepadState getState() public GLFWGamepadState getState() {
{
GLFWGamepadState state = GLFWGamepadState.create(); GLFWGamepadState state = GLFWGamepadState.create();
if (this.isGamepad()) if (this.isGamepad())
GLFW.glfwGetGamepadState(this.id, state); GLFW.glfwGetGamepadState(this.id, state);
return state; return state;
} }
public static @NotNull Controller byId(int id) public static @NotNull Controller byId(int id) {
{
if (id > GLFW.GLFW_JOYSTICK_LAST) { if (id > GLFW.GLFW_JOYSTICK_LAST) {
LambdaControlsClient.get().log("Controller '" + id + "' doesn't exist."); LambdaControlsClient.get().log("Controller '" + id + "' doesn't exist.");
id = GLFW.GLFW_JOYSTICK_LAST; id = GLFW.GLFW_JOYSTICK_LAST;
@@ -136,8 +127,7 @@ public class Controller implements Nameable
} }
} }
public static @NotNull Optional<Controller> byGuid(@NotNull String guid) public static @NotNull Optional<Controller> byGuid(@NotNull String guid) {
{
return CONTROLLERS.values().stream().filter(Controller::isConnected) return CONTROLLERS.values().stream().filter(Controller::isConnected)
.filter(controller -> controller.getGuid().equals(guid)) .filter(controller -> controller.getGuid().equals(guid))
.max(Comparator.comparingInt(Controller::getId)); .max(Comparator.comparingInt(Controller::getId));
@@ -146,13 +136,12 @@ public class Controller implements Nameable
/** /**
* Reads the specified resource and returns the raw data as a ByteBuffer. * Reads the specified resource and returns the raw data as a ByteBuffer.
* *
* @param resource The resource to read. * @param resource The resource to read.
* @param bufferSize The initial buffer size. * @param bufferSize The initial buffer size.
* @return The resource data. * @return The resource data.
* @throws IOException If an IO error occurs. * @throws IOException If an IO error occurs.
*/ */
private static ByteBuffer ioResourceToBuffer(String resource, int bufferSize) throws IOException private static ByteBuffer ioResourceToBuffer(String resource, int bufferSize) throws IOException {
{
ByteBuffer buffer = null; ByteBuffer buffer = null;
Path path = Paths.get(resource); Path path = Paths.get(resource);
@@ -171,8 +160,7 @@ public class Controller implements Nameable
/** /**
* Updates the controller mappings. * Updates the controller mappings.
*/ */
public static void updateMappings() public static void updateMappings() {
{
try { try {
if (!LambdaControlsClient.MAPPINGS_FILE.exists()) if (!LambdaControlsClient.MAPPINGS_FILE.exists())
return; return;

View File

@@ -41,14 +41,11 @@ import java.util.stream.Collectors;
* @version 1.4.3 * @version 1.4.3
* @since 1.1.0 * @since 1.1.0
*/ */
public class InputHandlers public class InputHandlers {
{ private InputHandlers() {
private InputHandlers()
{
} }
public static PressAction handleHotbar(boolean next) public static PressAction handleHotbar(boolean next) {
{
return (client, button, value, action) -> { return (client, button, value, action) -> {
if (action == ButtonState.RELEASE) if (action == ButtonState.RELEASE)
return false; return false;
@@ -68,7 +65,7 @@ public class InputHandlers
nextTab = ItemGroup.GROUPS.length - 1; nextTab = ItemGroup.GROUPS.length - 1;
else if (nextTab >= ItemGroup.GROUPS.length) else if (nextTab >= ItemGroup.GROUPS.length)
nextTab = 0; nextTab = 0;
inventory.lambdacontrols_setSelectedTab(ItemGroup.GROUPS[nextTab]); inventory.lambdacontrols$setSelectedTab(ItemGroup.GROUPS[nextTab]);
return true; return true;
} else if (client.currentScreen instanceof InventoryScreen) { } else if (client.currentScreen instanceof InventoryScreen) {
RecipeBookWidgetAccessor recipeBook = (RecipeBookWidgetAccessor) ((InventoryScreen) client.currentScreen).getRecipeBookWidget(); RecipeBookWidgetAccessor recipeBook = (RecipeBookWidgetAccessor) ((InventoryScreen) client.currentScreen).getRecipeBookWidget();
@@ -84,7 +81,7 @@ public class InputHandlers
currentTab.setToggled(false); currentTab.setToggled(false);
recipeBook.setCurrentTab(currentTab = tabs.get(nextTab)); recipeBook.setCurrentTab(currentTab = tabs.get(nextTab));
currentTab.setToggled(true); currentTab.setToggled(true);
recipeBook.lambdacontrols_refreshResults(true); recipeBook.lambdacontrols$refreshResults(true);
return true; return true;
} else if (client.currentScreen instanceof AdvancementsScreen) { } else if (client.currentScreen instanceof AdvancementsScreen) {
AdvancementsScreenAccessor screen = (AdvancementsScreenAccessor) client.currentScreen; AdvancementsScreenAccessor screen = (AdvancementsScreenAccessor) client.currentScreen;
@@ -109,8 +106,7 @@ public class InputHandlers
}; };
} }
public static boolean handlePauseGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) public static boolean handlePauseGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) {
{
if (action == ButtonState.PRESS) { if (action == ButtonState.PRESS) {
// If in game, then pause the game. // If in game, then pause the game.
if (client.currentScreen == null) if (client.currentScreen == null)
@@ -126,21 +122,19 @@ public class InputHandlers
/** /**
* Handles the screenshot action. * Handles the screenshot action.
* *
* @param client The client instance. * @param client The client instance.
* @param binding The binding which fired the action. * @param binding The binding which fired the action.
* @param action The action done on the binding. * @param action The action done on the binding.
* @return True if handled, else false. * @return True if handled, else false.
*/ */
public static boolean handleScreenshot(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) public static boolean handleScreenshot(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) {
{
if (action == ButtonState.RELEASE) if (action == ButtonState.RELEASE)
ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().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 boolean handleToggleSneak(@NotNull MinecraftClient client, @NotNull ButtonBinding button, float value, @NotNull ButtonState action) public static boolean handleToggleSneak(@NotNull MinecraftClient client, @NotNull ButtonBinding button, float value, @NotNull ButtonState action) {
{
button.asKeyBinding().ifPresent(binding -> { button.asKeyBinding().ifPresent(binding -> {
boolean sneakToggled = client.options.sneakToggled; boolean sneakToggled = client.options.sneakToggled;
if (client.player.abilities.flying && sneakToggled) if (client.player.abilities.flying && sneakToggled)
@@ -152,8 +146,7 @@ public class InputHandlers
return true; return true;
} }
public static PressAction handleInventorySlotPad(int direction) public static PressAction handleInventorySlotPad(int direction) {
{
return (client, binding, value, action) -> { return (client, binding, value, action) -> {
if (!(client.currentScreen instanceof HandledScreen && action != ButtonState.RELEASE)) if (!(client.currentScreen instanceof HandledScreen && action != ButtonState.RELEASE))
return false; return false;
@@ -166,7 +159,7 @@ public class InputHandlers
double mouseY = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight(); double mouseY = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
// Finds the hovered slot. // Finds the hovered slot.
Slot mouseSlot = accessor.lambdacontrols_getSlotAt(mouseX, mouseY); Slot mouseSlot = accessor.lambdacontrols$getSlotAt(mouseX, mouseY);
// Finds the closest slot in the GUI within 14 pixels. // Finds the closest slot in the GUI within 14 pixels.
Optional<Slot> closestSlot = inventory.getScreenHandler().slots.parallelStream() Optional<Slot> closestSlot = inventory.getScreenHandler().slots.parallelStream()
@@ -224,36 +217,33 @@ public class InputHandlers
/** /**
* Returns always true to the filter. * Returns always true to the filter.
* *
* @param client The client instance. * @param client The client instance.
* @param binding The affected binding. * @param binding The affected binding.
* @return True. * @return True.
*/ */
public static boolean always(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean always(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return true; return true;
} }
/** /**
* Returns whether the client is in game or not. * Returns whether the client is in game or not.
* *
* @param client The client instance. * @param client The client instance.
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in game, else false. * @return True if the client is in game, else false.
*/ */
public static boolean inGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return client.currentScreen == null; return client.currentScreen == null;
} }
/** /**
* Returns whether the client is in a non-interactive screen (which means require mouse input) or not. * Returns whether the client is in a non-interactive screen (which means require mouse input) or not.
* *
* @param client The client instance. * @param client The client instance.
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in a non-interactive screen, else false. * @return True if the client is in a non-interactive screen, else false.
*/ */
public static boolean inNonInteractiveScreens(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inNonInteractiveScreens(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
if (client.currentScreen == null) if (client.currentScreen == null)
return false; return false;
return !LambdaInput.isScreenInteractive(client.currentScreen); return !LambdaInput.isScreenInteractive(client.currentScreen);
@@ -262,24 +252,22 @@ public class InputHandlers
/** /**
* Returns whether the client is in an inventory or not. * Returns whether the client is in an inventory or not.
* *
* @param client The client instance. * @param client The client instance.
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in an inventory, else false. * @return True if the client is in an inventory, else false.
*/ */
public static boolean inInventory(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inInventory(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return client.currentScreen instanceof HandledScreen; return client.currentScreen instanceof HandledScreen;
} }
/** /**
* Returns whether the client is in the advancements screen or not. * Returns whether the client is in the advancements screen or not.
* *
* @param client The client instance. * @param client The client instance.
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in the advancements screen, else false. * @return True if the client is in the advancements screen, else false.
*/ */
public static boolean inAdvancements(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inAdvancements(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return client.currentScreen instanceof AdvancementsScreen; return client.currentScreen instanceof AdvancementsScreen;
} }
} }

View File

@@ -36,31 +36,27 @@ import java.util.stream.Stream;
* @version 1.4.0 * @version 1.4.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class InputManager public class InputManager {
{ public static final InputManager INPUT_MANAGER = new InputManager();
public static final InputManager INPUT_MANAGER = new InputManager(); private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
private static final List<ButtonBinding> BINDINGS = new ArrayList<>(); private static final List<ButtonCategory> CATEGORIES = new ArrayList<>();
private static final List<ButtonCategory> CATEGORIES = new ArrayList<>(); public static final Map<Integer, ButtonState> STATES = new HashMap<>();
public static final Map<Integer, ButtonState> STATES = new HashMap<>(); public static final Map<Integer, Float> BUTTON_VALUES = new HashMap<>();
public static final Map<Integer, Float> BUTTON_VALUES = new HashMap<>(); private int prevTargetMouseX = 0;
private int prevTargetMouseX = 0; private int prevTargetMouseY = 0;
private int prevTargetMouseY = 0; private int targetMouseX = 0;
private int targetMouseX = 0; private int targetMouseY = 0;
private int targetMouseY = 0;
protected InputManager() protected InputManager() {
{
} }
public void tick(@NotNull MinecraftClient client) public void tick(@NotNull MinecraftClient client) {
{
if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) { if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) {
this.controllerTick(client); this.controllerTick(client);
} }
} }
public void controllerTick(@NotNull MinecraftClient client) public void controllerTick(@NotNull MinecraftClient client) {
{
this.prevTargetMouseX = this.targetMouseX; this.prevTargetMouseX = this.targetMouseX;
this.prevTargetMouseY = this.targetMouseY; this.prevTargetMouseY = this.targetMouseY;
} }
@@ -70,32 +66,29 @@ public class InputManager
* *
* @param client The client instance. * @param client The client instance.
*/ */
public void updateMousePosition(@NotNull MinecraftClient client) public void updateMousePosition(@NotNull MinecraftClient client) {
{
Objects.requireNonNull(client, "Client instance cannot be null."); Objects.requireNonNull(client, "Client instance cannot be null.");
if (this.prevTargetMouseX != this.targetMouseX || this.prevTargetMouseY != this.targetMouseY) { if (this.prevTargetMouseX != this.targetMouseX || this.prevTargetMouseY != this.targetMouseY) {
double mouseX = this.prevTargetMouseX + (this.targetMouseX - this.prevTargetMouseX) * client.getTickDelta() + 0.5; double mouseX = this.prevTargetMouseX + (this.targetMouseX - this.prevTargetMouseX) * client.getTickDelta() + 0.5;
double mouseY = this.prevTargetMouseY + (this.targetMouseY - this.prevTargetMouseY) * client.getTickDelta() + 0.5; double mouseY = this.prevTargetMouseY + (this.targetMouseY - this.prevTargetMouseY) * client.getTickDelta() + 0.5;
if (!LambdaControlsClient.get().config.hasVirtualMouse()) if (!LambdaControlsClient.get().config.hasVirtualMouse())
GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouseX, mouseY); GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouseX, mouseY);
((MouseAccessor) client.mouse).lambdacontrols_onCursorPos(client.getWindow().getHandle(), mouseX, mouseY); ((MouseAccessor) client.mouse).lambdacontrols$onCursorPos(client.getWindow().getHandle(), mouseX, mouseY);
} }
} }
/** /**
* Resets the mouse position. * Resets the mouse position.
* *
* @param windowWidth The window width. * @param windowWidth The window width.
* @param windowHeight The window height. * @param windowHeight The window height.
*/ */
public void resetMousePosition(int windowWidth, int windowHeight) public void resetMousePosition(int windowWidth, int windowHeight) {
{
this.targetMouseX = this.prevTargetMouseX = (int) (windowWidth / 2.F); this.targetMouseX = this.prevTargetMouseX = (int) (windowWidth / 2.F);
this.targetMouseY = this.prevTargetMouseY = (int) (windowHeight / 2.F); this.targetMouseY = this.prevTargetMouseY = (int) (windowHeight / 2.F);
} }
public void resetMouseTarget(@NotNull MinecraftClient client) public void resetMouseTarget(@NotNull MinecraftClient client) {
{
double mouseX = client.mouse.getX(); double mouseX = client.mouse.getX();
double mouseY = client.mouse.getY(); double mouseY = client.mouse.getY();
this.prevTargetMouseX = this.targetMouseX = (int) mouseX; this.prevTargetMouseX = this.targetMouseX = (int) mouseX;
@@ -108,8 +101,7 @@ public class InputManager
* @param binding The binding to check. * @param binding The binding to check.
* @return True if the binding is registered, else false. * @return True if the binding is registered, else false.
*/ */
public static boolean hasBinding(@NotNull ButtonBinding binding) public static boolean hasBinding(@NotNull ButtonBinding binding) {
{
return BINDINGS.contains(binding); return BINDINGS.contains(binding);
} }
@@ -119,8 +111,7 @@ public class InputManager
* @param name The name of the binding to check. * @param name The name of the binding to check.
* @return True if the binding is registered, else false. * @return True if the binding is registered, else false.
*/ */
public static boolean hasBinding(@NotNull String name) public static boolean hasBinding(@NotNull String name) {
{
return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name)); return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name));
} }
@@ -130,8 +121,7 @@ public class InputManager
* @param identifier The identifier of the binding to check. * @param identifier The identifier of the binding to check.
* @return True if the binding is registered, else false. * @return True if the binding is registered, else false.
*/ */
public static boolean hasBinding(@NotNull Identifier identifier) public static boolean hasBinding(@NotNull Identifier identifier) {
{
return hasBinding(identifier.getNamespace() + "." + identifier.getName()); return hasBinding(identifier.getNamespace() + "." + identifier.getName());
} }
@@ -141,39 +131,33 @@ public class InputManager
* @param binding The binding to register. * @param binding The binding to register.
* @return The registered binding. * @return The registered binding.
*/ */
public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) {
{
if (hasBinding(binding)) if (hasBinding(binding))
throw new IllegalStateException("Cannot register twice a button binding in the registry."); throw new IllegalStateException("Cannot register twice a button binding in the registry.");
BINDINGS.add(binding); BINDINGS.add(binding);
return binding; return binding;
} }
public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
{
return registerBinding(new ButtonBinding(id.getNamespace() + "." + id.getName(), defaultButton, actions, filter, hasCooldown)); return registerBinding(new ButtonBinding(id.getNamespace() + "." + id.getName(), defaultButton, actions, filter, hasCooldown));
} }
public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, boolean hasCooldown) {
{
return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown); return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown);
} }
public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
{
return registerBinding(new Identifier(id.getNamespace(), id.getPath()), defaultButton, actions, filter, hasCooldown); return registerBinding(new Identifier(id.getNamespace(), id.getPath()), defaultButton, actions, filter, hasCooldown);
} }
public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, boolean hasCooldown) {
{
return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown); return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown);
} }
/** /**
* Sorts bindings to get bindings with the higher button counts first. * Sorts bindings to get bindings with the higher button counts first.
*/ */
public static void sortBindings() public static void sortBindings() {
{
synchronized (BINDINGS) { synchronized (BINDINGS) {
List<ButtonBinding> sorted = BINDINGS.stream().sorted(Collections.reverseOrder(Comparator.comparingInt(binding -> binding.getButton().length))) List<ButtonBinding> sorted = BINDINGS.stream().sorted(Collections.reverseOrder(Comparator.comparingInt(binding -> binding.getButton().length)))
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -188,24 +172,20 @@ public class InputManager
* @param category The category to register. * @param category The category to register.
* @return The registered category. * @return The registered category.
*/ */
public static ButtonCategory registerCategory(@NotNull ButtonCategory category) public static ButtonCategory registerCategory(@NotNull ButtonCategory category) {
{
CATEGORIES.add(category); CATEGORIES.add(category);
return category; return category;
} }
public static ButtonCategory registerCategory(@NotNull Identifier identifier, int priority) public static ButtonCategory registerCategory(@NotNull Identifier identifier, int priority) {
{
return registerCategory(new ButtonCategory(identifier, priority)); return registerCategory(new ButtonCategory(identifier, priority));
} }
public static ButtonCategory registerCategory(@NotNull Identifier identifier) public static ButtonCategory registerCategory(@NotNull Identifier identifier) {
{
return registerCategory(new ButtonCategory(identifier)); return registerCategory(new ButtonCategory(identifier));
} }
protected static ButtonCategory registerDefaultCategory(@NotNull String key, @NotNull Consumer<ButtonCategory> keyAdder) protected static ButtonCategory registerDefaultCategory(@NotNull String key, @NotNull Consumer<ButtonCategory> keyAdder) {
{
ButtonCategory category = registerCategory(new Identifier("minecraft", key), CATEGORIES.size()); ButtonCategory category = registerCategory(new Identifier("minecraft", key), CATEGORIES.size());
keyAdder.accept(category); keyAdder.accept(category);
return category; return category;
@@ -216,8 +196,7 @@ public class InputManager
* *
* @param config The configuration instance. * @param config The configuration instance.
*/ */
public static void loadButtonBindings(@NotNull LambdaControlsConfig config) public static void loadButtonBindings(@NotNull LambdaControlsConfig config) {
{
List<ButtonBinding> queue = new ArrayList<>(BINDINGS); List<ButtonBinding> queue = new ArrayList<>(BINDINGS);
queue.forEach(config::loadButtonBinding); queue.forEach(config::loadButtonBinding);
} }
@@ -228,8 +207,7 @@ public class InputManager
* @param binding The binding. * @param binding The binding.
* @return The current state of the binding. * @return The current state of the binding.
*/ */
public static @NotNull ButtonState getBindingState(@NotNull ButtonBinding binding) public static @NotNull ButtonState getBindingState(@NotNull ButtonBinding binding) {
{
ButtonState state = ButtonState.REPEAT; ButtonState state = ButtonState.REPEAT;
for (int btn : binding.getButton()) { for (int btn : binding.getButton()) {
ButtonState btnState = InputManager.STATES.getOrDefault(btn, ButtonState.NONE); ButtonState btnState = InputManager.STATES.getOrDefault(btn, ButtonState.NONE);
@@ -246,8 +224,7 @@ public class InputManager
return state; return state;
} }
public static float getBindingValue(@NotNull ButtonBinding binding, @NotNull ButtonState state) public static float getBindingValue(@NotNull ButtonBinding binding, @NotNull ButtonState state) {
{
if (state.isUnpressed()) if (state.isUnpressed())
return 0.f; return 0.f;
@@ -269,8 +246,7 @@ public class InputManager
* @param button The button to check. * @param button The button to check.
* @return True if the button has duplicated bindings, else false. * @return True if the button has duplicated bindings, else false.
*/ */
public static boolean hasDuplicatedBindings(int[] button) public static boolean hasDuplicatedBindings(int[] button) {
{
return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1; return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1;
} }
@@ -280,8 +256,7 @@ public class InputManager
* @param binding The binding to check. * @param binding The binding to check.
* @return True if the button has duplicated bindings, else false. * @return True if the button has duplicated bindings, else false.
*/ */
public static boolean hasDuplicatedBindings(ButtonBinding binding) public static boolean hasDuplicatedBindings(ButtonBinding binding) {
{
return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1; return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1;
} }
@@ -292,8 +267,7 @@ public class InputManager
* @param buttons2 Second set of buttons. * @param buttons2 Second set of buttons.
* @return True if the two sets of buttons are equivalent, else false. * @return True if the two sets of buttons are equivalent, else false.
*/ */
public static boolean areButtonsEquivalent(int[] buttons1, int[] buttons2) public static boolean areButtonsEquivalent(int[] buttons1, int[] buttons2) {
{
if (buttons1.length != buttons2.length) if (buttons1.length != buttons2.length)
return false; return false;
int count = 0; int count = 0;
@@ -312,19 +286,17 @@ public class InputManager
* Returns whether the button set contains the specified button or not. * Returns whether the button set contains the specified button or not.
* *
* @param buttons The button set. * @param buttons The button set.
* @param button The button to check. * @param button The button to check.
* @return True if the button set contains the specified button, else false. * @return True if the button set contains the specified button, else false.
*/ */
public static boolean containsButton(int[] buttons, int button) public static boolean containsButton(int[] buttons, int button) {
{
return Arrays.stream(buttons).anyMatch(btn -> btn == button); return Arrays.stream(buttons).anyMatch(btn -> btn == button);
} }
/** /**
* Updates the button states. * Updates the button states.
*/ */
public static void updateStates() public static void updateStates() {
{
STATES.forEach((btn, state) -> { STATES.forEach((btn, state) -> {
if (state == ButtonState.PRESS) if (state == ButtonState.PRESS)
STATES.put(btn, ButtonState.REPEAT); STATES.put(btn, ButtonState.REPEAT);
@@ -333,8 +305,7 @@ public class InputManager
}); });
} }
public static void updateBindings(@NotNull MinecraftClient client) public static void updateBindings(@NotNull MinecraftClient client) {
{
List<Integer> skipButtons = new ArrayList<>(); List<Integer> skipButtons = new ArrayList<>();
Map<ButtonBinding, Pair<ButtonState, Float>> states = new HashMap<>(); Map<ButtonBinding, Pair<ButtonState, Float>> states = new HashMap<>();
for (ButtonBinding binding : BINDINGS) { for (ButtonBinding binding : BINDINGS) {
@@ -367,54 +338,48 @@ public class InputManager
}); });
} }
public static void queueMousePosition(double x, double y) public static void queueMousePosition(double x, double y) {
{
INPUT_MANAGER.targetMouseX = (int) MathHelper.clamp(x, 0, MinecraftClient.getInstance().getWindow().getWidth()); INPUT_MANAGER.targetMouseX = (int) MathHelper.clamp(x, 0, MinecraftClient.getInstance().getWindow().getWidth());
INPUT_MANAGER.targetMouseY = (int) MathHelper.clamp(y, 0, MinecraftClient.getInstance().getWindow().getHeight()); INPUT_MANAGER.targetMouseY = (int) MathHelper.clamp(y, 0, MinecraftClient.getInstance().getWindow().getHeight());
} }
public static void queueMoveMousePosition(double x, double y) public static void queueMoveMousePosition(double x, double y) {
{
queueMousePosition(INPUT_MANAGER.targetMouseX + x, INPUT_MANAGER.targetMouseY + y); queueMousePosition(INPUT_MANAGER.targetMouseX + x, INPUT_MANAGER.targetMouseY + y);
} }
public static @NotNull Stream<ButtonBinding> streamBindings() public static @NotNull Stream<ButtonBinding> streamBindings() {
{
return BINDINGS.stream(); return BINDINGS.stream();
} }
public static @NotNull Stream<ButtonCategory> streamCategories() public static @NotNull Stream<ButtonCategory> streamCategories() {
{
return CATEGORIES.stream(); return CATEGORIES.stream();
} }
/** /**
* Returns a new key binding instance. * Returns a new key binding instance.
* *
* @param id The identifier of the key binding. * @param id The identifier of the key binding.
* @param type The type. * @param type The type.
* @param code The code. * @param code The code.
* @param category The category of the key binding. * @param category The category of the key binding.
* @return The key binding. * @return The key binding.
* @see #makeKeyBinding(Identifier, InputUtil.Type, int, String) * @see #makeKeyBinding(Identifier, InputUtil.Type, int, String)
*/ */
public static @NotNull KeyBinding makeKeyBinding(@NotNull net.minecraft.util.Identifier id, InputUtil.Type type, int code, @NotNull String category) public static @NotNull KeyBinding makeKeyBinding(@NotNull net.minecraft.util.Identifier id, InputUtil.Type type, int code, @NotNull String category) {
{
return makeKeyBinding(new Identifier(id.getNamespace(), id.getPath()), type, code, category); return makeKeyBinding(new Identifier(id.getNamespace(), id.getPath()), type, code, category);
} }
/** /**
* Returns a new key binding instance. * Returns a new key binding instance.
* *
* @param id The identifier of the key binding. * @param id The identifier of the key binding.
* @param type The type. * @param type The type.
* @param code The code. * @param code The code.
* @param category The category of the key binding. * @param category The category of the key binding.
* @return The key binding. * @return The key binding.
* @see #makeKeyBinding(net.minecraft.util.Identifier, InputUtil.Type, int, String) * @see #makeKeyBinding(net.minecraft.util.Identifier, InputUtil.Type, int, String)
*/ */
public static @NotNull KeyBinding makeKeyBinding(@NotNull Identifier id, InputUtil.Type type, int code, @NotNull String category) public static @NotNull KeyBinding makeKeyBinding(@NotNull Identifier id, InputUtil.Type type, int code, @NotNull String category) {
{
return new KeyBinding(String.format("key.%s.%s", id.getNamespace(), id.getName()), type, code, category); return new KeyBinding(String.format("key.%s.%s", id.getNamespace(), id.getName()), type, code, category);
} }
} }

View File

@@ -23,8 +23,7 @@ import org.jetbrains.annotations.NotNull;
* @since 1.0.0 * @since 1.0.0
*/ */
@FunctionalInterface @FunctionalInterface
public interface PressAction public interface PressAction {
{
PressAction DEFAULT_ACTION = (client, button, value, action) -> { PressAction DEFAULT_ACTION = (client, button, value, action) -> {
if (action == ButtonState.REPEAT || client.currentScreen != null) if (action == ButtonState.REPEAT || client.currentScreen != null)
return false; return false;

View File

@@ -9,11 +9,11 @@
package dev.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import dev.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import dev.lambdaurora.lambdacontrols.LambdaControlsConstants; import dev.lambdaurora.lambdacontrols.LambdaControlsConstants;
import dev.lambdaurora.lambdacontrols.client.HudSide; import dev.lambdaurora.lambdacontrols.client.HudSide;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.spruceui.hud.Hud; import me.lambdaurora.spruceui.hud.Hud;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@@ -35,34 +35,31 @@ import org.jetbrains.annotations.Nullable;
* @version 1.3.2 * @version 1.3.2
* @since 1.0.0 * @since 1.0.0
*/ */
public class LambdaControlsHud extends Hud public class LambdaControlsHud extends Hud {
{
private final LambdaControlsClient mod; private final LambdaControlsClient mod;
private MinecraftClient client; private MinecraftClient client;
private int attackWidth = 0; private int attackWidth = 0;
private int attackButtonWidth = 0; private int attackButtonWidth = 0;
private int dropItemWidth = 0; private int dropItemWidth = 0;
private int dropItemButtonWidth = 0; private int dropItemButtonWidth = 0;
private int inventoryWidth = 0; private int inventoryWidth = 0;
private int inventoryButtonWidth = 0; private int inventoryButtonWidth = 0;
private int swapHandsWidth = 0; private int swapHandsWidth = 0;
private int swapHandsButtonWidth = 0; private int swapHandsButtonWidth = 0;
private int useWidth = 0; private int useWidth = 0;
private int useButtonWidth = 0; private int useButtonWidth = 0;
private BlockHitResult placeHitResult; private BlockHitResult placeHitResult;
private String attackAction = ""; private String attackAction = "";
private String placeAction = ""; private String placeAction = "";
private int ticksDisplayedCrosshair = 0; private int ticksDisplayedCrosshair = 0;
public LambdaControlsHud(@NotNull LambdaControlsClient mod) public LambdaControlsHud(@NotNull LambdaControlsClient mod) {
{
super(new Identifier(LambdaControlsConstants.NAMESPACE, "hud/button_indicator")); super(new Identifier(LambdaControlsConstants.NAMESPACE, "hud/button_indicator"));
this.mod = mod; this.mod = mod;
} }
@Override @Override
public void init(@NotNull MinecraftClient client, int screenWidth, int screenHeight) public void init(@NotNull MinecraftClient client, int screenWidth, int screenHeight) {
{
super.init(client, screenWidth, screenHeight); super.init(client, screenWidth, screenHeight);
this.client = client; this.client = client;
this.inventoryWidth = this.width(ButtonBinding.INVENTORY); this.inventoryWidth = this.width(ButtonBinding.INVENTORY);
@@ -79,8 +76,7 @@ public class LambdaControlsHud extends Hud
* Renders the LambdaControls' HUD. * Renders the LambdaControls' HUD.
*/ */
@Override @Override
public void render(MatrixStack matrices, float tickDelta) public void render(MatrixStack matrices, float tickDelta) {
{
if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER && this.client.currentScreen == null) { if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER && this.client.currentScreen == null) {
int y = bottom(2); int y = bottom(2);
this.renderFirstIcons(matrices, this.mod.config.getHudSide() == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y); this.renderFirstIcons(matrices, this.mod.config.getHudSide() == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
@@ -103,8 +99,7 @@ public class LambdaControlsHud extends Hud
} }
} }
public void renderFirstIcons(MatrixStack matrices, int x, int y) public void renderFirstIcons(MatrixStack matrices, int x, int y) {
{
int offset = 2 + this.inventoryWidth + this.inventoryButtonWidth + 4; int offset = 2 + this.inventoryWidth + this.inventoryButtonWidth + 4;
int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x : x - this.inventoryButtonWidth; int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x : x - this.inventoryButtonWidth;
this.drawButton(matrices, currentX, y, ButtonBinding.INVENTORY, true); this.drawButton(matrices, currentX, y, ButtonBinding.INVENTORY, true);
@@ -119,8 +114,7 @@ public class LambdaControlsHud extends Hud
this.drawButton(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty()); this.drawButton(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty());
} }
public void renderSecondIcons(MatrixStack matrices, int x, int y) public void renderSecondIcons(MatrixStack matrices, int x, int y) {
{
int offset; int offset;
int currentX = x; int currentX = x;
if (!this.placeAction.isEmpty()) { if (!this.placeAction.isEmpty()) {
@@ -142,8 +136,7 @@ public class LambdaControlsHud extends Hud
this.drawButton(matrices, currentX, y, ButtonBinding.ATTACK, this.attackWidth != 0); this.drawButton(matrices, currentX, y, ButtonBinding.ATTACK, this.attackWidth != 0);
} }
public void renderFirstSection(MatrixStack matrices, int x, int y) public void renderFirstSection(MatrixStack matrices, int x, int y) {
{
int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x + this.inventoryButtonWidth + 2 : x - this.inventoryButtonWidth - 2 - this.inventoryWidth; int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x + this.inventoryButtonWidth + 2 : x - this.inventoryButtonWidth - 2 - this.inventoryWidth;
this.drawTip(matrices, currentX, y, ButtonBinding.INVENTORY, true); this.drawTip(matrices, currentX, y, ButtonBinding.INVENTORY, true);
currentX += this.mod.config.getHudSide() == HudSide.LEFT ? this.inventoryWidth + 4 + this.swapHandsButtonWidth + 2 currentX += this.mod.config.getHudSide() == HudSide.LEFT ? this.inventoryWidth + 4 + this.swapHandsButtonWidth + 2
@@ -158,8 +151,7 @@ public class LambdaControlsHud extends Hud
this.drawTip(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty()); this.drawTip(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty());
} }
public void renderSecondSection(MatrixStack matrices, int x, int y) public void renderSecondSection(MatrixStack matrices, int x, int y) {
{
int currentX = x; int currentX = x;
if (!this.placeAction.isEmpty()) { if (!this.placeAction.isEmpty()) {
@@ -181,8 +173,7 @@ public class LambdaControlsHud extends Hud
} }
@Override @Override
public void tick() public void tick() {
{
super.tick(); super.tick();
if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER) { if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER) {
if (this.client.crosshairTarget == null) if (this.client.crosshairTarget == null)
@@ -249,41 +240,34 @@ public class LambdaControlsHud extends Hud
} }
@Override @Override
public boolean hasTicks() public boolean hasTicks() {
{
return true; return true;
} }
private int bottom(int y) private int bottom(int y) {
{
return this.client.getWindow().getScaledHeight() - y - LambdaControlsRenderer.ICON_SIZE; return this.client.getWindow().getScaledHeight() - y - LambdaControlsRenderer.ICON_SIZE;
} }
private int width(@NotNull ButtonBinding binding) private int width(@NotNull ButtonBinding binding) {
{
return this.width(binding.getTranslationKey()); return this.width(binding.getTranslationKey());
} }
private int width(@Nullable String text) private int width(@Nullable String text) {
{
if (text == null || text.isEmpty()) if (text == null || text.isEmpty())
return 0; return 0;
return this.client.textRenderer.getWidth(I18n.translate(text)); return this.client.textRenderer.getWidth(I18n.translate(text));
} }
private void drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) private void drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) {
{
if (display) if (display)
LambdaControlsRenderer.drawButton(matrices, x, y, button, this.client); LambdaControlsRenderer.drawButton(matrices, x, y, button, this.client);
} }
private void drawTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) private void drawTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) {
{
this.drawTip(matrices, x, y, button.getTranslationKey(), display); this.drawTip(matrices, x, y, button.getTranslationKey(), display);
} }
private void drawTip(MatrixStack matrices, int x, int y, @NotNull String action, boolean display) private void drawTip(MatrixStack matrices, int x, int y, @NotNull String action, boolean display) {
{
if (!display) if (!display)
return; return;
String translatedAction = I18n.translate(action); String translatedAction = I18n.translate(action);

View File

@@ -10,11 +10,11 @@
package dev.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.LambdaInput; import dev.lambdaurora.lambdacontrols.client.LambdaInput;
import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import dev.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.DrawableHelper;
@@ -33,14 +33,12 @@ import org.lwjgl.glfw.GLFW;
* @version 1.5.0 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
public class LambdaControlsRenderer public class LambdaControlsRenderer {
{ public static final int ICON_SIZE = 20;
public static final int ICON_SIZE = 20;
private static final int BUTTON_SIZE = 15; private static final int BUTTON_SIZE = 15;
private static final int AXIS_SIZE = 18; private static final int AXIS_SIZE = 18;
public static int getButtonSize(int button) public static int getButtonSize(int button) {
{
switch (button) { switch (button) {
case -1: case -1:
return 0; return 0;
@@ -64,8 +62,7 @@ public class LambdaControlsRenderer
* @param binding The binding. * @param binding The binding.
* @return The width. * @return The width.
*/ */
public static int getBindingIconWidth(@NotNull ButtonBinding binding) public static int getBindingIconWidth(@NotNull ButtonBinding binding) {
{
return getBindingIconWidth(binding.getButton()); return getBindingIconWidth(binding.getButton());
} }
@@ -75,8 +72,7 @@ public class LambdaControlsRenderer
* @param buttons The buttons. * @param buttons The buttons.
* @return The width. * @return The width.
*/ */
public static int getBindingIconWidth(int[] buttons) public static int getBindingIconWidth(int[] buttons) {
{
int width = 0; int width = 0;
for (int i = 0; i < buttons.length; i++) { for (int i = 0; i < buttons.length; i++) {
width += ICON_SIZE; width += ICON_SIZE;
@@ -87,13 +83,11 @@ public class LambdaControlsRenderer
return width; return width;
} }
public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, @NotNull MinecraftClient client) public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, @NotNull MinecraftClient client) {
{
return drawButton(matrices, x, y, button.getButton(), client); return drawButton(matrices, x, y, button.getButton(), client);
} }
public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, int[] buttons, @NotNull MinecraftClient client) public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, int[] buttons, @NotNull MinecraftClient client) {
{
int height = 0; int height = 0;
int length = 0; int length = 0;
int currentX = x; int currentX = x;
@@ -112,8 +106,7 @@ public class LambdaControlsRenderer
} }
@SuppressWarnings("deprecated") @SuppressWarnings("deprecated")
public static int drawButton(MatrixStack matrices, int x, int y, int button, @NotNull MinecraftClient client) public static int drawButton(MatrixStack matrices, int x, int y, int button, @NotNull MinecraftClient client) {
{
boolean second = false; boolean second = false;
if (button == -1) if (button == -1)
return 0; return 0;
@@ -204,13 +197,11 @@ public class LambdaControlsRenderer
return ICON_SIZE; return ICON_SIZE;
} }
public static int drawButtonTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display, @NotNull MinecraftClient client) public static int drawButtonTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display, @NotNull MinecraftClient client) {
{
return drawButtonTip(matrices, x, y, button.getButton(), button.getTranslationKey(), display, client); return drawButtonTip(matrices, x, y, button.getButton(), button.getTranslationKey(), display, client);
} }
public static int drawButtonTip(MatrixStack matrices, int x, int y, int[] button, @NotNull String action, boolean display, @NotNull MinecraftClient client) public static int drawButtonTip(MatrixStack matrices, int x, int y, int[] button, @NotNull String action, boolean display, @NotNull MinecraftClient client) {
{
if (display) { if (display) {
int buttonWidth = drawButton(matrices, x, y, button, client).key; int buttonWidth = drawButton(matrices, x, y, button, client).key;
@@ -223,13 +214,11 @@ public class LambdaControlsRenderer
return -10; return -10;
} }
private static int getButtonTipWidth(@NotNull String action, @NotNull TextRenderer textRenderer) private static int getButtonTipWidth(@NotNull String action, @NotNull TextRenderer textRenderer) {
{
return 15 + 5 + textRenderer.getWidth(action); return 15 + 5 + textRenderer.getWidth(action);
} }
public static void renderVirtualCursor(@NotNull MatrixStack matrices, @NotNull MinecraftClient client) public static void renderVirtualCursor(@NotNull MatrixStack matrices, @NotNull MinecraftClient client) {
{
if (!LambdaControlsClient.get().config.hasVirtualMouse() || (client.currentScreen == null || LambdaInput.isScreenInteractive(client.currentScreen))) if (!LambdaControlsClient.get().config.hasVirtualMouse() || (client.currentScreen == null || LambdaInput.isScreenInteractive(client.currentScreen)))
return; return;
@@ -243,7 +232,7 @@ public class LambdaControlsRenderer
int guiLeft = inventoryScreen.getX(); int guiLeft = inventoryScreen.getX();
int guiTop = inventoryScreen.getY(); int guiTop = inventoryScreen.getY();
Slot slot = inventoryScreen.lambdacontrols_getSlotAt(mouseX, mouseY); Slot slot = inventoryScreen.lambdacontrols$getSlotAt(mouseX, mouseY);
if (slot != null) { if (slot != null) {
mouseX = guiLeft + slot.x; mouseX = guiLeft + slot.x;
@@ -273,14 +262,13 @@ public class LambdaControlsRenderer
/** /**
* Draws the virtual cursor. * Draws the virtual cursor.
* *
* @param matrices The matrix stack. * @param matrices The matrix stack.
* @param x X coordinate. * @param x X coordinate.
* @param y Y coordinate. * @param y Y coordinate.
* @param hoverSlot True if hovering a slot, else false. * @param hoverSlot True if hovering a slot, else false.
* @param client The client instance. * @param client The client instance.
*/ */
public static void drawCursor(@NotNull MatrixStack matrices, int x, int y, boolean hoverSlot, @NotNull MinecraftClient client) public static void drawCursor(@NotNull MatrixStack matrices, int x, int y, boolean hoverSlot, @NotNull MinecraftClient client) {
{
client.getTextureManager().bindTexture(LambdaControlsClient.CURSOR_TEXTURE); client.getTextureManager().bindTexture(LambdaControlsClient.CURSOR_TEXTURE);
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();

View File

@@ -9,8 +9,8 @@
package dev.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.client.ring.RingPage;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.ring.RingPage;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@@ -22,25 +22,21 @@ import net.minecraft.text.TranslatableText;
* @version 1.4.3 * @version 1.4.3
* @since 1.4.3 * @since 1.4.3
*/ */
public class RingScreen extends Screen public class RingScreen extends Screen {
{
protected final LambdaControlsClient mod; protected final LambdaControlsClient mod;
public RingScreen() public RingScreen() {
{
super(new TranslatableText("lambdacontrols.menu.title.ring")); super(new TranslatableText("lambdacontrols.menu.title.ring"));
this.mod = LambdaControlsClient.get(); this.mod = LambdaControlsClient.get();
} }
@Override @Override
public boolean isPauseScreen() public boolean isPauseScreen() {
{
return false; return false;
} }
@Override @Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
{
super.render(matrices, mouseX, mouseY, delta); super.render(matrices, mouseX, mouseY, delta);
RingPage page = this.mod.ring.getCurrentPage(); RingPage page = this.mod.ring.getCurrentPage();
@@ -49,8 +45,7 @@ public class RingScreen extends Screen
} }
@Override @Override
public boolean mouseReleased(double mouseX, double mouseY, int button) public boolean mouseReleased(double mouseX, double mouseY, int button) {
{
/*if (LambdaControlsClient.BINDING_RING.matchesMouse(button)) { /*if (LambdaControlsClient.BINDING_RING.matchesMouse(button)) {
this.onClose(); this.onClose();
return true; return true;

View File

@@ -17,10 +17,8 @@ import org.jetbrains.annotations.NotNull;
/** /**
* Represents the touchscreen overlay * Represents the touchscreen overlay
*/ */
public class TouchscreenOverlay extends Screen public class TouchscreenOverlay extends Screen {
{ public TouchscreenOverlay(@NotNull LambdaControlsClient mod) {
public TouchscreenOverlay(@NotNull LambdaControlsClient mod)
{
super(new LiteralText("Touchscreen overlay")); super(new LiteralText("Touchscreen overlay"));
} }
/*public static final Identifier WIDGETS_LOCATION = new Identifier("lambdacontrols", "textures/gui/widgets.png"); /*public static final Identifier WIDGETS_LOCATION = new Identifier("lambdacontrols", "textures/gui/widgets.png");

View File

@@ -9,8 +9,8 @@
package dev.lambdaurora.lambdacontrols.client.gui.widget; package dev.lambdaurora.lambdacontrols.client.gui.widget;
import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer;
import me.lambdaurora.spruceui.Position; import me.lambdaurora.spruceui.Position;
import me.lambdaurora.spruceui.SpruceTexts; import me.lambdaurora.spruceui.SpruceTexts;
import me.lambdaurora.spruceui.widget.AbstractSpruceIconButtonWidget; import me.lambdaurora.spruceui.widget.AbstractSpruceIconButtonWidget;

View File

@@ -14,8 +14,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(AbstractButtonWidget.class) @Mixin(AbstractButtonWidget.class)
public interface AbstractButtonWidgetAccessor public interface AbstractButtonWidgetAccessor {
{
@Accessor("height") @Accessor("height")
int getHeight(); int getHeight();
} }

View File

@@ -22,8 +22,7 @@ import java.util.Map;
* Represents an accessor of {@link AdvancementsScreen}. * Represents an accessor of {@link AdvancementsScreen}.
*/ */
@Mixin(AdvancementsScreen.class) @Mixin(AdvancementsScreen.class)
public interface AdvancementsScreenAccessor public interface AdvancementsScreenAccessor {
{
@Accessor("advancementHandler") @Accessor("advancementHandler")
ClientAdvancementManager getAdvancementManager(); ClientAdvancementManager getAdvancementManager();

View File

@@ -1,32 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.mixin;
import dev.lambdaurora.lambdacontrols.LambdaControls;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin
{
@Inject(method = "onGameJoin", at = @At(value = "TAIL"))
private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci)
{
ClientSidePacketRegistry.INSTANCE.sendToServer(LambdaControls.HELLO_CHANNEL, LambdaControls.get().makeHello(LambdaControlsClient.get().config.getControlsMode()));
ClientSidePacketRegistry.INSTANCE.sendToServer(LambdaControls.CONTROLS_MODE_CHANNEL,
LambdaControls.get().makeControlsModeBuffer(LambdaControlsClient.get().config.getControlsMode()));
}
}

View File

@@ -31,7 +31,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
*/ */
@Mixin(ClientPlayerEntity.class) @Mixin(ClientPlayerEntity.class)
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity { public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
private boolean lambdacontrols_driftingPrevented = false; private boolean lambdacontrols$driftingPrevented = false;
@Shadow @Shadow
protected abstract boolean hasMovementInput(); protected abstract boolean hasMovementInput();
@@ -56,13 +56,13 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity
if (type == MovementType.SELF) { if (type == MovementType.SELF) {
if (this.abilities.flying && (!mod.config.hasFlyDrifting() || !mod.config.hasFlyVerticalDrifting())) { if (this.abilities.flying && (!mod.config.hasFlyDrifting() || !mod.config.hasFlyVerticalDrifting())) {
if (!this.hasMovementInput()) { if (!this.hasMovementInput()) {
if (!this.lambdacontrols_driftingPrevented) { if (!this.lambdacontrols$driftingPrevented) {
if (!mod.config.hasFlyDrifting()) if (!mod.config.hasFlyDrifting())
this.setVelocity(this.getVelocity().multiply(0, 1.0, 0)); this.setVelocity(this.getVelocity().multiply(0, 1.0, 0));
} }
this.lambdacontrols_driftingPrevented = true; this.lambdacontrols$driftingPrevented = true;
} else } else
this.lambdacontrols_driftingPrevented = false; this.lambdacontrols$driftingPrevented = false;
} }
} }
} }

View File

@@ -26,20 +26,17 @@ import org.spongepowered.asm.mixin.injection.Redirect;
* Injects the new controls settings button. * Injects the new controls settings button.
*/ */
@Mixin(ControlsOptionsScreen.class) @Mixin(ControlsOptionsScreen.class)
public class ControlsOptionsScreenMixin extends GameOptionsScreen public class ControlsOptionsScreenMixin extends GameOptionsScreen {
{ public ControlsOptionsScreenMixin(Screen parent, GameOptions gameOptions, Text text) {
public ControlsOptionsScreenMixin(Screen parent, GameOptions gameOptions, Text text)
{
super(parent, gameOptions, text); super(parent, gameOptions, text);
} }
@Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/ControlsOptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 1)) @Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/ControlsOptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 1))
private AbstractButtonWidget onInit(ControlsOptionsScreen screen, AbstractButtonWidget btn) private AbstractButtonWidget onInit(ControlsOptionsScreen screen, AbstractButtonWidget btn) {
{
/*if (this.parent instanceof ControllerControlsWidget) /*if (this.parent instanceof ControllerControlsWidget)
return this.addButton(btn); return this.addButton(btn);
else*/ else*/
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), new TranslatableText("menu.options"), return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), new TranslatableText("menu.options"),
b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, true)))); b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, true))));
} }
} }

View File

@@ -22,8 +22,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
* Represents an accessor to CreativeInventoryScreen. * Represents an accessor to CreativeInventoryScreen.
*/ */
@Mixin(CreativeInventoryScreen.class) @Mixin(CreativeInventoryScreen.class)
public interface CreativeInventoryScreenAccessor public interface CreativeInventoryScreenAccessor {
{
/** /**
* Gets the selected tab. * Gets the selected tab.
* *
@@ -38,7 +37,7 @@ public interface CreativeInventoryScreenAccessor
* @param group The tab's item group. * @param group The tab's item group.
*/ */
@Invoker("setSelectedTab") @Invoker("setSelectedTab")
void lambdacontrols_setSelectedTab(@NotNull ItemGroup group); void lambdacontrols$setSelectedTab(@NotNull ItemGroup group);
/** /**
* Returns whether the slot belongs to the creative inventory or not. * Returns whether the slot belongs to the creative inventory or not.
@@ -47,7 +46,7 @@ public interface CreativeInventoryScreenAccessor
* @return True if the slot is from the creative inventory, else false. * @return True if the slot is from the creative inventory, else false.
*/ */
@Invoker("isCreativeInventorySlot") @Invoker("isCreativeInventorySlot")
boolean lambdacontrols_isCreativeInventorySlot(@Nullable Slot slot); boolean lambdacontrols$isCreativeInventorySlot(@Nullable Slot slot);
/** /**
* Returns whether the current tab has a scrollbar or not. * Returns whether the current tab has a scrollbar or not.
@@ -55,5 +54,5 @@ public interface CreativeInventoryScreenAccessor
* @return True if the current tab has a scrollbar, else false. * @return True if the current tab has a scrollbar, else false.
*/ */
@Invoker("hasScrollbar") @Invoker("hasScrollbar")
boolean lambdacontrols_hasScrollbar(); boolean lambdacontrols$hasScrollbar();
} }

View File

@@ -14,8 +14,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(EntryListWidget.class) @Mixin(EntryListWidget.class)
public interface EntryListWidgetAccessor public interface EntryListWidgetAccessor {
{
@Invoker("moveSelection") @Invoker("moveSelection")
void lambdacontrols_moveSelection(EntryListWidget.MoveDirection direction); void lambdacontrols$moveSelection(EntryListWidget.MoveDirection direction);
} }

View File

@@ -22,14 +22,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* Sets the default of the Auto-Jump option to false. * Sets the default of the Auto-Jump option to false.
*/ */
@Mixin(GameOptions.class) @Mixin(GameOptions.class)
public class GameOptionsMixin public class GameOptionsMixin {
{
@Shadow @Shadow
public boolean autoJump; public boolean autoJump;
@Inject(method = "load", at = @At("HEAD")) @Inject(method = "load", at = @At("HEAD"))
public void onInit(CallbackInfo ci) public void onInit(CallbackInfo ci) {
{
// Set default value of the Auto-Jump option to false. // Set default value of the Auto-Jump option to false.
this.autoJump = false; this.autoJump = false;
} }

View File

@@ -21,15 +21,13 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameRenderer.class) @Mixin(GameRenderer.class)
public class GameRendererMixin public class GameRendererMixin {
{
@Shadow @Shadow
@Final @Final
private MinecraftClient client; private MinecraftClient client;
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;getX()D")) @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;getX()D"))
private void onRender(float tickDelta, long startTime, boolean fullRender, CallbackInfo ci) private void onRender(float tickDelta, long startTime, boolean fullRender, CallbackInfo ci) {
{
if (this.client.currentScreen != null && LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) if (this.client.currentScreen != null && LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER)
LambdaControlsClient.get().input.onPreRenderScreen(this.client, this.client.currentScreen); LambdaControlsClient.get().input.onPreRenderScreen(this.client, this.client.currentScreen);
} }

View File

@@ -32,8 +32,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* Represents the mixin for the class ContainerScreen. * Represents the mixin for the class ContainerScreen.
*/ */
@Mixin(HandledScreen.class) @Mixin(HandledScreen.class)
public abstract class HandledScreenMixin implements HandledScreenAccessor public abstract class HandledScreenMixin implements HandledScreenAccessor {
{
@Accessor("x") @Accessor("x")
public abstract int getX(); public abstract int getX();
@@ -41,17 +40,16 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor
public abstract int getY(); public abstract int getY();
@Invoker("getSlotAt") @Invoker("getSlotAt")
public abstract Slot lambdacontrols_getSlotAt(double posX, double posY); public abstract Slot lambdacontrols$getSlotAt(double posX, double posY);
@Invoker("isClickOutsideBounds") @Invoker("isClickOutsideBounds")
public abstract boolean lambdacontrols_isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button); public abstract boolean lambdacontrols$isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button);
@Invoker("onMouseClick") @Invoker("onMouseClick")
public abstract void lambdacontrols_onMouseClick(@Nullable Slot slot, int slotId, int clickData, SlotActionType actionType); public abstract void lambdacontrols$onMouseClick(@Nullable Slot slot, int slotId, int clickData, SlotActionType actionType);
@Inject(method = "render", at = @At("RETURN")) @Inject(method = "render", at = @At("RETURN"))
public void onRender(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) public void onRender(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
{
if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) { if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) {
MinecraftClient client = MinecraftClient.getInstance(); MinecraftClient client = MinecraftClient.getInstance();
int x = 2, y = client.getWindow().getScaledHeight() - 2 - LambdaControlsRenderer.ICON_SIZE; int x = 2, y = client.getWindow().getScaledHeight() - 2 - LambdaControlsRenderer.ICON_SIZE;

View File

@@ -15,8 +15,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@Mixin(KeyBinding.class) @Mixin(KeyBinding.class)
public class KeyBindingMixin implements KeyBindingAccessor public class KeyBindingMixin implements KeyBindingAccessor {
{
@Shadow @Shadow
private int timesPressed; private int timesPressed;
@@ -24,8 +23,7 @@ public class KeyBindingMixin implements KeyBindingAccessor
private boolean pressed; private boolean pressed;
@Override @Override
public boolean lambdacontrols_press() public boolean lambdacontrols$press() {
{
boolean oldPressed = this.pressed; boolean oldPressed = this.pressed;
if (!this.pressed) if (!this.pressed)
this.pressed = true; this.pressed = true;
@@ -34,8 +32,7 @@ public class KeyBindingMixin implements KeyBindingAccessor
} }
@Override @Override
public boolean lambdacontrols_unpress() public boolean lambdacontrols$unpress() {
{
if (this.pressed) { if (this.pressed) {
this.pressed = false; this.pressed = false;
return true; return true;

View File

@@ -38,8 +38,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin public abstract class MinecraftClientMixin {
{
@Shadow @Shadow
@Nullable @Nullable
public HitResult crosshairTarget; public HitResult crosshairTarget;
@@ -63,26 +62,24 @@ public abstract class MinecraftClientMixin
@Shadow @Shadow
private int itemUseCooldown; private int itemUseCooldown;
private BlockPos lambdacontrols_lastTargetPos; private BlockPos lambdacontrols$lastTargetPos;
private Vec3d lambdacontrols_lastPos; private Vec3d lambdacontrols$lastPos;
private Direction lambdacontrols_lastTargetSide; private Direction lambdacontrols$lastTargetSide;
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo ci) private void onInit(CallbackInfo ci) {
{
LambdaControlsClient.get().onMcInit((MinecraftClient) (Object) this); LambdaControlsClient.get().onMcInit((MinecraftClient) (Object) this);
} }
@Inject(method = "tick", at = @At("HEAD")) @Inject(method = "tick", at = @At("HEAD"))
private void onStartTick(CallbackInfo ci) private void onStartTick(CallbackInfo ci) {
{
if (this.player == null) if (this.player == null)
return; return;
if (!LambdaControlsFeature.FAST_BLOCK_PLACING.isAvailable()) if (!LambdaControlsFeature.FAST_BLOCK_PLACING.isAvailable())
return; return;
if (this.lambdacontrols_lastPos == null) if (this.lambdacontrols$lastPos == null)
this.lambdacontrols_lastPos = this.player.getPos(); this.lambdacontrols$lastPos = this.player.getPos();
int cooldown = this.itemUseCooldown; int cooldown = this.itemUseCooldown;
BlockHitResult hitResult; BlockHitResult hitResult;
@@ -91,50 +88,41 @@ public abstract class MinecraftClientMixin
BlockPos targetPos = hitResult.getBlockPos(); BlockPos targetPos = hitResult.getBlockPos();
Direction side = hitResult.getSide(); Direction side = hitResult.getSide();
boolean sidewaysBlockPlacing = this.lambdacontrols_lastTargetPos == null || !targetPos.equals(this.lambdacontrols_lastTargetPos.offset(this.lambdacontrols_lastTargetSide)); boolean sidewaysBlockPlacing = this.lambdacontrols$lastTargetPos == null || !targetPos.equals(this.lambdacontrols$lastTargetPos.offset(this.lambdacontrols$lastTargetSide));
boolean backwardsBlockPlacing = this.player.input.movementForward < 0.0f && (this.lambdacontrols_lastTargetPos == null || targetPos.equals(this.lambdacontrols_lastTargetPos.offset(this.lambdacontrols_lastTargetSide))); boolean backwardsBlockPlacing = this.player.input.movementForward < 0.0f && (this.lambdacontrols$lastTargetPos == null || targetPos.equals(this.lambdacontrols$lastTargetPos.offset(this.lambdacontrols$lastTargetSide)));
if (cooldown > 1 if (cooldown > 1
&& !targetPos.equals(this.lambdacontrols_lastTargetPos) && !targetPos.equals(this.lambdacontrols$lastTargetPos)
&& (sidewaysBlockPlacing || backwardsBlockPlacing)) { && (sidewaysBlockPlacing || backwardsBlockPlacing)) {
this.itemUseCooldown = 1; this.itemUseCooldown = 1;
} }
this.lambdacontrols_lastTargetPos = targetPos.toImmutable(); this.lambdacontrols$lastTargetPos = targetPos.toImmutable();
this.lambdacontrols_lastTargetSide = side; this.lambdacontrols$lastTargetSide = side;
} }
// Removed front placing sprinting as way too cheaty. // Removed front placing sprinting as way too cheaty.
else if (this.player.isSprinting()) { /*else if (this.player.isSprinting()) {
hitResult = LambdaControlsClient.get().reacharound.getLastReacharoundResult(); hitResult = LambdaControlsClient.get().reacharound.getLastReacharoundResult();
if (hitResult != null) { if (hitResult != null) {
if (cooldown > 0) if (cooldown > 0)
this.itemUseCooldown = 0; this.itemUseCooldown = 0;
} }
} }*/
this.lambdacontrols_lastPos = this.player.getPos(); this.lambdacontrols$lastPos = this.player.getPos();
} }
@Inject(method = "render", at = @At("HEAD")) @Inject(method = "render", at = @At("HEAD"))
private void onRender(boolean fullRender, CallbackInfo ci) private void onRender(boolean fullRender, CallbackInfo ci) {
{
LambdaControlsClient.get().onRender((MinecraftClient) (Object) (this)); LambdaControlsClient.get().onRender((MinecraftClient) (Object) (this));
} }
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;render(FJZ)V", shift = At.Shift.AFTER)) @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;render(FJZ)V", shift = At.Shift.AFTER))
private void renderVirtualCursor(boolean fullRender, CallbackInfo ci) private void renderVirtualCursor(boolean fullRender, CallbackInfo ci) {
{
LambdaControlsRenderer.renderVirtualCursor(new MatrixStack(), (MinecraftClient) (Object) this); LambdaControlsRenderer.renderVirtualCursor(new MatrixStack(), (MinecraftClient) (Object) this);
} }
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V", at = @At("RETURN"))
private void onLeave(@Nullable Screen screen, CallbackInfo ci)
{
LambdaControlsClient.get().onLeave();
}
@Inject(method = "doItemUse()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true) @Inject(method = "doItemUse()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
private void onItemUse(CallbackInfo ci, Hand[] hands, int handCount, int handIndex, Hand hand, ItemStack stackInHand) private void onItemUse(CallbackInfo ci, Hand[] hands, int handCount, int handIndex, Hand hand, ItemStack stackInHand) {
{
LambdaControlsClient mod = LambdaControlsClient.get(); LambdaControlsClient mod = LambdaControlsClient.get();
if (!stackInHand.isEmpty() && this.player.pitch > 35.0F && mod.reacharound.isReacharoundAvailable()) { if (!stackInHand.isEmpty() && this.player.pitch > 35.0F && mod.reacharound.isReacharoundAvailable()) {
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.isOnGround()) { if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.isOnGround()) {

View File

@@ -36,7 +36,7 @@ public abstract class MouseMixin implements MouseAccessor
private MinecraftClient client; private MinecraftClient client;
@Invoker("onCursorPos") @Invoker("onCursorPos")
public abstract void lambdacontrols_onCursorPos(long window, double x, double y); public abstract void lambdacontrols$onCursorPos(long window, double x, double y);
@Inject(method = "method_1605", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/Screen;mouseReleased(DDI)Z")) @Inject(method = "method_1605", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/Screen;mouseReleased(DDI)Z"))
private void onMouseBackButton(boolean[] result, double mouseX, double mouseY, int button, CallbackInfo ci) private void onMouseBackButton(boolean[] result, double mouseX, double mouseY, int button, CallbackInfo ci)

View File

@@ -25,16 +25,13 @@ import org.spongepowered.asm.mixin.injection.Redirect;
* Injects the new controls settings button. * Injects the new controls settings button.
*/ */
@Mixin(OptionsScreen.class) @Mixin(OptionsScreen.class)
public class OptionsScreenMixin extends Screen public class OptionsScreenMixin extends Screen {
{ protected OptionsScreenMixin(Text title) {
protected OptionsScreenMixin(Text title)
{
super(title); super(title);
} }
@Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/OptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 7)) @Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/OptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 7))
private AbstractButtonWidget lambdacontrols_onInit(OptionsScreen screen, AbstractButtonWidget btn) private AbstractButtonWidget lambdacontrols$onInit(OptionsScreen screen, AbstractButtonWidget btn) {
{
if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) { if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) {
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), btn.getMessage(), return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), btn.getMessage(),
b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, false)))); b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, false))));

View File

@@ -18,8 +18,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
import java.util.List; import java.util.List;
@Mixin(RecipeBookWidget.class) @Mixin(RecipeBookWidget.class)
public interface RecipeBookWidgetAccessor public interface RecipeBookWidgetAccessor {
{
@Accessor("tabButtons") @Accessor("tabButtons")
List<RecipeGroupButtonWidget> getTabButtons(); List<RecipeGroupButtonWidget> getTabButtons();
@@ -30,5 +29,5 @@ public interface RecipeBookWidgetAccessor
void setCurrentTab(RecipeGroupButtonWidget currentTab); void setCurrentTab(RecipeGroupButtonWidget currentTab);
@Invoker("refreshResults") @Invoker("refreshResults")
void lambdacontrols_refreshResults(boolean resetCurrentPage); void lambdacontrols$refreshResults(boolean resetCurrentPage);
} }

View File

@@ -41,8 +41,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* Handles the rendering of the block outline of the reach-around features. * Handles the rendering of the block outline of the reach-around features.
*/ */
@Mixin(WorldRenderer.class) @Mixin(WorldRenderer.class)
public abstract class WorldRendererMixin public abstract class WorldRendererMixin {
{
@Shadow @Shadow
@Final @Final
private MinecraftClient client; private MinecraftClient client;
@@ -55,8 +54,7 @@ public abstract class WorldRendererMixin
private BufferBuilderStorage bufferBuilders; private BufferBuilderStorage bufferBuilders;
@Shadow @Shadow
private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) {
{
} }
@Inject( @Inject(
@@ -69,8 +67,7 @@ public abstract class WorldRendererMixin
) )
) )
private void onOutlineRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, private void onOutlineRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer,
LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
{
if (this.client.crosshairTarget == null || this.client.crosshairTarget.getType() != HitResult.Type.MISS || !LambdaControlsClient.get().config.shouldRenderReacharoundOutline()) if (this.client.crosshairTarget == null || this.client.crosshairTarget.getType() != HitResult.Type.MISS || !LambdaControlsClient.get().config.shouldRenderReacharoundOutline())
return; return;
BlockHitResult result = LambdaControlsClient.get().reacharound.getLastReacharoundResult(); BlockHitResult result = LambdaControlsClient.get().reacharound.getLastReacharoundResult();

View File

@@ -14,28 +14,23 @@ import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class DummyRingAction extends RingAction public class DummyRingAction extends RingAction {
{ public DummyRingAction(@NotNull Config config) {
public DummyRingAction(@NotNull Config config)
{
super(config); super(config);
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return "dummy"; return "dummy";
} }
@Override @Override
public void onAction(@NotNull RingButtonMode mode) public void onAction(@NotNull RingButtonMode mode) {
{
} }
@Override @Override
public void drawIcon(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) public void drawIcon(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) {
{
drawCenteredString(matrices, textRenderer, this.getName(), x + 25, y + 25 - textRenderer.fontHeight / 2, 0xffffff); drawCenteredString(matrices, textRenderer, this.getName(), x + 25, y + 25 - textRenderer.fontHeight / 2, 0xffffff);
} }
} }

View File

@@ -21,26 +21,22 @@ import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier; import java.util.function.Supplier;
public class KeyBindingRingAction extends RingAction public class KeyBindingRingAction extends RingAction {
{ public static final Factory FACTORY = new Factory();
public static final Factory FACTORY = new Factory(); public final KeyBinding binding;
public final KeyBinding binding;
public KeyBindingRingAction(@NotNull Config config, @NotNull KeyBinding binding) public KeyBindingRingAction(@NotNull Config config, @NotNull KeyBinding binding) {
{
super(config); super(config);
this.binding = binding; this.binding = binding;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.binding.getTranslationKey(); return this.binding.getTranslationKey();
} }
@Override @Override
public void onAction(@NotNull RingButtonMode mode) public void onAction(@NotNull RingButtonMode mode) {
{
KeyBindingAccessor accessor = (KeyBindingAccessor) this.binding; KeyBindingAccessor accessor = (KeyBindingAccessor) this.binding;
switch (mode) { switch (mode) {
case PRESS: case PRESS:
@@ -55,22 +51,18 @@ public class KeyBindingRingAction extends RingAction
} }
@Override @Override
public void drawIcon(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) public void drawIcon(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) {
{
drawCenteredText(matrices, textRenderer, new TranslatableText(this.getName()), x + 25, y + 25 - textRenderer.fontHeight / 2, 0xffffff); drawCenteredText(matrices, textRenderer, new TranslatableText(this.getName()), x + 25, y + 25 - textRenderer.fontHeight / 2, 0xffffff);
} }
protected static class Factory implements RingAction.Factory protected static class Factory implements RingAction.Factory {
{
@Override @Override
public @NotNull Supplier<RingAction> newFromGui(@NotNull Screen screen) public @NotNull Supplier<RingAction> newFromGui(@NotNull Screen screen) {
{
return () -> null; return () -> null;
} }
@Override @Override
public @Nullable RingAction parse(@NotNull Config config) public @Nullable RingAction parse(@NotNull Config config) {
{
return null; return null;
} }
} }

View File

@@ -10,9 +10,9 @@
package dev.lambdaurora.lambdacontrols.client.ring; package dev.lambdaurora.lambdacontrols.client.ring;
import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.Config;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@@ -26,22 +26,19 @@ import java.util.List;
* @version 1.5.0 * @version 1.5.0
* @since 1.4.0 * @since 1.4.0
*/ */
public final class LambdaRing public final class LambdaRing {
{
public static final int ELEMENT_SIZE = 50; public static final int ELEMENT_SIZE = 50;
private final Object2ObjectMap<String, RingAction.Factory> actionFactories = new Object2ObjectOpenHashMap<>(); private final Object2ObjectMap<String, RingAction.Factory> actionFactories = new Object2ObjectOpenHashMap<>();
private final List<RingPage> pages = new ArrayList<>(Collections.singletonList(RingPage.DEFAULT)); private final List<RingPage> pages = new ArrayList<>(Collections.singletonList(RingPage.DEFAULT));
private final LambdaControlsClient mod; private final LambdaControlsClient mod;
private int currentPage = 0; private int currentPage = 0;
public LambdaRing(@NotNull LambdaControlsClient mod) public LambdaRing(@NotNull LambdaControlsClient mod) {
{
this.mod = mod; this.mod = mod;
} }
public void registerAction(@NotNull String name, @NotNull RingAction.Factory factory) public void registerAction(@NotNull String name, @NotNull RingAction.Factory factory) {
{
if (this.actionFactories.containsKey(name)) { if (this.actionFactories.containsKey(name)) {
this.mod.warn("Tried to register twice a ring action: \"" + name + "\"."); this.mod.warn("Tried to register twice a ring action: \"" + name + "\".");
return; return;
@@ -54,8 +51,7 @@ public final class LambdaRing
* *
* @param config The configuration. * @param config The configuration.
*/ */
public void load(@NotNull Config config) public void load(@NotNull Config config) {
{
List<Config> configPages = config.get("ring.pages"); List<Config> configPages = config.get("ring.pages");
if (configPages != null) { if (configPages != null) {
this.pages.clear(); this.pages.clear();
@@ -68,8 +64,7 @@ public final class LambdaRing
} }
} }
public @NotNull RingPage getCurrentPage() public @NotNull RingPage getCurrentPage() {
{
if (this.currentPage >= this.pages.size()) if (this.currentPage >= this.pages.size())
this.currentPage = this.pages.size() - 1; this.currentPage = this.pages.size() - 1;
else if (this.currentPage < 0) else if (this.currentPage < 0)

View File

@@ -29,13 +29,11 @@ import java.util.function.Supplier;
* @version 1.5.0 * @version 1.5.0
* @since 1.4.0 * @since 1.4.0
*/ */
public abstract class RingAction extends DrawableHelper implements Nameable public abstract class RingAction extends DrawableHelper implements Nameable {
{ protected Config config;
protected Config config;
protected boolean activated = false; protected boolean activated = false;
public RingAction(@NotNull Config config) public RingAction(@NotNull Config config) {
{
this.config = config; this.config = config;
} }
@@ -44,8 +42,7 @@ public abstract class RingAction extends DrawableHelper implements Nameable
* *
* @return The text name. * @return The text name.
*/ */
public Text getTextName() public Text getTextName() {
{
return new TranslatableText(this.getName()); return new TranslatableText(this.getName());
} }
@@ -54,13 +51,11 @@ public abstract class RingAction extends DrawableHelper implements Nameable
* *
* @return True if the action is activated, else false. * @return True if the action is activated, else false.
*/ */
public boolean isActivated() public boolean isActivated() {
{
return this.activated; return this.activated;
} }
public void activate(@NotNull RingButtonMode mode) public void activate(@NotNull RingButtonMode mode) {
{
this.activated = !this.activated; this.activated = !this.activated;
this.onAction(mode); this.onAction(mode);
@@ -68,8 +63,7 @@ public abstract class RingAction extends DrawableHelper implements Nameable
public abstract void onAction(@NotNull RingButtonMode mode); public abstract void onAction(@NotNull RingButtonMode mode);
public void render(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) public void render(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) {
{
fill(matrices, x, y, x + LambdaRing.ELEMENT_SIZE, y + LambdaRing.ELEMENT_SIZE, hovered ? 0xbb777777 : 0xbb000000); fill(matrices, x, y, x + LambdaRing.ELEMENT_SIZE, y + LambdaRing.ELEMENT_SIZE, hovered ? 0xbb777777 : 0xbb000000);
drawIcon(matrices, textRenderer, x, y, hovered); drawIcon(matrices, textRenderer, x, y, hovered);
} }
@@ -82,8 +76,7 @@ public abstract class RingAction extends DrawableHelper implements Nameable
* @version 1.4.3 * @version 1.4.3
* @since 1.4.3 * @since 1.4.3
*/ */
public interface Factory public interface Factory {
{
@NotNull Supplier<RingAction> newFromGui(@NotNull Screen screen); @NotNull Supplier<RingAction> newFromGui(@NotNull Screen screen);
@Nullable RingAction parse(@NotNull Config config); @Nullable RingAction parse(@NotNull Config config);

View File

@@ -21,17 +21,15 @@ import org.jetbrains.annotations.NotNull;
* @version 1.4.0 * @version 1.4.0
* @since 1.4.0 * @since 1.4.0
*/ */
public enum RingButtonMode implements Nameable public enum RingButtonMode implements Nameable {
{
PRESS("press"), PRESS("press"),
HOLD("hold"), HOLD("hold"),
TOGGLE("toggle"); TOGGLE("toggle");
private final String name; private final String name;
private final Text text; private final Text text;
RingButtonMode(@NotNull String name) RingButtonMode(@NotNull String name) {
{
this.name = name; this.name = name;
this.text = new TranslatableText(this.getTranslationKey()); this.text = new TranslatableText(this.getTranslationKey());
} }
@@ -41,8 +39,7 @@ public enum RingButtonMode implements Nameable
* *
* @return The next ring button mode. * @return The next ring button mode.
*/ */
public @NotNull RingButtonMode next() public @NotNull RingButtonMode next() {
{
RingButtonMode[] v = values(); RingButtonMode[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -54,8 +51,7 @@ public enum RingButtonMode implements Nameable
* *
* @return The translation key of this ring button mode. * @return The translation key of this ring button mode.
*/ */
public @NotNull String getTranslationKey() public @NotNull String getTranslationKey() {
{
return "lambdacontrols.ring.button_mode." + this.getName(); return "lambdacontrols.ring.button_mode." + this.getName();
} }
@@ -64,14 +60,12 @@ public enum RingButtonMode implements Nameable
* *
* @return The translated name of this ring button mode. * @return The translated name of this ring button mode.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name; return this.name;
} }
} }

View File

@@ -25,15 +25,13 @@ import java.util.Optional;
* @version 1.5.0 * @version 1.5.0
* @since 1.4.0 * @since 1.4.0
*/ */
public class RingPage extends DrawableHelper public class RingPage extends DrawableHelper {
{
public static final RingPage DEFAULT = new RingPage("Default"); public static final RingPage DEFAULT = new RingPage("Default");
public final String name; public final String name;
private RingAction[] actions = new RingAction[8]; private RingAction[] actions = new RingAction[8];
public RingPage(@NotNull String name) public RingPage(@NotNull String name) {
{
this.name = name; this.name = name;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
this.actions[i] = null; this.actions[i] = null;
@@ -43,15 +41,14 @@ public class RingPage extends DrawableHelper
/** /**
* Renders the ring page. * Renders the ring page.
* *
* @param matrices The matrices. * @param matrices The matrices.
* @param width The screen width. * @param width The screen width.
* @param height The screen height. * @param height The screen height.
* @param mouseX The mouse X-coordinate. * @param mouseX The mouse X-coordinate.
* @param mouseY The mouse Y-coordinate. * @param mouseY The mouse Y-coordinate.
* @param tickDelta The tick delta. * @param tickDelta The tick delta.
*/ */
public void render(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int width, int height, int mouseX, int mouseY, float tickDelta) public void render(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int width, int height, int mouseX, int mouseY, float tickDelta) {
{
int centerX = width / 2; int centerX = width / 2;
int centerY = height / 2; int centerY = height / 2;
@@ -83,8 +80,7 @@ public class RingPage extends DrawableHelper
} }
} }
private static boolean isHovered(int x, int y, int mouseX, int mouseY) private static boolean isHovered(int x, int y, int mouseX, int mouseY) {
{
return mouseX >= x && mouseY >= y && mouseX <= x + LambdaRing.ELEMENT_SIZE && mouseY <= y + LambdaRing.ELEMENT_SIZE; return mouseX >= x && mouseY >= y && mouseX <= x + LambdaRing.ELEMENT_SIZE && mouseY <= y + LambdaRing.ELEMENT_SIZE;
} }
@@ -94,8 +90,7 @@ public class RingPage extends DrawableHelper
* @param config The configuration. * @param config The configuration.
* @return An optional ring page. * @return An optional ring page.
*/ */
public static @NotNull Optional<RingPage> parseRingPage(@NotNull Config config) public static @NotNull Optional<RingPage> parseRingPage(@NotNull Config config) {
{
String name = config.get("name"); String name = config.get("name");
if (name == null) if (name == null)
return Optional.empty(); return Optional.empty();

View File

@@ -16,8 +16,7 @@ import org.jetbrains.annotations.Nullable;
/** /**
* Represents an accessor to AbstractContainerScreen. * Represents an accessor to AbstractContainerScreen.
*/ */
public interface HandledScreenAccessor public interface HandledScreenAccessor {
{
/** /**
* Gets the left coordinate of the GUI. * Gets the left coordinate of the GUI.
* *
@@ -39,17 +38,17 @@ public interface HandledScreenAccessor
* @param pos_y The Y position to check. * @param pos_y The Y position to check.
* @return The slot at the specified position. * @return The slot at the specified position.
*/ */
Slot lambdacontrols_getSlotAt(double pos_x, double pos_y); Slot lambdacontrols$getSlotAt(double pos_x, double pos_y);
boolean lambdacontrols_isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button); boolean lambdacontrols$isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button);
/** /**
* Handles a mouse click on the specified slot. * Handles a mouse click on the specified slot.
* *
* @param slot The slot instance. * @param slot The slot instance.
* @param slotId The slot id. * @param slotId The slot id.
* @param clickData The click data. * @param clickData The click data.
* @param actionType The action type. * @param actionType The action type.
*/ */
void lambdacontrols_onMouseClick(@Nullable Slot slot, int slotId, int clickData, SlotActionType actionType); void lambdacontrols$onMouseClick(@Nullable Slot slot, int slotId, int clickData, SlotActionType actionType);
} }

View File

@@ -12,17 +12,15 @@ package dev.lambdaurora.lambdacontrols.client.util;
/** /**
* Represents a Minecraft keybinding with extra access. * Represents a Minecraft keybinding with extra access.
*/ */
public interface KeyBindingAccessor public interface KeyBindingAccessor {
{ boolean lambdacontrols$press();
boolean lambdacontrols_press();
boolean lambdacontrols_unpress(); boolean lambdacontrols$unpress();
default boolean lambdacontrols_handlePressState(boolean pressed) default boolean lambdacontrols_handlePressState(boolean pressed) {
{
if (pressed) if (pressed)
return this.lambdacontrols_press(); return this.lambdacontrols$press();
else else
return this.lambdacontrols_unpress(); return this.lambdacontrols$unpress();
} }
} }

View File

@@ -12,7 +12,6 @@ package dev.lambdaurora.lambdacontrols.client.util;
/** /**
* Represents mouse's extra access. * Represents mouse's extra access.
*/ */
public interface MouseAccessor public interface MouseAccessor {
{ void lambdacontrols$onCursorPos(long window, double x, double y);
void lambdacontrols_onCursorPos(long window, double x, double y);
} }

View File

@@ -23,8 +23,7 @@ import org.jetbrains.annotations.NotNull;
* @since 1.1.0 * @since 1.1.0
*/ */
@FunctionalInterface @FunctionalInterface
public interface PlayerChangeControlsModeCallback public interface PlayerChangeControlsModeCallback {
{
Event<PlayerChangeControlsModeCallback> EVENT = EventFactory.createArrayBacked(PlayerChangeControlsModeCallback.class, listeners -> (player, controlsMode) -> { Event<PlayerChangeControlsModeCallback> EVENT = EventFactory.createArrayBacked(PlayerChangeControlsModeCallback.class, listeners -> (player, controlsMode) -> {
for (PlayerChangeControlsModeCallback event : listeners) { for (PlayerChangeControlsModeCallback event : listeners) {
event.apply(player, controlsMode); event.apply(player, controlsMode);

View File

@@ -6,7 +6,6 @@
"AbstractButtonWidgetAccessor", "AbstractButtonWidgetAccessor",
"AdvancementsScreenAccessor", "AdvancementsScreenAccessor",
"ClientPlayerEntityMixin", "ClientPlayerEntityMixin",
"ClientPlayNetworkHandlerMixin",
"ControlsOptionsScreenMixin", "ControlsOptionsScreenMixin",
"CreativeInventoryScreenAccessor", "CreativeInventoryScreenAccessor",
"EntryListWidgetAccessor", "EntryListWidgetAccessor",