2018-08-25 06:38:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
2018-09-17 22:11:40 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2018-08-25 06:38:53 +00:00
|
|
|
* 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
|
2018-09-17 22:11:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-08-25 06:38:53 +00:00
|
|
|
*
|
2018-09-17 22:11:40 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2018-08-25 06:38:53 +00:00
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package baritone.utils;
|
|
|
|
|
2019-04-18 01:10:47 +00:00
|
|
|
import baritone.api.utils.Helper;
|
2018-11-14 06:15:01 +00:00
|
|
|
import baritone.api.utils.IPlayerContext;
|
2019-09-19 19:28:56 +00:00
|
|
|
import baritone.utils.accessor.IPlayerControllerMP;
|
|
|
|
import net.minecraft.client.Minecraft;
|
2018-08-25 06:38:53 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-11-06 04:37:54 +00:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2018-08-25 06:38:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Brady
|
|
|
|
* @since 8/25/2018
|
|
|
|
*/
|
|
|
|
public final class BlockBreakHelper implements Helper {
|
2018-09-17 03:19:41 +00:00
|
|
|
|
2018-11-14 06:15:01 +00:00
|
|
|
private boolean didBreakLastTick;
|
2018-08-25 06:38:53 +00:00
|
|
|
|
2019-02-26 22:57:44 +00:00
|
|
|
private final IPlayerContext playerContext;
|
2018-09-17 03:16:05 +00:00
|
|
|
|
2018-11-14 06:15:01 +00:00
|
|
|
public BlockBreakHelper(IPlayerContext playerContext) {
|
|
|
|
this.playerContext = playerContext;
|
|
|
|
}
|
|
|
|
|
2019-07-18 05:41:09 +00:00
|
|
|
private void tryBreakBlock(BlockPos pos, EnumFacing side) {
|
2018-11-14 06:15:01 +00:00
|
|
|
if (playerContext.playerController().onPlayerDamageBlock(pos, side)) {
|
|
|
|
playerContext.player().swingArm(EnumHand.MAIN_HAND);
|
2018-08-25 06:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 06:15:01 +00:00
|
|
|
public void stopBreakingBlock() {
|
2018-12-15 18:27:19 +00:00
|
|
|
// The player controller will never be null, but the player can be
|
2019-09-19 19:28:56 +00:00
|
|
|
if (playerContext.player() != null && didBreakLastTick) {
|
|
|
|
if (((IPlayerControllerMP) mc.playerController).getCurrentBlock().getY() != -1) {
|
|
|
|
// insane bypass to check breaking succeeded
|
|
|
|
((IPlayerControllerMP) mc.playerController).setIsHittingBlock(true);
|
|
|
|
}
|
2018-11-14 06:15:01 +00:00
|
|
|
playerContext.playerController().resetBlockRemoving();
|
2019-09-19 19:28:56 +00:00
|
|
|
didBreakLastTick = false;
|
2018-11-06 04:37:54 +00:00
|
|
|
}
|
2018-08-25 06:38:53 +00:00
|
|
|
}
|
2018-11-06 04:37:54 +00:00
|
|
|
|
2018-11-14 06:15:01 +00:00
|
|
|
|
2019-01-10 03:11:53 +00:00
|
|
|
public void tick(boolean isLeftClick) {
|
2018-11-14 21:48:09 +00:00
|
|
|
RayTraceResult trace = playerContext.objectMouseOver();
|
2018-11-06 04:37:54 +00:00
|
|
|
boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK;
|
|
|
|
|
2018-11-14 06:15:01 +00:00
|
|
|
if (isLeftClick && isBlockTrace) {
|
2019-09-19 19:28:56 +00:00
|
|
|
if (!didBreakLastTick) {
|
|
|
|
((IPlayerControllerMP) Minecraft.getMinecraft().playerController).callSyncCurrentPlayItem();
|
|
|
|
Minecraft.getMinecraft().playerController.clickBlock(trace.getBlockPos(), trace.sideHit);
|
|
|
|
playerContext.player().swingArm(EnumHand.MAIN_HAND);
|
|
|
|
}
|
2018-11-06 04:37:54 +00:00
|
|
|
tryBreakBlock(trace.getBlockPos(), trace.sideHit);
|
|
|
|
didBreakLastTick = true;
|
|
|
|
} else if (didBreakLastTick) {
|
|
|
|
stopBreakingBlock();
|
|
|
|
didBreakLastTick = false;
|
|
|
|
}
|
2019-09-19 19:28:56 +00:00
|
|
|
((IPlayerControllerMP) Minecraft.getMinecraft().playerController).setIsHittingBlock(false);
|
2018-11-06 04:37:54 +00:00
|
|
|
}
|
2018-08-25 06:38:53 +00:00
|
|
|
}
|