mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-14 07:35:10 +01:00
🚧 WIP on REI compatiblity.
This commit is contained in:
@@ -48,6 +48,7 @@ dependencies {
|
|||||||
|
|
||||||
// Compatibility mods
|
// Compatibility mods
|
||||||
modCompile "io.github.joaoh1:okzoomer:2.1.0-beta.2"
|
modCompile "io.github.joaoh1:okzoomer:2.1.0-beta.2"
|
||||||
|
modCompile "me.shedaniel:RoughlyEnoughItems:3.4.5"
|
||||||
|
|
||||||
api project(":core")
|
api project(":core")
|
||||||
shadow project(":core")
|
shadow project(":core")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
package me.lambdaurora.lambdacontrols.client;
|
package me.lambdaurora.lambdacontrols.client;
|
||||||
|
|
||||||
import me.lambdaurora.lambdacontrols.LambdaControlsFeature;
|
import me.lambdaurora.lambdacontrols.LambdaControlsFeature;
|
||||||
|
import me.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
|
||||||
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
|
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
|
||||||
import me.lambdaurora.lambdacontrols.client.controller.Controller;
|
import me.lambdaurora.lambdacontrols.client.controller.Controller;
|
||||||
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
|
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
|
||||||
@@ -614,7 +615,7 @@ public class LambdaInput
|
|||||||
|
|
||||||
private static boolean isScreenInteractive(@NotNull Screen screen)
|
private static boolean isScreenInteractive(@NotNull Screen screen)
|
||||||
{
|
{
|
||||||
return !(screen instanceof AdvancementsScreen || screen instanceof ContainerScreen);
|
return !(screen instanceof AdvancementsScreen || screen instanceof ContainerScreen || LambdaControlsCompat.requireMouseOnScreen(screen));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspired from https://github.com/MrCrayfish/Controllable/blob/1.14.X/src/main/java/com/mrcrayfish/controllable/client/ControllerInput.java#L686.
|
// Inspired from https://github.com/MrCrayfish/Controllable/blob/1.14.X/src/main/java/com/mrcrayfish/controllable/client/ControllerInput.java#L686.
|
||||||
|
|||||||
@@ -10,13 +10,14 @@
|
|||||||
package me.lambdaurora.lambdacontrols.client.compat;
|
package me.lambdaurora.lambdacontrols.client.compat;
|
||||||
|
|
||||||
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a compatibility handler for a mod.
|
* Represents a compatibility handler for a mod.
|
||||||
*
|
*
|
||||||
* @author LambdAurora
|
* @author LambdAurora
|
||||||
* @version 1.1.0
|
* @version 1.2.0
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
public interface CompatHandler
|
public interface CompatHandler
|
||||||
@@ -27,4 +28,15 @@ public interface CompatHandler
|
|||||||
* @param mod This mod instance.
|
* @param mod This mod instance.
|
||||||
*/
|
*/
|
||||||
void handle(@NotNull LambdaControlsClient mod);
|
void handle(@NotNull LambdaControlsClient mod);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the mouse is required on the specified screen.
|
||||||
|
*
|
||||||
|
* @param screen The screen.
|
||||||
|
* @return True if the mouse is requried on the specified screen, else false.
|
||||||
|
*/
|
||||||
|
default boolean requireMouseOnScreen(@NotNull Screen screen)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,13 @@ package me.lambdaurora.lambdacontrols.client.compat;
|
|||||||
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
||||||
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
|
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import org.aperlambda.lambdacommon.utils.LambdaReflection;
|
import org.aperlambda.lambdacommon.utils.LambdaReflection;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a compatibility handler.
|
* Represents a compatibility handler.
|
||||||
*
|
*
|
||||||
@@ -24,6 +28,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public class LambdaControlsCompat
|
public class LambdaControlsCompat
|
||||||
{
|
{
|
||||||
|
private static final List<CompatHandler> HANDLERS = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes compatibility with other mods if needed.
|
* Initializes compatibility with other mods if needed.
|
||||||
*
|
*
|
||||||
@@ -33,8 +39,24 @@ public class LambdaControlsCompat
|
|||||||
{
|
{
|
||||||
if (FabricLoader.getInstance().isModLoaded("okzoomer") && LambdaReflection.doesClassExist(OkZoomerCompat.OKZOOMER_CLASS_PATH)) {
|
if (FabricLoader.getInstance().isModLoaded("okzoomer") && LambdaReflection.doesClassExist(OkZoomerCompat.OKZOOMER_CLASS_PATH)) {
|
||||||
mod.log("Adding okzoomer compatibility...");
|
mod.log("Adding okzoomer compatibility...");
|
||||||
new OkZoomerCompat().handle(mod);
|
HANDLERS.add(new OkZoomerCompat());
|
||||||
}
|
}
|
||||||
|
if (FabricLoader.getInstance().isModLoaded("roughlyenoughitems")) {
|
||||||
|
mod.log("Adding REI compatiblity...");
|
||||||
|
HANDLERS.add(new ReiCompat());
|
||||||
|
}
|
||||||
|
HANDLERS.forEach(handler -> handler.handle(mod));
|
||||||
InputManager.loadButtonBindings(mod.config);
|
InputManager.loadButtonBindings(mod.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the mouse is required on the specified screen.
|
||||||
|
*
|
||||||
|
* @param screen The screen.
|
||||||
|
* @return True if the mouse is requried on the specified screen, else false.
|
||||||
|
*/
|
||||||
|
public static boolean requireMouseOnScreen(@NotNull Screen screen)
|
||||||
|
{
|
||||||
|
return HANDLERS.stream().anyMatch(handler -> handler.requireMouseOnScreen(screen));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* 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 me.lambdaurora.lambdacontrols.client.compat;
|
||||||
|
|
||||||
|
import me.lambdaurora.lambdacontrols.client.ButtonState;
|
||||||
|
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
||||||
|
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
|
||||||
|
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
|
||||||
|
import me.lambdaurora.lambdacontrols.client.controller.PressAction;
|
||||||
|
import me.shedaniel.rei.gui.RecipeViewingScreen;
|
||||||
|
import me.shedaniel.rei.gui.VillagerRecipeViewingScreen;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_BUTTON_LEFT_BUMPER;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a compatibility handler for REI.
|
||||||
|
*
|
||||||
|
* @author LambdAurora
|
||||||
|
* @version 1.2.0
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public class ReiCompat implements CompatHandler
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handle(@NotNull LambdaControlsClient mod)
|
||||||
|
{
|
||||||
|
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "tab_right"))
|
||||||
|
.buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
|
||||||
|
.filter((client, binding) -> isViewingScreen(client.currentScreen))
|
||||||
|
.action(tabAction(true))
|
||||||
|
.cooldown(true)
|
||||||
|
.build());
|
||||||
|
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "tab_left"))
|
||||||
|
.buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
|
||||||
|
.filter((client, binding) -> isViewingScreen(client.currentScreen))
|
||||||
|
.action(tabAction(false))
|
||||||
|
.cooldown(true)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requireMouseOnScreen(@NotNull Screen screen)
|
||||||
|
{
|
||||||
|
return isViewingScreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isViewingScreen(@NotNull Screen screen)
|
||||||
|
{
|
||||||
|
return screen instanceof RecipeViewingScreen || screen instanceof VillagerRecipeViewingScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PressAction tabAction(boolean right)
|
||||||
|
{
|
||||||
|
return (client, button, action) -> {
|
||||||
|
if (action == ButtonState.RELEASE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (client.currentScreen instanceof RecipeViewingScreen) {
|
||||||
|
RecipeViewingScreen screen = (RecipeViewingScreen) client.currentScreen;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user