use of me.earth.earthhack.impl.event.events.network.MotionUpdateEvent in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method doObby.
private void doObby(MotionUpdateEvent event, Vec3i[] offsets) {
if (event.getStage() == Stage.PRE) {
// TODO: this looks very similar to AutoTrap,
// maybe its possible to abstract this even further?
module.rotations = null;
module.blocksPlaced = 0;
for (BlockPos confirmed : module.confirmed) {
module.placed.remove(confirmed);
}
module.placed.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() >= module.confirm.getValue());
BlockPos playerPos = PositionUtil.getPosition();
BlockPos[] positions = new BlockPos[offsets.length];
for (int i = 0; i < offsets.length; i++) {
Vec3i offset = offsets[i];
if (module.mode.getValue() == AntiTrapMode.Fill) {
if (mc.world.getBlockState(playerPos.add(offset.getX() / 2, 0, offset.getZ() / 2)).getBlock() == Blocks.BEDROCK) {
continue;
}
}
positions[i] = playerPos.add(offset);
}
if (module.offhand.getValue()) {
if (!InventoryUtil.isHolding(Blocks.OBSIDIAN)) {
module.previous = OFFHAND.returnIfPresent(Offhand::getMode, null);
OFFHAND.computeIfPresent(o -> o.setMode(OffhandMode.CRYSTAL));
return;
}
} else {
module.slot = InventoryUtil.findHotbarBlock(Blocks.OBSIDIAN);
if (module.slot == -1) {
ModuleUtil.disable(module, TextColor.RED + "No Obsidian found.");
return;
}
}
boolean done = true;
List<BlockPos> toPlace = new LinkedList<>();
for (BlockPos pos : positions) {
if (pos == null) {
continue;
}
if (module.mode.getValue() == AntiTrapMode.Fill && !module.highFill.getValue() && pos.getY() > playerPos.getY()) {
continue;
}
if (mc.world.getBlockState(pos).getMaterial().isReplaceable()) {
toPlace.add(pos);
done = false;
}
}
if (done) {
module.disable();
return;
}
boolean hasPlaced = false;
Optional<BlockPos> crystalPos = toPlace.stream().filter(pos -> !mc.world.getEntitiesWithinAABB(EntityEnderCrystal.class, new AxisAlignedBB(pos)).isEmpty() && mc.world.getBlockState(pos).getMaterial().isReplaceable()).findFirst();
if (crystalPos.isPresent()) {
BlockPos pos = crystalPos.get();
hasPlaced = module.placeBlock(pos);
}
// Only after here we need to use the Helper to get the BlockStates.
if (!hasPlaced) {
for (BlockPos pos : toPlace) {
if (!module.placed.containsKey(pos) && HELPER.getBlockState(pos).getMaterial().isReplaceable()) {
module.confirmed.remove(pos);
if (module.placeBlock(pos)) {
break;
}
}
}
}
if (module.rotate.getValue() != Rotate.None) {
if (module.rotations != null) {
event.setYaw(module.rotations[0]);
event.setPitch(module.rotations[1]);
}
} else {
Locks.acquire(Locks.PLACE_SWITCH_LOCK, module::execute);
}
} else {
Locks.acquire(Locks.PLACE_SWITCH_LOCK, module::execute);
}
}
use of me.earth.earthhack.impl.event.events.network.MotionUpdateEvent in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method invoke.
@Override
public void invoke(MotionUpdateEvent event) {
if (event.getStage() == Stage.PRE) {
module.clicked.clear();
module.blocksPlaced = 0;
module.rotations = null;
module.pistonSlot = InventoryUtil.findHotbarBlock(Blocks.PISTON, Blocks.STICKY_PISTON);
if (module.pistonSlot == -1 && shouldDisable(PistonStage.PISTON)) {
module.disableWithMessage("<" + module.getDisplayName() + "> " + TextColor.RED + "No Pistons found!");
return;
}
module.redstoneSlot = InventoryUtil.findHotbarBlock(Blocks.REDSTONE_BLOCK, Blocks.REDSTONE_TORCH);
if (module.redstoneSlot == -1 && shouldDisable(PistonStage.REDSTONE)) {
module.disableWithMessage("<" + module.getDisplayName() + "> " + TextColor.RED + "No Redstone found!");
return;
}
module.crystalSlot = InventoryUtil.findHotbarItem(Items.END_CRYSTAL);
if (module.crystalSlot == -1 && shouldDisable(PistonStage.CRYSTAL)) {
module.disableWithMessage("<" + module.getDisplayName() + "> " + TextColor.RED + "No Crystals found!");
return;
}
if (module.reset && module.nextTimer.passed(module.next.getValue()) && module.current != null) {
module.current.setValid(false);
}
if (module.current == null || !module.current.isValid()) {
module.current = module.findTarget();
if (module.current == null || !module.current.isValid()) {
return;
}
}
module.stage = module.current.getOrder()[module.index];
while (module.index < 3 && module.stage == null) {
module.index++;
module.stage = module.current.getOrder()[module.index];
}
while (module.blocksPlaced < module.blocks.getValue()) {
if (!runPre() || module.rotations != null && module.rotate.getValue() == Rotate.Normal) {
break;
}
}
if (module.blocksPlaced > 0) {
module.timer.reset(module.delay.getValue());
}
if (module.rotations != null) {
event.setYaw(module.rotations[0]);
event.setPitch(module.rotations[1]);
}
} else {
if (module.current == null || !module.current.isValid()) {
return;
}
Locks.acquire(Locks.PLACE_SWITCH_LOCK, () -> {
module.slot = mc.player.inventory.currentItem;
boolean sneak = module.blocksPlaced == 0 || module.actions.isEmpty() || module.smartSneak.getValue() && !(Managers.ACTION.isSneaking() || module.clicked.stream().anyMatch(b -> SpecialBlocks.shouldSneak(b, false)));
if (!sneak) {
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
}
CollectionUtil.emptyQueue(module.actions);
if (!sneak) {
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
}
if (mc.player.inventory.currentItem != module.slot) {
InventoryUtil.switchTo(module.slot);
}
});
}
}
use of me.earth.earthhack.impl.event.events.network.MotionUpdateEvent in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method invoke.
@Override
public void invoke(MotionUpdateEvent event) {
if (event.getStage() == Stage.PRE) {
} else {
}
if (module.steal.getValue() && mc.currentScreen == null && !module.shouldRegear) {
BlockPos craftingPos = module.getShulkerBox();
float[] rotations = RotationUtil.getRotations(craftingPos, EnumFacing.UP);
RayTraceResult ray = RotationUtil.rayTraceTo(craftingPos, mc.world);
float[] f = RayTraceUtil.hitVecToPlaceVec(craftingPos, ray.hitVec);
if (module.rotate.getValue() == Rotate.Normal) {
event.setYaw(rotations[0]);
event.setPitch(rotations[1]);
} else if (module.rotate.getValue() != Rotate.None) {
PacketUtil.doRotation(rotations[0], rotations[1], mc.player.onGround);
}
NetworkUtil.send(new CPacketPlayerTryUseItemOnBlock(craftingPos, ray.sideHit, EnumHand.MAIN_HAND, f[0], f[1], f[2]));
return;
}
if (module.shouldRegear && mc.currentScreen == null) {
BlockPos optimal = module.getOptimalPlacePos(false);
int slot;
boolean swapped = false;
if (module.placeEchest.getValue() && module.getBlock(Blocks.ENDER_CHEST) == null && InventoryUtil.findHotbarBlock(Blocks.ENDER_CHEST) != -1 && !module.hasKit() && optimal != null) {
slot = InventoryUtil.findHotbarBlock(Blocks.ENDER_CHEST);
if (slot == -1)
return;
module.slot = slot;
EnumFacing facing = BlockUtil.getFacing(optimal);
module.placeBlock(optimal.offset(facing), facing.getOpposite());
if (module.rotate.getValue() == Rotate.Normal && module.rotations != null) {
event.setYaw(module.rotations[0]);
event.setPitch(module.rotations[1]);
}
module.execute();
return;
}
if (module.grabShulker.getValue() && module.getBlock(Blocks.ENDER_CHEST) != null && module.getShulkerBox() == null && mc.currentScreen == null && !module.hasKit()) {
BlockPos craftingPos = module.getBlock(Blocks.ENDER_CHEST);
float[] rotations = RotationUtil.getRotations(craftingPos, EnumFacing.UP);
RayTraceResult ray = RotationUtil.rayTraceTo(craftingPos, mc.world);
float[] f = RayTraceUtil.hitVecToPlaceVec(craftingPos, ray.hitVec);
if (module.rotate.getValue() == Rotate.Normal) {
event.setYaw(rotations[0]);
event.setPitch(rotations[1]);
} else if (module.rotate.getValue() != Rotate.None) {
PacketUtil.doRotation(rotations[0], rotations[1], mc.player.onGround);
}
NetworkUtil.send(new CPacketPlayerTryUseItemOnBlock(craftingPos, ray.sideHit, EnumHand.MAIN_HAND, f[0], f[1], f[2]));
return;
}
if (module.placeShulker.getValue() && module.getShulkerBox() == null && module.hasKit() && optimal != null) {
optimal = module.getOptimalPlacePos(true);
if (optimal == null)
return;
slot = InventoryUtil.findInHotbar(stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock() instanceof BlockShulkerBox);
int inventorySlot = InventoryUtil.findInInventory(stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock() instanceof BlockShulkerBox, true);
if (slot == -1) {
if (inventorySlot == -1)
return;
slot = InventoryUtil.hotbarToInventory(8);
mc.playerController.windowClick(0, inventorySlot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, slot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, inventorySlot, 0, ClickType.PICKUP, mc.player);
swapped = true;
}
module.slot = slot;
EnumFacing facing = EnumFacing.DOWN;
module.placeBlock(optimal.offset(facing), facing.getOpposite());
if (module.rotate.getValue() == Rotate.Normal && module.rotations != null) {
event.setYaw(module.rotations[0]);
event.setPitch(module.rotations[1]);
}
module.execute();
if (swapped) {
mc.playerController.windowClick(0, inventorySlot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, slot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, inventorySlot, 0, ClickType.PICKUP, mc.player);
}
return;
}
BlockPos craftingPos = module.getShulkerBox();
if (craftingPos == null)
return;
float[] rotations = RotationUtil.getRotations(craftingPos, EnumFacing.UP);
RayTraceResult ray = RotationUtil.rayTraceTo(craftingPos, mc.world);
float[] f = RayTraceUtil.hitVecToPlaceVec(craftingPos, ray.hitVec);
if (module.rotate.getValue() == Rotate.Normal) {
event.setYaw(rotations[0]);
event.setPitch(rotations[1]);
} else if (module.rotate.getValue() != Rotate.None) {
PacketUtil.doRotation(rotations[0], rotations[1], mc.player.onGround);
}
NetworkUtil.send(new CPacketPlayerTryUseItemOnBlock(craftingPos, ray.sideHit, EnumHand.MAIN_HAND, f[0], f[1], f[2]));
module.shouldRegear = false;
}
}
use of me.earth.earthhack.impl.event.events.network.MotionUpdateEvent in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method start.
public static void start(Surround module, MotionUpdateEvent event) {
module.rotations = null;
module.attacking = null;
module.blocksPlaced = 0;
module.center();
if (module.updatePosAndBlocks()) {
// confirmed blocks can now be checked for blockstate changes.
module.placed.removeAll(module.confirmed);
boolean hasPlaced = false;
// ensure that we attack the pos with the crystal first before
// the others, so we dont have to deal with switchcooldown.
Optional<BlockPos> crystalPos = module.targets.stream().filter(pos -> !mc.world.getEntitiesWithinAABB(EntityEnderCrystal.class, new AxisAlignedBB(pos)).isEmpty() && mc.world.getBlockState(pos).getMaterial().isReplaceable()).findFirst();
if (crystalPos.isPresent()) {
BlockPos pos = crystalPos.get();
module.confirmed.remove(pos);
hasPlaced = module.placeBlock(pos);
}
if (!hasPlaced || !module.crystalCheck.getValue()) {
List<BlockPos> surrounding = new ArrayList<>(module.targets);
if (module.getPlayer().motionX != 0.0 || module.getPlayer().motionZ != 0.0) {
// place in front of us first to stop our movement.
// I am aware that this looks really bad
BlockPos pos = new BlockPos(module.getPlayer()).add(module.getPlayer().motionX * 10000, 0, module.getPlayer().motionZ * 10000);
surrounding.sort(Comparator.comparingDouble(p -> p.distanceSq(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5)));
}
for (BlockPos pos : surrounding) {
if (!module.placed.contains(pos) && mc.world.getBlockState(pos).getMaterial().isReplaceable()) {
module.confirmed.remove(pos);
if (module.placeBlock(pos)) {
break;
}
}
}
}
}
if (module.blocksPlaced == 0) {
module.placed.clear();
}
if (module.rotate.getValue() != Rotate.None) {
if (module.rotations != null) {
Managers.ROTATION.setBlocking(true);
event.setYaw(module.rotations[0]);
event.setPitch(module.rotations[1]);
if (Surround.FREECAM.isEnabled()) {
Surround.FREECAM.get().rotate(module.rotations[0], module.rotations[1]);
}
}
} else if (module.setPosition) {
// if we dont need to rotate and are centered, send immediately.
Locks.acquire(Locks.PLACE_SWITCH_LOCK, module::execute);
}
}
use of me.earth.earthhack.impl.event.events.network.MotionUpdateEvent in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method invoke.
@Override
public void invoke(MotionUpdateEvent event) {
if (module.action == null && !module.timer.passed(module.delay.getValue()) || !Managers.NCP.getClickTimer().passed(module.globalDelay.getValue()) || mc.player.isCreative() || !InventoryUtil.validScreen() || AUTO_ARMOR.returnIfPresent(AutoArmor::isActive, false) || !module.inInventory.getValue() && mc.currentScreen instanceof GuiInventory || !module.cleanInLoot.getValue() && !mc.world.getEntitiesWithinAABB(EntityItem.class, RotationUtil.getRotationPlayer().getEntityBoundingBox()).isEmpty() && (!module.cleanWithFull.getValue() || !isInvFull())) {
return;
}
if (event.getStage() == Stage.PRE) {
// TODO: use invalidate thingy to only calc when necessary?
if (module.stack.getValue() && stack() || module.xCarry.getValue() && doXCarry()) {
return;
}
Map<Item, ItemToDrop> items = new HashMap<>();
boolean prio = module.prioHotbar.getValue();
Item drag = null;
ItemStack draggedStack = mc.player.inventory.getItemStack();
if (check(draggedStack, -2, items)) {
drag = draggedStack.getItem();
} else if (!draggedStack.isEmpty()) {
return;
}
for (int i = prio ? 44 : 9; prio ? i > 8 : i <= 44; // noinspection ConstantConditions (??? am i stupid ???)
i = (prio ? --i : ++i)) {
ItemStack stack = InventoryUtil.get(i);
check(stack, i, items);
}
WindowClick action = null;
if (drag != null) {
ItemToDrop dragged = items.get(drag);
if (dragged != null && dragged.shouldDrop()) {
action = new WindowClick(-999, ItemStack.EMPTY, mc.player.inventory.getItemStack());
}
} else {
for (ItemToDrop toDrop : items.values()) {
if (toDrop.shouldDrop()) {
int s = toDrop.getSlot();
action = new WindowClick(-1, ItemStack.EMPTY, s, InventoryUtil.get(s), -1, p -> p.windowClick(0, s, 1, ClickType.THROW, mc.player));
break;
}
}
}
if (action != null) {
if (module.rotate.getValue()) {
if (MovementUtil.isMoving()) {
// behind us
event.setYaw(event.getYaw() - 180.0f);
} else {
event.setYaw(getYaw(event.getYaw()));
}
// slightly up so we throw further
event.setPitch(-5.0f);
module.action = action;
} else {
module.action = action;
module.runAction();
}
}
} else {
module.runAction();
}
}
Aggregations