mirror of
https://github.com/cabaletta/baritone
synced 2025-02-19 13:37:03 +00:00
commit
4399b7c2fb
@ -1394,6 +1394,16 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Long> elytraNetherSeed = new Setting<>(146008555100680L);
|
||||
|
||||
/**
|
||||
* Automatically swap the current elytra with a new one when the durability gets too low
|
||||
*/
|
||||
public final Setting<Boolean> elytraAutoSwap = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* The minimum durability an elytra can have before being swapped
|
||||
*/
|
||||
public final Setting<Integer> elytraMinimumDurability = new Setting<>(5);
|
||||
|
||||
/**
|
||||
* A map of lowercase setting field names to their respective setting
|
||||
*/
|
||||
|
@ -51,10 +51,12 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityFireworkRocket;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.play.server.SPacketPlayerPosLook;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
@ -115,6 +117,10 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
private Solution pendingSolution;
|
||||
private boolean solveNextTick;
|
||||
|
||||
// auto swap
|
||||
private int invTickCountdown = 0;
|
||||
private final Queue<Runnable> transactionQueue = new LinkedList<>();
|
||||
|
||||
private ElytraBehavior(Baritone baritone) {
|
||||
super(baritone);
|
||||
this.clearLines = new CopyOnWriteArrayList<>();
|
||||
@ -538,6 +544,8 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
}
|
||||
}
|
||||
|
||||
tickInventoryTransactions();
|
||||
|
||||
// Certified mojang employee incident
|
||||
if (this.remainingFireworkTicks > 0) {
|
||||
this.remainingFireworkTicks--;
|
||||
@ -585,6 +593,8 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
return;
|
||||
}
|
||||
|
||||
trySwapElytra();
|
||||
|
||||
if (ctx.player().collidedHorizontally) {
|
||||
logDirect("hbonk");
|
||||
}
|
||||
@ -1248,6 +1258,53 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
return mat == Material.AIR || (ignoreLava && mat == Material.LAVA);
|
||||
}
|
||||
|
||||
private void tickInventoryTransactions() {
|
||||
if (invTickCountdown <= 0) {
|
||||
Runnable r = transactionQueue.poll();
|
||||
if (r != null) {
|
||||
r.run();
|
||||
invTickCountdown = Baritone.settings().ticksBetweenInventoryMoves.value;
|
||||
}
|
||||
}
|
||||
if (invTickCountdown > 0) invTickCountdown--;
|
||||
}
|
||||
|
||||
private void queueWindowClick(int windowId, int slotId, int button, ClickType type) {
|
||||
transactionQueue.add(() -> ctx.playerController().windowClick(windowId, slotId, button, type, ctx.player()));
|
||||
}
|
||||
|
||||
private int findGoodElytra() {
|
||||
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
|
||||
for (int i = 0; i < invy.size(); i++) {
|
||||
ItemStack slot = invy.get(i);
|
||||
if (slot.getItem() == Items.ELYTRA && (slot.getItem().getMaxDamage() - slot.getItemDamage()) > Baritone.settings().elytraMinimumDurability.value) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void trySwapElytra() {
|
||||
if (!Baritone.settings().elytraAutoSwap.value || !transactionQueue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack chest = ctx.player().inventory.armorInventory.get(2);
|
||||
if (chest.getItem() != Items.ELYTRA
|
||||
|| chest.getItem().getMaxDamage() - chest.getItemDamage() > Baritone.settings().elytraMinimumDurability.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
int goodElytraSlot = findGoodElytra();
|
||||
if (goodElytraSlot != -1) {
|
||||
final int CHEST_SLOT = 6;
|
||||
final int slotId = goodElytraSlot < 9 ? goodElytraSlot + 36 : goodElytraSlot;
|
||||
queueWindowClick(ctx.player().inventoryContainer.windowId, slotId, 0, ClickType.PICKUP);
|
||||
queueWindowClick(ctx.player().inventoryContainer.windowId, CHEST_SLOT, 0, ClickType.PICKUP);
|
||||
queueWindowClick(ctx.player().inventoryContainer.windowId, slotId, 0, ClickType.PICKUP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minecraft 1.12's pushOutOfBlocks logic doesn't account for players being able to fit under single block spaces,
|
||||
* so whenever the edge of a ceiling is encountered while elytra flying it tries to push the player out.
|
||||
|
@ -199,12 +199,10 @@ public final class NetherPathfinderContext {
|
||||
} else {
|
||||
id = (int) ((jl | longArray[k] << (64 - l)) & maxEntryValue);
|
||||
}
|
||||
Octree.setBlock(ptr,
|
||||
((idx & 255) & 15),
|
||||
yReal + (idx >> 8),
|
||||
((idx & 255) >> 4),
|
||||
id != airId
|
||||
);
|
||||
int x = (idx & 15);
|
||||
int y = yReal + (idx >> 8);
|
||||
int z = ((idx >> 4) & 15);
|
||||
Octree.setBlock(ptr, x, y, z, id != airId);
|
||||
}
|
||||
}
|
||||
Octree.setIsFromJava(ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user