Search in sources :

Example 1 with LadderBlock

use of net.minecraft.block.LadderBlock in project minecolonies by Minecolonies.

the class MinecoloniesAdvancedPathNavigate method handlePathPointOnLadder.

private boolean handlePathPointOnLadder(final PathPointExtended pEx) {
    Vector3d vec3 = this.getPath().getNextEntityPos(this.ourEntity);
    final BlockPos entityPos = new BlockPos(this.ourEntity.position());
    if (vec3.distanceToSqr(ourEntity.getX(), vec3.y, ourEntity.getZ()) < 0.6 && Math.abs(vec3.y - entityPos.getY()) <= 2.0) {
        // This way he is less nervous and gets up the ladder
        double newSpeed = 0.3;
        switch(pEx.getLadderFacing()) {
            // Any of these values is climbing, so adjust our direction of travel towards the ladder
            case NORTH:
                vec3 = vec3.add(0, 0, 0.4);
                break;
            case SOUTH:
                vec3 = vec3.add(0, 0, -0.4);
                break;
            case WEST:
                vec3 = vec3.add(0.4, 0, 0);
                break;
            case EAST:
                vec3 = vec3.add(-0.4, 0, 0);
                break;
            case UP:
                vec3 = vec3.add(0, 1, 0);
                break;
            // Any other value is going down, so lets not move at all
            default:
                newSpeed = 0;
                mob.setShiftKeyDown(true);
                isSneaking = true;
                this.ourEntity.getMoveControl().setWantedPosition(vec3.x, vec3.y, vec3.z, 0.2);
                break;
        }
        if (newSpeed > 0) {
            if (!(level.getBlockState(ourEntity.blockPosition()).getBlock() instanceof LadderBlock)) {
                this.ourEntity.setDeltaMovement(this.ourEntity.getDeltaMovement().add(0, 0.1D, 0));
            }
            this.ourEntity.getMoveControl().setWantedPosition(vec3.x, vec3.y, vec3.z, newSpeed);
        } else {
            if (level.getBlockState(entityPos.below()).isLadder(level, entityPos.below(), ourEntity)) {
                this.ourEntity.setYya(-0.5f);
            } else {
                return false;
            }
            return true;
        }
    }
    return false;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) LadderBlock(net.minecraft.block.LadderBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with LadderBlock

use of net.minecraft.block.LadderBlock in project BleachHack by BleachDrinker420.

the class AutoParkour method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (smartPos != null) {
        if (mc.player.getY() - 0.5 < smartPos.getY() && mc.player.getVelocity().y < 0) {
            smartPos = null;
        }
    }
    if (!mc.player.isSneaking() && mc.player.isOnGround()) {
        smartPos = null;
        Box box = mc.player.getBoundingBox().offset(0, -0.51, 0);
        Stream<VoxelShape> blockCollisions = mc.world.getBlockCollisions(mc.player, box);
        if (blockCollisions.findAny().isEmpty()) {
            if (getSetting(0).asToggle().getState() && !mc.player.isSprinting()) {
                mc.player.setSprinting(true);
                mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.START_SPRINTING));
            }
            if (getSetting(1).asToggle().getState()) {
                Vec3d lookVec = mc.player.getPos().add(new Vec3d(0, 0, 3.5).rotateY(-(float) Math.toRadians(mc.player.getYaw())));
                BlockPos nearestPos = BlockPos.streamOutwards(mc.player.getBlockPos().down(), 4, 1, 4).map(BlockPos::toImmutable).filter(pos -> (mc.world.isTopSolid(pos, mc.player) && mc.world.getBlockCollisions(mc.player, new Box(pos.up(), pos.add(1, 3, 1))).findAny().isEmpty()) || mc.world.getBlockState(pos).getBlock() instanceof LadderBlock || mc.world.getBlockState(pos.up()).getBlock() instanceof LadderBlock).filter(pos -> mc.player.getPos().distanceTo(Vec3d.of(pos).add(0.5, 1, 0.5)) >= 1).filter(pos -> mc.player.getPos().distanceTo(Vec3d.of(pos).add(0.5, 1, 0.5)) <= 4.5).sorted(Comparator.comparing(pos -> pos.getSquaredDistance(lookVec, false))).findFirst().orElse(null);
                if (nearestPos != null) {
                    smartPos = nearestPos;
                }
            }
            mc.player.jump();
        }
    }
}
Also used : BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) ModuleCategory(org.bleachhack.module.ModuleCategory) EventClientMove(org.bleachhack.event.events.EventClientMove) Box(net.minecraft.util.math.Box) EventWorldRender(org.bleachhack.event.events.EventWorldRender) BlockPos(net.minecraft.util.math.BlockPos) Renderer(org.bleachhack.util.render.Renderer) VoxelShape(net.minecraft.util.shape.VoxelShape) Mode(net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket.Mode) Module(org.bleachhack.module.Module) QuadColor(org.bleachhack.util.render.color.QuadColor) LadderBlock(net.minecraft.block.LadderBlock) Stream(java.util.stream.Stream) Vec3d(net.minecraft.util.math.Vec3d) SettingColor(org.bleachhack.setting.module.SettingColor) SettingToggle(org.bleachhack.setting.module.SettingToggle) Comparator(java.util.Comparator) ClientCommandC2SPacket(net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket) EventTick(org.bleachhack.event.events.EventTick) VoxelShape(net.minecraft.util.shape.VoxelShape) ClientCommandC2SPacket(net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket) LadderBlock(net.minecraft.block.LadderBlock) Box(net.minecraft.util.math.Box) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 3 with LadderBlock

use of net.minecraft.block.LadderBlock in project minecolonies by ldtteam.

the class MinecoloniesAdvancedPathNavigate method handlePathPointOnLadder.

private boolean handlePathPointOnLadder(final PathPointExtended pEx) {
    Vector3d vec3 = this.getPath().getNextEntityPos(this.ourEntity);
    final BlockPos entityPos = new BlockPos(this.ourEntity.position());
    if (vec3.distanceToSqr(ourEntity.getX(), vec3.y, ourEntity.getZ()) < 0.6 && Math.abs(vec3.y - entityPos.getY()) <= 2.0) {
        // This way he is less nervous and gets up the ladder
        double newSpeed = 0.3;
        switch(pEx.getLadderFacing()) {
            // Any of these values is climbing, so adjust our direction of travel towards the ladder
            case NORTH:
                vec3 = vec3.add(0, 0, 0.4);
                break;
            case SOUTH:
                vec3 = vec3.add(0, 0, -0.4);
                break;
            case WEST:
                vec3 = vec3.add(0.4, 0, 0);
                break;
            case EAST:
                vec3 = vec3.add(-0.4, 0, 0);
                break;
            case UP:
                vec3 = vec3.add(0, 1, 0);
                break;
            // Any other value is going down, so lets not move at all
            default:
                newSpeed = 0;
                mob.setShiftKeyDown(true);
                isSneaking = true;
                this.ourEntity.getMoveControl().setWantedPosition(vec3.x, vec3.y, vec3.z, 0.2);
                break;
        }
        if (newSpeed > 0) {
            if (!(level.getBlockState(ourEntity.blockPosition()).getBlock() instanceof LadderBlock)) {
                this.ourEntity.setDeltaMovement(this.ourEntity.getDeltaMovement().add(0, 0.1D, 0));
            }
            this.ourEntity.getMoveControl().setWantedPosition(vec3.x, vec3.y, vec3.z, newSpeed);
        } else {
            if (level.getBlockState(entityPos.below()).isLadder(level, entityPos.below(), ourEntity)) {
                this.ourEntity.setYya(-0.5f);
            } else {
                return false;
            }
            return true;
        }
    }
    return false;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) LadderBlock(net.minecraft.block.LadderBlock) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

LadderBlock (net.minecraft.block.LadderBlock)3 BlockPos (net.minecraft.util.math.BlockPos)3 Vector3d (net.minecraft.util.math.vector.Vector3d)2 Comparator (java.util.Comparator)1 Stream (java.util.stream.Stream)1 ClientCommandC2SPacket (net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket)1 Mode (net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket.Mode)1 Box (net.minecraft.util.math.Box)1 Vec3d (net.minecraft.util.math.Vec3d)1 VoxelShape (net.minecraft.util.shape.VoxelShape)1 EventClientMove (org.bleachhack.event.events.EventClientMove)1 EventTick (org.bleachhack.event.events.EventTick)1 EventWorldRender (org.bleachhack.event.events.EventWorldRender)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1 Module (org.bleachhack.module.Module)1 ModuleCategory (org.bleachhack.module.ModuleCategory)1 SettingColor (org.bleachhack.setting.module.SettingColor)1 SettingToggle (org.bleachhack.setting.module.SettingToggle)1 Renderer (org.bleachhack.util.render.Renderer)1 QuadColor (org.bleachhack.util.render.color.QuadColor)1