From f8f058828bf8ff8111c1f726d6ef704bafa4613b Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Mon, 26 Aug 2024 19:04:23 +0530 Subject: [PATCH] AutoTotem keybind and predicate changes in Scaffold --- .../module/modules/combat/AutoTotem.java | 66 ++++++++++++------- .../module/modules/movement/Scaffold.java | 5 +- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/main/java/dev/heliosclient/module/modules/combat/AutoTotem.java b/src/main/java/dev/heliosclient/module/modules/combat/AutoTotem.java index 6e96e51..b9850fe 100644 --- a/src/main/java/dev/heliosclient/module/modules/combat/AutoTotem.java +++ b/src/main/java/dev/heliosclient/module/modules/combat/AutoTotem.java @@ -3,11 +3,13 @@ import dev.heliosclient.HeliosClient; import dev.heliosclient.event.SubscribeEvent; import dev.heliosclient.event.events.TickEvent; +import dev.heliosclient.event.events.input.KeyPressedEvent; import dev.heliosclient.event.events.player.PacketEvent; import dev.heliosclient.module.Categories; import dev.heliosclient.module.Module_; import dev.heliosclient.module.settings.BooleanSetting; import dev.heliosclient.module.settings.DoubleSetting; +import dev.heliosclient.module.settings.KeyBind; import dev.heliosclient.module.settings.SettingGroup; import dev.heliosclient.util.ChatUtils; import dev.heliosclient.util.ColorUtils; @@ -57,8 +59,16 @@ public class AutoTotem extends Module_ { .build() ); + KeyBind totemSwitchKey = sgGeneral.add(new KeyBind.Builder() + .name("Totem Switch Key") + .description("When you press this key, the module will automatically switch to a totem") + .value(KeyBind.none()) + .onSettingChange(this) + .build() + ); + int totemCount = 0; - private TickTimer timer = new TickTimer(); + private final TickTimer timer = new TickTimer(); boolean lastNoTotemNotified = false; public AutoTotem() { @@ -80,6 +90,14 @@ public void onDisable() { lastNoTotemNotified = false; } + @SubscribeEvent + public void onKey(KeyPressedEvent e){ + if(e.getKey() == totemSwitchKey.value){ + doAutoTotem(); + timer.restartTimer(); + } + } + //High @SubscribeEvent(priority = SubscribeEvent.Priority.HIGHEST) public void onTick(TickEvent.WORLD event) { @@ -94,44 +112,46 @@ public void onTick(TickEvent.WORLD event) { return; } if(always.value || isPlayerLow()) { - boolean offhandHasItem = !mc.player.getOffHandStack().isEmpty(); - - int itemSlot = InventoryUtils.findItemInInventory(Items.TOTEM_OF_UNDYING); - if(itemSlot == -1){ - return; - } - - //if is hotbar then swap item with offhand super fast. - if(itemSlot >= 0 && itemSlot < 9){ - InventoryUtils.swapToSlot(itemSlot,true); - mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN)); - InventoryUtils.swapBackHotbar(); - }else { - InventoryUtils.moveItem(itemSlot,45, SlotActionType.PICKUP, SlotActionType.PICKUP); - - if(offhandHasItem){ - mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId,itemSlot,0,SlotActionType.PICKUP,mc.player); - } - } + doAutoTotem(); if(log.value){ ChatUtils.sendHeliosMsg("Restocked Totem, Totems left: " + InventoryUtils.getItemCountInInventory(Items.TOTEM_OF_UNDYING)); } - return; } }); - }else if(log.value && !lastNoTotemNotified){ + } else if(log.value && !lastNoTotemNotified){ ChatUtils.sendHeliosMsg(ColorUtils.red + "No Totems left in your inventory"); lastNoTotemNotified = true; } } + public void doAutoTotem(){ + boolean offhandHasItem = !mc.player.getOffHandStack().isEmpty(); + int itemSlot = InventoryUtils.findItemInInventory(Items.TOTEM_OF_UNDYING); + if(itemSlot == -1 || itemSlot == InventoryUtils.OFFHAND){ + return; + } + + //if is hotbar then swap item with offhand super fast. + if(itemSlot >= 0 && itemSlot < 9){ + InventoryUtils.swapToSlot(itemSlot,true); + mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN)); + InventoryUtils.swapBackHotbar(); + }else { + InventoryUtils.moveItem(itemSlot,45, SlotActionType.PICKUP, SlotActionType.PICKUP); + + if(offhandHasItem){ + mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId,itemSlot,0,SlotActionType.PICKUP,mc.player); + } + } + } + @SubscribeEvent public void packetReceive(PacketEvent.RECEIVE e){ if(e.packet instanceof EntityStatusS2CPacket packet){ if(packet.getStatus() != 35 || packet.getEntity(mc.world) != mc.player) return; - timer.restartTimer(); + timer.setTicks(delay.getInt()); } } diff --git a/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java b/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java index dfc5159..ca9ae4b 100644 --- a/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java +++ b/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java @@ -7,8 +7,8 @@ import dev.heliosclient.module.Module_; import dev.heliosclient.module.settings.*; import dev.heliosclient.module.settings.lists.BlockListSetting; -import dev.heliosclient.util.blocks.BlockUtils; import dev.heliosclient.util.ColorUtils; +import dev.heliosclient.util.blocks.BlockUtils; import dev.heliosclient.util.player.InventoryUtils; import dev.heliosclient.util.player.PlayerUtils; import dev.heliosclient.util.render.GradientBlockRenderer; @@ -38,6 +38,7 @@ public class Scaffold extends Module_ { .description("Blocks to place") .iSettingChange(this) .blocks(Blocks.DIRT, Blocks.TNT, Blocks.OBSIDIAN) + .filter(block -> !BlockUtils.airBreed(block) && !BlockUtils.isClickable(block)) .build() ); DropDownSetting towerMode = sgGeneral.add(new DropDownSetting.Builder() @@ -247,7 +248,7 @@ public void placeFromCenter(BlockPos center) { int itemSlot = -2; if (autoSwitch.value) { for(Block block: blocks.getSelectedEntries()){ - itemSlot = InventoryUtils.findInHotbar(item -> block.asItem() != item); + itemSlot = InventoryUtils.findInHotbar(item -> block.asItem() == item); if (itemSlot != -1) { break;