2012-03-26 20:55:35 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class PathfinderGoalBreed extends PathfinderGoal {
|
|
|
|
|
|
|
|
private EntityAnimal d;
|
|
|
|
World a;
|
|
|
|
private EntityAnimal e;
|
2013-07-01 13:03:00 +02:00
|
|
|
int b;
|
|
|
|
double c;
|
2012-03-26 20:55:35 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public PathfinderGoalBreed(EntityAnimal entityanimal, double d0) {
|
2012-03-26 20:55:35 +02:00
|
|
|
this.d = entityanimal;
|
|
|
|
this.a = entityanimal.world;
|
2013-07-01 13:03:00 +02:00
|
|
|
this.c = d0;
|
2012-03-26 20:55:35 +02:00
|
|
|
this.a(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a() {
|
2014-03-21 05:26:30 +01:00
|
|
|
if (!this.d.ce()) {
|
2012-03-26 20:55:35 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this.e = this.f();
|
|
|
|
return this.e != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b() {
|
2014-03-21 05:26:30 +01:00
|
|
|
return this.e.isAlive() && this.e.ce() && this.b < 60;
|
2012-03-26 20:55:35 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void d() {
|
2012-03-26 20:55:35 +02:00
|
|
|
this.e = null;
|
|
|
|
this.b = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void e() {
|
2014-03-21 05:26:30 +01:00
|
|
|
this.d.getControllerLook().a(this.e, 10.0F, (float) this.d.bv());
|
2013-07-01 13:03:00 +02:00
|
|
|
this.d.getNavigation().a((Entity) this.e, this.c);
|
2012-03-26 20:55:35 +02:00
|
|
|
++this.b;
|
2014-03-21 05:26:30 +01:00
|
|
|
if (this.b >= 60 && this.d.f(this.e) < 9.0D) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.g();
|
2012-03-26 20:55:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private EntityAnimal f() {
|
|
|
|
float f = 8.0F;
|
|
|
|
List list = this.a.a(this.d.getClass(), this.d.boundingBox.grow((double) f, (double) f, (double) f));
|
2013-03-13 23:33:27 +01:00
|
|
|
double d0 = Double.MAX_VALUE;
|
|
|
|
EntityAnimal entityanimal = null;
|
2012-03-26 20:55:35 +02:00
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityAnimal entityanimal1 = (EntityAnimal) iterator.next();
|
2012-03-26 20:55:35 +02:00
|
|
|
|
2014-03-21 05:26:30 +01:00
|
|
|
if (this.d.mate(entityanimal1) && this.d.f(entityanimal1) < d0) {
|
2013-03-13 23:33:27 +01:00
|
|
|
entityanimal = entityanimal1;
|
2014-03-21 05:26:30 +01:00
|
|
|
d0 = this.d.f(entityanimal1);
|
2012-03-26 20:55:35 +02:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2012-03-26 20:55:35 +02:00
|
|
|
|
|
|
|
return entityanimal;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
private void g() {
|
2012-11-06 13:05:28 +01:00
|
|
|
EntityAgeable entityageable = this.d.createChild(this.e);
|
2012-03-26 20:55:35 +02:00
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
if (entityageable != null) {
|
2013-09-11 02:35:43 +02:00
|
|
|
// CraftBukkit start - set persistence for tame animals
|
|
|
|
if (entityageable instanceof EntityTameableAnimal && ((EntityTameableAnimal) entityageable).isTamed()) {
|
|
|
|
entityageable.persistent = true;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2014-03-21 05:26:30 +01:00
|
|
|
EntityHuman entityhuman = this.d.cd();
|
2013-11-04 14:07:38 +01:00
|
|
|
|
2014-03-21 05:26:30 +01:00
|
|
|
if (entityhuman == null && this.e.cd() != null) {
|
|
|
|
entityhuman = this.e.cd();
|
2013-11-04 14:07:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entityhuman != null) {
|
|
|
|
entityhuman.a(StatisticList.x);
|
|
|
|
if (this.d instanceof EntityCow) {
|
|
|
|
entityhuman.a((Statistic) AchievementList.H);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 20:55:35 +02:00
|
|
|
this.d.setAge(6000);
|
|
|
|
this.e.setAge(6000);
|
2014-03-21 05:26:30 +01:00
|
|
|
this.d.cf();
|
|
|
|
this.e.cf();
|
2012-11-06 13:05:28 +01:00
|
|
|
entityageable.setAge(-24000);
|
|
|
|
entityageable.setPositionRotation(this.d.locX, this.d.locY, this.d.locZ, 0.0F, 0.0F);
|
|
|
|
this.a.addEntity(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
|
2014-03-21 05:26:30 +01:00
|
|
|
Random random = this.d.aH();
|
2012-03-26 20:55:35 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 7; ++i) {
|
|
|
|
double d0 = random.nextGaussian() * 0.02D;
|
|
|
|
double d1 = random.nextGaussian() * 0.02D;
|
|
|
|
double d2 = random.nextGaussian() * 0.02D;
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.a.addParticle("heart", this.d.locX + (double) (random.nextFloat() * this.d.width * 2.0F) - (double) this.d.width, this.d.locY + 0.5D + (double) (random.nextFloat() * this.d.length), this.d.locZ + (double) (random.nextFloat() * this.d.width * 2.0F) - (double) this.d.width, d0, d1, d2);
|
2012-03-26 20:55:35 +02:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.a.getGameRules().getBoolean("doMobLoot")) {
|
|
|
|
this.a.addEntity(new EntityExperienceOrb(this.a, this.d.locX, this.d.locY, this.d.locZ, random.nextInt(7) + 1));
|
|
|
|
}
|
2012-03-26 20:55:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|