Search in sources :

Example 11 with PathPoint

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

the class RenderNavigator method render.

public void render(boolean wirePath, boolean xRayEnabled, float partialTicks) {
    if (path == null)
        return;
    GL11.glDepthMask(false);
    if (xRayEnabled)
        GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glLineWidth(5.0F);
    boolean noDestinationPath = !tracedToDestination();
    BufferBuilder wr = Tessellator.getInstance().getBuffer();
    GL11.glPushMatrix();
    GL11.glTranslated(0, 0.01D, 0);
    // Draws just wires
    if (wirePath) {
        if (noDestinationPath) {
            GL11.glEnable(GL11.GL_LINE_STIPPLE);
            GL11.glLineStipple(4, (short) 0x00FF);
        }
        for (int i = 1; i < path.getCurrentPathLength(); i++) {
            double red = 1;
            if (path.getCurrentPathLength() - i < 200) {
                red = (path.getCurrentPathLength() - i) * 0.005D;
            }
            GL11.glColor4d(red, 1 - red, 0, 0.5D);
            PathPoint lastPoint = path.getPathPointFromIndex(i - 1);
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            wr.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION);
            wr.pos(lastPoint.x + 0.5D, lastPoint.y, lastPoint.z + 0.5D).endVertex();
            wr.pos((lastPoint.x + pathPoint.x) / 2D + 0.5D, Math.max(lastPoint.y, pathPoint.y), (lastPoint.z + pathPoint.z) / 2D + 0.5D).endVertex();
            wr.pos(pathPoint.x + 0.5D, pathPoint.y, pathPoint.z + 0.5D).endVertex();
            Tessellator.getInstance().draw();
        }
    } else {
        if (noDestinationPath) {
            if (increaseAlpha) {
                alphaValue += 0.005D;
                if (alphaValue > 0.3D)
                    increaseAlpha = false;
            } else {
                alphaValue -= 0.005D;
                if (alphaValue < 0.2D)
                    increaseAlpha = true;
            }
        } else {
            if (alphaValue > 0.2D)
                alphaValue -= 0.005D;
        }
        for (int i = 0; i < path.getCurrentPathLength(); i++) {
            double red = 1;
            if (path.getCurrentPathLength() - i < 200) {
                red = (path.getCurrentPathLength() - i) * 0.005D;
            }
            GL11.glColor4d(red, 1 - red, 0, alphaValue);
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
            wr.pos(pathPoint.x, pathPoint.y, pathPoint.z).endVertex();
            wr.pos(pathPoint.x, pathPoint.y, pathPoint.z + 1).endVertex();
            wr.pos(pathPoint.x + 1, pathPoint.y, pathPoint.z + 1).endVertex();
            wr.pos(pathPoint.x + 1, pathPoint.y, pathPoint.z).endVertex();
            Tessellator.getInstance().draw();
        }
    }
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LINE_STIPPLE);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 12 with PathPoint

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

the class EntityPathNavigateDrone method getPathToPos.

@Nullable
@Override
public Path getPathToPos(BlockPos pos) {
    // When the destination is not a valid block, we can stop right away
    if (!pathfindingEntity.isBlockValidPathfindBlock(pos) || pathfindingEntity.getDistanceSqToCenter(pos) < 0.3)
        return null;
    // Store the potential teleport destination
    telPos = pos;
    // If we are forced to teleport, trigger right away
    if (forceTeleport) {
        teleportCounter = 0;
        return null;
    }
    pathfindingEntity.setStandby(false);
    teleportCounter = -1;
    Path path = super.getPathToPos(pos);
    // Only paths that actually end up where we want to are valid, not just halfway.
    if (path != null) {
        PathPoint lastPoint = path.getFinalPathPoint();
        if (lastPoint != null && (lastPoint.x != pos.getX() || lastPoint.y != pos.getY() || lastPoint.z != pos.getZ())) {
            path = null;
        }
    }
    // If no valid flight path, teleport instead.
    if (path == null) {
        teleportCounter = 0;
    }
    return path;
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) Nullable(javax.annotation.Nullable)

Example 13 with PathPoint

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

the class PathfinderDrone method findPath.

@Nullable
private Path findPath(IBlockAccess worldIn, EntityLiving entitylivingIn, double x, double y, double z, float maxDistance) {
    this.path.clearPath();
    this.nodeProcessor.init(worldIn, entitylivingIn);
    PathPoint pathpoint = this.nodeProcessor.getStart();
    PathPoint pathpoint1 = this.nodeProcessor.getPathPointToCoords(x, y, z);
    Path path = this.findPath(pathpoint, pathpoint1, maxDistance);
    this.nodeProcessor.postProcess();
    return path;
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) Nullable(javax.annotation.Nullable)

Example 14 with PathPoint

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

the class PathfinderDrone method createPath.

/**
 * Returns a new PathEntity for a given start and end point
 */
private Path createPath(PathPoint start, PathPoint end) {
    int i = 1;
    for (PathPoint pathpoint = end; pathpoint.previous != null; pathpoint = pathpoint.previous) {
        ++i;
    }
    PathPoint[] apathpoint = new PathPoint[i];
    PathPoint pathpoint1 = end;
    --i;
    for (apathpoint[i] = end; pathpoint1.previous != null; apathpoint[i] = pathpoint1) {
        pathpoint1 = pathpoint1.previous;
        --i;
    }
    return new Path(apathpoint);
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 15 with PathPoint

use of net.minecraft.pathfinding.PathPoint 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)

Aggregations

PathPoint (net.minecraft.pathfinding.PathPoint)22 BlockPos (net.minecraft.util.math.BlockPos)10 Path (net.minecraft.pathfinding.Path)8 PathNodeType (net.minecraft.pathfinding.PathNodeType)5 Nullable (javax.annotation.Nullable)4 Block (net.minecraft.block.Block)3 PathEntity (net.minecraft.pathfinding.PathEntity)3 HashSet (java.util.HashSet)2 World (net.minecraft.world.World)2 BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)2 NotNull (org.jetbrains.annotations.NotNull)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IBlockState (net.minecraft.block.state.IBlockState)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 PathFinderDrone (net.minecraft.pathfinding.PathFinderDrone)1 PathNavigateGround (net.minecraft.pathfinding.PathNavigateGround)1 Vec3 (net.minecraft.util.Vec3)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1