Skip to content

Commit

Permalink
AutoTotem keybind and predicate changes in Scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Aug 26, 2024
1 parent 256d001 commit f8f0588
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
66 changes: 43 additions & 23 deletions src/main/java/dev/heliosclient/module/modules/combat/AutoTotem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f8f0588

Please sign in to comment.