This commit is contained in:
Leijurv 2018-09-09 07:16:46 -07:00
commit b31930ebd2
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
30 changed files with 186 additions and 97 deletions

View File

@ -50,7 +50,7 @@ PathingBehavior.INSTANCE.path();
## Can I use Baritone as a library in my hacked client? ## Can I use Baritone as a library in my hacked client?
Sure! Sure! (As long as usage is in compliance with the GPL 3 License)
## How is it so fast? ## How is it so fast?

View File

@ -39,9 +39,15 @@ public class BaritoneTweaker implements ITweaker {
@Override @Override
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
this.args = new ArrayList<>(args); this.args = new ArrayList<>(args);
if (gameDir != null) addArg("gameDir", gameDir.getAbsolutePath()); if (gameDir != null) {
if (assetsDir != null) addArg("assetsDir", assetsDir.getAbsolutePath()); addArg("gameDir", gameDir.getAbsolutePath());
if (profile != null) addArg("version", profile); }
if (assetsDir != null) {
addArg("assetsDir", assetsDir.getAbsolutePath());
}
if (profile != null) {
addArg("version", profile);
}
} }
@Override @Override

View File

@ -42,9 +42,10 @@ public class MixinEntityPlayerSP {
private void sendChatMessage(String msg, CallbackInfo ci) { private void sendChatMessage(String msg, CallbackInfo ci) {
ChatEvent event = new ChatEvent(msg); ChatEvent event = new ChatEvent(msg);
Baritone.INSTANCE.getGameEventHandler().onSendChatMessage(event); Baritone.INSTANCE.getGameEventHandler().onSendChatMessage(event);
if (event.isCancelled()) if (event.isCancelled()) {
ci.cancel(); ci.cancel();
} }
}
@Inject( @Inject(
method = "onUpdate", method = "onUpdate",

View File

@ -37,7 +37,8 @@ public class MixinKeyBinding {
cancellable = true cancellable = true
) )
private void isKeyDown(CallbackInfoReturnable<Boolean> cir) { private void isKeyDown(CallbackInfoReturnable<Boolean> cir) {
if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) {
cir.setReturnValue(true); cir.setReturnValue(true);
} }
} }
}

View File

@ -39,7 +39,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(NetworkManager.class) @Mixin(NetworkManager.class)
public class MixinNetworkManager { public class MixinNetworkManager {
@Shadow private Channel channel; @Shadow
private Channel channel;
@Inject( @Inject(
method = "dispatchPacket", method = "dispatchPacket",
@ -73,7 +74,8 @@ public class MixinNetworkManager {
at = @At("RETURN") at = @At("RETURN")
) )
private void postProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) { private void postProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
if (this.channel.isOpen()) if (this.channel.isOpen()) {
Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent(EventState.POST, packet)); Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent(EventState.POST, packet));
} }
} }
}

View File

@ -49,7 +49,6 @@ import org.lwjgl.input.Keyboard;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
/** /**
* @author Brady * @author Brady
@ -61,12 +60,20 @@ public final class GameEventHandler implements IGameEventListener, Helper {
@Override @Override
public final void onTick(TickEvent event) { public final void onTick(TickEvent event) {
dispatch(listener -> listener.onTick(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onTick(event);
}
}
} }
@Override @Override
public final void onPlayerUpdate(PlayerUpdateEvent event) { public final void onPlayerUpdate(PlayerUpdateEvent event) {
dispatch(listener -> listener.onPlayerUpdate(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onPlayerUpdate(event);
}
}
} }
@Override @Override
@ -80,17 +87,26 @@ public final class GameEventHandler implements IGameEventListener, Helper {
if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) { if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
int keyCode = keyBinding.getKeyCode(); int keyCode = keyBinding.getKeyCode();
if (keyCode < Keyboard.KEYBOARD_SIZE) if (keyCode < Keyboard.KEYBOARD_SIZE) {
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode); KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
} }
} }
}
dispatch(IGameEventListener::onProcessKeyBinds); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onProcessKeyBinds();
}
}
} }
@Override @Override
public final void onSendChatMessage(ChatEvent event) { public final void onSendChatMessage(ChatEvent event) {
dispatch(listener -> listener.onSendChatMessage(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onSendChatMessage(event);
}
}
} }
@Override @Override
@ -116,18 +132,20 @@ public final class GameEventHandler implements IGameEventListener, Helper {
} }
dispatch(listener -> listener.onChunkEvent(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onChunkEvent(event);
}
}
} }
@Override @Override
public final void onRenderPass(RenderEvent event) { public final void onRenderPass(RenderEvent event) {
/* for (IGameEventListener l : listeners) {
WorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> { if (canDispatch(l)) {
drawChunkLine(region.getX() * 512 + chunk.getX() * 16, region.getZ() * 512 + chunk.getZ() * 16, event.getPartialTicks()); l.onRenderPass(event);
}))); }
*/ }
dispatch(listener -> listener.onRenderPass(event));
} }
@Override @Override
@ -141,52 +159,77 @@ public final class GameEventHandler implements IGameEventListener, Helper {
break; break;
case POST: case POST:
cache.closeWorld(); cache.closeWorld();
if (event.getWorld() != null) if (event.getWorld() != null) {
cache.initWorld(event.getWorld()); cache.initWorld(event.getWorld());
}
break; break;
} }
dispatch(listener -> listener.onWorldEvent(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onWorldEvent(event);
}
}
} }
@Override @Override
public final void onSendPacket(PacketEvent event) { public final void onSendPacket(PacketEvent event) {
dispatch(listener -> listener.onSendPacket(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onSendPacket(event);
}
}
} }
@Override @Override
public final void onReceivePacket(PacketEvent event) { public final void onReceivePacket(PacketEvent event) {
dispatch(listener -> listener.onReceivePacket(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onReceivePacket(event);
}
}
} }
@Override @Override
public void onPlayerRelativeMove(RelativeMoveEvent event) { public void onPlayerRelativeMove(RelativeMoveEvent event) {
dispatch(listener -> listener.onPlayerRelativeMove(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onPlayerRelativeMove(event);
}
}
} }
@Override @Override
public void onBlockInteract(BlockInteractEvent event) { public void onBlockInteract(BlockInteractEvent event) {
dispatch(listener -> listener.onBlockInteract(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onBlockInteract(event);
}
}
} }
@Override @Override
public void onPlayerDeath() { public void onPlayerDeath() {
dispatch(IGameEventListener::onPlayerDeath); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onPlayerDeath();
}
}
} }
@Override @Override
public void onPathEvent(PathEvent event) { public void onPathEvent(PathEvent event) {
dispatch(listener -> listener.onPathEvent(event)); for (IGameEventListener l : listeners) {
if (canDispatch(l)) {
l.onPathEvent(event);
}
}
} }
public final void registerEventListener(IGameEventListener listener) { public final void registerEventListener(IGameEventListener listener) {
this.listeners.add(listener); this.listeners.add(listener);
} }
private void dispatch(Consumer<IGameEventListener> dispatchFunction) {
this.listeners.stream().filter(this::canDispatch).forEach(dispatchFunction);
}
private boolean canDispatch(IGameEventListener listener) { private boolean canDispatch(IGameEventListener listener) {
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled(); return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
} }

View File

@ -52,8 +52,9 @@ public class Behavior implements AbstractGameEventListener, Toggleable, Helper {
@Override @Override
public final boolean setEnabled(boolean enabled) { public final boolean setEnabled(boolean enabled) {
boolean newState = getNewState(this.enabled, enabled); boolean newState = getNewState(this.enabled, enabled);
if (newState == this.enabled) if (newState == this.enabled) {
return this.enabled; return this.enabled;
}
if (this.enabled = newState) { if (this.enabled = newState) {
onStart(); onStart();

View File

@ -19,9 +19,9 @@ package baritone.behavior.impl;
import baritone.Baritone; import baritone.Baritone;
import baritone.Settings; import baritone.Settings;
import baritone.behavior.Behavior;
import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.RelativeMoveEvent; import baritone.api.event.events.RelativeMoveEvent;
import baritone.behavior.Behavior;
import baritone.utils.Rotation; import baritone.utils.Rotation;
public class LookBehavior extends Behavior { public class LookBehavior extends Behavior {
@ -57,8 +57,9 @@ public class LookBehavior extends Behavior {
@Override @Override
public void onPlayerUpdate(PlayerUpdateEvent event) { public void onPlayerUpdate(PlayerUpdateEvent event) {
if (this.target == null) if (this.target == null) {
return; return;
}
// Whether or not we're going to silently set our angles // Whether or not we're going to silently set our angles
boolean silent = Baritone.settings().antiCheatCompatibility.get(); boolean silent = Baritone.settings().antiCheatCompatibility.get();
@ -102,8 +103,9 @@ public class LookBehavior extends Behavior {
player().rotationYaw = this.lastYaw; player().rotationYaw = this.lastYaw;
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
if (!Baritone.settings().antiCheatCompatibility.get()) if (!Baritone.settings().antiCheatCompatibility.get()) {
this.target = null; this.target = null;
}
break; break;
} }
} }

View File

@ -67,9 +67,10 @@ public final class LookBehaviorUtils implements Helper {
return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f)); return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f));
} }
Optional<Rotation> possibleRotation = reachableCenter(pos); Optional<Rotation> possibleRotation = reachableCenter(pos);
System.out.println("center: " + possibleRotation); //System.out.println("center: " + possibleRotation);
if (possibleRotation.isPresent()) if (possibleRotation.isPresent()) {
return possibleRotation; return possibleRotation;
}
IBlockState state = BlockStateInterface.get(pos); IBlockState state = BlockStateInterface.get(pos);
AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos); AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos);
@ -78,9 +79,10 @@ public final class LookBehaviorUtils implements Helper {
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff)); possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
if (possibleRotation.isPresent()) if (possibleRotation.isPresent()) {
return possibleRotation; return possibleRotation;
} }
}
return Optional.empty(); return Optional.empty();
} }

View File

@ -1,9 +1,9 @@
package baritone.behavior.impl; package baritone.behavior.impl;
import baritone.behavior.Behavior;
import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PacketEvent;
import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import baritone.behavior.Behavior;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketCloseWindow; import net.minecraft.network.play.client.CPacketCloseWindow;
@ -38,9 +38,10 @@ public class MemoryBehavior extends Behavior {
@Override @Override
public void onPlayerUpdate(PlayerUpdateEvent event) { public void onPlayerUpdate(PlayerUpdateEvent event) {
if (event.getState() == EventState.PRE) if (event.getState() == EventState.PRE) {
updateInventory(); updateInventory();
} }
}
@Override @Override
public void onSendPacket(PacketEvent event) { public void onSendPacket(PacketEvent event) {

View File

@ -389,8 +389,9 @@ public class PathingBehavior extends Behavior {
}); });
long end = System.nanoTime(); long end = System.nanoTime();
//System.out.println((end - split) + " " + (split - start)); //System.out.println((end - split) + " " + (split - start));
// if (end - start > 0) // if (end - start > 0) {
// System.out.println("Frame took " + (split - start) + " " + (end - split)); // System.out.println("Frame took " + (split - start) + " " + (end - split));
//}
} }
} }

View File

@ -199,7 +199,8 @@ public final class CachedChunk implements IBlockTypeAccess {
* @throws IllegalArgumentException if the bitset size exceeds the maximum size * @throws IllegalArgumentException if the bitset size exceeds the maximum size
*/ */
private static void validateSize(BitSet data) { private static void validateSize(BitSet data) {
if (data.size() > SIZE) if (data.size() > SIZE) {
throw new IllegalArgumentException("BitSet of invalid length provided"); throw new IllegalArgumentException("BitSet of invalid length provided");
} }
} }
}

View File

@ -112,13 +112,15 @@ public final class CachedRegion implements IBlockTypeAccess {
} }
try { try {
Path path = Paths.get(directory); Path path = Paths.get(directory);
if (!Files.exists(path)) if (!Files.exists(path)) {
Files.createDirectories(path); Files.createDirectories(path);
}
System.out.println("Saving region " + x + "," + z + " to disk " + path); System.out.println("Saving region " + x + "," + z + " to disk " + path);
Path regionFile = getRegionFile(path, this.x, this.z); Path regionFile = getRegionFile(path, this.x, this.z);
if (!Files.exists(regionFile)) if (!Files.exists(regionFile)) {
Files.createFile(regionFile); Files.createFile(regionFile);
}
try ( try (
FileOutputStream fileOut = new FileOutputStream(regionFile.toFile()); FileOutputStream fileOut = new FileOutputStream(regionFile.toFile());
GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384); GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384);
@ -175,12 +177,14 @@ public final class CachedRegion implements IBlockTypeAccess {
public synchronized void load(String directory) { public synchronized void load(String directory) {
try { try {
Path path = Paths.get(directory); Path path = Paths.get(directory);
if (!Files.exists(path)) if (!Files.exists(path)) {
Files.createDirectories(path); Files.createDirectories(path);
}
Path regionFile = getRegionFile(path, this.x, this.z); Path regionFile = getRegionFile(path, this.x, this.z);
if (!Files.exists(regionFile)) if (!Files.exists(regionFile)) {
return; return;
}
System.out.println("Loading region " + x + "," + z + " from disk " + path); System.out.println("Loading region " + x + "," + z + " from disk " + path);
long start = System.nanoTime() / 1000000L; long start = System.nanoTime() / 1000000L;

View File

@ -128,11 +128,13 @@ public final class CachedWorld implements IBlockTypeAccess {
int regionX = xoff + playerRegionX; int regionX = xoff + playerRegionX;
int regionZ = zoff + playerRegionZ; int regionZ = zoff + playerRegionZ;
CachedRegion region = getOrCreateRegion(regionX, regionZ); CachedRegion region = getOrCreateRegion(regionX, regionZ);
if (region != null) if (region != null) {
for (BlockPos pos : region.getLocationsOf(block)) for (BlockPos pos : region.getLocationsOf(block)) {
res.add(pos); res.add(pos);
} }
} }
}
}
if (res.size() >= minimum) { if (res.size() >= minimum) {
return res; return res;
} }
@ -153,8 +155,9 @@ public final class CachedWorld implements IBlockTypeAccess {
} }
long start = System.nanoTime() / 1000000L; long start = System.nanoTime() / 1000000L;
this.cachedRegions.values().parallelStream().forEach(region -> { this.cachedRegions.values().parallelStream().forEach(region -> {
if (region != null) if (region != null) {
region.save(this.directory); region.save(this.directory);
}
}); });
long now = System.nanoTime() / 1000000L; long now = System.nanoTime() / 1000000L;
System.out.println("World save took " + (now - start) + "ms"); System.out.println("World save took " + (now - start) + "ms");
@ -163,8 +166,9 @@ public final class CachedWorld implements IBlockTypeAccess {
public final void reloadAllFromDisk() { public final void reloadAllFromDisk() {
long start = System.nanoTime() / 1000000L; long start = System.nanoTime() / 1000000L;
this.cachedRegions.values().forEach(region -> { this.cachedRegions.values().forEach(region -> {
if (region != null) if (region != null) {
region.load(this.directory); region.load(this.directory);
}
}); });
long now = System.nanoTime() / 1000000L; long now = System.nanoTime() / 1000000L;
System.out.println("World load took " + (now - start) + "ms"); System.out.println("World load took " + (now - start) + "ms");
@ -199,8 +203,9 @@ public final class CachedWorld implements IBlockTypeAccess {
public void forEachRegion(Consumer<CachedRegion> consumer) { public void forEachRegion(Consumer<CachedRegion> consumer) {
this.cachedRegions.forEach((id, r) -> { this.cachedRegions.forEach((id, r) -> {
if (r != null) if (r != null) {
consumer.accept(r); consumer.accept(r);
}
}); });
} }
@ -213,8 +218,9 @@ public final class CachedWorld implements IBlockTypeAccess {
* @return The region ID * @return The region ID
*/ */
private long getRegionID(int regionX, int regionZ) { private long getRegionID(int regionX, int regionZ) {
if (!isRegionInWorld(regionX, regionZ)) if (!isRegionInWorld(regionX, regionZ)) {
return 0; return 0;
}
return (long) regionX & 0xFFFFFFFFL | ((long) regionZ & 0xFFFFFFFFL) << 32; return (long) regionX & 0xFFFFFFFFL | ((long) regionZ & 0xFFFFFFFFL) << 32;
} }

View File

@ -61,8 +61,9 @@ public class Waypoints {
waypoints.put(tag, new HashSet<>()); waypoints.put(tag, new HashSet<>());
Path fileName = directory.resolve(tag.name().toLowerCase() + ".mp4"); Path fileName = directory.resolve(tag.name().toLowerCase() + ".mp4");
if (!Files.exists(fileName)) if (!Files.exists(fileName)) {
return; return;
}
try ( try (
FileInputStream fileIn = new FileInputStream(fileName.toFile()); FileInputStream fileIn = new FileInputStream(fileName.toFile());

View File

@ -18,9 +18,9 @@
package baritone.chunk; package baritone.chunk;
import baritone.Baritone; import baritone.Baritone;
import baritone.utils.Helper;
import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IAnvilChunkLoader;
import baritone.utils.accessor.IChunkProviderServer; import baritone.utils.accessor.IChunkProviderServer;
import baritone.utils.Helper;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.server.integrated.IntegratedServer; import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
@ -102,7 +102,8 @@ public enum WorldProvider implements Helper {
} }
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) { public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
if (this.currentWorld != null) if (this.currentWorld != null) {
currentWorldConsumer.accept(this.currentWorld); currentWorldConsumer.accept(this.currentWorld);
} }
} }
}

View File

@ -26,7 +26,7 @@ import baritone.utils.pathing.BetterBlockPos;
* *
* @author leijurv * @author leijurv
*/ */
public class PathNode { public final class PathNode {
/** /**
* The position of this node * The position of this node
@ -103,8 +103,9 @@ public class PathNode {
// GOTTA GO FAST // GOTTA GO FAST
// ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE // ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE
// SKRT SKRT // SKRT SKRT
//if (obj == null || !(obj instanceof PathNode)) //if (obj == null || !(obj instanceof PathNode)) {
// return false; // return false;
//}
//final PathNode other = (PathNode) obj; //final PathNode other = (PathNode) obj;
//return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal); //return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal);

View File

@ -70,8 +70,9 @@ public abstract class Movement implements Helper, MovementHelper {
public double getCost(CalculationContext context) { public double getCost(CalculationContext context) {
if (cost == null) { if (cost == null) {
if (context == null) if (context == null) {
context = new CalculationContext(); context = new CalculationContext();
}
cost = calculateCost(context); cost = calculateCost(context);
} }
return cost; return cost;
@ -132,13 +133,15 @@ public abstract class Movement implements Helper, MovementHelper {
}); });
latestState.getInputStates().replaceAll((input, forced) -> false); latestState.getInputStates().replaceAll((input, forced) -> false);
if (!this.didBreakLastTick) if (!this.didBreakLastTick) {
BlockBreakHelper.stopBreakingBlock(); BlockBreakHelper.stopBreakingBlock();
}
currentState = latestState; currentState = latestState;
if (isFinished()) if (isFinished()) {
onFinish(latestState); onFinish(latestState);
}
return currentState.getStatus(); return currentState.getStatus();
} }

View File

@ -73,10 +73,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.AIR) { if (block == Blocks.AIR) {
return true; return true;
} }
if (block instanceof BlockFire if (block instanceof BlockFire || block instanceof BlockTripWire || block instanceof BlockWeb || block instanceof BlockEndPortal) {
|| block instanceof BlockTripWire
|| block instanceof BlockWeb
|| block instanceof BlockEndPortal) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
return false; return false;
} }
if (block instanceof BlockDoor || block instanceof BlockFenceGate) { if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@ -162,30 +159,35 @@ public interface MovementHelper extends ActionCosts, Helper {
} }
static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) { static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) {
if (playerPos.equals(doorPos)) if (playerPos.equals(doorPos)) {
return false; return false;
}
IBlockState state = BlockStateInterface.get(doorPos); IBlockState state = BlockStateInterface.get(doorPos);
if (!(state.getBlock() instanceof BlockDoor)) if (!(state.getBlock() instanceof BlockDoor)) {
return true; return true;
}
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN); return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
} }
static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) { static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) {
if (playerPos.equals(gatePos)) if (playerPos.equals(gatePos)) {
return false; return false;
}
IBlockState state = BlockStateInterface.get(gatePos); IBlockState state = BlockStateInterface.get(gatePos);
if (!(state.getBlock() instanceof BlockFenceGate)) if (!(state.getBlock() instanceof BlockFenceGate)) {
return true; return true;
}
return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN); return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN);
} }
static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) { static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) {
if (playerPos.equals(blockPos)) if (playerPos.equals(blockPos)) {
return false; return false;
}
EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis(); EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis();
boolean open = blockState.getValue(propertyOpen); boolean open = blockState.getValue(propertyOpen);
@ -295,8 +297,9 @@ public interface MovementHelper extends ActionCosts, Helper {
} }
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
double strVsBlock = context.getToolSet().getStrVsBlock(state); double strVsBlock = context.getToolSet().getStrVsBlock(state);
if (strVsBlock < 0) if (strVsBlock < 0) {
return COST_INF; return COST_INF;
}
double result = m / strVsBlock; double result = m / strVsBlock;
if (includeFalling) { if (includeFalling) {

View File

@ -123,8 +123,9 @@ public class MovementAscend extends Movement {
super.updateState(state); super.updateState(state);
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump // TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly) // for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
if (state.getStatus() != MovementStatus.RUNNING) if (state.getStatus() != MovementStatus.RUNNING) {
return state; return state;
}
if (playerFeet().equals(dest)) { if (playerFeet().equals(dest)) {
return state.setStatus(MovementStatus.SUCCESS); return state.setStatus(MovementStatus.SUCCESS);

View File

@ -67,8 +67,9 @@ public class MovementDescend extends Movement {
@Override @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
if (state.getStatus() != MovementStatus.RUNNING) if (state.getStatus() != MovementStatus.RUNNING) {
return state; return state;
}
BlockPos playerFeet = playerFeet(); BlockPos playerFeet = playerFeet();
if (playerFeet.equals(dest)) { if (playerFeet.equals(dest)) {

View File

@ -119,8 +119,9 @@ public class MovementDiagonal extends Movement {
@Override @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
if (state.getStatus() != MovementState.MovementStatus.RUNNING) if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
return state; return state;
}
if (playerFeet().equals(dest)) { if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS); state.setStatus(MovementState.MovementStatus.SUCCESS);

View File

@ -60,8 +60,9 @@ public class MovementDownward extends Movement {
@Override @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
if (state.getStatus() != MovementState.MovementStatus.RUNNING) if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
return state; return state;
}
if (playerFeet().equals(dest)) { if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS); state.setStatus(MovementState.MovementStatus.SUCCESS);

View File

@ -96,8 +96,9 @@ public class MovementFall extends Movement {
@Override @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
if (state.getStatus() != MovementStatus.RUNNING) if (state.getStatus() != MovementStatus.RUNNING) {
return state; return state;
}
BlockPos playerFeet = playerFeet(); BlockPos playerFeet = playerFeet();
Rotation targetRotation = null; Rotation targetRotation = null;
@ -123,8 +124,7 @@ public class MovementFall extends Movement {
} else { } else {
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false)); state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
} }
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 // lilypads if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 || BlockStateInterface.isWater(dest))) { // 0.094 because lilypads
|| BlockStateInterface.isWater(dest))) {
if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) { if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY); player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
if (player().motionY >= 0) { if (player().motionY >= 0) {

View File

@ -121,8 +121,9 @@ public class MovementPillar extends Movement {
@Override @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
if (state.getStatus() != MovementState.MovementStatus.RUNNING) if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
return state; return state;
}
IBlockState fromDown = BlockStateInterface.get(src); IBlockState fromDown = BlockStateInterface.get(src);
boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine;

View File

@ -125,9 +125,9 @@ public class MovementTraverse extends Movement {
@Override @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
if (state.getStatus() != MovementState.MovementStatus.RUNNING) if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
return state; return state;
}
state.setInput(InputOverrideHandler.Input.SNEAK, false); state.setInput(InputOverrideHandler.Input.SNEAK, false);
Block fd = BlockStateInterface.get(src.down()).getBlock(); Block fd = BlockStateInterface.get(src.down()).getBlock();

View File

@ -35,8 +35,9 @@ public class BlockStateInterface implements Helper {
public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability
// Invalid vertical position // Invalid vertical position
if (pos.getY() < 0 || pos.getY() >= 256) if (pos.getY() < 0 || pos.getY() >= 256) {
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
}
if (!Baritone.settings().pathThroughCachedOnly.get()) { if (!Baritone.settings().pathThroughCachedOnly.get()) {
Chunk cached = prev; Chunk cached = prev;

View File

@ -216,11 +216,13 @@ public final class PathRenderer implements Helper {
y2 = 0; y2 = 0;
minY = 0 - renderPosY; minY = 0 - renderPosY;
maxY = 256 - renderPosY; maxY = 256 - renderPosY;
} else { } else if (goal instanceof GoalComposite) {
for (Goal g : ((GoalComposite) goal).goals()) { for (Goal g : ((GoalComposite) goal).goals()) {
drawLitDankGoalBox(player, g, partialTicks, color); drawLitDankGoalBox(player, g, partialTicks, color);
} }
return; return;
} else {
return;
} }
GlStateManager.enableBlend(); GlStateManager.enableBlend();

View File

@ -87,8 +87,9 @@ public class ToolSet implements Helper {
ItemStack contents = player().inventory.getStackInSlot(slot); ItemStack contents = player().inventory.getStackInSlot(slot);
float blockHard = state.getBlockHardness(null, null); float blockHard = state.getBlockHardness(null, null);
if (blockHard < 0) if (blockHard < 0) {
return -1; return -1;
}
float speed = contents.getDestroySpeed(state); float speed = contents.getDestroySpeed(state);
if (speed > 1) { if (speed > 1) {

View File

@ -60,12 +60,12 @@ public final class BetterBlockPos extends BlockPos {
} }
@Override @Override
public final int hashCode() { public int hashCode() {
return (int) hashCode; return (int) hashCode;
} }
@Override @Override
public final boolean equals(Object o) { public boolean equals(Object o) {
if (o == null) { if (o == null) {
return false; return false;
} }