forked from Luohuayu/CatServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPotion.java.patch
175 lines (170 loc) · 7.33 KB
/
Potion.java.patch
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
--- ../src-base/minecraft/net/minecraft/potion/Potion.java
+++ ../src-work/minecraft/net/minecraft/potion/Potion.java
@@ -13,7 +13,9 @@
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.MobEffects;
+import net.minecraft.network.play.server.SPacketUpdateHealth;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
@@ -21,16 +23,18 @@
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
-public class Potion
+public class Potion extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<Potion>
{
- public static final RegistryNamespaced<ResourceLocation, Potion> REGISTRY = new RegistryNamespaced<ResourceLocation, Potion>();
+ public static final RegistryNamespaced<ResourceLocation, Potion> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(Potion.class);
private final Map<IAttribute, AttributeModifier> attributeModifierMap = Maps.<IAttribute, AttributeModifier>newHashMap();
private final boolean isBadEffect;
private final int liquidColor;
private String name = "";
private int statusIconIndex = -1;
- private double effectiveness;
+ public double effectiveness;
private boolean beneficial;
@Nullable
@@ -78,14 +82,14 @@
{
if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth())
{
- entityLivingBaseIn.heal(1.0F);
+ entityLivingBaseIn.heal(1.0F, RegainReason.MAGIC_REGEN);
}
}
else if (this == MobEffects.POISON)
{
if (entityLivingBaseIn.getHealth() > 1.0F)
{
- entityLivingBaseIn.attackEntityFrom(DamageSource.MAGIC, 1.0F);
+ entityLivingBaseIn.attackEntityFrom(CraftEventFactory.POISON, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
}
}
else if (this == MobEffects.WITHER)
@@ -100,7 +104,19 @@
{
if (!entityLivingBaseIn.world.isRemote)
{
- ((EntityPlayer)entityLivingBaseIn).getFoodStats().addStats(amplifier + 1, 1.0F);
+ // ((EntityPlayer)entityLivingBaseIn).getFoodStats().addStats(amplifier + 1, 1.0F);
+ // CraftBukkit start
+ EntityPlayer entityhuman = (EntityPlayer) entityLivingBaseIn;
+ int oldFoodLevel = entityhuman.getFoodStats().foodLevel;
+
+ org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, amplifier + 1 + oldFoodLevel);
+
+ if (!event.isCancelled()) {
+ entityhuman.getFoodStats().addStats(event.getFoodLevel() - oldFoodLevel, 1.0F);
+ }
+
+ ((EntityPlayerMP) entityhuman).connection.sendPacket(new SPacketUpdateHealth(((EntityPlayerMP) entityhuman).getBukkitEntity().getScaledHealth(), entityhuman.getFoodStats().foodLevel, entityhuman.getFoodStats().foodSaturationLevel));
+ // CraftBukkit end
}
}
else if ((this != MobEffects.INSTANT_HEALTH || entityLivingBaseIn.isEntityUndead()) && (this != MobEffects.INSTANT_DAMAGE || !entityLivingBaseIn.isEntityUndead()))
@@ -112,7 +128,7 @@
}
else
{
- entityLivingBaseIn.heal((float)Math.max(4 << amplifier, 0));
+ entityLivingBaseIn.heal((float)Math.max(4 << amplifier, 0), RegainReason.MAGIC);
}
}
@@ -222,7 +238,6 @@
return this.statusIconIndex;
}
- @SideOnly(Side.CLIENT)
public boolean isBadEffect()
{
return this.isBadEffect;
@@ -293,7 +308,85 @@
return modifier.getAmount() * (double)(amplifier + 1);
}
+ /* ======================================== FORGE START =====================================*/
+
+ /**
+ * If the Potion effect should be displayed in the players inventory
+ * @param effect the active PotionEffect
+ * @return true to display it (default), false to hide it.
+ */
+ public boolean shouldRender(PotionEffect effect) { return true; }
+
+ /**
+ * If the standard PotionEffect text (name and duration) should be drawn when this potion is active.
+ * @param effect the active PotionEffect
+ * @return true to draw the standard text
+ */
+ public boolean shouldRenderInvText(PotionEffect effect)
+ {
+ return true;
+ }
+
+ /**
+ * If the Potion effect should be displayed in the player's ingame HUD
+ * @param effect the active PotionEffect
+ * @return true to display it (default), false to hide it.
+ */
+ public boolean shouldRenderHUD(PotionEffect effect)
+ {
+ return true;
+ }
+
+ /**
+ * Called to draw the this Potion onto the player's inventory when it's active.
+ * This can be used to e.g. render Potion icons from your own texture.
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param effect the active PotionEffect
+ * @param mc the Minecraft instance, for convenience
+ */
@SideOnly(Side.CLIENT)
+ public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc) { }
+
+ /**
+ * Called to draw the this Potion onto the player's ingame HUD when it's active.
+ * This can be used to e.g. render Potion icons from your own texture.
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param effect the active PotionEffect
+ * @param mc the Minecraft instance, for convenience
+ * @param alpha the alpha value, blinks when the potion is about to run out
+ */
+ @SideOnly(Side.CLIENT)
+ public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha) { }
+
+ /**
+ * Get a fresh list of items that can cure this Potion.
+ * All new PotionEffects created from this Potion will call this to initialize the default curative items
+ * @see PotionEffect#getCurativeItems
+ * @return A list of items that can cure this Potion
+ */
+ public java.util.List<net.minecraft.item.ItemStack> getCurativeItems()
+ {
+ java.util.ArrayList<net.minecraft.item.ItemStack> ret = new java.util.ArrayList<net.minecraft.item.ItemStack>();
+ ret.add(new net.minecraft.item.ItemStack(net.minecraft.init.Items.MILK_BUCKET));
+ return ret;
+ }
+
+ /**
+ * Used for determining {@code PotionEffect} sort order in GUIs.
+ * Defaults to the {@code PotionEffect}'s liquid color.
+ * @param potionEffect the {@code PotionEffect} instance containing the potion
+ * @return a value used to sort {@code PotionEffect}s in GUIs
+ */
+ public int getGuiSortColor(PotionEffect potionEffect)
+ {
+ return this.getLiquidColor();
+ }
+
+ /* ======================================== FORGE END =====================================*/
+
+ @SideOnly(Side.CLIENT)
public boolean isBeneficial()
{
return this.beneficial;