Search in sources :

Example 1 with IPlayerContext

use of baritone.api.utils.IPlayerContext in project baritone by cabaletta.

the class Avoidance method create.

public static List<Avoidance> create(IPlayerContext ctx) {
    if (!Baritone.settings().avoidance.value) {
        return Collections.emptyList();
    }
    List<Avoidance> res = new ArrayList<>();
    double mobSpawnerCoeff = Baritone.settings().mobSpawnerAvoidanceCoefficient.value;
    double mobCoeff = Baritone.settings().mobAvoidanceCoefficient.value;
    if (mobSpawnerCoeff != 1.0D) {
        ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.value)));
    }
    if (mobCoeff != 1.0D) {
        ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).filter(entity -> (!(entity instanceof EntitySpider)) || ctx.player().getBrightness() < 0.5).filter(entity -> !(entity instanceof EntityPigZombie) || ((EntityPigZombie) entity).isAngry()).filter(entity -> !(entity instanceof EntityEnderman) || ((EntityEnderman) entity).isScreaming()).forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
    }
    return res;
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) BetterBlockPos(baritone.api.utils.BetterBlockPos) List(java.util.List) EntityPigZombie(net.minecraft.entity.monster.EntityPigZombie) EntityMob(net.minecraft.entity.monster.EntityMob) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Baritone(baritone.Baritone) IPlayerContext(baritone.api.utils.IPlayerContext) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) BlockPos(net.minecraft.util.math.BlockPos) Collections(java.util.Collections) EntitySpider(net.minecraft.entity.monster.EntitySpider) ArrayList(java.util.ArrayList) EntityPigZombie(net.minecraft.entity.monster.EntityPigZombie) ArrayList(java.util.ArrayList) BetterBlockPos(baritone.api.utils.BetterBlockPos) BlockPos(net.minecraft.util.math.BlockPos) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) EntitySpider(net.minecraft.entity.monster.EntitySpider)

Example 2 with IPlayerContext

use of baritone.api.utils.IPlayerContext 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 IPlayerContext

use of baritone.api.utils.IPlayerContext 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 IPlayerContext

use of baritone.api.utils.IPlayerContext in project Spark-Client by Spark-Client-Development.

the class MixinRenderChunk method getBlockState.

@Redirect(method = "rebuildChunk", at = @At(value = "INVOKE", target = "net/minecraft/world/ChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"))
private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) {
    if (Baritone.settings().renderCachedChunks.getValue() && !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.get0(pos);
        }
    }
    return chunkCache.getBlockState(pos);
}
Also used : IPlayerContext(baritone.api.utils.IPlayerContext) Baritone(baritone.Baritone) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with IPlayerContext

use of baritone.api.utils.IPlayerContext in project baritone by cabaletta.

the class MixinRenderChunk method getBlockState.

@Redirect(method = "rebuildChunk", at = @At(value = "INVOKE", target = "net/minecraft/world/ChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"))
private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) {
    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.get0(pos);
        }
    }
    return chunkCache.getBlockState(pos);
}
Also used : IPlayerContext(baritone.api.utils.IPlayerContext) Baritone(baritone.Baritone) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Baritone (baritone.Baritone)8 IPlayerContext (baritone.api.utils.IPlayerContext)8 Redirect (org.spongepowered.asm.mixin.injection.Redirect)6 BlockPos (net.minecraft.util.math.BlockPos)4 BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Long2DoubleOpenHashMap (it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 RenderChunk (net.minecraft.client.renderer.chunk.RenderChunk)2 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)2 EntityMob (net.minecraft.entity.monster.EntityMob)2 EntityPigZombie (net.minecraft.entity.monster.EntityPigZombie)2 EntitySpider (net.minecraft.entity.monster.EntitySpider)2