Search in sources :

Example 1 with PathEntity

use of net.minecraft.pathfinding.PathEntity in project PneumaticCraft by MineMaarten.

the class CoordTrackUpgradeHandler method navigateToSurface.

@SideOnly(Side.CLIENT)
public EnumNavigationResult navigateToSurface(EntityPlayer player) {
    World worldObj = player.worldObj;
    int y = worldObj.getHeightValue((int) player.posX, (int) player.posZ);
    PathEntity path = worldObj.getEntityPathToXYZ(player, (int) player.posX, y, (int) player.posZ, SEARCH_RANGE, true, true, false, true);
    EnumNavigationResult result = path != null ? EnumNavigationResult.EASY_PATH : EnumNavigationResult.DRONE_PATH;
    if (path != null) {
        for (int i = 0; i < path.getCurrentPathLength(); i++) {
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            if (worldObj.canBlockSeeTheSky(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord)) {
                coordTracker = new RenderCoordWireframe(worldObj, pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord);
                navigator = new RenderNavigator(worldObj, pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord);
                return EnumNavigationResult.EASY_PATH;
            }
        }
    }
    path = getDronePath(player, (int) player.posX, y, (int) player.posZ);
    if (path != null) {
        for (int i = 0; i < path.getCurrentPathLength(); i++) {
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            if (worldObj.canBlockSeeTheSky(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord)) {
                coordTracker = new RenderCoordWireframe(worldObj, pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord);
                navigator = new RenderNavigator(worldObj, pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord);
                return EnumNavigationResult.DRONE_PATH;
            }
        }
    }
    return EnumNavigationResult.NO_PATH;
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) World(net.minecraft.world.World) PathEntity(net.minecraft.pathfinding.PathEntity) PathPoint(net.minecraft.pathfinding.PathPoint) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 2 with PathEntity

use of net.minecraft.pathfinding.PathEntity in project PneumaticCraft by MineMaarten.

the class EntityPathNavigateDrone method getEntityPathToXYZ.

public PathEntity getEntityPathToXYZ(EntityDrone par1Entity, int par2, int par3, int par4, float par5, boolean par6, boolean par7, boolean par8, boolean par9) {
    if (!par1Entity.isBlockValidPathfindBlock(par2, par3, par4))
        return null;
    PathEntity pathentity = null;
    int l = MathHelper.floor_double(par1Entity.posX);
    int i1 = MathHelper.floor_double(par1Entity.posY);
    int j1 = MathHelper.floor_double(par1Entity.posZ);
    if (!forceTeleport || l == par2 && i1 == par3 && j1 == par4) {
        int k1 = (int) (par5 + 8.0F);
        int l1 = l - k1;
        int i2 = i1 - k1;
        int j2 = j1 - k1;
        int k2 = l + k1;
        int l2 = i1 + k1;
        int i3 = j1 + k1;
        ChunkCache chunkcache = new ChunkCache(par1Entity.worldObj, l1, i2, j2, k2, l2, i3, 0);
        pathentity = new PathFinderDrone(par1Entity, chunkcache, par6, par7, pathThroughLiquid, par9).createEntityPathTo(par1Entity, par2, par3, par4, par5);
        if (pathentity != null) {
            PathPoint finalPoint = pathentity.getFinalPathPoint();
            if (finalPoint == null || finalPoint.xCoord != par2 || finalPoint.yCoord != par3 || finalPoint.zCoord != par4)
                pathentity = null;
        }
    }
    teleportCounter = pathentity != null ? -1 : 0;
    telX = par2;
    telY = par3;
    telZ = par4;
    par1Entity.setStandby(false);
    return pathentity;
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) ChunkCache(net.minecraft.world.ChunkCache) PathFinderDrone(net.minecraft.pathfinding.PathFinderDrone) PathEntity(net.minecraft.pathfinding.PathEntity) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 3 with PathEntity

use of net.minecraft.pathfinding.PathEntity in project ArsMagica2 by Mithion.

the class EntityAITargetNearbyInanimate method startExecuting.

@Override
public void startExecuting() {
    double dist = 10000;
    for (Class c : targetTypes) {
        List<Entity> potentialTargets = taskOwner.worldObj.getEntitiesWithinAABB(c, taskOwner.boundingBox.expand(targetDistance, 1, targetDistance));
        for (Entity e : potentialTargets) {
            if (isSuitableTarget(e)) {
                //sanity check
                //can we get to the item?
                PathEntity pe = taskOwner.getNavigator().getPathToXYZ(e.posX, e.posY, e.posZ);
                if (pe != null) {
                    double eDist = taskOwner.getDistanceSqToEntity(e);
                    if (eDist < dist) {
                        this.target = e;
                        dist = eDist;
                    }
                }
            }
        }
    }
    if (this.target != null)
        ExtendedProperties.For(taskOwner).setInanimateTarget(this.target);
    super.startExecuting();
}
Also used : PathEntity(net.minecraft.pathfinding.PathEntity) Entity(net.minecraft.entity.Entity) PathEntity(net.minecraft.pathfinding.PathEntity)

Example 4 with PathEntity

use of net.minecraft.pathfinding.PathEntity in project PneumaticCraft by MineMaarten.

the class EntityDrone method onUpdate.

@Override
public void onUpdate() {
    if (firstTick) {
        firstTick = false;
        volume = PneumaticValues.DRONE_VOLUME + getUpgrades(ItemMachineUpgrade.UPGRADE_VOLUME_DAMAGE) * PneumaticValues.VOLUME_VOLUME_UPGRADE;
        hasLiquidImmunity = getUpgrades(ItemMachineUpgrade.UPGRADE_SECURITY) > 0;
        if (hasLiquidImmunity) {
            ((EntityPathNavigateDrone) getPathNavigator()).pathThroughLiquid = true;
        }
        speed = 0.1 + Math.min(10, getUpgrades(ItemMachineUpgrade.UPGRADE_SPEED_DAMAGE)) * 0.01;
        lifeUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_ITEM_LIFE);
        if (!worldObj.isRemote)
            setHasMinigun(getUpgrades(ItemMachineUpgrade.UPGRADE_ENTITY_TRACKER) > 0);
        aiManager.setWidgets(progWidgets);
    }
    boolean enabled = !disabledByHacking && getPressure(null) > 0.01F;
    if (!worldObj.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;
        PathEntity path = getNavigator().getPath();
        if (path != null) {
            PathPoint target = path.getFinalPathPoint();
            if (target != null) {
                setTargetedBlock(target.xCoord, target.yCoord, target.zCoord);
            } else {
                setTargetedBlock(0, 0, 0);
            }
        } else {
            setTargetedBlock(0, 0, 0);
        }
        if (worldObj.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);
            Block block = null;
            for (int i = 0; i < 3; i++) {
                block = worldObj.getBlock(x, y, z);
                if (block.getMaterial() != Material.air)
                    break;
                y--;
            }
            if (block.getMaterial() != Material.air) {
                Vec3 vec = Vec3.createVectorHelper(posY - y, 0, 0);
                vec.rotateAroundY((float) (rand.nextFloat() * Math.PI * 2));
                worldObj.spawnParticle("blockcrack_" + Block.getIdFromBlock(block) + "_" + worldObj.getBlockMetadata(x, y, z), posX + vec.xCoord, y + 1, posZ + vec.zCoord, vec.xCoord, 0, vec.zCoord);
            }
        }
    }
    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(worldObj.getBlock(x, y, z))) {
                        worldObj.setBlock(x, y, z, Blocks.air, 0, 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 (!worldObj.isRemote && isEntityAlive()) /*((FakePlayerItemInWorldManager)fakePlayer.theItemInWorldManager).isDigging()*/
    {
        for (int i = 0; i < 4; i++) {
            getFakePlayer().theItemInWorldManager.updateBlockRemoving();
        }
    }
    super.onUpdate();
    if (hasMinigun())
        getMinigun().setAttackTarget(getAttackTarget()).update(posX, posY, posZ);
    if (!worldObj.isRemote && isEntityAlive()) {
        if (enabled)
            aiManager.onUpdateTasks();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            if (getEmittingRedstone(d) > 0) {
                if (worldObj.isAirBlock((int) Math.floor(posX + width / 2), (int) Math.floor(posY), (int) Math.floor(posZ + width / 2))) {
                    worldObj.setBlock((int) Math.floor(posX + width / 2), (int) Math.floor(posY), (int) Math.floor(posZ + width / 2), Blockss.droneRedstoneEmitter);
                }
                break;
            }
        }
    }
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) Vec3(net.minecraft.util.Vec3) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) PathEntity(net.minecraft.pathfinding.PathEntity) PathPoint(net.minecraft.pathfinding.PathPoint)

Aggregations

PathEntity (net.minecraft.pathfinding.PathEntity)4 PathPoint (net.minecraft.pathfinding.PathPoint)3 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 PathFinderDrone (net.minecraft.pathfinding.PathFinderDrone)1 Vec3 (net.minecraft.util.Vec3)1 ChunkCache (net.minecraft.world.ChunkCache)1 World (net.minecraft.world.World)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1