Search in sources :

Example 11 with Path

use of net.minecraft.pathfinding.Path in project pnc-repressurized by TeamPneumatic.

the class EntityDrone method onUpdate.

@Override
public void onUpdate() {
    if (firstTick) {
        firstTick = false;
        volume = PneumaticValues.DRONE_VOLUME + getUpgrades(EnumUpgrade.VOLUME) * PneumaticValues.VOLUME_VOLUME_UPGRADE;
        hasLiquidImmunity = getUpgrades(EnumUpgrade.SECURITY) > 0;
        if (hasLiquidImmunity) {
            ((EntityPathNavigateDrone) getPathNavigator()).pathThroughLiquid = true;
        }
        setPathPriority(PathNodeType.WATER, hasLiquidImmunity ? 0.0f : -1.0f);
        speed = 0.1 + Math.min(10, getUpgrades(EnumUpgrade.SPEED)) * 0.01;
        lifeUpgrades = getUpgrades(EnumUpgrade.ITEM_LIFE);
        if (!world.isRemote)
            setHasMinigun(getUpgrades(EnumUpgrade.ENTITY_TRACKER) > 0);
        aiManager.setWidgets(progWidgets);
        energy.setCapacity(100000 + 100000 * getUpgrades(EnumUpgrade.VOLUME));
    }
    boolean enabled = !disabledByHacking && getPressure(null) > 0.01F;
    if (!world.isRemote) {
        setAccelerating(!standby && enabled);
        if (isAccelerating()) {
            fallDistance = 0;
        }
        if (lifeUpgrades > 0) {
            int interval = 10 / lifeUpgrades;
            if (interval == 0 || ticksExisted % interval == 0) {
                heal(1);
            }
        }
        if (!isSuffocating) {
            suffocationCounter = 40;
        }
        isSuffocating = false;
        Path path = getNavigator().getPath();
        if (path != null) {
            PathPoint target = path.getFinalPathPoint();
            if (target != null) {
                setTargetedBlock(new BlockPos(target.x, target.y, target.z));
            } else {
                setTargetedBlock(null);
            }
        } else {
            setTargetedBlock(null);
        }
        if (world.getTotalWorldTime() % 20 == 0) {
            updateSyncedPlayers();
        }
    } else {
        if (digLaser != null)
            digLaser.update();
        oldLaserExtension = laserExtension;
        if (getActiveProgramKey().equals("dig")) {
            laserExtension = Math.min(1, laserExtension + LASER_EXTEND_SPEED);
        } else {
            laserExtension = Math.max(0, laserExtension - LASER_EXTEND_SPEED);
        }
        if (isAccelerating()) {
            int x = (int) Math.floor(posX);
            int y = (int) Math.floor(posY - 1);
            int z = (int) Math.floor(posZ);
            BlockPos pos = new BlockPos(x, y, z);
            IBlockState state = null;
            for (int i = 0; i < 3; i++) {
                state = world.getBlockState(pos);
                if (state.getMaterial() != Material.AIR)
                    break;
                y--;
            }
            if (state.getMaterial() != Material.AIR) {
                Vec3d vec = new Vec3d(posY - y, 0, 0);
                vec = vec.rotateYaw((float) (rand.nextFloat() * Math.PI * 2));
                world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + vec.x, y + 1, posZ + vec.z, vec.x, 0, vec.z, Block.getStateId(world.getBlockState(pos)));
            }
        }
    }
    if (hasLiquidImmunity) {
        for (int x = (int) posX - 1; x <= (int) (posX + width); x++) {
            for (int y = (int) posY - 1; y <= (int) (posY + height + 1); y++) {
                for (int z = (int) posZ - 2; z <= (int) (posZ + width); z++) {
                    if (PneumaticCraftUtils.isBlockLiquid(world.getBlockState(new BlockPos(x, y, z)).getBlock())) {
                        world.setBlockState(new BlockPos(x, y, z), Blocks.AIR.getDefaultState(), 2);
                    }
                }
            }
        }
    }
    if (isAccelerating()) {
        motionX *= 0.3D;
        motionY *= 0.3D;
        motionZ *= 0.3D;
        propSpeed = Math.min(1, propSpeed + 0.04F);
        addAir(null, -1);
    } else {
        propSpeed = Math.max(0, propSpeed - 0.04F);
    }
    oldPropRotation = propRotation;
    propRotation += propSpeed;
    if (!world.isRemote && isEntityAlive()) {
        for (int i = 0; i < 4; i++) {
            getFakePlayer().interactionManager.updateBlockRemoving();
        }
    }
    super.onUpdate();
    if (hasMinigun())
        getMinigun().setAttackTarget(getAttackTarget()).update(posX, posY, posZ);
    if (!world.isRemote && isEntityAlive()) {
        if (enabled)
            aiManager.onUpdateTasks();
        for (EnumFacing d : EnumFacing.VALUES) {
            if (getEmittingRedstone(d) > 0) {
                if (world.isAirBlock(new BlockPos((int) Math.floor(posX + width / 2), (int) Math.floor(posY), (int) Math.floor(posZ + width / 2)))) {
                    world.setBlockState(new BlockPos((int) Math.floor(posX + width / 2), (int) Math.floor(posY), (int) Math.floor(posZ + width / 2)), Blockss.DRONE_REDSTONE_EMITTER.getDefaultState());
                }
                break;
            }
        }
    }
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) PathPoint(net.minecraft.pathfinding.PathPoint) Vec3d(net.minecraft.util.math.Vec3d)

Example 12 with Path

use of net.minecraft.pathfinding.Path in project MorePlanets by SteveKunG.

the class EntityShlime method updateAITasks.

@Override
public void updateAITasks() {
    if (this.moveHelper.getSpeed() > 0.8D) {
        this.setMoveType(EnumMoveType.SPRINT);
    } else {
        this.setMoveType(EnumMoveType.HOP);
    }
    if (this.currentMoveTypeDuration > 0) {
        --this.currentMoveTypeDuration;
    }
    this.sheepTimer = this.entityAIEatGrass.getEatingGrassTimer();
    super.updateAITasks();
    if (this.onGround) {
        if (!this.wasOnGround) {
            this.setJumping(false, EnumMoveType.NONE);
            this.checkLandingDelay();
        }
        ShlimeJumpHelper jump = (ShlimeJumpHelper) this.jumpHelper;
        if (!jump.getIsJumping()) {
            if (this.moveHelper.isUpdating() && this.currentMoveTypeDuration == 0) {
                Path pathentity = this.navigator.getPath();
                Vec3d vec3 = new Vec3d(this.moveHelper.getX(), this.moveHelper.getY(), this.moveHelper.getZ());
                if (pathentity != null && pathentity.getCurrentPathIndex() < pathentity.getCurrentPathLength()) {
                    vec3 = pathentity.getPosition(this);
                }
                this.calculateRotationYaw(vec3.x, vec3.z);
                this.doMovementAction(this.moveType);
            }
        } else if (!jump.canJump()) {
            this.enableJumpControl();
        }
    }
    this.wasOnGround = this.onGround;
}
Also used : Path(net.minecraft.pathfinding.Path) Vec3d(net.minecraft.util.math.Vec3d)

Example 13 with Path

use of net.minecraft.pathfinding.Path in project BloodMagic by WayofTime.

the class EntityAIPickUpAlly method shouldExecute.

/**
 * Returns whether the EntityAIBase should begin execution.
 */
public boolean shouldExecute() {
    if (this.entity.getRidingEntity() != null) {
        return false;
    }
    AxisAlignedBB bb = new AxisAlignedBB(entity.posX - 0.5, entity.posY - 0.5, entity.posZ - 0.5, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5).grow(5);
    List<EntityLivingBase> list = this.entity.getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, bb, new EntityAspectedDemonBase.WillTypePredicate(entity.getType()));
    for (EntityLivingBase testEntity : list) {
        if (testEntity != this.entity) {
            Path path = this.entity.getNavigator().getPathToEntityLiving(testEntity);
            if (path != null) {
                this.entityPathEntity = path;
                this.pickupTarget = testEntity;
                return true;
            }
        }
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Path(net.minecraft.pathfinding.Path) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityAspectedDemonBase(WayofTime.bloodmagic.entity.mob.EntityAspectedDemonBase)

Example 14 with Path

use of net.minecraft.pathfinding.Path in project MorePlanets by SteveKunG.

the class EntityShlime method updateAITasks.

@Override
public void updateAITasks() {
    if (this.currentMoveTypeDuration > 0) {
        --this.currentMoveTypeDuration;
    }
    if (this.onGround) {
        if (!this.wasOnGround) {
            this.setJumping(false);
            this.checkLandingDelay();
        }
        ShlimeJumpHelper helper = (ShlimeJumpHelper) this.jumpHelper;
        if (!helper.getIsJumping()) {
            if (this.moveHelper.isUpdating() && this.currentMoveTypeDuration == 0) {
                Path path = this.navigator.getPath();
                Vec3d vec3d = new Vec3d(this.moveHelper.getX(), this.moveHelper.getY(), this.moveHelper.getZ());
                if (path != null && path.getCurrentPathIndex() < path.getCurrentPathLength()) {
                    vec3d = path.getPosition(this);
                }
                this.calculateRotationYaw(vec3d.x, vec3d.z);
                this.startJumping();
            }
        } else if (!helper.canJump()) {
            this.enableJumpControl();
        }
    }
    this.wasOnGround = this.onGround;
    this.sheepTimer = this.entityAIEatGrass.getEatingGrassTimer();
    super.updateAITasks();
}
Also used : Path(net.minecraft.pathfinding.Path) Vec3d(net.minecraft.util.math.Vec3d)

Example 15 with Path

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

the class AbstractPathJob method search.

/**
 * Perform the search.
 *
 * @return Path of a path to the given location, a best-effort, or null.
 */
@Nullable
protected Path search() {
    Node bestNode = getAndSetupStartNode();
    double bestNodeResultScore = getNodeResultScore(bestNode);
    while (!nodesOpen.isEmpty()) {
        if (Thread.currentThread().isInterrupted()) {
            return null;
        }
        final Node currentNode = nodesOpen.poll();
        totalNodesVisited++;
        currentNode.setCounterVisited(totalNodesVisited);
        handleDebugOptions(currentNode);
        if (isAtDestination(currentNode)) {
            bestNode = currentNode;
            result.setPathReachesDestination(true);
            break;
        }
        // If this is the closest node to our destination, treat it as our best node
        final double nodeResultScore = getNodeResultScore(currentNode);
        if (nodeResultScore > bestNodeResultScore) {
            bestNode = currentNode;
            bestNodeResultScore = nodeResultScore;
        }
        if (BlockPosUtil.getDistanceSquared2D(currentNode.pos, start) <= maxRange * maxRange) {
            walkCurrentNode(currentNode);
        }
    }
    @NotNull final Path path = finalizePath(bestNode);
    handleDebugDraw();
    return path;
}
Also used : Path(net.minecraft.pathfinding.Path) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Path (net.minecraft.pathfinding.Path)16 PathPoint (net.minecraft.pathfinding.PathPoint)8 Vec3d (net.minecraft.util.math.Vec3d)5 BlockPos (net.minecraft.util.math.BlockPos)4 Nullable (javax.annotation.Nullable)3 NotNull (org.jetbrains.annotations.NotNull)3 PathNavigateGround (net.minecraft.pathfinding.PathNavigateGround)2 Nullable (org.jetbrains.annotations.Nullable)2 EntityAspectedDemonBase (WayofTime.bloodmagic.entity.mob.EntityAspectedDemonBase)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntitySilverfish (net.minecraft.entity.monster.EntitySilverfish)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1