use of mathax.client.eventbus.EventHandler in project Client by MatHax.
the class Auto32K method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
if (phase <= 7) {
if (mode.get() == Mode.Hopper) {
FindItemResult findShulker = InvUtils.findInHotbar(this::isShulkerBox);
FindItemResult findHopper = InvUtils.findInHotbar(Items.HOPPER);
if (isValidSlot(findShulker) || isValidSlot(findHopper))
return;
List<BlockPos> sortedBlocks = findValidBlocksHopper();
sortedBlocks.sort(Comparator.comparingDouble(value -> mc.player.squaredDistanceTo(value.getX(), value.getY(), value.getZ())));
Iterator<BlockPos> sortedIterator = sortedBlocks.iterator();
BlockPos bestBlock = null;
if (sortedIterator.hasNext())
bestBlock = sortedIterator.next();
if (bestBlock != null) {
while (!BlockUtils.place(bestBlock, findHopper, true, 100, false)) {
if (sortedIterator.hasNext())
bestBlock = sortedIterator.next().up();
else
break;
}
mc.player.setSneaking(true);
if (!BlockUtils.place(bestBlock.up(), findShulker, true, 100, false)) {
error("Failed to place.");
toggle();
return;
}
mc.player.setSneaking(false);
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing(), bestBlock.up(), false));
phase = 8;
}
} else if (mode.get() == Mode.Dispenser) {
FindItemResult shulkerSlot = InvUtils.find(this::isShulkerBox);
FindItemResult hopperSlot = InvUtils.find(Items.HOPPER);
FindItemResult dispenserSlot = InvUtils.find(Items.DISPENSER);
FindItemResult redstoneSlot = InvUtils.find(Items.REDSTONE_BLOCK);
if ((isValidSlot(shulkerSlot) && mode.get() == Mode.Hopper) || isValidSlot(hopperSlot) || isValidSlot(dispenserSlot) || isValidSlot(redstoneSlot))
return;
if (phase == 0) {
bestBlock = findValidBlocksDispenser();
if (bestBlock == null)
return;
if (!BlockUtils.place(bestBlock.add(x, 0, z), hopperSlot, true, 100, false)) {
error("Failed to place.");
toggle();
return;
}
phase += 1;
} else if (phase == 1) {
mc.player.getInventory().selectedSlot = dispenserSlot.slot();
if (x == -1)
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(-90f, mc.player.getPitch(), mc.player.isOnGround()));
else if (x == 1)
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(90f, mc.player.getPitch(), mc.player.isOnGround()));
else if (z == -1)
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(1f, mc.player.getPitch(), mc.player.isOnGround()));
else if (z == 1)
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(179f, mc.player.getPitch(), mc.player.isOnGround()));
phase += 1;
} else if (phase == 2) {
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), Direction.UP, bestBlock, false));
phase += 1;
} else if (phase == 3) {
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing().getOpposite(), bestBlock.up(), false));
phase += 1;
} else if (phase == 4 && mc.currentScreen instanceof Generic3x3ContainerScreen) {
mc.player.getMovementSpeed();
InvUtils.move().from(shulkerSlot.slot()).toId(4);
phase += 1;
} else if (phase == 5 && mc.currentScreen instanceof Generic3x3ContainerScreen) {
mc.player.closeHandledScreen();
phase += 1;
} else if (phase == 6) {
mc.player.getInventory().selectedSlot = redstoneSlot.slot();
mc.player.setSneaking(true);
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing().getOpposite(), bestBlock.up(2), false));
mc.player.setSneaking(false);
phase += 1;
} else if (phase == 7) {
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing().getOpposite(), bestBlock.add(x, 0, z), false));
phase += 1;
}
}
} else if (phase == 8) {
if (mc.currentScreen instanceof HopperScreen) {
if (fillHopper.get() && !throwawayItems.get().isEmpty()) {
int slot = -1;
int count = 0;
Iterator<Block> blocks = throwawayItems.get().iterator();
for (Item item = blocks.next().asItem(); blocks.hasNext(); item = blocks.next().asItem()) {
for (int i = 5; i <= 40; i++) {
ItemStack stack = mc.player.getInventory().getStack(i);
if (stack.getItem() == item && stack.getCount() >= 4) {
slot = i;
count = stack.getCount();
break;
}
}
if (count >= 4)
break;
}
for (int i = 1; i < 5; i++) {
if (mc.player.currentScreenHandler.getSlot(i).getStack().getItem() instanceof AirBlockItem)
InvUtils.move().from(slot - 4).toId(i);
}
}
boolean manage = true;
int slot = -1;
int dropSlot = -1;
for (int i = 32; i < 41; i++) {
if (EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(i).getStack()) > 5) {
manage = false;
slot = i;
break;
} else if (mc.player.currentScreenHandler.getSlot(i).getStack().getItem() instanceof SwordItem && EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(i).getStack()) <= 5) {
dropSlot = i;
}
}
if (dropSlot != -1)
InvUtils.drop().slot(dropSlot);
if (autoMove.get() && manage) {
int slot2 = mc.player.getInventory().getEmptySlot();
if (slot2 < 9 && slot2 != -1 && EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(0).getStack()) > 5)
InvUtils.move().fromId(0).to(slot2 - 4);
else if (EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(0).getStack()) <= 5 && mc.player.currentScreenHandler.getSlot(0).getStack().getItem() != Items.AIR)
InvUtils.drop().slotId(0);
}
if (slot != -1)
mc.player.getInventory().selectedSlot = slot - 32;
} else
toggle();
}
}
use of mathax.client.eventbus.EventHandler in project Client by MatHax.
the class AutoAnvil method onTick.
@EventHandler
private void onTick(TickEvent.Pre event) {
if (toggleOnBreak.get() && target != null && target.getInventory().getArmorStack(3).isEmpty()) {
error("Target head slot is empty, disabling...");
toggle();
return;
}
if (TargetUtils.isBadTarget(target, range.get()))
target = TargetUtils.getPlayerTarget(range.get(), priority.get());
if (TargetUtils.isBadTarget(target, range.get()))
return;
if (placeButton.get()) {
FindItemResult floorBlock = InvUtils.findInHotbar(itemStack -> Block.getBlockFromItem(itemStack.getItem()) instanceof AbstractPressurePlateBlock || Block.getBlockFromItem(itemStack.getItem()) instanceof AbstractButtonBlock);
BlockUtils.place(target.getBlockPos(), floorBlock, rotate.get(), 0, false);
}
if (timer >= delay.get()) {
timer = 0;
FindItemResult anvil = InvUtils.findInHotbar(itemStack -> Block.getBlockFromItem(itemStack.getItem()) instanceof AnvilBlock);
if (!anvil.found())
return;
for (int i = height.get(); i > 1; i--) {
BlockPos blockPos = target.getBlockPos().up().add(0, i, 0);
for (int j = 0; j < i; j++) {
if (!mc.world.getBlockState(target.getBlockPos().up(j + 1)).getMaterial().isReplaceable())
break;
}
if (BlockUtils.place(blockPos, anvil, rotate.get(), 0) && !multiPlace.get())
break;
}
} else
timer++;
}
use of mathax.client.eventbus.EventHandler in project Client by MatHax.
the class TextRadarHud method onReceivePacket.
@EventHandler
private void onReceivePacket(PacketEvent.Receive event) {
if (!totemPops.get())
return;
if (!(event.packet instanceof EntityStatusS2CPacket))
return;
EntityStatusS2CPacket p = (EntityStatusS2CPacket) event.packet;
if (p.getStatus() != 35)
return;
Entity entity = p.getEntity(mc.world);
if (!(entity instanceof PlayerEntity))
return;
synchronized (totemPopMap) {
int pops = totemPopMap.getOrDefault(entity.getUuid(), 0);
totemPopMap.put(entity.getUuid(), ++pops);
}
}
use of mathax.client.eventbus.EventHandler in project Client by MatHax.
the class AutoCity method onTick.
@EventHandler
private void onTick(TickEvent.Pre event) {
if (TargetUtils.isBadTarget(target, targetRange.get())) {
PlayerEntity search = TargetUtils.getPlayerTarget(targetRange.get(), SortPriority.Lowest_Distance);
if (search != target)
sentMessage = false;
target = search;
}
if (TargetUtils.isBadTarget(target, targetRange.get())) {
target = null;
mineTarget = null;
if (selfToggle.get())
toggle();
return;
}
mineTarget = EntityUtils.getCityBlock(target);
if (mineTarget == null) {
if (selfToggle.get()) {
error("No target block found, disabling...");
toggle();
}
target = null;
return;
}
if (selfToggle.get() && PlayerUtils.distanceTo(mineTarget) > mc.interactionManager.getReachDistance()) {
error("Target block out of reach, disabling...");
toggle();
return;
}
if (!sentMessage) {
info("Attempting to city (highlight)%s(default).", target.getEntityName());
sentMessage = true;
}
FindItemResult pickaxe = InvUtils.find(itemStack -> itemStack.getItem() == Items.DIAMOND_PICKAXE || itemStack.getItem() == Items.NETHERITE_PICKAXE);
if (!pickaxe.isHotbar()) {
if (selfToggle.get()) {
error("No pickaxe found, disabling...");
toggle();
}
return;
}
if (support.get())
BlockUtils.place(mineTarget.down(1), InvUtils.findInHotbar(Items.OBSIDIAN), rotate.get(), 0, true);
InvUtils.swap(pickaxe.slot(), false);
if (rotate.get())
Rotations.rotate(Rotations.getYaw(mineTarget), Rotations.getPitch(mineTarget), () -> mine(mineTarget));
else
mine(mineTarget);
if (selfToggle.get())
toggle();
}
use of mathax.client.eventbus.EventHandler in project Client by MatHax.
the class BurrowNotifier method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
for (PlayerEntity player : mc.world.getPlayers()) {
if (isBurrowValid(player)) {
burrowedPlayers.add(player);
warning("(highlight)%s(default) is burrowed!", player.getEntityName());
}
if (burrowedPlayers.contains(player) && !PlayerUtils.isBurrowed(player, true)) {
burrowedPlayers.remove(player);
warning("(highlight)%s(default) is no longer burrowed.", player.getEntityName());
}
}
}
Aggregations