use of net.minecraft.pathfinding.PathNavigate in project Galacticraft by micdoodle8.
the class TileEntityArclamp method update.
@Override
public void update() {
boolean initialLight = false;
if (RedstoneUtil.isBlockReceivingRedstone(this.worldObj, this.getPos())) {
if (this.isActive) {
this.isActive = false;
this.revertAir();
this.markDirty();
}
} else if (!this.isActive && this.pos.getX() >= -30000000 + 32 && this.pos.getZ() >= -30000000 + 32 && this.pos.getX() < 30000000 - 32 && this.pos.getZ() < 30000000 - 32) {
this.isActive = true;
initialLight = true;
}
if (this.isActive) {
// Test for first tick after placement
if (this.thisAABB == null) {
initialLight = true;
int side = this.getBlockMetadata();
switch(side) {
case 0:
// Down
this.sideRear = side;
this.facingSide = this.facing + 2;
break;
case 1:
// Up
this.sideRear = side;
this.facingSide = this.facing + 2;
break;
case 2:
// North
this.sideRear = side;
this.facingSide = this.facing;
if (this.facing > 1) {
this.facingSide = 7 - this.facing;
}
break;
case 3:
// South
this.sideRear = side;
this.facingSide = this.facing;
if (this.facing > 1) {
this.facingSide += 2;
}
break;
case 4:
// West
this.sideRear = side;
this.facingSide = this.facing;
break;
case 5:
// East
this.sideRear = side;
this.facingSide = this.facing;
if (this.facing > 1) {
this.facingSide = 5 - this.facing;
}
break;
default:
}
this.thisAABB = getAABBforSideAndFacing();
}
if (initialLight || this.ticks % 100 == 0) {
this.lightArea();
}
if (!this.worldObj.isRemote && this.worldObj.rand.nextInt(20) == 0) {
List<Entity> moblist = this.worldObj.getEntitiesInAABBexcluding(null, this.thisAABB, IMob.mobSelector);
if (!moblist.isEmpty()) {
Vec3 thisVec3 = new Vec3(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
for (Entity entry : moblist) {
if (!(entry instanceof EntityCreature)) {
continue;
}
EntityCreature mob = (EntityCreature) entry;
// Check whether the mob can actually *see* the arclamp tile
// if (this.worldObj.func_147447_a(thisPos, new Vec3(entry.posX, entry.posY, entry.posZ), true, true, false) != null) continue;
PathNavigate nav = mob.getNavigator();
if (nav == null) {
continue;
}
Vec3 vecNewTarget = RandomPositionGenerator.findRandomTargetBlockAwayFrom(mob, 28, 11, this.thisPos);
if (vecNewTarget == null) {
continue;
}
double distanceNew = vecNewTarget.squareDistanceTo(thisVec3);
double distanceCurrent = thisVec3.squareDistanceTo(new Vec3(mob.posX, mob.posY, mob.posZ));
if (distanceNew > distanceCurrent) {
Vec3 vecOldTarget = null;
if (nav.getPath() != null && !nav.getPath().isFinished()) {
vecOldTarget = nav.getPath().getPosition(mob);
}
if (vecOldTarget == null || distanceCurrent > vecOldTarget.squareDistanceTo(thisVec3)) {
nav.tryMoveToXYZ(vecNewTarget.xCoord, vecNewTarget.yCoord, vecNewTarget.zCoord, 1.3D);
}
}
}
}
}
}
this.ticks++;
}
use of net.minecraft.pathfinding.PathNavigate in project Galacticraft by micdoodle8.
the class TileEntityEmergencyBox method scareMobs.
private void scareMobs() {
List<Entity> moblist = this.worldObj.getEntitiesInAABBexcluding(null, mobsAABB, IMob.mobSelector);
if (!moblist.isEmpty()) {
for (Entity entry : moblist) {
if (!(entry instanceof EntityCreature && entry instanceof IEntityBreathable)) {
continue;
}
EntityCreature mob = (EntityCreature) entry;
PathNavigate nav = mob.getNavigator();
if (nav == null) {
continue;
}
Vec3 vecNewTarget = RandomPositionGenerator.findRandomTargetBlockAwayFrom(mob, 12, 5, vec3Centre);
if (vecNewTarget == null) {
vecNewTarget = RandomPositionGenerator.findRandomTargetBlockAwayFrom(mob, 14, 7, vec3Centre);
if (vecNewTarget == null)
continue;
}
double distanceNew = vecNewTarget.squareDistanceTo(thisVec3);
double distanceCurrent = thisVec3.squareDistanceTo(new Vec3(mob.posX, mob.posY, mob.posZ));
if (distanceNew > distanceCurrent) {
Vec3 vecOldTarget = null;
if (nav.getPath() != null && !nav.getPath().isFinished()) {
vecOldTarget = nav.getPath().getPosition(mob);
}
if (vecOldTarget == null || distanceCurrent > vecOldTarget.squareDistanceTo(thisVec3)) {
nav.tryMoveToXYZ(vecNewTarget.xCoord, vecNewTarget.yCoord, vecNewTarget.zCoord, 1.3D);
}
}
}
}
}
Aggregations