Skip to content

Commit

Permalink
MidnightControls 1.1.0 - 1.19, Inventory Improvements
Browse files Browse the repository at this point in the history
- Update to 1.19
- Make buttons for Item/Stack Grabbing and Quick Moving configurable
- Add Keybinds for moving between Fabric Creative Inventory Pages
  • Loading branch information
Motschen committed Jun 9, 2022
1 parent bca73c9 commit 6e64c7c
Show file tree
Hide file tree
Showing 32 changed files with 624 additions and 274 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dependencies {

modImplementation "org.quiltmc:quilt-json5:1.0.0"
//modImplementation "maven.modrinth:sodium:${project.sodium_version}"
modImplementation("me.shedaniel:RoughlyEnoughItems-runtime-fabric:${project.rei_version}")
//modImplementation("maven.modrinth:emi:${project.emi_version}")
modImplementation "maven.modrinth:emotecraft:${project.emotecraft_version}"
modImplementation "io.github.kosmx:bendy-lib:${project.bendylib_version}"

Expand Down
269 changes: 269 additions & 0 deletions controller_banner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.22
loader_version=0.13.3
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.7

# Mod Properties
mod_version = 1.0.0
mod_version = 1.1.0
maven_group = eu.midnightdust
archives_base_name = midnightcontrols
modrinth_id=bXX9h73M

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.46.6+1.18
sodium_version=mc1.18.2-0.4.1
spruceui_version=3.3.2+1.17
midnightlib_version=0.4.0
modmenu_version=2.0.2
emotecraft_version=2.1-MC1.18.1-fabric
fabric_version=0.55.2+1.19
sodium_version=mc1.19-0.4.1
spruceui_version=4.0.0+1.19
midnightlib_version=0.5.2
modmenu_version=4.0.0
emotecraft_version=2.1.3-SNAPSHOT-build.29-MC1.19-fabric
bendylib_version=2.0.+
rei_version=7.4.456
emi_version=0.1.1+1.18.2

# Ok Zoomer and LibZoomer are temporarily disabled for the time being, as we are currently using Reflection at runtime instead in OkZoomerCompat due to there being two major, completely incompatible API versions.
# ok_zoomer_version=5.0.0-beta.3+1.17.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -38,7 +38,7 @@ public class MidnightControls implements ModInitializer {
public static final Identifier FEATURE_CHANNEL = new Identifier(MidnightControlsConstants.FEATURE_CHANNEL.toString());
public static final Identifier HELLO_CHANNEL = new Identifier(MidnightControlsConstants.HELLO_CHANNEL.toString());

public static final TranslatableText NOT_BOUND_TEXT = new TranslatableText("midnightcontrols.not_bound");
public static final Text NOT_BOUND_TEXT = Text.translatable("midnightcontrols.not_bound");

public final Logger logger = LogManager.getLogger("MidnightControls");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

package eu.midnightdust.midnightcontrols.client;

import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull;

Expand All @@ -26,22 +24,22 @@
* @since 1.0.0
*/
public enum ControllerType implements Nameable {
DEFAULT(0, new LiteralText("Default")),
DUALSHOCK(1, new LiteralText("Dualshock")),
DUALSENSE(2, new LiteralText("Dualsense")),
SWITCH(3, new LiteralText("Switch")),
XBOX_360(4, new LiteralText("Xbox 360")),
XBOX(5, new LiteralText("Xbox")),
STEAM_DECK(6, new LiteralText("Steam Deck")),
STEAM_CONTROLLER(7, new LiteralText("Steam Controller")),
OUYA(8, new LiteralText("Ouya"));
DEFAULT(0, Text.of("Default")),
DUALSHOCK(1, Text.of("Dualshock")),
DUALSENSE(2, Text.of("Dualsense")),
SWITCH(3, Text.of("Switch")),
XBOX_360(4, Text.of("Xbox 360")),
XBOX(5, Text.of("Xbox")),
STEAM_DECK(6, Text.of("Steam Deck")),
STEAM_CONTROLLER(7, Text.of("Steam Controller")),
OUYA(8, Text.of("Ouya"));

private final int id;
private final Text text;

ControllerType(int id) {
this.id = id;
this.text = new TranslatableText("midnightcontrols.controller_type." + this.getName());
this.text = Text.translatable("midnightcontrols.controller_type." + this.getName());
}

ControllerType(int id, @NotNull Text text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package eu.midnightdust.midnightcontrols.client;

import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull;

Expand All @@ -31,7 +30,7 @@ public enum HudSide implements Nameable {
private final Text text;

HudSide() {
this.text = new TranslatableText(this.getTranslationKey());
this.text = Text.translatable(this.getTranslationKey());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -133,10 +132,10 @@ public void onMcInit(@NotNull MinecraftClient client) {
GLFW.glfwSetJoystickCallback((jid, event) -> {
if (event == GLFW.GLFW_CONNECTED) {
var controller = Controller.byId(jid);
client.getToastManager().add(new SystemToast(SystemToast.Type.TUTORIAL_HINT, new TranslatableText("midnightcontrols.controller.connected", jid),
new LiteralText(controller.getName())));
client.getToastManager().add(new SystemToast(SystemToast.Type.TUTORIAL_HINT, Text.translatable("midnightcontrols.controller.connected", jid),
Text.literal(controller.getName())));
} else if (event == GLFW.GLFW_DISCONNECTED) {
client.getToastManager().add(new SystemToast(SystemToast.Type.TUTORIAL_HINT, new TranslatableText("midnightcontrols.controller.disconnected", jid),
client.getToastManager().add(new SystemToast(SystemToast.Type.TUTORIAL_HINT, Text.translatable("midnightcontrols.controller.disconnected", jid),
null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class MidnightControlsConfig extends MidnightConfig {
@Entry public static VirtualMouseSkin virtualMouseSkin = VirtualMouseSkin.DEFAULT_LIGHT;
@Entry public static Object controllerID = 0;
@Entry public static Object secondControllerID = -1;
@Entry public static List<String> mouseScreens = List.of("me.jellysquid.mods.sodium.client.gui","net.coderbot.iris.gui","net.minecraft.client.gui.screen.advancement", "net.minecraft.client.gui.screen.pack.PackScreen", "net.minecraft.class_5375", "net.minecraft.class_457", "net.minecraft.class_408");
@Entry public static List<String> mouseScreens = List.of("me.jellysquid.mods.sodium.client.gui","net.coderbot.iris.gui","net.minecraft.client.gui.screen.advancement", "net.minecraft.client.gui.screen.pack.PackScreen", "net.minecraft.class_5375", "net.minecraft.class_457", "net.minecraft.class_408", "me.flashyreese.mods.reeses_sodium_options.client.gui");
@Entry public static Map<String, String> BINDINGS = Map.of();

private static final Pattern BUTTON_BINDING_PATTERN = Pattern.compile("(-?\\d+)\\+?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import dev.lambdaurora.spruceui.widget.SpruceElement;
import dev.lambdaurora.spruceui.widget.SpruceLabelWidget;
import dev.lambdaurora.spruceui.widget.container.SpruceParentWidget;
import net.fabricmc.fabric.impl.item.group.CreativeGuiExtensions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.ParentElement;
Expand All @@ -45,18 +46,15 @@
import net.minecraft.client.gui.widget.SliderWidget;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import org.aperlambda.lambdacommon.utils.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWGamepadState;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.*;

import static org.lwjgl.glfw.GLFW.*;

Expand All @@ -71,7 +69,7 @@ public class MidnightInput {
private static final Map<Integer, Integer> BUTTON_COOLDOWNS = new HashMap<>();
// Cooldowns
public int actionGuiCooldown = 0;
private boolean ignoreNextARelease = false;
public boolean ignoreNextARelease = false;
private double targetYaw = 0.0;
private double targetPitch = 0.0;
private float prevXAxis = 0.f;
Expand All @@ -80,7 +78,7 @@ public class MidnightInput {
private int targetMouseY = 0;
private float mouseSpeedX = 0.f;
private float mouseSpeedY = 0.f;
private int inventoryInteractionCooldown = 0;
public int inventoryInteractionCooldown = 0;

private ControllerControlsWidget controlsInput = null;

Expand Down Expand Up @@ -315,14 +313,17 @@ private void handleButton(@NotNull MinecraftClient client, int button, int actio
if (client.currentScreen != null && client.currentScreen.getClass() != TitleScreen.class) {
if (!MidnightControlsCompat.handleMenuBack(client, client.currentScreen))
if (!this.tryGoBack(client.currentScreen))
client.currentScreen.onClose();
client.currentScreen.close();
return;
}
}
}

if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.currentScreen != null && !isScreenInteractive(client.currentScreen)
&& this.actionGuiCooldown == 0) {
if (client.currentScreen instanceof CreativeInventoryScreen creativeScreen && ((HandledScreenAccessor) creativeScreen).midnightcontrols$getSlotAt(
client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth(),
client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight()) != null) return;
if (!this.ignoreNextARelease) {
double mouseX = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth();
double mouseY = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
Expand All @@ -347,58 +348,57 @@ private void handleButton(@NotNull MinecraftClient client, int button, int actio
* @return {@code true} if an inventory interaction was done
*/
private boolean handleInventory(@NotNull MinecraftClient client, int button) {
if (!(client.currentScreen instanceof HandledScreen))
return false;

if (client.interactionManager == null || client.player == null)
return false;

if (this.inventoryInteractionCooldown > 0)
return true;

if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) {
client.player.closeHandledScreen();
return true;
}

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();

var screen = (HandledScreen) client.currentScreen;
var accessor = (HandledScreenAccessor) screen;
Slot slot = ((HandledScreenAccessor) client.currentScreen).midnightcontrols$getSlotAt(x, y);

int slotId;
if (slot == null) {
if (client.player.currentScreenHandler.getCursorStack().isEmpty())
return false;
slotId = accessor.midnightcontrols$isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1;
} else {
slotId = slot.id;
}

var actionType = SlotActionType.PICKUP;
int clickData = GLFW.GLFW_MOUSE_BUTTON_1;
switch (button) {
case GLFW_GAMEPAD_BUTTON_A:
if (screen instanceof CreativeInventoryScreen)
if (((CreativeInventoryScreenAccessor) screen).midnightcontrols$isCreativeInventorySlot(slot))
actionType = SlotActionType.CLONE;
if (slot != null && MidnightControlsCompat.streamCompatHandlers().anyMatch(handler -> handler.isCreativeSlot(screen, slot)))
actionType = SlotActionType.CLONE;
break;
case GLFW.GLFW_GAMEPAD_BUTTON_X:
clickData = GLFW_MOUSE_BUTTON_2;
break;
case GLFW.GLFW_GAMEPAD_BUTTON_Y:
actionType = SlotActionType.QUICK_MOVE;
break;
default:
return false;
}

accessor.midnightcontrols$onMouseClick(slot, slotId, clickData, actionType);
return true;
// if (!(client.currentScreen instanceof HandledScreen screen))
// return false;
//
// if (client.interactionManager == null || client.player == null)
// return false;
//
// if (this.inventoryInteractionCooldown > 0)
// return true;
//
// if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) {
// client.player.closeHandledScreen();
// return true;
// }
//
// 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();
//
// var accessor = (HandledScreenAccessor) screen;
// Slot slot = ((HandledScreenAccessor) client.currentScreen).midnightcontrols$getSlotAt(x, y);
//
// int slotId;
// if (slot == null) {
// if (client.player.currentScreenHandler.getCursorStack().isEmpty())
// return false;
// slotId = accessor.midnightcontrols$isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1;
// } else {
// slotId = slot.id;
// }
//
// var actionType = SlotActionType.PICKUP;
// int clickData = GLFW.GLFW_MOUSE_BUTTON_1;
// switch (button) {
// case GLFW_GAMEPAD_BUTTON_A:
// if (screen instanceof CreativeInventoryScreen)
// if (((CreativeInventoryScreenAccessor) screen).midnightcontrols$isCreativeInventorySlot(slot))
// actionType = SlotActionType.CLONE;
// if (slot != null && MidnightControlsCompat.streamCompatHandlers().anyMatch(handler -> handler.isCreativeSlot(screen, slot)))
// actionType = SlotActionType.CLONE;
// break;
// case GLFW.GLFW_GAMEPAD_BUTTON_X:
// clickData = GLFW_MOUSE_BUTTON_2;
// break;
// case GLFW.GLFW_GAMEPAD_BUTTON_Y:
// actionType = SlotActionType.QUICK_MOVE;
// break;
// default:
// return false;
// }
//
// accessor.midnightcontrols$onMouseClick(slot, slotId, clickData, actionType);
return false;
}

/**
Expand All @@ -411,9 +411,9 @@ public boolean tryGoBack(@NotNull Screen screen) {
var set = ImmutableSet.of("gui.back", "gui.done", "gui.cancel", "gui.toTitle", "gui.toMenu");
return screen.children().stream().filter(element -> element instanceof PressableWidget)
.map(element -> (PressableWidget) element)
.filter(element -> element.getMessage() instanceof TranslatableText)
.filter(element -> element.getMessage() != null && element.getMessage().getContent() != null)
.anyMatch(element -> {
if (set.stream().anyMatch(key -> key.equals(((TranslatableText) element.getMessage()).getKey()))) {
if (set.stream().anyMatch(key -> element.getMessage().getContent().toString().equals(key))) {
element.onPress();
return true;
}
Expand Down Expand Up @@ -511,6 +511,17 @@ private void handleAxe(@NotNull MinecraftClient client, int axis, float value, f
}
return;
}
} else if (client.currentScreen != null) {
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y && absValue >= deadZone) {
client.currentScreen.children().stream().filter(element -> element instanceof EntryListWidget)
.map(element -> (EntryListWidget<?>) element)
.filter(element -> element.getType().isFocused())
.anyMatch(element -> {
element.mouseScrolled(0.0, 0.0, -value);
return true;
});
return;
}
}

absValue -= deadZone;
Expand Down Expand Up @@ -593,7 +604,7 @@ private boolean handleAButton(@NotNull Screen screen, @NotNull Element focused)
labelWidget.onPress();
return true;
} else if (focused instanceof WorldListWidget list) {
list.getSelectedAsOptional().ifPresent(WorldListWidget.Entry::play);
list.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::play);
return true;
} else if (focused instanceof MultiplayerServerListWidget list) {
var entry = list.getSelectedOrNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package eu.midnightdust.midnightcontrols.client;

import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull;

Expand All @@ -34,7 +33,7 @@ public enum VirtualMouseSkin implements Nameable {

VirtualMouseSkin(String name) {
this.name = name;
this.text = new TranslatableText(this.getTranslationKey());
this.text = Text.translatable(this.getTranslationKey());
}

/**
Expand Down
Loading

0 comments on commit 6e64c7c

Please sign in to comment.