Remove non-deprecated references of LambdaJCommon

Sorry Lambda!
This is needed for Neoforge support and to reduce the file size in the future.
This commit is contained in:
Martin Prokoph
2024-07-18 00:27:32 +02:00
parent 241228dcde
commit 0d2bd6e4cb
15 changed files with 80 additions and 92 deletions

View File

@@ -22,7 +22,7 @@ import java.util.Optional;
* @version 1.7.0
* @since 1.0.0
*/
public enum ControlsMode implements Nameable {
public enum ControlsMode {
DEFAULT,
CONTROLLER,
TOUCHSCREEN;
@@ -49,7 +49,6 @@ public enum ControlsMode implements Nameable {
return "midnightcontrols.controls_mode." + this.getName();
}
@Override
public @NotNull String getName() {
return this.name().toLowerCase();
}

View File

@@ -29,13 +29,13 @@ public class EMICompat implements CompatHandler {
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))
.category(category)
.action((client,action,value,buttonState)->handleEmiPages(false)).cooldown()
.filter(((client, buttonBinding) -> EmiApi.getHandledScreen() != null))
.filter(((buttonBinding) -> EmiApi.getHandledScreen() != null))
.register();
new ButtonBinding.Builder("emi_page_right")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true))
.category(category)
.action((client,action,value,buttonState)->handleEmiPages(true)).cooldown()
.filter(((client, buttonBinding) -> EmiApi.getHandledScreen() != null))
.filter(((buttonBinding) -> EmiApi.getHandledScreen() != null))
.register();
}
public static boolean isEMIEnabled() {

View File

@@ -9,6 +9,7 @@
package eu.midnightdust.midnightcontrols.client.controller;
import com.google.common.base.Predicates;
import eu.midnightdust.midnightcontrols.client.enums.ButtonState;
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import eu.midnightdust.midnightcontrols.client.gui.RingScreen;
@@ -18,14 +19,14 @@ import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.aperlambda.lambdacommon.utils.function.PairPredicate;
import org.aperlambda.lambdacommon.utils.function.Predicates;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
import static org.lwjgl.glfw.GLFW.*;
/**
@@ -63,7 +64,7 @@ public class ButtonBinding {
public static final ButtonBinding HOTBAR_RIGHT = new Builder("hotbar_right").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
.action(InputHandlers.handleHotbar(true)).onlyInGame().cooldown().register();
public static final ButtonBinding INVENTORY = new Builder("inventory").buttons(GLFW_GAMEPAD_BUTTON_Y).onlyInGame().cooldown().register();
public static final ButtonBinding EXIT = new Builder("exit").buttons(GLFW_GAMEPAD_BUTTON_B).filter((client, buttonBinding) -> client.currentScreen != null && buttonBinding.cooldown == 0 && INVENTORY.cooldown == 0)
public static final ButtonBinding EXIT = new Builder("exit").buttons(GLFW_GAMEPAD_BUTTON_B).filter((buttonBinding) -> client.currentScreen != null && buttonBinding.cooldown == 0 && INVENTORY.cooldown == 0)
.action(InputHandlers.handleExit()).cooldown().register();
public static final ButtonBinding JUMP = new Builder("jump").buttons(GLFW_GAMEPAD_BUTTON_A).onlyInGame().register();
public static final ButtonBinding LEFT = new Builder("left").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, false))
@@ -91,9 +92,9 @@ public class ButtonBinding {
.actions(InputHandlers::handleToggleSprint).onlyInGame().cooldown().register();
public static final ButtonBinding SWAP_HANDS = new Builder("swap_hands").buttons(GLFW_GAMEPAD_BUTTON_X).onlyInGame().cooldown().register();
public static final ButtonBinding TAB_LEFT = new Builder("tab_back").buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
.action(InputHandlers.handleHotbar(false)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements).or((client, binding) -> client.currentScreen != null)).cooldown().register();
.action(InputHandlers.handleHotbar(false)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements).or((binding) -> client.currentScreen != null)).cooldown().register();
public static final ButtonBinding TAB_RIGHT = new Builder("tab_next").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
.action(InputHandlers.handleHotbar(true)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements).or((client, binding) -> client.currentScreen != null)).cooldown().register();
.action(InputHandlers.handleHotbar(true)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements).or((binding) -> client.currentScreen != null)).cooldown().register();
public static final ButtonBinding PAGE_LEFT = new Builder("page_back").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))
.action(InputHandlers.handlePage(false)).filter(InputHandlers::inInventory).cooldown(30).register();
public static final ButtonBinding PAGE_RIGHT = new Builder("page_next").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true))
@@ -112,14 +113,14 @@ public class ButtonBinding {
private final String key;
private final Text text;
private KeyBinding mcKeyBinding = null;
protected PairPredicate<MinecraftClient, ButtonBinding> filter;
protected Predicate<ButtonBinding> filter;
private final List<PressAction> actions = new ArrayList<>(Collections.singletonList(PressAction.DEFAULT_ACTION));
private final boolean hasCooldown;
private int cooldownLength = 5;
private int cooldown = 0;
private boolean pressed = false;
public ButtonBinding(String key, int[] defaultButton, List<PressAction> actions, PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
public ButtonBinding(String key, int[] defaultButton, List<PressAction> actions, Predicate<ButtonBinding> filter, boolean hasCooldown) {
this.setButton(this.defaultButton = defaultButton);
this.key = key;
this.text = Text.translatable(this.key);
@@ -127,7 +128,7 @@ public class ButtonBinding {
this.actions.addAll(actions);
this.hasCooldown = hasCooldown;
}
public ButtonBinding(String key, int[] defaultButton, List<PressAction> actions, PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown, int cooldownLength) {
public ButtonBinding(String key, int[] defaultButton, List<PressAction> actions, Predicate<ButtonBinding> filter, boolean hasCooldown, int cooldownLength) {
this.setButton(this.defaultButton = defaultButton);
this.key = key;
this.text = Text.translatable(this.key);
@@ -138,10 +139,10 @@ public class ButtonBinding {
}
public ButtonBinding(String key, int[] defaultButton, boolean hasCooldown) {
this(key, defaultButton, Collections.emptyList(), Predicates.pairAlwaysTrue(), hasCooldown);
this(key, defaultButton, Collections.emptyList(), Predicates.alwaysTrue(), hasCooldown);
}
public ButtonBinding(String key, int[] defaultButton, boolean hasCooldown, int cooldownLength) {
this(key, defaultButton, Collections.emptyList(), Predicates.pairAlwaysTrue(), hasCooldown, cooldownLength);
this(key, defaultButton, Collections.emptyList(), Predicates.alwaysTrue(), hasCooldown, cooldownLength);
}
/**
@@ -252,11 +253,10 @@ public class ButtonBinding {
/**
* Returns whether the button binding is available in the current context.
*
* @param client the client instance
* @return true if the button binding is available, else false
*/
public boolean isAvailable(@NotNull MinecraftClient client) {
return this.filter.test(client, this);
public boolean isAvailable() {
return this.filter.test(this);
}
/**
@@ -480,7 +480,7 @@ public class ButtonBinding {
private final String key;
private int[] buttons = new int[0];
private final List<PressAction> actions = new ArrayList<>();
private PairPredicate<MinecraftClient, ButtonBinding> filter = Predicates.pairAlwaysTrue();
private Predicate<ButtonBinding> filter = Predicates.alwaysTrue();
private boolean cooldown = false;
private int cooldownLength = 5;
private ButtonCategory category = null;
@@ -499,6 +499,10 @@ public class ButtonBinding {
public Builder(@NotNull Identifier identifier) {
this(identifier.getNamespace() + "." + identifier.getPath());
}
@Deprecated
public Builder(@NotNull org.aperlambda.lambdacommon.Identifier identifier) {
this(identifier.getNamespace() + "." + identifier.getName());
}
/**
* Defines the default buttons of the {@link ButtonBinding}.
@@ -548,7 +552,7 @@ public class ButtonBinding {
* @param filter the filter
* @return the builder instance
*/
public Builder filter(@NotNull PairPredicate<MinecraftClient, ButtonBinding> filter) {
public Builder filter(@NotNull Predicate<ButtonBinding> filter) {
this.filter = filter;
return this;
}
@@ -557,8 +561,8 @@ public class ButtonBinding {
* Sets the filter of {@link ButtonBinding} to only in game.
*
* @return the builder instance
* @see #filter(PairPredicate)
* @see InputHandlers#inGame(MinecraftClient, ButtonBinding)
* @see #filter(Predicate)
* @see InputHandlers#inGame(ButtonBinding)
*/
public Builder onlyInGame() {
return this.filter(InputHandlers::inGame);
@@ -568,8 +572,8 @@ public class ButtonBinding {
* Sets the filter of {@link ButtonBinding} to only in inventory.
*
* @return the builder instance
* @see #filter(PairPredicate)
* @see InputHandlers#inInventory(MinecraftClient, ButtonBinding)
* @see #filter(Predicate)
* @see InputHandlers#inInventory(ButtonBinding)
*/
public Builder onlyInInventory() {
return this.filter(InputHandlers::inInventory);

View File

@@ -43,7 +43,7 @@ import static org.lwjgl.BufferUtils.createByteBuffer;
* @version 1.7.0
* @since 1.0.0
*/
public record Controller(int id) implements Nameable {
public record Controller(int id) {
private static final Map<Integer, Controller> CONTROLLERS = new HashMap<>();
/**
@@ -79,7 +79,6 @@ public record Controller(int id) implements Nameable {
*
* @return the controller's name
*/
@Override
public @NotNull String getName() {
var name = this.isGamepad() ? GLFW.glfwGetGamepadName(this.id) : GLFW.glfwGetJoystickName(this.id);
return name == null ? String.valueOf(this.id()) : name;

View File

@@ -37,6 +37,7 @@ import org.lwjgl.glfw.GLFW;
import java.util.Optional;
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_2;
@@ -268,33 +269,30 @@ public class InputHandlers {
/**
* Returns always true to the filter.
*
* @param client the client instance
* @param binding the affected binding
* @return true
*/
public static boolean always(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
public static boolean always(@NotNull ButtonBinding binding) {
return true;
}
/**
* Returns whether the client is in game or not.
*
* @param client the client instance
* @param binding the affected binding
* @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 ButtonBinding binding) {
return (client.currentScreen == null && MidnightControlsClient.input.screenCloseCooldown <= 0) || client.currentScreen instanceof TouchscreenOverlay || client.currentScreen instanceof RingScreen;
}
/**
* Returns whether the client is in a non-interactive screen (which means require mouse input) or not.
*
* @param client the client instance
* @param binding the affected binding
* @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 ButtonBinding binding) {
if (client.currentScreen == null)
return false;
return !MidnightInput.isScreenInteractive(client.currentScreen);
@@ -303,22 +301,20 @@ public class InputHandlers {
/**
* Returns whether the client is in an inventory or not.
*
* @param client the client instance
* @param binding the affected binding
* @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 ButtonBinding binding) {
return client.currentScreen instanceof HandledScreen;
}
/**
* Returns whether the client is in the advancements screen or not.
*
* @param client the client instance
* @param binding the affected binding
* @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 ButtonBinding binding) {
return client.currentScreen instanceof AdvancementsScreen;
}
}

View File

@@ -27,6 +27,7 @@ import org.lwjgl.glfw.GLFW;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
@@ -166,7 +167,7 @@ public class InputManager {
}
@Deprecated
public static @NotNull ButtonBinding registerBinding(@NotNull org.aperlambda.lambdacommon.Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
public static @NotNull ButtonBinding registerBinding(@NotNull org.aperlambda.lambdacommon.Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull Predicate<ButtonBinding> filter, boolean hasCooldown) {
return registerBinding(Identifier.of(id.getNamespace(), id.getName()), defaultButton, actions, filter, hasCooldown);
}
@@ -175,7 +176,7 @@ public class InputManager {
return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown);
}
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 Predicate<ButtonBinding> filter, boolean hasCooldown) {
return registerBinding(new ButtonBinding(id.getNamespace() + "." + id.getPath(), defaultButton, actions, filter, hasCooldown));
}
@@ -345,7 +346,7 @@ public class InputManager {
}
var states = new Object2ObjectOpenHashMap<ButtonBinding, ButtonStateValue>();
for (var binding : BINDINGS) {
var state = binding.isAvailable(client) ? getBindingState(binding) : ButtonState.NONE;
var state = binding.isAvailable() ? getBindingState(binding) : ButtonState.NONE;
if (skipButtons.intStream().anyMatch(btn -> containsButton(binding.getButton(), btn))) {
if (binding.isPressed())
state = ButtonState.RELEASE;

View File

@@ -10,7 +10,6 @@
package eu.midnightdust.midnightcontrols.client.enums;
import net.minecraft.text.Text;
import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@@ -22,7 +21,7 @@ import java.util.Optional;
* @version 1.7.0
* @since 1.2.0
*/
public enum VirtualMouseSkin implements Nameable {
public enum VirtualMouseSkin {
DEFAULT_LIGHT("default_light"),
DEFAULT_DARK("default_dark"),
SECOND_LIGHT("second_light"),
@@ -66,7 +65,6 @@ public enum VirtualMouseSkin implements Nameable {
return this.text;
}
@Override
public @NotNull String getName() {
return this.name;
}

View File

@@ -9,6 +9,7 @@
package eu.midnightdust.midnightcontrols.client.mixin;
import com.llamalad7.mixinextras.sugar.Local;
import eu.midnightdust.midnightcontrols.MidnightControlsFeature;
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
@@ -108,8 +109,8 @@ public abstract class MinecraftClientMixin {
}
}
@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) {
@Inject(method = "doItemUse()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"), cancellable = true)
private void onItemUse(CallbackInfo ci, @Local Hand hand, @Local ItemStack stackInHand) {
if (player != null && !stackInHand.isEmpty() && this.player.getPitch(0.f) > 35.0F && reacharound.isReacharoundAvailable()) {
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.isOnGround()) {
if (!stackInHand.isEmpty() && stackInHand.getItem() instanceof BlockItem) {

View File

@@ -34,7 +34,6 @@ public class ButtonBindingRingAction extends RingAction {
this.binding = binding;
}
@Override
public @NotNull String getName() {
return this.binding.getTranslationKey();
}

View File

@@ -27,21 +27,12 @@ import java.util.function.Supplier;
* @version 1.5.0
* @since 1.4.0
*/
public abstract class RingAction implements Nameable {
public abstract class RingAction {
protected boolean activated = false;
public RingAction() {
}
/**
* Gets the text name of the ring action.
*
* @return the text name
*/
public Text getTextName() {
return Text.translatable(this.getName());
}
/**
* Returns whether the action is activated or not.
*

View File

@@ -5,8 +5,8 @@
"version": "${version}",
"description": "Adds controller support and enhanced controls overall.",
"authors": [
"LambdAurora",
"Motschen"
"Motschen",
"LambdAurora"
],
"contributors": [
"akemin-dayo",

View File

@@ -41,6 +41,11 @@ configurations {
dependencies {
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-neoforge")
include modImplementation ("maven.modrinth:obsidianui:${project.obsidianui_version}-neoforge") {}
shadowBundle('org.aperlambda:lambdajcommon:1.8.1') {
exclude group: 'com.google.code.gson'
exclude group: 'com.google.guava'
}
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')

View File

@@ -1,28 +0,0 @@
package com.example.yourmod.neoforge;
import com.example.yourmod.YourMod;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.common.Mod;
import static com.example.yourmod.YourMod.MOD_ID;
@Mod(value = MOD_ID)
public class YourModNeoForge {
public YourModNeoForge() {
YourMod.init();
}
@Mod(value = MOD_ID, dist = Dist.CLIENT)
public static class YourModClientNeoforge {
public YourModClientNeoforge() {
YourMod.initClient();
}
}
@Mod(value = MOD_ID, dist = Dist.DEDICATED_SERVER)
public static class YourModServerNeoforge {
public YourModServerNeoforge() {
YourMod.initServer();
}
}
}

View File

@@ -0,0 +1,22 @@
package eu.midnightdust.midnightcontrols.neoforge;
import eu.midnightdust.midnightcontrols.MidnightControls;
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.common.Mod;
import static eu.midnightdust.midnightcontrols.MidnightControlsConstants.NAMESPACE;
@Mod(value = NAMESPACE)
public class MidnightControlsNeoForge {
public MidnightControlsNeoForge() {
MidnightControls.init();
}
@Mod(value = NAMESPACE, dist = Dist.CLIENT)
public static class YourModClientNeoforge {
public YourModClientNeoforge() {
MidnightControlsClient.initClient();
}
}
}

View File

@@ -4,33 +4,34 @@ loaderVersion = "[2,)"
license = "MIT License"
[[mods]]
modId = "yourmod"
modId = "midnightcontrols"
version = "${version}"
displayName = "Your Mod"
displayName = "MidnightControls"
logoFile = "icon.png"
authors = "You!"
authors = "Motschen, LambdAurora"
contributors = "akemin-dayo, DioEgizio, dogtopus, egeesin, EnnuiL, FlashyReese, gyular, Hambaka, Ivanoks, joaoh1, KiskaUWU, Madis0, RaptaG, ronniedude, spudpiggy, TrueHorse"
description = '''
An example multiloader mod featuring MidnightLib!
Adds controller support and enhanced controls overall.
'''
[[mixins]]
config = "yourmod.mixins.json"
config = "midnightcontrols.mixins.json"
[[dependencies.yourmod]]
[[dependencies.midnightcontrols]]
modId = "neoforge"
mandatory = true
versionRange = "[21.0,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.yourmod]]
[[dependencies.midnightcontrols]]
modId = "minecraft"
mandatory = true
versionRange = "[1.21,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.yourmod]]
[[dependencies.midnightcontrols]]
modId = "midnightlib"
mandatory = true
versionRange = "[1.0,)"