|
| 1 | +package com.ref.aea.mixin.ae; |
| 2 | + |
| 3 | +import appeng.api.stacks.GenericStack; |
| 4 | +import appeng.client.gui.AEBaseScreen; |
| 5 | +import appeng.client.gui.me.common.MEStorageScreen; |
| 6 | +import appeng.client.gui.me.common.Repo; |
| 7 | +import appeng.client.gui.style.ScreenStyle; |
| 8 | +import appeng.helpers.InventoryAction; |
| 9 | +import appeng.integration.modules.jei.GenericEntryStackHelper; |
| 10 | +import appeng.menu.me.common.GridInventoryEntry; |
| 11 | +import appeng.menu.me.common.MEStorageMenu; |
| 12 | +import mezz.jei.api.runtime.IJeiRuntime; |
| 13 | +import mezz.jei.common.Internal; |
| 14 | +import net.minecraft.client.Minecraft; |
| 15 | +import net.minecraft.client.gui.screens.Screen; |
| 16 | +import net.minecraft.network.chat.Component; |
| 17 | +import net.minecraft.world.entity.player.Inventory; |
| 18 | +import net.minecraft.world.inventory.ClickType; |
| 19 | +import net.minecraftforge.api.distmarker.Dist; |
| 20 | +import net.minecraftforge.api.distmarker.OnlyIn; |
| 21 | +import org.jetbrains.annotations.Nullable; |
| 22 | +import org.spongepowered.asm.mixin.Final; |
| 23 | +import org.spongepowered.asm.mixin.Mixin; |
| 24 | +import org.spongepowered.asm.mixin.Shadow; |
| 25 | +import org.spongepowered.asm.mixin.injection.At; |
| 26 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 27 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 28 | + |
| 29 | +@OnlyIn(Dist.CLIENT) |
| 30 | +@Mixin(value = MEStorageScreen.class) |
| 31 | +public abstract class MEStorageScreenMixin<T extends MEStorageMenu> extends AEBaseScreen<T> { |
| 32 | + |
| 33 | + @Final |
| 34 | + @Shadow(remap = false) |
| 35 | + protected Repo repo; |
| 36 | + |
| 37 | + @Shadow(remap = false) |
| 38 | + protected abstract void handleGridInventoryEntryMouseClick( |
| 39 | + @Nullable GridInventoryEntry entry, int mouseButton, ClickType clickType); |
| 40 | + |
| 41 | + public MEStorageScreenMixin( |
| 42 | + T menu, Inventory playerInventory, Component title, ScreenStyle style) { |
| 43 | + super(menu, playerInventory, title, style); |
| 44 | + } |
| 45 | + |
| 46 | + @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) |
| 47 | + private void onMouseClicked( |
| 48 | + double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir) { |
| 49 | + if (Internal.getClientToggleState().isCheatItemsEnabled()) return; |
| 50 | + |
| 51 | + boolean isMiddle = Minecraft.getInstance().options.keyPickItem.matchesMouse(button); |
| 52 | + boolean isShift = Screen.hasShiftDown(); |
| 53 | + |
| 54 | + if (!isShift && !isMiddle) return; |
| 55 | + |
| 56 | + IJeiRuntime jeiRuntime = Internal.getJeiRuntime(); |
| 57 | + jeiRuntime |
| 58 | + .getBookmarkOverlay() |
| 59 | + .getIngredientUnderMouse() |
| 60 | + .ifPresent( |
| 61 | + typedIngredient -> { |
| 62 | + GenericStack stack = GenericEntryStackHelper.ingredientToStack(typedIngredient); |
| 63 | + if (stack == null) return; |
| 64 | + |
| 65 | + GridInventoryEntry entry = |
| 66 | + repo.getAllEntries().stream() |
| 67 | + .filter(e -> stack.what().equals(e.getWhat())) |
| 68 | + .findFirst() |
| 69 | + .orElse(null); |
| 70 | + |
| 71 | + ClickType clickType = isShift ? ClickType.QUICK_MOVE : ClickType.CLONE; |
| 72 | + |
| 73 | + this.handleGridInventoryEntryMouseClick(entry, button, clickType); |
| 74 | + |
| 75 | + cir.setReturnValue(true); |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + @Inject(method = "mouseScrolled", at = @At("HEAD"), cancellable = true) |
| 80 | + private void onMouseScrolled( |
| 81 | + double mouseX, double mouseY, double delta, CallbackInfoReturnable<Boolean> cir) { |
| 82 | + if (Internal.getClientToggleState().isCheatItemsEnabled() |
| 83 | + || delta == 0 |
| 84 | + || !Screen.hasShiftDown()) return; |
| 85 | + IJeiRuntime jeiRuntime = Internal.getJeiRuntime(); |
| 86 | + jeiRuntime |
| 87 | + .getBookmarkOverlay() |
| 88 | + .getIngredientUnderMouse() |
| 89 | + .ifPresent( |
| 90 | + typedIngredient -> { |
| 91 | + GenericStack stack = GenericEntryStackHelper.ingredientToStack(typedIngredient); |
| 92 | + if (stack == null) return; |
| 93 | + |
| 94 | + repo.getAllEntries().stream() |
| 95 | + .filter(e -> stack.what().equals(e.getWhat())) |
| 96 | + .findFirst() |
| 97 | + .ifPresent( |
| 98 | + entry -> { |
| 99 | + InventoryAction action = |
| 100 | + delta > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; |
| 101 | + this.menu.handleInteraction(entry.getSerial(), action); |
| 102 | + cir.setReturnValue(true); |
| 103 | + }); |
| 104 | + }); |
| 105 | + } |
| 106 | +} |
0 commit comments