Paper/nms-patches/MobEffectList.patch

87 lines
4.0 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/MobEffectList.java
+++ b/net/minecraft/server/MobEffectList.java
2018-07-15 02:00:00 +02:00
@@ -8,6 +8,11 @@
import java.util.function.Supplier;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
+// CraftBukkit end
+
public class MobEffectList {
2016-02-29 22:32:46 +01:00
public static final RegistryMaterials<MinecraftKey, MobEffectList> REGISTRY = new RegistryMaterials();
2018-07-15 02:00:00 +02:00
@@ -26,7 +31,7 @@
2016-02-29 22:32:46 +01:00
}
2016-02-29 22:32:46 +01:00
public static int getId(MobEffectList mobeffectlist) {
- return MobEffectList.REGISTRY.a((Object) mobeffectlist);
+ return MobEffectList.REGISTRY.a(mobeffectlist); // CraftBukkit - decompile error
}
2018-07-15 02:00:00 +02:00
protected MobEffectList(boolean flag, int i) {
@@ -48,11 +53,11 @@
public void tick(EntityLiving entityliving, int i) {
2016-02-29 22:32:46 +01:00
if (this == MobEffects.REGENERATION) {
if (entityliving.getHealth() < entityliving.getMaxHealth()) {
- entityliving.heal(1.0F);
+ entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
}
2016-02-29 22:32:46 +01:00
} else if (this == MobEffects.POISON) {
if (entityliving.getHealth() > 1.0F) {
- entityliving.damageEntity(DamageSource.MAGIC, 1.0F);
+ entityliving.damageEntity(CraftEventFactory.POISON, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
}
2016-02-29 22:32:46 +01:00
} else if (this == MobEffects.WITHER) {
entityliving.damageEntity(DamageSource.WITHER, 1.0F);
2018-07-15 02:00:00 +02:00
@@ -60,14 +65,25 @@
2016-11-17 02:41:03 +01:00
((EntityHuman) entityliving).applyExhaustion(0.005F * (float) (i + 1));
2016-02-29 22:32:46 +01:00
} else if (this == MobEffects.SATURATION && entityliving instanceof EntityHuman) {
2015-02-26 23:41:06 +01:00
if (!entityliving.world.isClientSide) {
- ((EntityHuman) entityliving).getFoodData().eat(i + 1, 1.0F);
+ // CraftBukkit start
+ EntityHuman entityhuman = (EntityHuman) entityliving;
+ int oldFoodLevel = entityhuman.getFoodData().foodLevel;
+
+ org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, i + 1 + oldFoodLevel);
+
+ if (!event.isCancelled()) {
+ entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, 1.0F);
+ }
+
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
+ // CraftBukkit end
}
2018-07-22 04:00:00 +02:00
} else if ((this != MobEffects.HEAL || entityliving.cp()) && (this != MobEffects.HARM || !entityliving.cp())) {
if (this == MobEffects.HARM && !entityliving.cp() || this == MobEffects.HEAL && entityliving.cp()) {
entityliving.damageEntity(DamageSource.MAGIC, (float) (6 << i));
}
} else {
- entityliving.heal((float) Math.max(4 << i, 0));
+ entityliving.heal((float) Math.max(4 << i, 0), RegainReason.MAGIC); // CraftBukkit
}
}
2018-07-15 02:00:00 +02:00
@@ -88,7 +104,7 @@
}
} else {
j = (int) (d0 * (double) (4 << i) + 0.5D);
- entityliving.heal((float) j);
+ entityliving.heal((float) j, RegainReason.MAGIC); // CraftBukkit
}
}
2018-07-15 02:00:00 +02:00
@@ -217,6 +233,11 @@
a(28, "slow_falling", (new MobEffectList(false, 16773073)).b(8, 0).l());
a(29, "conduit_power", (new MobEffectList(false, 1950417)).b(9, 0).l());
a(30, "dolphins_grace", (new MobEffectList(false, 8954814)).b(10, 0).l());
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
2016-06-09 03:43:49 +02:00
+ for (Object effect : REGISTRY) {
+ org.bukkit.potion.PotionEffectType.registerPotionEffectType(new org.bukkit.craftbukkit.potion.CraftPotionEffectType((MobEffectList) effect));
2016-02-29 22:32:46 +01:00
+ }
+ // CraftBukkit end
}
2018-07-15 02:00:00 +02:00
private static void a(int i, String s, MobEffectList mobeffectlist) {