13
0
geforkt von Mirrors/Paper
Paper/nms-patches/EntityWolf.patch
blablubbabc 8879c31485 SPIGOT-4893: Don't reset angry state of wolves without target.
Wolves will 'silently' lose their target when teleporting between
dimensions or the chunk getting reloaded. To reset the angry state in
those cases, the check got moved into the loading method.
2019-05-11 13:11:52 +10:00

112 Zeilen
5.1 KiB
Diff

--- a/net/minecraft/server/EntityWolf.java
+++ b/net/minecraft/server/EntityWolf.java
@@ -4,6 +4,11 @@
import java.util.function.Predicate;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
+// CraftBukkit end
+
public class EntityWolf extends EntityTameableAnimal {
private static final DataWatcherObject<Float> DATA_HEALTH = DataWatcher.a(EntityWolf.class, DataWatcherRegistry.c);
@@ -42,7 +47,7 @@
this.goalSelector.a(10, new PathfinderGoalRandomLookaround(this));
this.targetSelector.a(1, new PathfinderGoalOwnerHurtByTarget(this));
this.targetSelector.a(2, new PathfinderGoalOwnerHurtTarget(this));
- this.targetSelector.a(3, (new PathfinderGoalHurtByTarget(this, new Class[0])).a());
+ this.targetSelector.a(3, (new PathfinderGoalHurtByTarget(this, new Class[0])).a(new Class[0])); // CraftBukkit - decompile error
this.targetSelector.a(4, new PathfinderGoalRandomTargetNonTamed<>(this, EntityAnimal.class, false, EntityWolf.bD));
this.targetSelector.a(4, new PathfinderGoalRandomTargetNonTamed<>(this, EntityTurtle.class, false, EntityTurtle.bz));
this.targetSelector.a(5, new PathfinderGoalNearestAttackableTarget<>(this, EntitySkeletonAbstract.class, false));
@@ -61,6 +66,22 @@
this.getAttributeMap().b(GenericAttributes.ATTACK_DAMAGE).setValue(2.0D);
}
+ // CraftBukkit - add overriden version
+ @Override
+ public boolean setGoalTarget(EntityLiving entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fire) {
+ if (!super.setGoalTarget(entityliving, reason, fire)) {
+ return false;
+ }
+ entityliving = getGoalTarget();
+ if (entityliving == null) {
+ this.setAngry(false);
+ } else if (!this.isTamed()) {
+ this.setAngry(true);
+ }
+ return true;
+ }
+ // CraftBukkit end
+
@Override
public void setGoalTarget(@Nullable EntityLiving entityliving) {
super.setGoalTarget(entityliving);
@@ -101,6 +122,11 @@
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.setAngry(nbttagcompound.getBoolean("Angry"));
+ // CraftBukkit start - moved from below, SPIGOT-4893
+ if (this.getGoalTarget() == null && this.isAngry()) {
+ this.setAngry(false);
+ }
+ // CraftBukkit end
if (nbttagcompound.hasKeyOfType("CollarColor", 99)) {
this.setCollarColor(EnumColor.fromColorIndex(nbttagcompound.getInt("CollarColor")));
}
@@ -137,7 +163,7 @@
this.world.broadcastEntityEffect(this, (byte) 8);
}
- if (!this.world.isClientSide && this.getGoalTarget() == null && this.isAngry()) {
+ if (false && !this.world.isClientSide && this.getGoalTarget() == null && this.isAngry()) { // CraftBukkit - SPIGOT-4893
this.setAngry(false);
}
@@ -217,7 +243,8 @@
Entity entity = damagesource.getEntity();
if (this.goalSit != null) {
- this.goalSit.setSitting(false);
+ // CraftBukkit - moved into EntityLiving.d(DamageSource, float)
+ // this.goalSit.setSitting(false);
}
if (entity != null && !(entity instanceof EntityHuman) && !(entity instanceof EntityArrow)) {
@@ -264,7 +291,7 @@
itemstack.subtract(1);
}
- this.heal((float) item.getFoodInfo().getNutrition());
+ this.heal((float) item.getFoodInfo().getNutrition(), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit
return true;
}
} else if (item instanceof ItemDye) {
@@ -285,7 +312,7 @@
this.goalSit.setSitting(!this.isSitting());
this.jumping = false;
this.navigation.o();
- this.setGoalTarget((EntityLiving) null);
+ this.setGoalTarget((EntityLiving) null, TargetReason.FORGOT_TARGET, true); // CraftBukkit - reason
}
} else if (item == Items.BONE && !this.isAngry()) {
if (!entityhuman.abilities.canInstantlyBuild) {
@@ -293,12 +320,13 @@
}
if (!this.world.isClientSide) {
- if (this.random.nextInt(3) == 0) {
+ // CraftBukkit - added event call and isCancelled check.
+ if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
this.tame(entityhuman);
this.navigation.o();
this.setGoalTarget((EntityLiving) null);
this.goalSit.setSitting(true);
- this.setHealth(20.0F);
+ this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth()
this.r(true);
this.world.broadcastEntityEffect(this, (byte) 7);
} else {