1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
--- a/net/minecraft/server/MobEffectList.java
+++ b/net/minecraft/server/MobEffectList.java
@@ -8,6 +8,11 @@
import java.util.function.Supplier;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
+// CraftBukkit end
+
public class MobEffectList {
private final Map<IAttribute, AttributeModifier> a = Maps.newHashMap();
@@ -25,7 +30,7 @@
}
public static int getId(MobEffectList mobeffectlist) {
- return IRegistry.MOB_EFFECT.a((Object) mobeffectlist);
+ return IRegistry.MOB_EFFECT.a(mobeffectlist); // CraftBukkit - decompile error
}
protected MobEffectList(boolean flag, int i) {
@@ -47,11 +52,11 @@
public void tick(EntityLiving entityliving, int i) {
if (this == MobEffects.REGENERATION) {
if (entityliving.getHealth() < entityliving.getMaxHealth()) {
- entityliving.heal(1.0F);
+ entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
}
} 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
}
} else if (this == MobEffects.WITHER) {
entityliving.damageEntity(DamageSource.WITHER, 1.0F);
@@ -59,14 +64,25 @@
((EntityHuman) entityliving).applyExhaustion(0.005F * (float) (i + 1));
} else if (this == MobEffects.SATURATION && entityliving instanceof EntityHuman) {
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
}
} 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
}
}
@@ -87,7 +103,7 @@
}
} else {
j = (int) (d0 * (double) (4 << i) + 0.5D);
- entityliving.heal((float) j);
+ entityliving.heal((float) j, RegainReason.MAGIC); // CraftBukkit
}
}
@@ -216,6 +232,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());
+ // CraftBukkit start
+ for (Object effect : IRegistry.MOB_EFFECT) {
+ org.bukkit.potion.PotionEffectType.registerPotionEffectType(new org.bukkit.craftbukkit.potion.CraftPotionEffectType((MobEffectList) effect));
+ }
+ // CraftBukkit end
}
private static void a(int i, String s, MobEffectList mobeffectlist) {
|