Merge branch '1.19.4' into 1.20.5
This commit is contained in:
@@ -42,6 +42,7 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.AirBlock;
|
||||
import net.minecraft.world.level.block.BambooStalkBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.BonemealableBlock;
|
||||
@@ -95,6 +96,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
Items.NETHER_WART,
|
||||
Items.COCOA_BEANS,
|
||||
Blocks.SUGAR_CANE.asItem(),
|
||||
Blocks.BAMBOO.asItem(),
|
||||
Blocks.CACTUS.asItem()
|
||||
);
|
||||
|
||||
@@ -137,6 +139,15 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
return true;
|
||||
}
|
||||
},
|
||||
BAMBOO(Blocks.BAMBOO, null) {
|
||||
@Override
|
||||
public boolean readyToHarvest(Level world, BlockPos pos, BlockState state) {
|
||||
if (Baritone.settings().replantCrops.value) {
|
||||
return world.getBlockState(pos.below()).getBlock() instanceof BambooStalkBlock;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
CACTUS(Blocks.CACTUS, null) {
|
||||
@Override
|
||||
public boolean readyToHarvest(Level world, BlockPos pos, BlockState state) {
|
||||
@@ -191,20 +202,20 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
ArrayList<Block> scan = new ArrayList<>();
|
||||
for (Harvest harvest : Harvest.values()) {
|
||||
scan.add(harvest.block);
|
||||
}
|
||||
if (Baritone.settings().replantCrops.value) {
|
||||
scan.add(Blocks.FARMLAND);
|
||||
scan.add(Blocks.JUNGLE_LOG);
|
||||
if (Baritone.settings().replantNetherWart.value) {
|
||||
scan.add(Blocks.SOUL_SAND);
|
||||
}
|
||||
}
|
||||
|
||||
if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) {
|
||||
Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, 256, 10, 10));
|
||||
ArrayList<Block> scan = new ArrayList<>();
|
||||
for (Harvest harvest : Harvest.values()) {
|
||||
scan.add(harvest.block);
|
||||
}
|
||||
if (Baritone.settings().replantCrops.value) {
|
||||
scan.add(Blocks.FARMLAND);
|
||||
scan.add(Blocks.JUNGLE_LOG);
|
||||
if (Baritone.settings().replantNetherWart.value) {
|
||||
scan.add(Blocks.SOUL_SAND);
|
||||
}
|
||||
}
|
||||
|
||||
Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, Baritone.settings().farmMaxScanSize.value, 10, 10));
|
||||
}
|
||||
if (locations == null) {
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
@@ -256,7 +267,12 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
BetterBlockPos playerPos = ctx.playerFeet();
|
||||
double blockReachDistance = ctx.playerController().getBlockReachDistance();
|
||||
for (BlockPos pos : toBreak) {
|
||||
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
|
||||
continue;
|
||||
}
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||
if (rot.isPresent() && isSafeToCancel) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
@@ -270,10 +286,13 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
|
||||
both.addAll(openSoulsand);
|
||||
for (BlockPos pos : both) {
|
||||
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
|
||||
continue;
|
||||
}
|
||||
boolean soulsand = openSoulsand.contains(pos);
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), blockReachDistance, false);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
|
||||
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
|
||||
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
|
||||
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == Direction.UP) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
if (ctx.isLookingAt(pos)) {
|
||||
@@ -284,14 +303,17 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : openLog) {
|
||||
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
|
||||
continue;
|
||||
}
|
||||
for (Direction dir : Direction.Plane.HORIZONTAL) {
|
||||
if (!(ctx.world().getBlockState(pos.relative(dir)).getBlock() instanceof AirBlock)) {
|
||||
continue;
|
||||
}
|
||||
Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getNormal()).scale(0.5));
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false);
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, blockReachDistance, false);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) {
|
||||
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
|
||||
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
|
||||
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == dir) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
if (ctx.isLookingAt(pos)) {
|
||||
@@ -303,6 +325,9 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : bonemealable) {
|
||||
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
|
||||
continue;
|
||||
}
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
@@ -359,6 +384,14 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
}
|
||||
}
|
||||
if (goalz.isEmpty()) {
|
||||
logDirect("Farm failed");
|
||||
if (Baritone.settings().notificationOnFarmFail.value) {
|
||||
logNotification("Farm failed", true);
|
||||
}
|
||||
onLostControl();
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.utils;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.utils.accessor.IPlayerControllerMP;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
@@ -29,10 +30,10 @@ import net.minecraft.world.phys.HitResult;
|
||||
*/
|
||||
public final class BlockBreakHelper {
|
||||
// base ticks between block breaks caused by tick logic
|
||||
private static final int BASE_BREAK_DELAY = 2;
|
||||
private static final int BASE_BREAK_DELAY = 1;
|
||||
|
||||
private final IPlayerContext ctx;
|
||||
private boolean didBreakLastTick;
|
||||
private boolean wasHitting;
|
||||
private int breakDelayTimer = 0;
|
||||
|
||||
BlockBreakHelper(IPlayerContext ctx) {
|
||||
@@ -41,13 +42,10 @@ public final class BlockBreakHelper {
|
||||
|
||||
public void stopBreakingBlock() {
|
||||
// The player controller will never be null, but the player can be
|
||||
if (ctx.player() != null && didBreakLastTick) {
|
||||
if (!ctx.playerController().hasBrokenBlock()) {
|
||||
// insane bypass to check breaking succeeded
|
||||
ctx.playerController().setHittingBlock(true);
|
||||
}
|
||||
if (ctx.player() != null && wasHitting) {
|
||||
ctx.playerController().setHittingBlock(false);
|
||||
ctx.playerController().resetBlockRemoving();
|
||||
didBreakLastTick = false;
|
||||
wasHitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,24 +58,30 @@ public final class BlockBreakHelper {
|
||||
boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK;
|
||||
|
||||
if (isLeftClick && isBlockTrace) {
|
||||
if (!didBreakLastTick) {
|
||||
ctx.playerController().setHittingBlock(wasHitting);
|
||||
if (ctx.playerController().hasBrokenBlock()) {
|
||||
ctx.playerController().syncHeldItem();
|
||||
ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection());
|
||||
ctx.player().swing(InteractionHand.MAIN_HAND);
|
||||
} else {
|
||||
if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) {
|
||||
ctx.player().swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
if (ctx.playerController().hasBrokenBlock()) { // block broken this tick
|
||||
// break delay timer only applies for multi-tick block breaks like vanilla
|
||||
breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY;
|
||||
// must reset controller's destroy delay to prevent the client from delaying itself unnecessarily
|
||||
((IPlayerControllerMP) ctx.minecraft().gameMode).setDestroyDelay(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to break the block
|
||||
if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) {
|
||||
ctx.player().swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
// if true, we're breaking a block. if false, we broke the block this tick
|
||||
wasHitting = !ctx.playerController().hasBrokenBlock();
|
||||
// this value will be reset by the MC client handling mouse keys
|
||||
// since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true
|
||||
// we store and restore this value on the next tick to determine if we're breaking a block
|
||||
ctx.playerController().setHittingBlock(false);
|
||||
|
||||
didBreakLastTick = true;
|
||||
} else if (didBreakLastTick) {
|
||||
stopBreakingBlock();
|
||||
breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY;
|
||||
didBreakLastTick = false;
|
||||
} else {
|
||||
wasHitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,13 +74,11 @@ public class GuiClick extends Screen implements Helper {
|
||||
Vec3 far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv
|
||||
|
||||
if (near != null && far != null) {
|
||||
///
|
||||
Vec3 viewerPos = new Vec3(PathRenderer.posX(), PathRenderer.posY(), PathRenderer.posZ());
|
||||
LocalPlayer player = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().player();
|
||||
HitResult result = player.level().clip(new ClipContext(near.add(viewerPos), far.add(viewerPos), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
|
||||
if (result != null && result.getType() == HitResult.Type.BLOCK) {
|
||||
currentMouseOver = ((BlockHitResult) result).getBlockPos();
|
||||
System.out.println("currentMouseOver = " + currentMouseOver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,13 @@ public class ToolSet {
|
||||
* @return how long it would take in ticks
|
||||
*/
|
||||
public static double calculateSpeedVsBlock(ItemStack item, BlockState state) {
|
||||
float hardness = state.getDestroySpeed(null, null);
|
||||
float hardness;
|
||||
try {
|
||||
hardness = state.getDestroySpeed(null, null);
|
||||
} catch (NullPointerException npe) {
|
||||
// can't easily determine the hardness so treat it as unbreakable
|
||||
return -1;
|
||||
}
|
||||
if (hardness < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,11 @@ public interface IPlayerControllerMP {
|
||||
|
||||
void setIsHittingBlock(boolean isHittingBlock);
|
||||
|
||||
boolean isHittingBlock();
|
||||
|
||||
BlockPos getCurrentBlock();
|
||||
|
||||
void callSyncCurrentPlayItem();
|
||||
|
||||
void setDestroyDelay(int destroyDelay);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package baritone.utils.player;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.utils.accessor.IPlayerControllerMP;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@@ -54,7 +53,7 @@ public final class BaritonePlayerController implements IPlayerController {
|
||||
|
||||
@Override
|
||||
public boolean hasBrokenBlock() {
|
||||
return ((IPlayerControllerMP) mc.gameMode).getCurrentBlock().getY() == -1;
|
||||
return !((IPlayerControllerMP) mc.gameMode).isHittingBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user