More code improvements

This commit is contained in:
Martin Prokoph
2024-07-22 15:57:43 +02:00
parent a55e506af0
commit 78ada44d73
6 changed files with 9 additions and 45 deletions

View File

@@ -288,7 +288,7 @@ public class MidnightInput {
float rightX = polarUtil.polarX;
float rightY = polarUtil.polarY;
boolean isRadialMenu = client.currentScreen instanceof RingScreen || (EmotecraftCompat.isPresent() && EmotecraftCompat.isEmotecraftScreen(client.currentScreen));
boolean isRadialMenu = client.currentScreen instanceof RingScreen || (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.currentScreen));
if (!isRadialMenu) {
for (int i = 0; i < GLFW_GAMEPAD_AXIS_LEFT_TRIGGER; i++) {
@@ -427,7 +427,7 @@ public class MidnightInput {
private void handleJoystickAxis(AxisStorage storage) {
storage.setupButtonStates();
this.handleMovement(storage);
this.handleJoystickMovement(storage);
if (this.handleScreenScrolling(client.currentScreen, storage)) return;
@@ -496,7 +496,7 @@ public class MidnightInput {
}
}
private void handleMovement(AxisStorage storage) {
private void handleJoystickMovement(AxisStorage storage) {
float axisValue = storage.absValue;
if (!MidnightControlsConfig.analogMovement || (client.player != null && client.player.getVehicle() instanceof BoatEntity)) {
axisValue = (float) (storage.absValue - storage.deadZone);
@@ -505,10 +505,9 @@ public class MidnightInput {
}
axisValue = (float) Math.min(axisValue / MidnightControlsConfig.getAxisMaxValue(storage.axis), 1);
if (!MidnightControlsCompat.handleMovement(storage, axisValue)) {
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, true), storage.polarity == AxisStorage.Polarity.PLUS ? axisValue : 0.f);
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, false), storage.polarity == AxisStorage.Polarity.MINUS ? axisValue : 0.f);
}
if (AxisStorage.isLeftAxis(storage.axis) && MidnightControlsCompat.handleMovement(storage, axisValue)) return;
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, true), storage.polarity == AxisStorage.Polarity.PLUS ? axisValue : 0.f);
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, false), storage.polarity == AxisStorage.Polarity.MINUS ? axisValue : 0.f);
}
private boolean handleScreenScrolling(Screen screen, AxisStorage storage) {
@@ -587,7 +586,7 @@ public class MidnightInput {
else if (y > border) index = 6;
}
if (client.currentScreen instanceof RingScreen && index > -1) RingPage.selected = index;
if (EmotecraftCompat.isPresent() && EmotecraftCompat.isEmotecraftScreen(client.currentScreen)) EmotecraftCompat.handleEmoteSelector(index);
if (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.currentScreen)) EmotecraftCompat.handleEmoteSelector(index);
}
public boolean handleListWidgetScrolling(List<? extends Element> children, float value) {

View File

@@ -12,8 +12,6 @@ import org.lwjgl.glfw.GLFW;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
public class EMICompat implements CompatHandler {
protected static boolean isPresent;
public static boolean handleEmiPages(boolean direction) {
if (isEMIEnabled() && MidnightControlsClient.input.actionGuiCooldown == 0 && EmiScreenManager.getSearchPanel() != null && EmiScreenManager.getSearchPanel().pageLeft != null && EmiScreenManager.getSearchPanel().pageRight != null) {
if (direction) EmiScreenManager.getSearchPanel().pageRight.onPress();
@@ -40,14 +38,6 @@ public class EMICompat implements CompatHandler {
.filter(((buttonBinding) -> EmiApi.getHandledScreen() != null))
.register();
}
/**
* Returns whether EMI is present.
*
* @return true if EMI is present, else false
*/
public static boolean isPresent() {
return isPresent;
}
public static boolean isEMIEnabled() {
return EmiConfig.enabled;
}

View File

@@ -7,7 +7,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
public class EmotecraftCompat {
protected static boolean isPresent;
private static final MinecraftClient client = MinecraftClient.getInstance();
public static void openEmotecraftScreen(Screen parent) {
@@ -34,13 +33,4 @@ public class EmotecraftCompat {
InputManager.INPUT_MANAGER.updateMousePosition(client);
}
}
/**
* Returns whether Emotecraft is present.
*
* @return true if Emotecraft is present, else false
*/
public static boolean isPresent() {
return isPresent;
}
}

View File

@@ -6,8 +6,6 @@ import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
public class InventoryTabsCompat implements CompatHandler {
protected static boolean isPresent;
@Override
public boolean handleTabs(Screen screen, boolean next) {
if (screen instanceof HandledScreen<?> && !(screen instanceof CreativeInventoryScreen)) {
@@ -42,12 +40,4 @@ public class InventoryTabsCompat implements CompatHandler {
}
return false;
}
/**
* Returns whether InventoryTabs is present.
*
* @return true if InventoryTabs is present, else false
*/
public static boolean isPresent() {
return isPresent;
}
}

View File

@@ -43,7 +43,6 @@ public class MidnightControlsCompat {
if (PlatformFunctions.isModLoaded("emi")) {
log("Adding EMI compatibility...");
registerCompatHandler(new EMICompat());
EMICompat.isPresent = true;
}
if (PlatformFunctions.isModLoaded("hardcorequesting") && LambdaReflection.doesClassExist(HQMCompat.GUI_BASE_CLASS_PATH)) {
log("Adding HQM compatibility...");
@@ -64,10 +63,6 @@ public class MidnightControlsCompat {
if (PlatformFunctions.isModLoaded("inventorytabs")) {
log("Adding Inventory Tabs compatibility...");
registerCompatHandler(new InventoryTabsCompat());
InventoryTabsCompat.isPresent = true;
}
if (PlatformFunctions.isModLoaded("emotecraft")) {
EmotecraftCompat.isPresent = true;
}
HANDLERS.forEach(CompatHandler::handle);
InputManager.loadButtonBindings();

View File

@@ -57,7 +57,7 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor {
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.hudEnable) {
var client = MinecraftClient.getInstance();
int x = 2, y = client.getWindow().getScaledHeight() - 2 - MidnightControlsRenderer.ICON_SIZE;
if (EMICompat.isPresent() && EMICompat.isEMIEnabled()) {
if (PlatformFunctions.isModLoaded("emi") && EMICompat.isEMIEnabled()) {
x += 42;
}
if (!ButtonBinding.TAKE_ALL.isNotBound()) x = MidnightControlsRenderer.drawButtonTip(context, x, y, ButtonBinding.TAKE_ALL,true, client) + 2;
@@ -66,7 +66,7 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor {
x = 2;
y -= 24;
}
if (EMICompat.isPresent() && EMICompat.isEMIEnabled() && EMICompat.isSearchBarCentered()) {
if (PlatformFunctions.isModLoaded("emi") && EMICompat.isEMIEnabled() && EMICompat.isSearchBarCentered()) {
x = client.getWindow().getScaledWidth() - 4 - client.textRenderer.getWidth(Text.translatable("midnightcontrols.action.pickup"))
- client.textRenderer.getWidth(Text.translatable("midnightcontrols.action.quick_move"))
- 2 * MidnightControlsRenderer.getBindingIconWidth(ButtonBinding.TAKE) - MidnightControlsRenderer.getBindingIconWidth(ButtonBinding.QUICK_MOVE);