Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,7 @@ private void breakBed(BlockPos pos) {

if (!(mc.level.getBlockState(pos).getBlock() instanceof BedBlock)) return;

boolean wasSneaking = mc.player.isShiftKeyDown();
if (wasSneaking) mc.player.setShiftKeyDown(false);

mc.gameMode.useItemOn(mc.player, InteractionHand.OFF_HAND, new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false));

mc.player.setShiftKeyDown(wasSneaking);
BlockUtils.interact(new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false), InteractionHand.OFF_HAND, false);
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -198,7 +199,7 @@ private void burrow() {
if (!(mc.player.getInventory().getItem(block.slot()).getItem() instanceof BlockItem)) return;
InvUtils.swap(block.slot(), true);

mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND, new BlockHitResult(Utils.vec3(blockPos), Direction.UP, blockPos, false));
BlockUtils.interact(new BlockHitResult(Utils.vec3(blockPos), Direction.UP, blockPos, false), InteractionHand.MAIN_HAND, false);

InvUtils.swapBack();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.player.SlotUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -94,23 +95,10 @@ private boolean shouldWait() {
}

private int getSlot() {
for (int i = 0; i < mc.player.getInventory().getNonEquipmentItems().size(); i++) {
ItemStack itemStack = mc.player.getInventory().getItem(i);
if (blacklist.get().contains(itemStack.getItem())) continue;

if (Utils.hasEnchantments(itemStack, Enchantments.MENDING) && itemStack.getDamageValue() > 0) {
return i;
}
}

return -1;
return InvUtils.find(itemStack -> !blacklist.get().contains(itemStack.getItem()) && Utils.hasEnchantments(itemStack, Enchantments.MENDING) && itemStack.getDamageValue() > 0, SlotUtils.HOTBAR_START, SlotUtils.MAIN_END).slot();
}

private int getEmptySlot() {
for (int i = 0; i < mc.player.getInventory().getNonEquipmentItems().size(); i++) {
if (mc.player.getInventory().getItem(i).isEmpty()) return i;
}

return -1;
return InvUtils.find(ItemStack::isEmpty, SlotUtils.HOTBAR_START, SlotUtils.MAIN_END).slot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import meteordevelopment.meteorclient.events.entity.player.DoItemUseEvent;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.player.SwingMode;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -47,10 +47,7 @@ private void onTick(DoItemUseEvent event) {

if (mc.level.getBlockState(pos).hasBlockEntity()) {
for (InteractionHand hand : InteractionHand.values()) {
InteractionResult result = mc.gameMode.useItemOn(mc.player, hand, new BlockHitResult(new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
if (result instanceof InteractionResult.Success success && success.swingSource() == InteractionResult.SwingSource.PREDICTED) {
SwingMode.Both.interactSwing(hand);
}
InteractionResult result = BlockUtils.interact(new BlockHitResult(new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true), hand, true);

if (result instanceof InteractionResult.Success || result instanceof InteractionResult.Fail) {
event.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -140,8 +141,8 @@ private void interact() {
}
} else {
if (ticks >= tickInterval.get() && !entity.isOnFire()) {
mc.gameMode.useItemOn(mc.player, hand, new BlockHitResult(
entity.position().subtract(new Vec3(0, 1, 0)), Direction.UP, entity.blockPosition().below(), false));
BlockUtils.interact(new BlockHitResult(
entity.position().subtract(new Vec3(0, 1, 0)), Direction.UP, entity.blockPosition().below(), false), hand, false);
ticks = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,10 @@ protected void tick(HighwayBuilder b) {

// if we don't know what's in your echest, open it quickly while we have one available to check
if (!EChestMemory.isKnown()) {
if (b.rotation.get().place) Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () ->
b.mc.gameMode.useItemOn(b.mc.player, InteractionHand.MAIN_HAND, new BlockHitResult(Vec3.atCenterOf(bp), Direction.UP, bp, false)));
else
b.mc.gameMode.useItemOn(b.mc.player, InteractionHand.MAIN_HAND, new BlockHitResult(Vec3.atCenterOf(bp), Direction.UP, bp, false));
BlockHitResult bhr = new BlockHitResult(Vec3.atCenterOf(bp), Direction.UP, bp, false);

if (b.rotation.get().place) Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () -> BlockUtils.interact(bhr, InteractionHand.MAIN_HAND, true));
else BlockUtils.interact(bhr, InteractionHand.MAIN_HAND, true);

return;
}
Expand Down Expand Up @@ -1355,13 +1355,13 @@ protected void tick(HighwayBuilder b) {
} else {
// Place ender chest
int slot = findAndMoveToHotbar(b, itemStack -> itemStack.getItem() == Items.ENDER_CHEST);
if (slot == -1 || countItem(b, stack -> stack.getItem().equals(Items.ENDER_CHEST)) <= b.saveEchests.get()) {
if (slot == -1 || countItem(stack -> stack.getItem().equals(Items.ENDER_CHEST)) <= b.saveEchests.get()) {
stopTimerEnabled = true;
stopTimer = 12;
return;
}

if (countItem(b, stack -> stack.is(ItemTags.PICKAXES)) <= b.savePickaxes.get()) {
if (countItem(stack -> stack.is(ItemTags.PICKAXES)) <= b.savePickaxes.get()) {
if (b.searchEnderChest.get() || b.searchShulkers.get()) {
b.restockTask.setPickaxes();
}
Expand Down Expand Up @@ -1416,7 +1416,7 @@ protected void start(HighwayBuilder b) {
}

// next search your ender chest for raw items and shulkers containing items
if (slot == -1 && b.searchEnderChest.get() && countItem(b, stack -> stack.getItem().equals(Items.ENDER_CHEST)) > 0) {
if (slot == -1 && b.searchEnderChest.get() && countItem(stack -> stack.getItem().equals(Items.ENDER_CHEST)) > 0) {
// todo handle pulling ecs from shulker boxes so we can search through them

boolean stop = EChestMemory.isKnown();
Expand Down Expand Up @@ -1450,9 +1450,9 @@ protected void start(HighwayBuilder b) {
// by this point we have searched shulkers and your ender chest, and no more items could be found to pull from
if (slot == -1) {
boolean restockOccurred = (
(b.restockTask.materials && (hasItem(b, stack -> stack.getItem() instanceof BlockItem bi && b.blocksToPlace.get().contains(bi.getBlock())) || b.blocksToPlace.get().contains(Blocks.OBSIDIAN) && countItem(b, itemStack -> itemStack.getItem() == Items.ENDER_CHEST) > b.saveEchests.get())) ||
(b.restockTask.pickaxes && countItem(b, itemStack -> itemStack.is(ItemTags.PICKAXES)) > b.savePickaxes.get()) ||
(b.restockTask.food && hasItem(b, itemStack -> Utils.isFood(itemStack) && !Modules.get().get(AutoEat.class).blacklist.get().contains(itemStack.getItem())))
(b.restockTask.materials && (hasItem(stack -> stack.getItem() instanceof BlockItem bi && b.blocksToPlace.get().contains(bi.getBlock())) || b.blocksToPlace.get().contains(Blocks.OBSIDIAN) && countItem(itemStack -> itemStack.getItem() == Items.ENDER_CHEST) > b.saveEchests.get())) ||
(b.restockTask.pickaxes && countItem(itemStack -> itemStack.is(ItemTags.PICKAXES)) > b.savePickaxes.get()) ||
(b.restockTask.food && hasItem(itemStack -> Utils.isFood(itemStack) && !Modules.get().get(AutoEat.class).blacklist.get().contains(itemStack.getItem())))
);

if (restockOccurred) {
Expand Down Expand Up @@ -1499,7 +1499,7 @@ protected void tick(HighwayBuilder b) {
if (indicateStopping && !breakContainer) {
if (stopTimer > 0) stopTimer--;
else {
if (b.lastState == PlaceShulkerBlockade) {// && !(b.blocksToPlace.get().contains(Blocks.OBSIDIAN) && countItem(b, stack -> stack.getItem() == Items.ENDER_CHEST) > b.saveEchests.get() && !hasItem(b, stack -> stack.getItem() == Items.OBSIDIAN))) {
if (b.lastState == PlaceShulkerBlockade) {// && !(b.blocksToPlace.get().contains(Blocks.OBSIDIAN) && countItem(stack -> stack.getItem() == Items.ENDER_CHEST) > b.saveEchests.get() && !hasItem(stack -> stack.getItem() == Items.OBSIDIAN))) {
b.setState(MineShulkerBlockade);
} else {
b.setState(ThrowOutTrash, Forward);
Expand All @@ -1525,7 +1525,7 @@ protected void tick(HighwayBuilder b) {
if (b.restockTask.materials) {
slotsPulled += countSlots(b, itemStack -> itemStack.getItem() instanceof BlockItem bi && b.blocksToPlace.get().contains(bi.getBlock()));
if (b.blocksToPlace.get().contains(Blocks.OBSIDIAN))
slotsPulled += ((countItem(b, itemStack -> itemStack.getItem() == Items.ENDER_CHEST) - b.saveEchests.get()) * 8) / 64;
slotsPulled += ((countItem(itemStack -> itemStack.getItem() == Items.ENDER_CHEST) - b.saveEchests.get()) * 8) / 64;
}
if (b.restockTask.pickaxes)
slotsPulled += countSlots(b, itemStack -> itemStack.is(ItemTags.PICKAXES)) - b.savePickaxes.get();
Expand Down Expand Up @@ -1693,12 +1693,11 @@ private void handleContainerBlock(HighwayBuilder b, BlockPos bp) {
Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () -> BlockUtils.breakBlock(bp, true));
else BlockUtils.breakBlock(bp, true);
} else {
if (b.rotation.get().place) {
Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () ->
b.mc.gameMode.useItemOn(b.mc.player, InteractionHand.MAIN_HAND, new BlockHitResult(Vec3.atCenterOf(bp), Direction.UP, bp, false))
);
} else
b.mc.gameMode.useItemOn(b.mc.player, InteractionHand.MAIN_HAND, new BlockHitResult(Vec3.atCenterOf(bp), Direction.UP, bp, false));
BlockHitResult bhr = new BlockHitResult(Vec3.atCenterOf(bp), Direction.UP, bp, false);

if (b.rotation.get().place)
Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () -> BlockUtils.interact(bhr, InteractionHand.MAIN_HAND, true));
else BlockUtils.interact(bhr, InteractionHand.MAIN_HAND, true);

delayTimer = b.inventoryDelay.get();
}
Expand Down Expand Up @@ -2018,12 +2017,8 @@ protected void place(HighwayBuilder b, MBPIterator it, int slot, State nextState
if (finishedPlacing || !placed) b.setState(nextState);
}

private int findSlot(HighwayBuilder b, Predicate<ItemStack> predicate, boolean hotbar) {
for (int i = hotbar ? 0 : 9; i < (hotbar ? 9 : b.mc.player.getInventory().getNonEquipmentItems().size()); i++) {
if (predicate.test(b.mc.player.getInventory().getItem(i))) return i;
}

return -1;
private int findSlot(Predicate<ItemStack> predicate, boolean hotbar) {
return InvUtils.find(predicate, hotbar ? SlotUtils.HOTBAR_START : SlotUtils.MAIN_START, hotbar ? SlotUtils.HOTBAR_END : SlotUtils.MAIN_END).slot();
}

protected int findHotbarSlot(HighwayBuilder b, boolean replaceTools) {
Expand Down Expand Up @@ -2067,35 +2062,25 @@ protected int findHotbarSlot(HighwayBuilder b, boolean replaceTools) {
return -1;
}

protected boolean hasItem(HighwayBuilder b, Predicate<ItemStack> predicate) {
for (int i = 0; i < b.mc.player.getInventory().getNonEquipmentItems().size(); i++) {
if (predicate.test(b.mc.player.getInventory().getItem(i))) return true;
}

return false;
protected boolean hasItem(Predicate<ItemStack> predicate) {
return InvUtils.find(predicate, SlotUtils.HOTBAR_START, SlotUtils.MAIN_END).found();
}

protected int countItem(HighwayBuilder b, Predicate<ItemStack> predicate) {
int count = 0;
for (int i = 0; i < b.mc.player.getInventory().getNonEquipmentItems().size(); i++) {
ItemStack stack = b.mc.player.getInventory().getItem(i);
if (predicate.test(stack)) count += stack.getCount();
}

return count;
protected int countItem(Predicate<ItemStack> predicate) {
return InvUtils.find(predicate, SlotUtils.HOTBAR_START, SlotUtils.MAIN_END).count();
}

protected int findAndMoveToHotbar(HighwayBuilder b, Predicate<ItemStack> predicate) {
// Check hotbar
int slot = findSlot(b, predicate, true);
int slot = findSlot(predicate, true);
if (slot != -1) return slot;

// Find hotbar slot to move to
int hotbarSlot = findHotbarSlot(b, false);
if (hotbarSlot == -1) return -1;

// Check inventory
slot = findSlot(b, predicate, false);
slot = findSlot(predicate, false);

// Return if no items were found
if (slot == -1) return -1;
Expand Down Expand Up @@ -2131,7 +2116,7 @@ protected int findAndMoveBestToolToHotbar(HighwayBuilder b, BlockState blockStat

ItemStack bestStack = b.mc.player.getInventory().getItem(bestSlot);
if (bestStack.is(ItemTags.PICKAXES)) {
int count = countItem(b, stack -> stack.is(ItemTags.PICKAXES));
int count = countItem(stack -> stack.is(ItemTags.PICKAXES));

// If we are in the process of restocking pickaxes and happen to need one, we should allow using it
// as long as it has enough durability, since we will obtain more shortly thereafter
Expand Down Expand Up @@ -2165,7 +2150,7 @@ protected int findBlocksToPlace(HighwayBuilder b) {
int slot = findAndMoveToHotbar(b, itemStack -> itemStack.getItem() instanceof BlockItem blockItem && b.blocksToPlace.get().contains(blockItem.getBlock()));

if (slot == -1) {
if (b.mineEnderChests.get() && b.blocksToPlace.get().contains(Blocks.OBSIDIAN) && countItem(b, stack -> stack.getItem().equals(Items.ENDER_CHEST)) > b.saveEchests.get()) {
if (b.mineEnderChests.get() && b.blocksToPlace.get().contains(Blocks.OBSIDIAN) && countItem(stack -> stack.getItem().equals(Items.ENDER_CHEST)) > b.saveEchests.get()) {
// can grind echests for obsidian
b.setState(MineEnderChests);
} else if (b.searchEnderChest.get() || b.searchShulkers.get()) {
Expand Down Expand Up @@ -2853,7 +2838,7 @@ public boolean isReady() {
}

public boolean shouldRemove() {
boolean distance = !packet && Utils.distance(b.mc.player.getEyePosition().x, b.mc.player.getEyePosition().y, b.mc.player.getEyePosition().z, blockPos.getX() + direction.getStepX(), blockPos.getY() + direction.getStepY(), blockPos.getZ() + direction.getStepZ()) > b.mc.player.blockInteractionRange();
boolean distance = !packet && !PlayerUtils.isWithinReach(blockPos.getX() + direction.getStepX(), blockPos.getY() + direction.getStepY(), blockPos.getZ() + direction.getStepZ());

// a minimum amount of time needs to have elapsed for the timeout check to occur, otherwise it may trigger
// when it isn't supposed to due to latency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.render.BreakIndicators;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.Pool;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
Expand Down Expand Up @@ -224,7 +224,7 @@ public MyBlock set(StartBreakingBlockEvent event) {
public boolean shouldRemove() {
boolean broken = mc.level.getBlockState(blockPos).getBlock() != block;
boolean timeout = progress() > 2 && (mc.player.tickCount - startTime > 50);
boolean distance = Utils.distance(mc.player.getEyePosition().x, mc.player.getEyePosition().y, mc.player.getEyePosition().z, blockPos.getX() + direction.getStepX(), blockPos.getY() + direction.getStepY(), blockPos.getZ() + direction.getStepZ()) > mc.player.blockInteractionRange();
boolean distance = !PlayerUtils.isWithinReach(blockPos.getX() + direction.getStepX(), blockPos.getY() + direction.getStepY(), blockPos.getZ() + direction.getStepZ());

return broken || timeout || distance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import meteordevelopment.meteorclient.utils.PreInit;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.world.Dimension;
import meteordevelopment.meteorclient.utils.world.TickRate;
Expand Down Expand Up @@ -406,13 +407,7 @@ private static Value countItems(Starscript ss, int argCount) {
Item item = BuiltInRegistries.ITEM.getValue(id);
if (item == Items.AIR || mc.player == null) return Value.number(0);

int count = 0;
for (int i = 0; i < mc.player.getInventory().getContainerSize(); i++) {
ItemStack itemStack = mc.player.getInventory().getItem(i);
if (itemStack.getItem() == item) count += itemStack.getCount();
}

return Value.number(count);
return Value.number(InvUtils.find(item).count());
}

private static Value getMeteorPrefix() {
Expand Down
Loading
Loading