diff --git a/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java b/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java index d7cda8c..f96172f 100644 --- a/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java +++ b/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java @@ -66,7 +66,7 @@ public class ControllerBindings { register(ATTACK = new ControllerBinding<>(controller, GamepadBinds.RIGHT_TRIGGER, new ResourceLocation("controlify", "attack"), options.keyAttack, () -> false)); register(USE = new ControllerBinding<>(controller, GamepadBinds.LEFT_TRIGGER, new ResourceLocation("controlify", "use"), options.keyUse, () -> false)); register(SPRINT = new ControllerBinding<>(controller, GamepadBinds.LEFT_STICK_PRESS, new ResourceLocation("controlify", "sprint"), options.keySprint, () -> controller.config().toggleSprint)); - register(DROP = new ControllerBinding<>(controller, GamepadBinds.DPAD_DOWN, new ResourceLocation("controlify", "drop"), options.keyDrop, () -> false)); + register(DROP = new ControllerBinding<>(controller, GamepadBinds.DPAD_DOWN, new ResourceLocation("controlify", "drop"))); register(NEXT_SLOT = new ControllerBinding<>(controller, GamepadBinds.RIGHT_BUMPER, new ResourceLocation("controlify", "next_slot"))); register(PREV_SLOT = new ControllerBinding<>(controller, GamepadBinds.LEFT_BUMPER, new ResourceLocation("controlify", "prev_slot"))); register(PAUSE = new ControllerBinding<>(controller, GamepadBinds.START, new ResourceLocation("controlify", "pause"))); diff --git a/src/main/java/dev/isxander/controlify/ingame/InGameInputHandler.java b/src/main/java/dev/isxander/controlify/ingame/InGameInputHandler.java index 21c6f59..ce16c65 100644 --- a/src/main/java/dev/isxander/controlify/ingame/InGameInputHandler.java +++ b/src/main/java/dev/isxander/controlify/ingame/InGameInputHandler.java @@ -5,6 +5,7 @@ import dev.isxander.controlify.controller.Controller; import dev.isxander.controlify.api.event.ControlifyEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.player.KeyboardInput; +import net.minecraft.world.InteractionHand; public class InGameInputHandler { private final Controller controller; @@ -31,7 +32,7 @@ public class InGameInputHandler { } protected void handleKeybinds() { - if (Minecraft.getInstance().screen != null && !Minecraft.getInstance().screen.passEvents) + if (Minecraft.getInstance().screen != null) return; if (controller.bindings().PAUSE.justPressed()) { @@ -44,6 +45,14 @@ public class InGameInputHandler { if (controller.bindings().PREV_SLOT.justPressed()) { minecraft.player.getInventory().swapPaint(1); } + + if (!minecraft.player.isSpectator()) { + if (controller.bindings().DROP.justPressed()) { + minecraft.player.drop(false); + minecraft.player.swing(InteractionHand.MAIN_HAND); + } + } + } if (controller.bindings().TOGGLE_HUD_VISIBILITY.justPressed()) { minecraft.options.hideGui = !minecraft.options.hideGui; diff --git a/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/AbstractContainerScreenMixin.java b/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/AbstractContainerScreenMixin.java new file mode 100644 index 0000000..dfa8f90 --- /dev/null +++ b/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/AbstractContainerScreenMixin.java @@ -0,0 +1,26 @@ +package dev.isxander.controlify.mixins.feature.screenop.vanilla; + +import dev.isxander.controlify.screenop.ScreenProcessor; +import dev.isxander.controlify.screenop.ScreenProcessorProvider; +import dev.isxander.controlify.screenop.compat.vanilla.AbstractContainerScreenProcessor; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.Slot; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(AbstractContainerScreen.class) +public abstract class AbstractContainerScreenMixin implements ScreenProcessorProvider { + @Shadow @Nullable protected Slot hoveredSlot; + + @Shadow protected abstract void slotClicked(Slot slot, int slotId, int button, ClickType actionType); + + @Unique private final ScreenProcessor screenProcessor = new AbstractContainerScreenProcessor<>((AbstractContainerScreen) (Object) this, () -> hoveredSlot, this::slotClicked); + + @Override + public ScreenProcessor screenProcessor() { + return screenProcessor; + } +} diff --git a/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/CreativeModeInventoryScreenMixin.java b/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/CreativeModeInventoryScreenMixin.java index cfc6d8f..f12e526 100644 --- a/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/CreativeModeInventoryScreenMixin.java +++ b/src/main/java/dev/isxander/controlify/mixins/feature/screenop/vanilla/CreativeModeInventoryScreenMixin.java @@ -3,17 +3,24 @@ package dev.isxander.controlify.mixins.feature.screenop.vanilla; import dev.isxander.controlify.screenop.ScreenProcessor; import dev.isxander.controlify.screenop.ScreenProcessorProvider; import dev.isxander.controlify.screenop.compat.vanilla.CreativeModeInventoryScreenProcessor; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @Mixin(CreativeModeInventoryScreen.class) -public class CreativeModeInventoryScreenMixin implements ScreenProcessorProvider { - @Unique private final CreativeModeInventoryScreenProcessor controlify$screenProcessor - = new CreativeModeInventoryScreenProcessor((CreativeModeInventoryScreen) (Object) this); +public abstract class CreativeModeInventoryScreenMixin extends AbstractContainerScreen implements ScreenProcessorProvider { + @Unique private final CreativeModeInventoryScreenProcessor creativeScreenProcessor + = new CreativeModeInventoryScreenProcessor((CreativeModeInventoryScreen) (Object) this, () -> hoveredSlot, this::slotClicked); + + public CreativeModeInventoryScreenMixin(CreativeModeInventoryScreen.ItemPickerMenu handler, Inventory inventory, Component title) { + super(handler, inventory, title); + } @Override public ScreenProcessor screenProcessor() { - return controlify$screenProcessor; + return creativeScreenProcessor; } } diff --git a/src/main/java/dev/isxander/controlify/screenop/ScreenProcessor.java b/src/main/java/dev/isxander/controlify/screenop/ScreenProcessor.java index 9e7e202..a1c42aa 100644 --- a/src/main/java/dev/isxander/controlify/screenop/ScreenProcessor.java +++ b/src/main/java/dev/isxander/controlify/screenop/ScreenProcessor.java @@ -35,7 +35,7 @@ public class ScreenProcessor { handleComponentNavigation(controller); handleButtons(controller); } else { - handleVMouseNavigation(controller); + handleScreenVMouse(controller); } handleTabNavigation(controller); @@ -111,7 +111,7 @@ public class ScreenProcessor { } } - protected void handleVMouseNavigation(Controller controller) { + protected void handleScreenVMouse(Controller controller) { } diff --git a/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/AbstractContainerScreenProcessor.java b/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/AbstractContainerScreenProcessor.java new file mode 100644 index 0000000..e3cc99d --- /dev/null +++ b/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/AbstractContainerScreenProcessor.java @@ -0,0 +1,35 @@ +package dev.isxander.controlify.screenop.compat.vanilla; + +import dev.isxander.controlify.controller.Controller; +import dev.isxander.controlify.screenop.ScreenProcessor; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.Slot; + +import java.util.function.Supplier; + +public class AbstractContainerScreenProcessor> extends ScreenProcessor { + private final Supplier hoveredSlot; + private final ClickSlotFunction clickSlotFunction; + + public AbstractContainerScreenProcessor(T screen, Supplier hoveredSlot, ClickSlotFunction clickSlotFunction) { + super(screen); + this.hoveredSlot = hoveredSlot; + this.clickSlotFunction = clickSlotFunction; + } + + @Override + protected void handleScreenVMouse(Controller controller) { + if (controller.bindings().DROP.justPressed()) { + Slot slot = hoveredSlot.get(); + if (slot != null && slot.hasItem()) { + clickSlotFunction.clickSlot(slot, slot.index, 0, ClickType.THROW); + } + } + } + + @FunctionalInterface + public interface ClickSlotFunction { + void clickSlot(Slot slot, int slotId, int button, ClickType clickType); + } +} diff --git a/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/CreativeModeInventoryScreenProcessor.java b/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/CreativeModeInventoryScreenProcessor.java index 7063275..7ba3271 100644 --- a/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/CreativeModeInventoryScreenProcessor.java +++ b/src/main/java/dev/isxander/controlify/screenop/compat/vanilla/CreativeModeInventoryScreenProcessor.java @@ -4,15 +4,18 @@ import dev.isxander.controlify.controller.Controller; import dev.isxander.controlify.screenop.ScreenProcessor; import dev.isxander.controlify.mixins.feature.screenop.vanilla.CreativeModeInventoryScreenAccessor; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.CreativeModeTabs; -public class CreativeModeInventoryScreenProcessor extends ScreenProcessor { - public CreativeModeInventoryScreenProcessor(CreativeModeInventoryScreen screen) { - super(screen); +import java.util.function.Supplier; + +public class CreativeModeInventoryScreenProcessor extends AbstractContainerScreenProcessor { + public CreativeModeInventoryScreenProcessor(CreativeModeInventoryScreen screen, Supplier hoveredSlot, ClickSlotFunction clickSlotFunction) { + super(screen, hoveredSlot, clickSlotFunction); } @Override - protected void handleVMouseNavigation(Controller controller) { + protected void handleScreenVMouse(Controller controller) { var accessor = (CreativeModeInventoryScreenAccessor) screen; if (controller.bindings().GUI_NEXT_TAB.justPressed()) { @@ -27,5 +30,7 @@ public class CreativeModeInventoryScreenProcessor extends ScreenProcessor