Search in sources :

Example 1 with NodeProcessor

use of net.minecraft.pathfinding.NodeProcessor in project RuneCraftory by Flemmli97.

the class EntityMoveHelperNew method onUpdateMoveHelper.

/**
 * Made it so entities jump up blocks during strafing
 */
@Override
public void onUpdateMoveHelper() {
    if (this.action == EntityMoveHelper.Action.STRAFE) {
        float f = (float) this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue();
        float f1 = (float) this.speed * f;
        float f2 = this.moveForward;
        float f3 = this.moveStrafe;
        float f4 = MathHelper.sqrt(f2 * f2 + f3 * f3);
        if (f4 < 1.0F) {
            f4 = 1.0F;
        }
        f4 = f1 / f4;
        f2 = f2 * f4;
        f3 = f3 * f4;
        float f5 = MathHelper.sin(this.entity.rotationYaw * 0.017453292F);
        float f6 = MathHelper.cos(this.entity.rotationYaw * 0.017453292F);
        float f7 = (f2 * f6 - f3 * f5);
        float f8 = (f3 * f6 + f2 * f5);
        PathNavigate pathnavigate = this.entity.getNavigator();
        if (pathnavigate != null) {
            double len = Math.sqrt(f7 * f7 + f8 * f8);
            NodeProcessor nodeprocessor = pathnavigate.getNodeProcessor();
            int x = MathHelper.floor(this.entity.posX + (double) f7 / len);
            int y = MathHelper.floor(this.entity.posY);
            int z = MathHelper.floor(this.entity.posZ + (double) f8 / len);
            PathNodeType node = nodeprocessor != null ? nodeprocessor.getPathNodeType(this.entity.world, x, y, z) : PathNodeType.OPEN;
            // System.out.printf("%s %d %d %d \n", node, x, y, z);
            if (node == PathNodeType.BLOCKED) {
                int yAdd = 0;
                while (yAdd < this.entity.stepHeight) {
                    yAdd++;
                    node = nodeprocessor.getPathNodeType(this.entity.world, x, y + yAdd, z);
                    if (node == PathNodeType.WALKABLE) {
                        this.entity.getJumpHelper().setJumping();
                        break;
                    }
                }
            } else if (node != PathNodeType.WALKABLE) {
                this.moveForward = 1.0F;
                this.moveStrafe = 0.0F;
                f1 = f;
            }
        }
        this.entity.setAIMoveSpeed(f1);
        this.entity.setMoveForward(this.moveForward);
        this.entity.setMoveStrafing(this.moveStrafe);
        this.action = EntityMoveHelper.Action.WAIT;
    } else if (this.action == EntityMoveHelper.Action.MOVE_TO) {
        this.action = EntityMoveHelper.Action.WAIT;
        this.entity.setMoveStrafing(0);
        double d0 = this.posX - this.entity.posX;
        double d1 = this.posZ - this.entity.posZ;
        double d2 = this.posY - this.entity.posY;
        double d3 = d0 * d0 + d2 * d2 + d1 * d1;
        if (d3 < 2.500000277905201E-7D) {
            this.entity.setMoveForward(0.0F);
            return;
        }
        float f9 = (float) (MathHelper.atan2(d1, d0) * (180D / Math.PI)) - 90.0F;
        this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, f9, 90.0F);
        this.entity.setAIMoveSpeed((float) (this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()));
        if (d2 > (double) this.entity.stepHeight && d0 * d0 + d1 * d1 < (double) Math.max(1.0F, this.entity.width)) {
            this.entity.getJumpHelper().setJumping();
            this.action = EntityMoveHelper.Action.JUMPING;
        }
    } else if (this.action == EntityMoveHelper.Action.JUMPING) {
        this.entity.setAIMoveSpeed((float) (this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()));
        if (this.entity.onGround) {
            this.action = EntityMoveHelper.Action.WAIT;
        }
    } else {
        this.entity.setMoveForward(0.0F);
        this.entity.setMoveStrafing(0);
    }
}
Also used : NodeProcessor(net.minecraft.pathfinding.NodeProcessor) PathNodeType(net.minecraft.pathfinding.PathNodeType) PathNavigate(net.minecraft.pathfinding.PathNavigate)

Example 2 with NodeProcessor

use of net.minecraft.pathfinding.NodeProcessor in project minecolonies by ldtteam.

the class MovementHandler method tick.

@Override
public void tick() {
    if (this.operation == net.minecraft.entity.ai.controller.MovementController.Action.STRAFE) {
        final float speedAtt = (float) speedAtr.getValue();
        float speed = (float) this.speedModifier * speedAtt;
        float forward = this.strafeForwards;
        float strafe = this.strafeRight;
        float totalMovement = MathHelper.sqrt(forward * forward + strafe * strafe);
        if (totalMovement < 1.0F) {
            totalMovement = 1.0F;
        }
        totalMovement = speed / totalMovement;
        forward = forward * totalMovement;
        strafe = strafe * totalMovement;
        final float sinRotation = MathHelper.sin(this.mob.yRot * ((float) Math.PI / 180F));
        final float cosRotation = MathHelper.cos(this.mob.yRot * ((float) Math.PI / 180F));
        final float rot1 = forward * cosRotation - strafe * sinRotation;
        final float rot2 = strafe * cosRotation + forward * sinRotation;
        final PathNavigator pathnavigator = this.mob.getNavigation();
        final NodeProcessor nodeprocessor = pathnavigator.getNodeEvaluator();
        if (nodeprocessor.getBlockPathType(this.mob.level, MathHelper.floor(this.mob.getX() + (double) rot1), MathHelper.floor(this.mob.getY()), MathHelper.floor(this.mob.getZ() + (double) rot2)) != PathNodeType.WALKABLE) {
            this.strafeForwards = 1.0F;
            this.strafeRight = 0.0F;
            speed = speedAtt;
        }
        this.mob.setSpeed(speed);
        this.mob.setZza(this.strafeForwards);
        this.mob.setXxa(this.strafeRight);
        this.operation = net.minecraft.entity.ai.controller.MovementController.Action.WAIT;
    } else if (this.operation == net.minecraft.entity.ai.controller.MovementController.Action.MOVE_TO) {
        this.operation = net.minecraft.entity.ai.controller.MovementController.Action.WAIT;
        final double xDif = this.wantedX - this.mob.getX();
        final double zDif = this.wantedZ - this.mob.getZ();
        final double yDif = this.wantedY - this.mob.getY();
        final double dist = xDif * xDif + yDif * yDif + zDif * zDif;
        if (dist < (double) 2.5000003E-7F) {
            this.mob.setZza(0.0F);
            return;
        }
        final float range = (float) (MathHelper.atan2(zDif, xDif) * (double) (180F / (float) Math.PI)) - 90.0F;
        this.mob.yRot = this.rotlerp(this.mob.yRot, range, 90.0F);
        this.mob.setSpeed((float) (this.speedModifier * speedAtr.getValue()));
        final BlockPos blockpos = new BlockPos(this.mob.position());
        final BlockState blockstate = this.mob.level.getBlockState(blockpos);
        final Block block = blockstate.getBlock();
        final VoxelShape voxelshape = blockstate.getCollisionShape(this.mob.level, blockpos);
        if ((yDif > (double) this.mob.maxUpStep && xDif * xDif + zDif * zDif < (double) Math.max(1.0F, this.mob.getBbWidth())) || (!voxelshape.isEmpty() && this.mob.getY() < voxelshape.max(Direction.Axis.Y) + (double) blockpos.getY() && !block.is(BlockTags.DOORS) && !block.is(BlockTags.FENCES) && !block.is(BlockTags.FENCE_GATES)) && !block.isLadder(blockstate, this.mob.level, blockpos, this.mob)) {
            this.mob.getJumpControl().jump();
            this.operation = net.minecraft.entity.ai.controller.MovementController.Action.JUMPING;
        }
    } else if (this.operation == net.minecraft.entity.ai.controller.MovementController.Action.JUMPING) {
        this.mob.setSpeed((float) (this.speedModifier * speedAtr.getValue()));
        // Avoid beeing stuck in jumping while in liquids
        final BlockPos blockpos = new BlockPos(this.mob.position());
        final BlockState blockstate = this.mob.level.getBlockState(blockpos);
        if (this.mob.isOnGround() || blockstate.getMaterial().isLiquid()) {
            this.operation = net.minecraft.entity.ai.controller.MovementController.Action.WAIT;
        }
    } else {
        this.mob.setZza(0.0F);
    }
}
Also used : NodeProcessor(net.minecraft.pathfinding.NodeProcessor) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) PathNavigator(net.minecraft.pathfinding.PathNavigator)

Example 3 with NodeProcessor

use of net.minecraft.pathfinding.NodeProcessor in project CumServerPro by MCUmbrella.

the class EntityMoveHelper method onUpdateMoveHelper.

public void onUpdateMoveHelper() {
    if (this.action == Action.STRAFE) {
        float f = (float) this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue();
        float f1 = (float) this.speed * f;
        float f2 = this.moveForward;
        float f3 = this.moveStrafe;
        float f4 = MathHelper.sqrt(f2 * f2 + f3 * f3);
        if (f4 < 1.0F) {
            f4 = 1.0F;
        }
        f4 = f1 / f4;
        f2 = f2 * f4;
        f3 = f3 * f4;
        float f5 = MathHelper.sin(this.entity.rotationYaw * 0.017453292F);
        float f6 = MathHelper.cos(this.entity.rotationYaw * 0.017453292F);
        float f7 = f2 * f6 - f3 * f5;
        float f8 = f3 * f6 + f2 * f5;
        PathNavigate pathnavigate = this.entity.getNavigator();
        if (pathnavigate != null) {
            NodeProcessor nodeprocessor = pathnavigate.getNodeProcessor();
            if (nodeprocessor != null && nodeprocessor.getPathNodeType(this.entity.world, MathHelper.floor(this.entity.posX + (double) f7), MathHelper.floor(this.entity.posY), MathHelper.floor(this.entity.posZ + (double) f8)) != PathNodeType.WALKABLE) {
                this.moveForward = 1.0F;
                this.moveStrafe = 0.0F;
                f1 = f;
            }
        }
        this.entity.setAIMoveSpeed(f1);
        this.entity.setMoveForward(this.moveForward);
        this.entity.setMoveStrafing(this.moveStrafe);
        this.action = Action.WAIT;
    } else if (this.action == Action.MOVE_TO) {
        this.action = Action.WAIT;
        double d0 = this.posX - this.entity.posX;
        double d1 = this.posZ - this.entity.posZ;
        double d2 = this.posY - this.entity.posY;
        double d3 = d0 * d0 + d2 * d2 + d1 * d1;
        if (d3 < 2.500000277905201E-7D) {
            this.entity.setMoveForward(0.0F);
            return;
        }
        float f9 = (float) (MathHelper.atan2(d1, d0) * (180D / Math.PI)) - 90.0F;
        this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, f9, 90.0F);
        this.entity.setAIMoveSpeed((float) (this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()));
        if (d2 > (double) this.entity.stepHeight && d0 * d0 + d1 * d1 < (double) Math.max(1.0F, this.entity.width)) {
            this.entity.getJumpHelper().setJumping();
            this.action = Action.JUMPING;
        }
    } else if (this.action == Action.JUMPING) {
        this.entity.setAIMoveSpeed((float) (this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()));
        if (this.entity.onGround) {
            this.action = Action.WAIT;
        }
    } else {
        this.entity.setMoveForward(0.0F);
    }
}
Also used : NodeProcessor(net.minecraft.pathfinding.NodeProcessor) PathNavigate(net.minecraft.pathfinding.PathNavigate)

Example 4 with NodeProcessor

use of net.minecraft.pathfinding.NodeProcessor in project minecolonies by Minecolonies.

the class MovementHandler method tick.

@Override
public void tick() {
    if (this.operation == net.minecraft.entity.ai.controller.MovementController.Action.STRAFE) {
        final float speedAtt = (float) speedAtr.getValue();
        float speed = (float) this.speedModifier * speedAtt;
        float forward = this.strafeForwards;
        float strafe = this.strafeRight;
        float totalMovement = MathHelper.sqrt(forward * forward + strafe * strafe);
        if (totalMovement < 1.0F) {
            totalMovement = 1.0F;
        }
        totalMovement = speed / totalMovement;
        forward = forward * totalMovement;
        strafe = strafe * totalMovement;
        final float sinRotation = MathHelper.sin(this.mob.yRot * ((float) Math.PI / 180F));
        final float cosRotation = MathHelper.cos(this.mob.yRot * ((float) Math.PI / 180F));
        final float rot1 = forward * cosRotation - strafe * sinRotation;
        final float rot2 = strafe * cosRotation + forward * sinRotation;
        final PathNavigator pathnavigator = this.mob.getNavigation();
        final NodeProcessor nodeprocessor = pathnavigator.getNodeEvaluator();
        if (nodeprocessor.getBlockPathType(this.mob.level, MathHelper.floor(this.mob.getX() + (double) rot1), MathHelper.floor(this.mob.getY()), MathHelper.floor(this.mob.getZ() + (double) rot2)) != PathNodeType.WALKABLE) {
            this.strafeForwards = 1.0F;
            this.strafeRight = 0.0F;
            speed = speedAtt;
        }
        this.mob.setSpeed(speed);
        this.mob.setZza(this.strafeForwards);
        this.mob.setXxa(this.strafeRight);
        this.operation = net.minecraft.entity.ai.controller.MovementController.Action.WAIT;
    } else if (this.operation == net.minecraft.entity.ai.controller.MovementController.Action.MOVE_TO) {
        this.operation = net.minecraft.entity.ai.controller.MovementController.Action.WAIT;
        final double xDif = this.wantedX - this.mob.getX();
        final double zDif = this.wantedZ - this.mob.getZ();
        final double yDif = this.wantedY - this.mob.getY();
        final double dist = xDif * xDif + yDif * yDif + zDif * zDif;
        if (dist < (double) 2.5000003E-7F) {
            this.mob.setZza(0.0F);
            return;
        }
        final float range = (float) (MathHelper.atan2(zDif, xDif) * (double) (180F / (float) Math.PI)) - 90.0F;
        this.mob.yRot = this.rotlerp(this.mob.yRot, range, 90.0F);
        this.mob.setSpeed((float) (this.speedModifier * speedAtr.getValue()));
        final BlockPos blockpos = new BlockPos(this.mob.position());
        final BlockState blockstate = this.mob.level.getBlockState(blockpos);
        final Block block = blockstate.getBlock();
        final VoxelShape voxelshape = blockstate.getCollisionShape(this.mob.level, blockpos);
        if ((yDif > (double) this.mob.maxUpStep && xDif * xDif + zDif * zDif < (double) Math.max(1.0F, this.mob.getBbWidth())) || (!voxelshape.isEmpty() && this.mob.getY() < voxelshape.max(Direction.Axis.Y) + (double) blockpos.getY() && !block.is(BlockTags.DOORS) && !block.is(BlockTags.FENCES) && !block.is(BlockTags.FENCE_GATES)) && !block.isLadder(blockstate, this.mob.level, blockpos, this.mob)) {
            this.mob.getJumpControl().jump();
            this.operation = net.minecraft.entity.ai.controller.MovementController.Action.JUMPING;
        }
    } else if (this.operation == net.minecraft.entity.ai.controller.MovementController.Action.JUMPING) {
        this.mob.setSpeed((float) (this.speedModifier * speedAtr.getValue()));
        // Avoid beeing stuck in jumping while in liquids
        final BlockPos blockpos = new BlockPos(this.mob.position());
        final BlockState blockstate = this.mob.level.getBlockState(blockpos);
        if (this.mob.isOnGround() || blockstate.getMaterial().isLiquid()) {
            this.operation = net.minecraft.entity.ai.controller.MovementController.Action.WAIT;
        }
    } else {
        this.mob.setZza(0.0F);
    }
}
Also used : NodeProcessor(net.minecraft.pathfinding.NodeProcessor) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) PathNavigator(net.minecraft.pathfinding.PathNavigator)

Example 5 with NodeProcessor

use of net.minecraft.pathfinding.NodeProcessor in project Cavern2 by kegare.

the class EntityFlyHelper method onUpdateMoveHelper.

@Override
public void onUpdateMoveHelper() {
    if (action == EntityMoveHelper.Action.STRAFE) {
        entity.setNoGravity(false);
        float f1;
        float f2 = moveForward;
        float f3 = moveStrafe;
        float f4 = MathHelper.sqrt(f2 * f2 + f3 * f3);
        if (entity.onGround) {
            f1 = (float) (speed * entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue());
        } else {
            f1 = (float) (speed * entity.getEntityAttribute(SharedMonsterAttributes.FLYING_SPEED).getAttributeValue());
        }
        if (f4 < 1.0F) {
            f4 = 1.0F;
        }
        f4 = f1 / f4;
        f2 = f2 * f4;
        f3 = f3 * f4;
        float f5 = MathHelper.sin(entity.rotationYaw * 0.017453292F);
        float f6 = MathHelper.cos(entity.rotationYaw * 0.017453292F);
        float f7 = f2 * f6 - f3 * f5;
        float f8 = f3 * f6 + f2 * f5;
        PathNavigate pathnavigate = entity.getNavigator();
        if (pathnavigate != null) {
            NodeProcessor nodeprocessor = pathnavigate.getNodeProcessor();
            if (nodeprocessor != null && nodeprocessor.getPathNodeType(entity.world, MathHelper.floor(entity.posX + f7), MathHelper.floor(entity.posY), MathHelper.floor(entity.posZ + f8)) != PathNodeType.WALKABLE) {
                moveForward = 1.0F;
                moveStrafe = 0.0F;
            }
        }
        if (f4 < 8.800000277905201E-7D) {
            entity.setMoveVertical(0.0F);
            entity.setMoveForward(0.0F);
            return;
        }
        entity.setAIMoveSpeed(f1);
        entity.setMoveForward(moveForward);
        entity.setMoveStrafing(moveStrafe);
        action = EntityMoveHelper.Action.WAIT;
    } else if (action == EntityMoveHelper.Action.MOVE_TO) {
        action = EntityMoveHelper.Action.WAIT;
        entity.setNoGravity(true);
        double d0 = posX - entity.posX;
        double d1 = posY - entity.posY;
        double d2 = posZ - entity.posZ;
        double d3 = d0 * d0 + d1 * d1 + d2 * d2;
        if (d3 < 8.800000277905201E-7D) {
            entity.setMoveVertical(0.0F);
            entity.setMoveForward(0.0F);
            return;
        }
        float f = (float) (MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
        entity.rotationYaw = limitAngle(entity.rotationYaw, f, 10.0F);
        float f1;
        if (entity.onGround) {
            f1 = (float) (speed * entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue());
        } else {
            f1 = (float) (speed * entity.getEntityAttribute(SharedMonsterAttributes.FLYING_SPEED).getAttributeValue());
        }
        entity.setAIMoveSpeed(f1);
        double d4 = MathHelper.sqrt(d0 * d0 + d2 * d2);
        float f2 = (float) (-(MathHelper.atan2(d1, d4) * (180D / Math.PI)));
        entity.rotationPitch = limitAngle(entity.rotationPitch, f2, 10.0F);
        entity.setMoveVertical(d1 > 0.0D ? f1 : -f1);
    } else {
        entity.setNoGravity(false);
        entity.setMoveVertical(0.0F);
        entity.setMoveForward(0.0F);
    }
}
Also used : NodeProcessor(net.minecraft.pathfinding.NodeProcessor) PathNavigate(net.minecraft.pathfinding.PathNavigate)

Aggregations

NodeProcessor (net.minecraft.pathfinding.NodeProcessor)6 PathNavigate (net.minecraft.pathfinding.PathNavigate)4 Block (net.minecraft.block.Block)2 BlockState (net.minecraft.block.BlockState)2 PathNavigator (net.minecraft.pathfinding.PathNavigator)2 BlockPos (net.minecraft.util.math.BlockPos)2 VoxelShape (net.minecraft.util.math.shapes.VoxelShape)2 PathNodeType (net.minecraft.pathfinding.PathNodeType)1