Skip to content

Commit fcea327

Browse files
authored
fix(Quiver): read potion contents from ItemStack and fix inventory scan and head check (#6714)
1 parent 5a3028d commit fcea327

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

  • src/main/java/meteordevelopment/meteorclient/systems/modules/combat

‎src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Quiver.java‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
1616
import meteordevelopment.meteorclient.utils.player.FindItemResult;
1717
import meteordevelopment.meteorclient.utils.player.InvUtils;
18+
import meteordevelopment.meteorclient.utils.player.SlotUtils;
1819
import meteordevelopment.orbit.EventHandler;
1920
import net.minecraft.core.BlockPos;
2021
import net.minecraft.core.Direction;
@@ -27,6 +28,7 @@
2728
import net.minecraft.world.item.BowItem;
2829
import net.minecraft.world.item.ItemStack;
2930
import net.minecraft.world.item.Items;
31+
import net.minecraft.world.item.alchemy.PotionContents;
3032
import net.minecraft.world.level.block.Block;
3133
import net.minecraft.world.level.block.Blocks;
3234
import net.minecraft.world.level.block.state.BlockState;
@@ -115,6 +117,10 @@ public Quiver() {
115117

116118
@Override
117119
public void onActivate() {
120+
wasMainhand = true;
121+
wasHotbar = false;
122+
prevSlot = -1;
123+
118124
bow = InvUtils.find(Items.BOW);
119125
if (!shouldQuiver()) return;
120126

@@ -126,21 +132,22 @@ public void onActivate() {
126132
timer = 0;
127133

128134
if (!bow.isMainHand()) {
135+
wasMainhand = false;
129136
if (wasHotbar) InvUtils.swap(bow.slot(), true);
130137
else InvUtils.move().from(mc.player.getInventory().getSelectedSlot()).to(prevSlot);
131-
} else wasMainhand = true;
138+
}
132139

133140
arrowSlots.clear();
134141
Set<MobEffect> usedEffects = new HashSet<>();
135142

136-
for (int i = mc.player.getInventory().getContainerSize(); i > 0; i--) {
137-
if (i == mc.player.getInventory().getSelectedSlot()) continue;
143+
for (int i = SlotUtils.OFFHAND; i >= SlotUtils.HOTBAR_START; i--) {
144+
if (SlotUtils.isArmor(i) || i == mc.player.getInventory().getSelectedSlot()) continue;
138145

139146
ItemStack item = mc.player.getInventory().getItem(i);
140147

141148
if (item.getItem() != Items.TIPPED_ARROW) continue;
142149

143-
Iterator<MobEffectInstance> effects = item.getItem().components().get(DataComponents.POTION_CONTENTS).getAllEffects().iterator();
150+
Iterator<MobEffectInstance> effects = item.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).getAllEffects().iterator();
144151

145152
if (!effects.hasNext()) continue;
146153

@@ -157,9 +164,11 @@ public void onActivate() {
157164

158165
@Override
159166
public void onDeactivate() {
167+
mc.options.keyUse.setDown(false);
168+
160169
if (!wasMainhand) {
161170
if (wasHotbar) InvUtils.swapBack();
162-
else InvUtils.move().from(mc.player.getInventory().getSelectedSlot()).to(prevSlot);
171+
else if (prevSlot != -1) InvUtils.move().from(mc.player.getInventory().getSelectedSlot()).to(prevSlot);
163172
}
164173
}
165174

@@ -180,7 +189,7 @@ private void onTick(TickEvent.Pre event) {
180189
boolean charging = mc.options.keyUse.isDown();
181190

182191
if (!charging) {
183-
InvUtils.move().from(arrowSlots.getInt(0)).to(9);
192+
if (arrowSlots.getInt(0) != 9) InvUtils.move().from(arrowSlots.getInt(0)).to(9);
184193
mc.options.keyUse.setDown(true);
185194
} else {
186195
if (BowItem.getPowerForTime(mc.player.getTicksUsingItem()) >= 0.12) {
@@ -231,11 +240,11 @@ private boolean shouldQuiver() {
231240
}
232241

233242
private boolean headIsOpen() {
234-
testPos.set(mc.player.blockPosition().offset(0, 1, 0));
243+
testPos.setWithOffset(mc.player.blockPosition(), 0, 1, 0);
235244
BlockState pos1 = mc.level.getBlockState(testPos);
236245
if (((BlockBehaviourAccessor) pos1.getBlock()).meteor$isHasCollision()) return false;
237246

238-
testPos.offset(0, 1, 0);
247+
testPos.move(0, 1, 0);
239248
BlockState pos2 = mc.level.getBlockState(testPos);
240249
return !((BlockBehaviourAccessor) pos2.getBlock()).meteor$isHasCollision();
241250
}
@@ -252,7 +261,7 @@ private boolean isSurrounded(Player target) {
252261
for (Direction dir : Direction.values()) {
253262
if (dir == Direction.UP || dir == Direction.DOWN) continue;
254263

255-
testPos.set(target.blockPosition()).relative(dir);
264+
testPos.setWithOffset(target.blockPosition(), dir);
256265
Block block = mc.level.getBlockState(testPos).getBlock();
257266

258267
if (block != Blocks.OBSIDIAN && block != Blocks.BEDROCK && block != Blocks.RESPAWN_ANCHOR

0 commit comments

Comments
 (0)