1
0
forked from Clones/Controlify
This commit is contained in:
isXander
2023-03-26 19:56:23 +01:00
parent dc43657b95
commit c4fa5cbed3
9 changed files with 104 additions and 15 deletions

View File

@ -66,7 +66,7 @@ public class ControllerBindings<T extends ControllerState> {
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")));

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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<CreativeModeInventoryScreen.ItemPickerMenu> 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;
}
}

View File

@ -35,7 +35,7 @@ public class ScreenProcessor<T extends Screen> {
handleComponentNavigation(controller);
handleButtons(controller);
} else {
handleVMouseNavigation(controller);
handleScreenVMouse(controller);
}
handleTabNavigation(controller);
@ -111,7 +111,7 @@ public class ScreenProcessor<T extends Screen> {
}
}
protected void handleVMouseNavigation(Controller<?, ?> controller) {
protected void handleScreenVMouse(Controller<?, ?> controller) {
}

View File

@ -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<T extends AbstractContainerScreen<?>> extends ScreenProcessor<T> {
private final Supplier<Slot> hoveredSlot;
private final ClickSlotFunction clickSlotFunction;
public AbstractContainerScreenProcessor(T screen, Supplier<Slot> 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);
}
}

View File

@ -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<CreativeModeInventoryScreen> {
public CreativeModeInventoryScreenProcessor(CreativeModeInventoryScreen screen) {
super(screen);
import java.util.function.Supplier;
public class CreativeModeInventoryScreenProcessor extends AbstractContainerScreenProcessor<CreativeModeInventoryScreen> {
public CreativeModeInventoryScreenProcessor(CreativeModeInventoryScreen screen, Supplier<Slot> 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<Creati
if (newIndex < 0) newIndex = tabs.size() - 1;
accessor.invokeSelectTab(tabs.get(newIndex));
}
super.handleScreenVMouse(controller);
}
}

View File

@ -32,6 +32,7 @@
"feature.guide.screen.TabNavigationBarMixin",
"feature.screenop.vanilla.AbstractButtonMixin",
"feature.screenop.vanilla.AbstractContainerEventHandlerMixin",
"feature.screenop.vanilla.AbstractContainerScreenMixin",
"feature.screenop.vanilla.AbstractSelectionListMixin",
"feature.screenop.vanilla.AbstractSliderButtonMixin",
"feature.screenop.vanilla.ContainerObjectSelectionListEntryMixin",

View File

@ -67,19 +67,25 @@ public class ControlifyAutoTestClient implements ClientModInitializer {
boolean success = true;
for (var test : preLoadTests) {
success &= wrapTest(test);
success &= wrapTestExecution(test);
}
waitForLoadingComplete();
for (var test : postLoadTests) {
success &= wrapTest(test);
success &= wrapTestExecution(test);
}
LOGGER.info("--------");
if (success)
LOGGER.info("\u001b[32mAll tests passed!");
else
LOGGER.error("\n\u001b[31mSome tests failed!");
System.exit(success ? 0 : 1);
}
private boolean wrapTest(Test test) {
private boolean wrapTestExecution(Test test) {
LOGGER.info("\u001b[36mRunning test " + test.name() + "...");
try {
test.method().run();