Paper/src/main/java/net/minecraft/server/EntityWolf.java

365 Zeilen
12 KiB
Java

2012-03-10 03:52:32 +01:00
package net.minecraft.server;
public class EntityWolf extends EntityTameableAnimal {
2013-07-01 13:03:00 +02:00
private float bq;
private float br;
private boolean bs;
private boolean bt;
private float bu;
private float bv;
2012-03-10 03:52:32 +01:00
public EntityWolf(World world) {
super(world);
2012-07-29 09:33:13 +02:00
this.a(0.6F, 0.8F);
this.getNavigation().a(true);
2012-03-10 03:52:32 +01:00
this.goalSelector.a(1, new PathfinderGoalFloat(this));
2013-07-01 13:03:00 +02:00
this.goalSelector.a(2, this.bp);
2012-03-10 03:52:32 +01:00
this.goalSelector.a(3, new PathfinderGoalLeapAtTarget(this, 0.4F));
2013-07-01 13:03:00 +02:00
this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, 1.0D, true));
this.goalSelector.a(5, new PathfinderGoalFollowOwner(this, 1.0D, 10.0F, 2.0F));
this.goalSelector.a(6, new PathfinderGoalBreed(this, 1.0D));
this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 1.0D));
2012-03-10 03:52:32 +01:00
this.goalSelector.a(8, new PathfinderGoalBeg(this, 8.0F));
this.goalSelector.a(9, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
this.goalSelector.a(9, new PathfinderGoalRandomLookaround(this));
this.targetSelector.a(1, new PathfinderGoalOwnerHurtByTarget(this));
this.targetSelector.a(2, new PathfinderGoalOwnerHurtTarget(this));
this.targetSelector.a(3, new PathfinderGoalHurtByTarget(this, true));
2013-07-01 13:03:00 +02:00
this.targetSelector.a(4, new PathfinderGoalRandomTargetNonTamed(this, EntitySheep.class, 200, false));
this.setTamed(false);
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
protected void aD() {
super.aD();
2013-07-09 01:43:37 +02:00
this.getAttributeInstance(GenericAttributes.d).setValue(0.30000001192092896D);
2013-07-01 13:03:00 +02:00
if (this.isTamed()) {
2013-07-09 01:43:37 +02:00
this.getAttributeInstance(GenericAttributes.a).setValue(20.0D);
2013-07-01 13:03:00 +02:00
} else {
2013-07-09 01:43:37 +02:00
this.getAttributeInstance(GenericAttributes.a).setValue(8.0D);
2013-07-01 13:03:00 +02:00
}
}
2013-11-04 14:07:38 +01:00
public boolean bk() {
2012-03-10 03:52:32 +01:00
return true;
}
2013-01-17 10:28:44 +01:00
public void setGoalTarget(EntityLiving entityliving) {
super.setGoalTarget(entityliving);
2013-07-01 13:03:00 +02:00
if (entityliving == null) {
this.setAngry(false);
2013-07-09 01:43:37 +02:00
} else if (!this.isTamed()) {
2012-03-10 03:52:32 +01:00
this.setAngry(true);
}
}
2013-11-04 14:07:38 +01:00
protected void bp() {
this.datawatcher.watch(18, Float.valueOf(this.getHealth()));
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
protected void c() {
super.c();
2013-07-01 13:03:00 +02:00
this.datawatcher.a(18, new Float(this.getHealth()));
2012-07-29 09:33:13 +02:00
this.datawatcher.a(19, new Byte((byte) 0));
2013-11-04 14:07:38 +01:00
this.datawatcher.a(20, new Byte((byte) BlockCloth.b(1)));
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
protected void a(int i, int j, int k, Block block) {
2012-11-06 13:05:28 +01:00
this.makeSound("mob.wolf.step", 0.15F, 1.0F);
2012-03-10 03:52:32 +01:00
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setBoolean("Angry", this.isAngry());
nbttagcompound.setByte("CollarColor", (byte) this.getCollarColor());
2012-03-10 03:52:32 +01:00
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.setAngry(nbttagcompound.getBoolean("Angry"));
2013-11-04 14:07:38 +01:00
if (nbttagcompound.hasKeyOfType("CollarColor", 99)) {
this.setCollarColor(nbttagcompound.getByte("CollarColor"));
}
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
protected String t() {
// CraftBukkit - (getFloat(18) < 10) -> (getFloat(18) < this.getMaxHealth() / 2)
return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getFloat(18) < (this.getMaxHealth() / 2) ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
protected String aT() {
2012-03-10 03:52:32 +01:00
return "mob.wolf.hurt";
}
2013-11-04 14:07:38 +01:00
protected String aU() {
2012-03-10 03:52:32 +01:00
return "mob.wolf.death";
}
2013-11-04 14:07:38 +01:00
protected float bf() {
2012-03-10 03:52:32 +01:00
return 0.4F;
}
2013-11-04 14:07:38 +01:00
protected Item getLoot() {
return Item.d(-1);
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
public void e() {
super.e();
if (!this.world.isStatic && this.bs && !this.bt && !this.bQ() && this.onGround) {
2013-07-01 13:03:00 +02:00
this.bt = true;
this.bu = 0.0F;
this.bv = 0.0F;
2012-03-10 03:52:32 +01:00
this.world.broadcastEntityEffect(this, (byte) 8);
}
}
2013-11-04 14:07:38 +01:00
public void h() {
super.h();
2013-07-01 13:03:00 +02:00
this.br = this.bq;
2013-11-04 14:07:38 +01:00
if (this.ci()) {
2013-07-01 13:03:00 +02:00
this.bq += (1.0F - this.bq) * 0.4F;
2012-03-10 03:52:32 +01:00
} else {
2013-07-01 13:03:00 +02:00
this.bq += (0.0F - this.bq) * 0.4F;
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.ci()) {
2013-07-01 13:03:00 +02:00
this.g = 10;
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.L()) {
2013-07-01 13:03:00 +02:00
this.bs = true;
this.bt = false;
this.bu = 0.0F;
this.bv = 0.0F;
} else if ((this.bs || this.bt) && this.bt) {
if (this.bu == 0.0F) {
2013-11-04 14:07:38 +01:00
this.makeSound("mob.wolf.shake", this.bf(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
2012-03-10 03:52:32 +01:00
}
2013-07-01 13:03:00 +02:00
this.bv = this.bu;
this.bu += 0.05F;
if (this.bv >= 2.0F) {
this.bs = false;
this.bt = false;
this.bv = 0.0F;
this.bu = 0.0F;
2012-03-10 03:52:32 +01:00
}
2013-07-01 13:03:00 +02:00
if (this.bu > 0.4F) {
2012-03-10 03:52:32 +01:00
float f = (float) this.boundingBox.b;
2013-07-01 13:03:00 +02:00
int i = (int) (MathHelper.sin((this.bu - 0.4F) * 3.1415927F) * 7.0F);
2012-03-10 03:52:32 +01:00
for (int j = 0; j < i; ++j) {
float f1 = (this.random.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
float f2 = (this.random.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
this.world.addParticle("splash", this.locX + (double) f1, (double) (f + 0.8F), this.locZ + (double) f2, this.motX, this.motY, this.motZ);
2012-03-10 03:52:32 +01:00
}
}
}
}
public float getHeadHeight() {
return this.length * 0.8F;
}
2013-11-04 14:07:38 +01:00
public int x() {
return this.isSitting() ? 20 : super.x();
2012-03-10 03:52:32 +01:00
}
2013-07-01 13:03:00 +02:00
public boolean damageEntity(DamageSource damagesource, float f) {
2012-11-06 13:05:28 +01:00
if (this.isInvulnerable()) {
return false;
} else {
Entity entity = damagesource.getEntity();
2012-03-10 03:52:32 +01:00
2013-07-01 13:03:00 +02:00
this.bp.setSitting(false);
2012-11-06 13:05:28 +01:00
if (entity != null && !(entity instanceof EntityHuman) && !(entity instanceof EntityArrow)) {
2013-07-01 13:03:00 +02:00
f = (f + 1.0F) / 2.0F;
2012-11-06 13:05:28 +01:00
}
2012-03-10 03:52:32 +01:00
2013-07-01 13:03:00 +02:00
return super.damageEntity(damagesource, f);
2012-11-06 13:05:28 +01:00
}
2012-03-10 03:52:32 +01:00
}
2012-11-06 13:05:28 +01:00
public boolean m(Entity entity) {
2012-03-10 03:52:32 +01:00
int i = this.isTamed() ? 4 : 2;
2013-07-01 13:03:00 +02:00
return entity.damageEntity(DamageSource.mobAttack(this), (float) i);
2012-03-10 03:52:32 +01:00
}
2013-07-01 13:03:00 +02:00
public void setTamed(boolean flag) {
super.setTamed(flag);
if (flag) {
2013-07-09 01:43:37 +02:00
this.getAttributeInstance(GenericAttributes.a).setValue(20.0D);
2013-07-01 13:03:00 +02:00
} else {
2013-07-09 01:43:37 +02:00
this.getAttributeInstance(GenericAttributes.a).setValue(8.0D);
2013-07-01 13:03:00 +02:00
}
}
public boolean a(EntityHuman entityhuman) {
2012-03-10 03:52:32 +01:00
ItemStack itemstack = entityhuman.inventory.getItemInHand();
2012-07-29 09:33:13 +02:00
if (this.isTamed()) {
if (itemstack != null) {
2013-11-04 14:07:38 +01:00
if (itemstack.getItem() instanceof ItemFood) {
ItemFood itemfood = (ItemFood) itemstack.getItem();
2012-03-10 03:52:32 +01:00
2013-11-04 14:07:38 +01:00
if (itemfood.i() && this.datawatcher.getFloat(18) < 20.0F) {
if (!entityhuman.abilities.canInstantlyBuild) {
--itemstack.count;
}
2013-11-04 14:07:38 +01:00
this.heal((float) itemfood.getNutrition(itemstack));
if (itemstack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
}
2012-03-30 23:33:51 +02:00
return true;
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
} else if (itemstack.getItem() == Items.INK_SACK) {
int i = BlockCloth.b(itemstack.getData());
2012-03-10 03:52:32 +01:00
if (i != this.getCollarColor()) {
this.setCollarColor(i);
2012-11-06 13:05:28 +01:00
if (!entityhuman.abilities.canInstantlyBuild && --itemstack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
}
return true;
}
2012-03-10 03:52:32 +01:00
}
}
2013-07-01 13:03:00 +02:00
if (entityhuman.getName().equalsIgnoreCase(this.getOwnerName()) && !this.world.isStatic && !this.c(itemstack)) {
this.bp.setSitting(!this.isSitting());
this.bd = false;
2012-03-10 03:52:32 +01:00
this.setPathEntity((PathEntity) null);
2013-07-09 01:43:37 +02:00
this.setTarget((Entity) null);
this.setGoalTarget((EntityLiving) null);
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
} else if (itemstack != null && itemstack.getItem() == Items.BONE && !this.isAngry()) {
2012-07-29 09:33:13 +02:00
if (!entityhuman.abilities.canInstantlyBuild) {
--itemstack.count;
}
if (itemstack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
}
if (!this.world.isStatic) {
// CraftBukkit - added event call and isCancelled check.
if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
this.setTamed(true);
this.setPathEntity((PathEntity) null);
2013-01-17 10:28:44 +01:00
this.setGoalTarget((EntityLiving) null);
2013-07-01 13:03:00 +02:00
this.bp.setSitting(true);
this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth()
2013-07-01 13:03:00 +02:00
this.setOwnerName(entityhuman.getName());
2013-07-09 01:43:37 +02:00
this.i(true);
2012-07-29 09:33:13 +02:00
this.world.broadcastEntityEffect(this, (byte) 7);
} else {
2013-07-09 01:43:37 +02:00
this.i(false);
2012-07-29 09:33:13 +02:00
this.world.broadcastEntityEffect(this, (byte) 6);
}
}
return true;
2012-03-10 03:52:32 +01:00
}
2013-07-01 13:03:00 +02:00
return super.a(entityhuman);
2012-03-10 03:52:32 +01:00
}
public boolean c(ItemStack itemstack) {
2013-11-04 14:07:38 +01:00
return itemstack == null ? false : (!(itemstack.getItem() instanceof ItemFood) ? false : ((ItemFood) itemstack.getItem()).i());
2012-03-10 03:52:32 +01:00
}
2013-11-04 14:07:38 +01:00
public int bz() {
2012-03-10 03:52:32 +01:00
return 8;
}
public boolean isAngry() {
return (this.datawatcher.getByte(16) & 2) != 0;
}
public void setAngry(boolean flag) {
byte b0 = this.datawatcher.getByte(16);
if (flag) {
this.datawatcher.watch(16, Byte.valueOf((byte) (b0 | 2)));
} else {
this.datawatcher.watch(16, Byte.valueOf((byte) (b0 & -3)));
}
}
public int getCollarColor() {
return this.datawatcher.getByte(20) & 15;
}
public void setCollarColor(int i) {
this.datawatcher.watch(20, Byte.valueOf((byte) (i & 15)));
}
2012-11-06 13:05:28 +01:00
public EntityWolf b(EntityAgeable entityageable) {
2012-03-10 03:52:32 +01:00
EntityWolf entitywolf = new EntityWolf(this.world);
2012-11-16 17:13:34 +01:00
String s = this.getOwnerName();
if (s != null && s.trim().length() > 0) {
entitywolf.setOwnerName(s);
entitywolf.setTamed(true);
}
2012-03-10 03:52:32 +01:00
return entitywolf;
}
2013-07-09 01:43:37 +02:00
public void m(boolean flag) {
2012-07-29 09:33:13 +02:00
if (flag) {
this.datawatcher.watch(19, Byte.valueOf((byte) 1));
} else {
this.datawatcher.watch(19, Byte.valueOf((byte) 0));
}
2012-03-10 03:52:32 +01:00
}
public boolean mate(EntityAnimal entityanimal) {
if (entityanimal == this) {
return false;
} else if (!this.isTamed()) {
return false;
} else if (!(entityanimal instanceof EntityWolf)) {
return false;
} else {
EntityWolf entitywolf = (EntityWolf) entityanimal;
2013-11-04 14:07:38 +01:00
return !entitywolf.isTamed() ? false : (entitywolf.isSitting() ? false : this.cc() && entitywolf.cc());
2012-03-10 03:52:32 +01:00
}
}
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
public boolean ci() {
2012-07-29 09:33:13 +02:00
return this.datawatcher.getByte(19) == 1;
}
2012-11-06 13:05:28 +01:00
2013-07-01 13:03:00 +02:00
protected boolean isTypeNotPersistent() {
return !this.isTamed(); // CraftBukkit
2013-07-01 13:03:00 +02:00
}
2013-07-09 01:43:37 +02:00
public boolean a(EntityLiving entityliving, EntityLiving entityliving1) {
if (!(entityliving instanceof EntityCreeper) && !(entityliving instanceof EntityGhast)) {
if (entityliving instanceof EntityWolf) {
EntityWolf entitywolf = (EntityWolf) entityliving;
if (entitywolf.isTamed() && entitywolf.getOwner() == entityliving1) {
return false;
}
}
return entityliving instanceof EntityHuman && entityliving1 instanceof EntityHuman && !((EntityHuman) entityliving1).a((EntityHuman) entityliving) ? false : !(entityliving instanceof EntityHorse) || !((EntityHorse) entityliving).isTame();
} else {
return false;
}
}
2012-11-06 13:05:28 +01:00
public EntityAgeable createChild(EntityAgeable entityageable) {
return this.b(entityageable);
}
2012-03-10 03:52:32 +01:00
}