Search in sources :

Example 1 with Baritone

use of baritone.Baritone in project baritone by cabaletta.

the class WorldProvider method initWorld.

/**
 * Called when a new world is initialized to discover the
 *
 * @param dimension The ID of the world's dimension
 */
public final void initWorld(int dimension) {
    File directory;
    File readme;
    IntegratedServer integratedServer = mc.getIntegratedServer();
    // If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
    if (mc.isSingleplayer()) {
        WorldServer localServerWorld = integratedServer.getWorld(dimension);
        IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
        IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
        directory = loader.getChunkSaveLocation();
        // Gets the "depth" of this directory relative the the game's run directory, 2 is the location of the world
        if (directory.toPath().relativize(mc.gameDir.toPath()).getNameCount() != 2) {
            // subdirectory of the main save directory for this world
            directory = directory.getParentFile();
        }
        directory = new File(directory, "baritone");
        readme = directory;
    } else {
        // Otherwise, the server must be remote...
        String folderName;
        if (mc.getCurrentServerData() != null) {
            folderName = mc.getCurrentServerData().serverIP;
        } else {
            // replaymod causes null currentServerData and false singleplayer.
            currentWorld = null;
            return;
        }
        if (SystemUtils.IS_OS_WINDOWS) {
            folderName = folderName.replace(":", "_");
        }
        directory = new File(Baritone.getDir(), folderName);
        readme = Baritone.getDir();
    }
    // lol wtf is this baritone folder in my minecraft save?
    try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) {
        // good thing we have a readme
        out.write("https://github.com/cabaletta/baritone\n".getBytes());
    } catch (IOException ignored) {
    }
    // We will actually store the world data in a subfolder: "DIM<id>"
    Path dir = new File(directory, "DIM" + dimension).toPath();
    if (!Files.exists(dir)) {
        try {
            Files.createDirectories(dir);
        } catch (IOException ignored) {
        }
    }
    System.out.println("Baritone world data dir: " + dir);
    synchronized (worldCache) {
        this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension));
    }
}
Also used : Path(java.nio.file.Path) IAnvilChunkLoader(baritone.utils.accessor.IAnvilChunkLoader) Helper(baritone.api.utils.Helper) Files(java.nio.file.Files) SystemUtils(org.apache.commons.lang3.SystemUtils) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) Consumer(java.util.function.Consumer) IWorldProvider(baritone.api.cache.IWorldProvider) Baritone(baritone.Baritone) Map(java.util.Map) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) WorldServer(net.minecraft.world.WorldServer) Path(java.nio.file.Path) IChunkProviderServer(baritone.utils.accessor.IChunkProviderServer) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) IAnvilChunkLoader(baritone.utils.accessor.IAnvilChunkLoader) IChunkProviderServer(baritone.utils.accessor.IChunkProviderServer) FileOutputStream(java.io.FileOutputStream) WorldServer(net.minecraft.world.WorldServer) IOException(java.io.IOException) File(java.io.File)

Example 2 with Baritone

use of baritone.Baritone in project baritone by cabaletta.

the class MixinRenderChunk method isEmpty.

@Redirect(method = "rebuildChunk", at = @At(value = "INVOKE", target = "net/minecraft/world/ChunkCache.isEmpty()Z"))
private boolean isEmpty(ChunkCache chunkCache) {
    if (!chunkCache.isEmpty()) {
        return false;
    }
    if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
        Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
        IPlayerContext ctx = baritone.getPlayerContext();
        if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
            BlockPos position = ((RenderChunk) (Object) this).getPosition();
            // so if ANY of the adjacent chunks are loaded, we are unempty
            for (int dx = -1; dx <= 1; dx++) {
                for (int dz = -1; dz <= 1; dz++) {
                    if (baritone.bsi.isLoaded(16 * dx + position.getX(), 16 * dz + position.getZ())) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : RenderChunk(net.minecraft.client.renderer.chunk.RenderChunk) IPlayerContext(baritone.api.utils.IPlayerContext) Baritone(baritone.Baritone) BlockPos(net.minecraft.util.math.BlockPos) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with Baritone

use of baritone.Baritone in project baritone by cabaletta.

the class MixinChunkRenderWorker method isChunkExisting.

@Redirect(method = "processTask", at = @At(value = "INVOKE", target = "net/minecraft/client/renderer/chunk/ChunkRenderWorker.isChunkExisting(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/World;)Z"))
private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) {
    if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
        Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
        IPlayerContext ctx = baritone.getPlayerContext();
        if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
            return baritone.bsi.isLoaded(pos.getX(), pos.getZ()) || this.isChunkExisting(pos, world);
        }
    }
    return this.isChunkExisting(pos, world);
}
Also used : IPlayerContext(baritone.api.utils.IPlayerContext) Baritone(baritone.Baritone) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with Baritone

use of baritone.Baritone in project baritone by cabaletta.

the class MovementPillar method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    if (ctx.playerFeet().y < src.y) {
        return state.setStatus(MovementStatus.UNREACHABLE);
    }
    IBlockState fromDown = BlockStateInterface.get(ctx, src);
    if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(ctx, dest)) {
        // stay centered while swimming up a water column
        state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()), false));
        Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
        if (Math.abs(ctx.player().posX - destCenter.x) > 0.2 || Math.abs(ctx.player().posZ - destCenter.z) > 0.2) {
            state.setInput(Input.MOVE_FORWARD, true);
        }
        if (ctx.playerFeet().equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        return state;
    }
    boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE;
    boolean vine = fromDown.getBlock() == Blocks.VINE;
    Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch));
    if (!ladder) {
        state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true));
    }
    boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
    if (ladder) {
        BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
        if (against == null) {
            logDirect("Unable to climb vines. Consider disabling allowVines.");
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        if (ctx.playerFeet().equals(against.up()) || ctx.playerFeet().equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        if (MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) {
            state.setInput(Input.JUMP, true);
        }
        /*
            if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) {
                Baritone.moveTowardsBlock(from);
            }
             */
        MovementHelper.moveTowards(ctx, state, against);
        return state;
    } else {
        // Get ready to place a throwaway block
        if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, src.x, src.y, src.z)) {
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        // delay placement by 1 tick for ncp compatibility
        state.setInput(Input.SNEAK, ctx.player().posY > dest.getY() || ctx.player().posY < src.getY() + 0.2D);
        // since (lower down) we only right click once player.isSneaking, and that happens the tick after we request to sneak
        double diffX = ctx.player().posX - (dest.getX() + 0.5);
        double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
        double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
        double flatMotion = Math.sqrt(ctx.player().motionX * ctx.player().motionX + ctx.player().motionZ * ctx.player().motionZ);
        if (dist > 0.17) {
            // why 0.17? because it seemed like a good number, that's why
            // [explanation added after baritone port lol] also because it needs to be less than 0.2 because of the 0.3 sneak limit
            // and 0.17 is reasonably less than 0.2
            // If it's been more than forty ticks of trying to jump and we aren't done yet, go forward, maybe we are stuck
            state.setInput(Input.MOVE_FORWARD, true);
            // revise our target to both yaw and pitch if we're going to be moving forward
            state.setTarget(new MovementState.MovementTarget(rotation, true));
        } else if (flatMotion < 0.05) {
            // If our Y coordinate is above our goal, stop jumping
            state.setInput(Input.JUMP, ctx.player().posY < dest.getY());
        }
        if (!blockIsThere) {
            IBlockState frState = BlockStateInterface.get(ctx, src);
            Block fr = frState.getBlock();
            // TODO: Evaluate usage of getMaterial().isReplaceable()
            if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) {
                RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance()).map(rot -> new MovementState.MovementTarget(rot, true)).ifPresent(state::setTarget);
                // breaking is like 5x slower when you're jumping
                state.setInput(Input.JUMP, false);
                state.setInput(Input.CLICK_LEFT, true);
                blockIsThere = false;
            } else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos())) && ctx.player().posY > dest.getY() + 0.1) {
                state.setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    // If we are at our goal and the block below us is placed
    if (ctx.playerFeet().equals(dest) && blockIsThere) {
        return state.setStatus(MovementStatus.SUCCESS);
    }
    return state;
}
Also used : Rotation(baritone.api.utils.Rotation) ImmutableSet(com.google.common.collect.ImmutableSet) Blocks(net.minecraft.init.Blocks) VecUtils(baritone.api.utils.VecUtils) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) MovementHelper(baritone.pathing.movement.MovementHelper) BetterBlockPos(baritone.api.utils.BetterBlockPos) Objects(java.util.Objects) IBlockState(net.minecraft.block.state.IBlockState) IBaritone(baritone.api.IBaritone) MovementStatus(baritone.api.pathing.movement.MovementStatus) Movement(baritone.pathing.movement.Movement) Vec3d(net.minecraft.util.math.Vec3d) net.minecraft.block(net.minecraft.block) Baritone(baritone.Baritone) BlockStateInterface(baritone.utils.BlockStateInterface) RotationUtils(baritone.api.utils.RotationUtils) MovementState(baritone.pathing.movement.MovementState) Input(baritone.api.utils.input.Input) IBlockState(net.minecraft.block.state.IBlockState) CalculationContext(baritone.pathing.movement.CalculationContext) Rotation(baritone.api.utils.Rotation) Vec3d(net.minecraft.util.math.Vec3d) MovementState(baritone.pathing.movement.MovementState) IBaritone(baritone.api.IBaritone) Baritone(baritone.Baritone) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 5 with Baritone

use of baritone.Baritone in project baritone by cabaletta.

the class MineProcess method addNearby.

private void addNearby() {
    List<BlockPos> dropped = droppedItemsScan();
    knownOreLocations.addAll(dropped);
    BlockPos playerFeet = ctx.playerFeet();
    BlockStateInterface bsi = new BlockStateInterface(ctx);
    int searchDist = 10;
    // at least 10 * sqrt(3) with some extra space to account for positioning within the block
    double fakedBlockReachDistance = 20;
    for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) {
        for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) {
            for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) {
                // is an x-ray and it'll get caught
                if (filter.has(bsi.get0(x, y, z))) {
                    BlockPos pos = new BlockPos(x, y, z);
                    if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
                        knownOreLocations.add(pos);
                    }
                }
            }
        }
    }
    knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped);
}
Also used : IMineProcess(baritone.api.process.IMineProcess) java.util(java.util) Blocks(net.minecraft.init.Blocks) COST_INF(baritone.api.pathing.movement.ActionCosts.COST_INF) BaritoneProcessHelper(baritone.utils.BaritoneProcessHelper) MovementHelper(baritone.pathing.movement.MovementHelper) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) baritone.api.utils(baritone.api.utils) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) WorldScanner(baritone.cache.WorldScanner) BlockFalling(net.minecraft.block.BlockFalling) BlockAir(net.minecraft.block.BlockAir) PathingCommandType(baritone.api.process.PathingCommandType) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) Collectors(java.util.stream.Collectors) PathingCommand(baritone.api.process.PathingCommand) IBlockState(net.minecraft.block.state.IBlockState) baritone.api.pathing.goals(baritone.api.pathing.goals) Baritone(baritone.Baritone) CachedChunk(baritone.cache.CachedChunk) BlockStateInterface(baritone.utils.BlockStateInterface) Input(baritone.api.utils.input.Input) BlockStateInterface(baritone.utils.BlockStateInterface) CalculationContext(baritone.pathing.movement.CalculationContext) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Baritone (baritone.Baritone)16 BlockPos (net.minecraft.util.math.BlockPos)10 IPlayerContext (baritone.api.utils.IPlayerContext)6 Input (baritone.api.utils.input.Input)6 CalculationContext (baritone.pathing.movement.CalculationContext)6 MovementHelper (baritone.pathing.movement.MovementHelper)6 BlockStateInterface (baritone.utils.BlockStateInterface)6 IBlockState (net.minecraft.block.state.IBlockState)6 Blocks (net.minecraft.init.Blocks)6 Redirect (org.spongepowered.asm.mixin.injection.Redirect)6 IBaritone (baritone.api.IBaritone)4 baritone.api.pathing.goals (baritone.api.pathing.goals)4 COST_INF (baritone.api.pathing.movement.ActionCosts.COST_INF)4 IMineProcess (baritone.api.process.IMineProcess)4 PathingCommand (baritone.api.process.PathingCommand)4 PathingCommandType (baritone.api.process.PathingCommandType)4 baritone.api.utils (baritone.api.utils)4 CachedChunk (baritone.cache.CachedChunk)4 WorldScanner (baritone.cache.WorldScanner)4 Vec3d (net.minecraft.util.math.Vec3d)4