Block break simulation instead of input override for breaking, fixes #74
This commit is contained in:
parent
d14d0e131b
commit
8ff89e7400
@ -102,23 +102,6 @@ public class MixinMinecraft {
|
||||
Baritone.INSTANCE.getGameEventHandler().onProcessKeyBinds();
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = {
|
||||
"setIngameFocus",
|
||||
"runTick"
|
||||
},
|
||||
at = @At(
|
||||
value = "FIELD",
|
||||
opcode = Opcodes.PUTFIELD,
|
||||
target = "net/minecraft/client/Minecraft.leftClickCounter:I",
|
||||
ordinal = 0
|
||||
)
|
||||
)
|
||||
private void setLeftClickCounter(Minecraft mc, int value) {
|
||||
if (!Baritone.INSTANCE.isInitialized() || !Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown(mc.gameSettings.keyBindAttack))
|
||||
this.leftClickCounter = value;
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
|
||||
at = @At("HEAD")
|
||||
|
@ -29,6 +29,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLadder;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -54,6 +55,8 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
*/
|
||||
protected final BlockPos[] positionsToPlace;
|
||||
|
||||
private boolean didBreakLastTick;
|
||||
|
||||
private Double cost;
|
||||
|
||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace) {
|
||||
@ -114,10 +117,29 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
|
||||
// TODO: calculate movement inputs from latestState.getGoal().position
|
||||
// latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE
|
||||
|
||||
this.didBreakLastTick = false;
|
||||
|
||||
latestState.getInputStates().forEach((input, forced) -> {
|
||||
RayTraceResult trace = mc.objectMouseOver;
|
||||
boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK;
|
||||
boolean isLeftClick = forced && input == Input.CLICK_LEFT;
|
||||
|
||||
// If we're forcing left click, we're in a gui screen, and we're looking
|
||||
// at a block, break the block without a direct game input manipulation.
|
||||
if (mc.currentScreen != null && isLeftClick && isBlockTrace) {
|
||||
BlockBreakHelper.tryBreakBlock(trace.getBlockPos(), trace.sideHit);
|
||||
this.didBreakLastTick = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||
});
|
||||
latestState.getInputStates().replaceAll((input, forced) -> false);
|
||||
|
||||
if (!this.didBreakLastTick)
|
||||
BlockBreakHelper.stopBreakingBlock();
|
||||
|
||||
currentState = latestState;
|
||||
|
||||
if (isFinished())
|
||||
|
52
src/main/java/baritone/utils/BlockBreakHelper.java
Normal file
52
src/main/java/baritone/utils/BlockBreakHelper.java
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 8/25/2018
|
||||
*/
|
||||
public final class BlockBreakHelper implements Helper {
|
||||
|
||||
private BlockBreakHelper() {}
|
||||
|
||||
/**
|
||||
* The last block that we tried to break, if this value changes
|
||||
* between attempts, then we re-initialize the breaking process.
|
||||
*/
|
||||
private static BlockPos lastBlock;
|
||||
|
||||
public static void tryBreakBlock(BlockPos pos, EnumFacing side) {
|
||||
if (!pos.equals(lastBlock)) {
|
||||
mc.playerController.clickBlock(pos, side);
|
||||
}
|
||||
if (mc.playerController.onPlayerDamageBlock(pos, side)) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
lastBlock = pos;
|
||||
}
|
||||
|
||||
public static void stopBreakingBlock() {
|
||||
mc.playerController.resetBlockRemoving();
|
||||
lastBlock = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user