This commit is contained in:
Leijurv 2018-09-07 21:32:25 -07:00
parent 9052781889
commit 132e277388
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
27 changed files with 114 additions and 68 deletions

View File

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

View File

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

View File

@ -37,7 +37,8 @@ public class MixinKeyBinding {
cancellable = true
)
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);
}
}
}

View File

@ -39,13 +39,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(NetworkManager.class)
public class MixinNetworkManager {
@Shadow private Channel channel;
@Shadow
private Channel channel;
@Inject(
method = "dispatchPacket",
at = @At("HEAD")
)
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void >>[] futureListeners, CallbackInfo ci) {
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>>[] futureListeners, CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.PRE, inPacket));
}
@ -53,7 +54,7 @@ public class MixinNetworkManager {
method = "dispatchPacket",
at = @At("RETURN")
)
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void >>[] futureListeners, CallbackInfo ci) {
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>>[] futureListeners, CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.POST, inPacket));
}
@ -73,7 +74,8 @@ public class MixinNetworkManager {
at = @At("RETURN")
)
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));
}
}
}

View File

@ -80,8 +80,9 @@ public final class GameEventHandler implements IGameEventListener, Helper {
if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
int keyCode = keyBinding.getKeyCode();
if (keyCode < Keyboard.KEYBOARD_SIZE)
if (keyCode < Keyboard.KEYBOARD_SIZE) {
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
}
}
}
@ -141,8 +142,9 @@ public final class GameEventHandler implements IGameEventListener, Helper {
break;
case POST:
cache.closeWorld();
if (event.getWorld() != null)
if (event.getWorld() != null) {
cache.initWorld(event.getWorld());
}
break;
}

View File

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

View File

@ -19,9 +19,9 @@ package baritone.behavior.impl;
import baritone.Baritone;
import baritone.Settings;
import baritone.behavior.Behavior;
import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.RelativeMoveEvent;
import baritone.behavior.Behavior;
import baritone.utils.Rotation;
public class LookBehavior extends Behavior {
@ -57,8 +57,9 @@ public class LookBehavior extends Behavior {
@Override
public void onPlayerUpdate(PlayerUpdateEvent event) {
if (this.target == null)
if (this.target == null) {
return;
}
// Whether or not we're going to silently set our angles
boolean silent = Baritone.settings().antiCheatCompatibility.get();
@ -102,8 +103,9 @@ public class LookBehavior extends Behavior {
player().rotationYaw = this.lastYaw;
// 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;
}
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));
}
Optional<Rotation> possibleRotation = reachableCenter(pos);
System.out.println("center: " + possibleRotation);
if (possibleRotation.isPresent())
//System.out.println("center: " + possibleRotation);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
IBlockState state = BlockStateInterface.get(pos);
AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos);
@ -78,8 +79,9 @@ public final class LookBehaviorUtils implements Helper {
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
if (possibleRotation.isPresent())
if (possibleRotation.isPresent()) {
return possibleRotation;
}
}
return Optional.empty();
}

View File

@ -1,9 +1,9 @@
package baritone.behavior.impl;
import baritone.behavior.Behavior;
import baritone.api.event.events.PacketEvent;
import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.type.EventState;
import baritone.behavior.Behavior;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketCloseWindow;
@ -38,8 +38,9 @@ public class MemoryBehavior extends Behavior {
@Override
public void onPlayerUpdate(PlayerUpdateEvent event) {
if (event.getState() == EventState.PRE)
if (event.getState() == EventState.PRE) {
updateInventory();
}
}
@Override
@ -86,13 +87,13 @@ public class MemoryBehavior extends Behavior {
this.futureInventories.stream()
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
.findFirst().ifPresent(matched -> {
// Remove the future inventory
this.futureInventories.remove(matched);
// Remove the future inventory
this.futureInventories.remove(matched);
// Setup the remembered inventory
RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory());
inventory.windowId = packet.getWindowId();
inventory.size = packet.getSlotCount();
// Setup the remembered inventory
RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory());
inventory.windowId = packet.getWindowId();
inventory.size = packet.getSlotCount();
});
}

View File

@ -389,8 +389,9 @@ public class PathingBehavior extends Behavior {
});
long end = System.nanoTime();
//System.out.println((end - split) + " " + (split - start));
// if (end - start > 0)
// if (end - start > 0) {
// 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
*/
private static void validateSize(BitSet data) {
if (data.size() > SIZE)
if (data.size() > SIZE) {
throw new IllegalArgumentException("BitSet of invalid length provided");
}
}
}

View File

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

View File

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

View File

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

View File

@ -18,9 +18,9 @@
package baritone.chunk;
import baritone.Baritone;
import baritone.utils.Helper;
import baritone.utils.accessor.IAnvilChunkLoader;
import baritone.utils.accessor.IChunkProviderServer;
import baritone.utils.Helper;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.WorldServer;
@ -69,7 +69,7 @@ public enum WorldProvider implements Helper {
directory = new File(directory, "baritone");
readme = directory;
} else {
//remote
directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP);
@ -102,7 +102,8 @@ public enum WorldProvider implements Helper {
}
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
if (this.currentWorld != null)
if (this.currentWorld != null) {
currentWorldConsumer.accept(this.currentWorld);
}
}
}

View File

@ -103,8 +103,9 @@ public class PathNode {
// GOTTA GO FAST
// ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE
// SKRT SKRT
//if (obj == null || !(obj instanceof PathNode))
//if (obj == null || !(obj instanceof PathNode)) {
// return false;
//}
//final PathNode other = (PathNode) obj;
//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) {
if (cost == null) {
if (context == null)
if (context == null) {
context = new CalculationContext();
}
cost = calculateCost(context);
}
return cost;
@ -128,13 +129,15 @@ public abstract class Movement implements Helper, MovementHelper {
});
latestState.getInputStates().replaceAll((input, forced) -> false);
if (!this.didBreakLastTick)
if (!this.didBreakLastTick) {
BlockBreakHelper.stopBreakingBlock();
}
currentState = latestState;
if (isFinished())
if (isFinished()) {
onFinish(latestState);
}
return currentState.getStatus();
}

View File

@ -70,10 +70,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
Block block = state.getBlock();
if (block instanceof BlockFire
|| 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
if (block instanceof BlockFire || block instanceof BlockTripWire || block instanceof BlockWeb || block instanceof BlockEndPortal) {
return false;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@ -127,30 +124,35 @@ public interface MovementHelper extends ActionCosts, Helper {
}
static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) {
if (playerPos.equals(doorPos))
if (playerPos.equals(doorPos)) {
return false;
}
IBlockState state = BlockStateInterface.get(doorPos);
if (!(state.getBlock() instanceof BlockDoor))
if (!(state.getBlock() instanceof BlockDoor)) {
return true;
}
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
}
static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) {
if (playerPos.equals(gatePos))
if (playerPos.equals(gatePos)) {
return false;
}
IBlockState state = BlockStateInterface.get(gatePos);
if (!(state.getBlock() instanceof BlockFenceGate))
if (!(state.getBlock() instanceof BlockFenceGate)) {
return true;
}
return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN);
}
static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) {
if (playerPos.equals(blockPos))
if (playerPos.equals(blockPos)) {
return false;
}
EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis();
boolean open = blockState.getValue(propertyOpen);
@ -260,8 +262,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 strVsBlock = context.getToolSet().getStrVsBlock(state);
if (strVsBlock < 0)
if (strVsBlock < 0) {
return COST_INF;
}
double result = m / strVsBlock;
if (includeFalling) {

View File

@ -123,8 +123,9 @@ public class MovementAscend extends Movement {
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
// 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;
}
if (playerFeet().equals(dest)) {
return state.setStatus(MovementStatus.SUCCESS);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -125,9 +125,9 @@ public class MovementTraverse extends Movement {
@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
if (state.getStatus() != MovementState.MovementStatus.RUNNING)
if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
return state;
}
state.setInput(InputOverrideHandler.Input.SNEAK, false);
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
// Invalid vertical position
if (pos.getY() < 0 || pos.getY() >= 256)
if (pos.getY() < 0 || pos.getY() >= 256) {
return Blocks.AIR.getDefaultState();
}
if (!Baritone.settings().pathThroughCachedOnly.get()) {
Chunk cached = prev;

View File

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