use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.
the class EntityAIGateInteract method checkFenceGate.
/**
* Checks if the citizen is close enough to an existing fence gate.
*
* @param path the path through the fence.
* @return true if the gate can be passed
*/
private boolean checkFenceGate(@NotNull final Path path) {
final int maxLengthToCheck = Math.min(path.getCurrentPathIndex() + LENGTH_TO_CHECK, path.getCurrentPathLength());
for (int i = 0; i < maxLengthToCheck; ++i) {
final PathPoint pathpoint = path.getPathPointFromIndex(i);
for (int level = 0; level < HEIGHT_TO_CHECK; level++) {
this.gatePosition = new BlockPos(pathpoint.xCoord, pathpoint.yCoord + level, pathpoint.zCoord);
if (this.theEntity.getDistanceSq((double) this.gatePosition.getX(), this.theEntity.posY, (double) this.gatePosition.getZ()) <= MIN_DISTANCE) {
this.gateBlock = this.getBlockFence(this.gatePosition);
if (this.gateBlock != null) {
return true;
}
}
}
}
this.gatePosition = (new BlockPos(this.theEntity)).up();
this.gateBlock = this.getBlockFence(this.gatePosition);
return this.gateBlock != null;
}
use of net.minecraft.pathfinding.PathPoint in project PneumaticCraft by MineMaarten.
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();
Tessellator tess = Tessellator.instance;
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);
tess.startDrawing(GL11.GL_LINE_STRIP);
tess.addVertex(lastPoint.xCoord + 0.5D, lastPoint.yCoord, lastPoint.zCoord + 0.5D);
tess.addVertex((lastPoint.xCoord + pathPoint.xCoord) / 2D + 0.5D, Math.max(lastPoint.yCoord, pathPoint.yCoord), (lastPoint.zCoord + pathPoint.zCoord) / 2D + 0.5D);
tess.addVertex(pathPoint.xCoord + 0.5D, pathPoint.yCoord, pathPoint.zCoord + 0.5D);
tess.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);
tess.startDrawingQuads();
tess.addVertex(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord);
tess.addVertex(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord + 1);
tess.addVertex(pathPoint.xCoord + 1, pathPoint.yCoord, pathPoint.zCoord + 1);
tess.addVertex(pathPoint.xCoord + 1, pathPoint.yCoord, pathPoint.zCoord);
tess.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);
}
use of net.minecraft.pathfinding.PathPoint 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;
}
}
}
}
Aggregations