From 599a05bed9a82396b599cc10f416c4437b84986f Mon Sep 17 00:00:00 2001 From: jvyden Date: Sat, 8 Aug 2020 10:59:40 -0400 Subject: [PATCH] Add MiddleClickPearlModule --- .../impl/management/ModuleManager.java | 1 + .../module/misc/MiddleClickPearlModule.java | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/main/java/me/rigamortis/seppuku/impl/module/misc/MiddleClickPearlModule.java diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java index db57eeb..78be3c0 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java @@ -147,6 +147,7 @@ public final class ModuleManager { add(new HotBarRefillModule()); add(new QuickCraftModule()); add(new TotemNotifierModule()); + add(new MiddleClickPearlModule()); // p2w experience if (Seppuku.INSTANCE.getCapeManager().hasCape()) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/misc/MiddleClickPearlModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/misc/MiddleClickPearlModule.java new file mode 100644 index 0000000..a817620 --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/module/misc/MiddleClickPearlModule.java @@ -0,0 +1,58 @@ +package me.rigamortis.seppuku.impl.module.misc; + +import me.rigamortis.seppuku.api.event.EventStageable; +import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate; +import me.rigamortis.seppuku.api.module.Module; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemEnderPearl; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.RayTraceResult; +import org.lwjgl.input.Mouse; +import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; + +public class MiddleClickPearlModule extends Module { + private boolean clicked; + private final Minecraft mc = Minecraft.getMinecraft(); + public MiddleClickPearlModule() { + super("MiddleClickPearl", new String[]{"mcp", "autopearl"}, "Throws a pearl if you middle-click pointing in mid-air", "NONE", -1, ModuleType.MISC); + } + + @Listener + public void onUpdate(EventPlayerUpdate event) { + if(event.getStage() == EventStageable.EventStage.PRE) { + if(mc.currentScreen == null) { + if(Mouse.isButtonDown(2)) { + if(!this.clicked) { + final RayTraceResult result = mc.objectMouseOver; + if(result != null && result.typeOfHit == RayTraceResult.Type.MISS) { + final int pearlSlot = findPearlInHotbar(); + if(pearlSlot != -1) { + final int oldSlot = mc.player.inventory.currentItem; + mc.player.inventory.currentItem = pearlSlot; + mc.playerController.processRightClick(mc.player, mc.world, EnumHand.MAIN_HAND); + mc.player.inventory.currentItem = oldSlot; + } + } + } + this.clicked = true; + } else { + this.clicked = false; + } + } + } + } + + private boolean isItemStackPearl(final ItemStack itemStack) { + return itemStack.getItem() instanceof ItemEnderPearl; + } + + private int findPearlInHotbar() { + for (int index = 0; InventoryPlayer.isHotbar(index); index++) { + if (isItemStackPearl(mc.player.inventory.getStackInSlot(index))) return index; + } + return -1; + } +} \ No newline at end of file