0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-25 06:56:14 +00:00
craftbukkit/nms-patches/net/minecraft/world/entity/animal/EntityWolf.patch
2024-10-23 02:15:00 +11:00

106 lines
4.6 KiB
Diff

--- a/net/minecraft/world/entity/animal/EntityWolf.java
+++ b/net/minecraft/world/entity/animal/EntityWolf.java
@@ -86,6 +86,13 @@
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class EntityWolf extends EntityTameableAnimal implements IEntityAngerable, VariantHolder<Holder<WolfVariant>> {
private static final DataWatcherObject<Boolean> DATA_INTERESTED_ID = DataWatcher.defineId(EntityWolf.class, DataWatcherRegistry.BOOLEAN);
@@ -345,8 +352,14 @@
if (this.isInvulnerableTo(worldserver, damagesource)) {
return false;
} else {
+ // CraftBukkit start
+ boolean result = super.hurtServer(worldserver, damagesource, f);
+ if (!result) {
+ return result;
+ }
+ // CraftBukkit end
this.setOrderedToSit(false);
- return super.hurtServer(worldserver, damagesource, f);
+ return result; // CraftBukkit
}
}
@@ -356,10 +369,15 @@
}
@Override
- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) {
+ public boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { // CraftBukkit - void -> boolean
if (!this.canArmorAbsorb(damagesource)) {
- super.actuallyHurt(worldserver, damagesource, f);
+ return super.actuallyHurt(worldserver, damagesource, f, event); // CraftBukkit
} else {
+ // CraftBukkit start - SPIGOT-7815: if the damage was cancelled, no need to run the wolf armor behaviour
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
ItemStack itemstack = this.getBodyArmorItem();
int i = itemstack.getDamageValue();
int j = itemstack.getMaxDamage();
@@ -371,6 +389,7 @@
}
}
+ return false; // CraftBukkit
}
private boolean canArmorAbsorb(DamageSource damagesource) {
@@ -381,7 +400,7 @@
protected void applyTamingSideEffects() {
if (this.isTame()) {
this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(40.0D);
- this.setHealth(40.0F);
+ this.setHealth(this.getMaxHealth()); // CraftBukkit - 40.0 -> getMaxHealth()
} else {
this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(8.0D);
}
@@ -404,7 +423,7 @@
FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD);
float f = foodinfo != null ? (float) foodinfo.nutrition() : 1.0F;
- this.heal(2.0F * f);
+ this.heal(2.0F * f, EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit
return EnumInteractionResult.SUCCESS;
} else {
if (item instanceof ItemDye) {
@@ -440,7 +459,9 @@
if (world instanceof WorldServer) {
WorldServer worldserver = (WorldServer) world;
+ this.forceDrops = true; // CraftBukkit
this.spawnAtLocation(worldserver, itemstack1);
+ this.forceDrops = false; // CraftBukkit
}
return EnumInteractionResult.SUCCESS;
@@ -459,7 +480,7 @@
this.setOrderedToSit(!this.isOrderedToSit());
this.jumping = false;
this.navigation.stop();
- this.setTarget((EntityLiving) null);
+ this.setTarget((EntityLiving) null, EntityTargetEvent.TargetReason.FORGOT_TARGET, true); // CraftBukkit - reason
return EnumInteractionResult.SUCCESS.withoutItem();
} else {
return enuminteractionresult;
@@ -477,7 +498,8 @@
}
private void tryToTame(EntityHuman entityhuman) {
- 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.stop();
this.setTarget((EntityLiving) null);