PotionEffect .java

net.minecraft.potion.PotionEffect (class): members: readCustomPotionEffectFromNBT, writeCustomPotionEffectToNBT, getIsPotionDurationMax, setSplashPotion.

net.minecraft.potionclass256 linescommon6.6 KB

API Surface (17)

void combine(PotionEffect other)
int getPotionID()
int getDuration()
int getAmplifier()
void setSplashPotion(boolean splashPotion)
boolean getIsAmbient()
boolean getIsShowParticles()
boolean onUpdate(EntityLivingBase entityIn)
void performEffect(EntityLivingBase entityIn)
String getEffectName()
int hashCode()
String toString()
boolean equals(Object p_equals_1_)
NBTTagCompound writeCustomPotionEffectToNBT(NBTTagCompound nbt)
PotionEffect readCustomPotionEffectFromNBT(NBTTagCompound nbt)
void setPotionDurationMax(boolean maxDuration)
boolean getIsPotionDurationMax()

Fields & Constants (8)

LOGGER
potionID
duration
amplifier
isSplashPotion
isAmbient
isPotionDurationMax
showParticles

String literals (7)

", Duration: "
", Splash: true"
", Particles: false"
"Amplifier"
"Duration"
"Ambient"
"ShowParticles"

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

PotionEffect.java256 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.potion;
2
3
import net.minecraft.entity.EntityLivingBase;
4
import net.minecraft.nbt.NBTTagCompound;
5
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
7
8
public class PotionEffect
9
{
10
    private static final Logger LOGGER = LogManager.getLogger();
11
12
    /** ID value of the potion this effect matches. */
13
    private int potionID;
14
15
    /** The duration of the potion effect */
16
    private int duration;
17
18
    /** The amplifier of the potion effect */
19
    private int amplifier;
20
21
    /** Whether the potion is a splash potion */
22
    private boolean isSplashPotion;
23
24
    /** Whether the potion effect came from a beacon */
25
    private boolean isAmbient;
26
27
    /** True if potion effect duration is at maximum, false otherwise. */
28
    private boolean isPotionDurationMax;
29
    private boolean showParticles;
30
31
    public PotionEffect(int id, int effectDuration)
32
    {
33
        this(id, effectDuration, 0);
34
    }
35
36
    public PotionEffect(int id, int effectDuration, int effectAmplifier)
37
    {
38
        this(id, effectDuration, effectAmplifier, false, true);
39
    }
40
41
    public PotionEffect(int id, int effectDuration, int effectAmplifier, boolean ambient, boolean showParticles)
42
    {
43
        this.potionID = id;
44
        this.duration = effectDuration;
45
        this.amplifier = effectAmplifier;
46
        this.isAmbient = ambient;
47
        this.showParticles = showParticles;
48
    }
49
50
    public PotionEffect(PotionEffect other)
51
    {
52
        this.potionID = other.potionID;
53
        this.duration = other.duration;
54
        this.amplifier = other.amplifier;
55
        this.isAmbient = other.isAmbient;
56
        this.showParticles = other.showParticles;
57
    }
58
59
    /**
60
     * merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied
61
     * potion effect is assumed to be greater.
62
     */
63
    public void combine(PotionEffect other)
64
    {
65
        if (this.potionID != other.potionID)
66
        {
67
            LOGGER.warn("This method should only be called for matching effects!");
68
        }
69
70
        if (other.amplifier > this.amplifier)
71
        {
72
            this.amplifier = other.amplifier;
73
            this.duration = other.duration;
74
        }
75
        else if (other.amplifier == this.amplifier && this.duration < other.duration)
76
        {
77
            this.duration = other.duration;
78
        }
79
        else if (!other.isAmbient && this.isAmbient)
80
        {
81
            this.isAmbient = other.isAmbient;
82
        }
83
84
        this.showParticles = other.showParticles;
85
    }
86
87
    /**
88
     * Retrieve the ID of the potion this effect matches.
89
     */
90
    public int getPotionID()
91
    {
92
        return this.potionID;
93
    }
94
95
    public int getDuration()
96
    {
97
        return this.duration;
98
    }
99
100
    public int getAmplifier()
101
    {
102
        return this.amplifier;
103
    }
104
105
    /**
106
     * Set whether this potion is a splash potion.
107
     */
108
    public void setSplashPotion(boolean splashPotion)
109
    {
110
        this.isSplashPotion = splashPotion;
111
    }
112
113
    /**
114
     * Gets whether this potion effect originated from a beacon
115
     */
116
    public boolean getIsAmbient()
117
    {
118
        return this.isAmbient;
119
    }
120
121
    public boolean getIsShowParticles()
122
    {
123
        return this.showParticles;
124
    }
125
126
    public boolean onUpdate(EntityLivingBase entityIn)
127
    {
128
        if (this.duration > 0)
129
        {
130
            if (Potion.potionTypes[this.potionID].isReady(this.duration, this.amplifier))
131
            {
132
                this.performEffect(entityIn);
133
            }
134
135
            this.deincrementDuration();
136
        }
137
138
        return this.duration > 0;
139
    }
140
141
    private int deincrementDuration()
142
    {
143
        return --this.duration;
144
    }
145
146
    public void performEffect(EntityLivingBase entityIn)
147
    {
148
        if (this.duration > 0)
149
        {
150
            Potion.potionTypes[this.potionID].performEffect(entityIn, this.amplifier);
151
        }
152
    }
153
154
    public String getEffectName()
155
    {
156
        return Potion.potionTypes[this.potionID].getName();
157
    }
158
159
    public int hashCode()
160
    {
161
        return this.potionID;
162
    }
163
164
    public String toString()
165
    {
166
        String s = "";
167
168
        if (this.getAmplifier() > 0)
169
        {
170
            s = this.getEffectName() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration();
171
        }
172
        else
173
        {
174
            s = this.getEffectName() + ", Duration: " + this.getDuration();
175
        }
176
177
        if (this.isSplashPotion)
178
        {
179
            s = s + ", Splash: true";
180
        }
181
182
        if (!this.showParticles)
183
        {
184
            s = s + ", Particles: false";
185
        }
186
187
        return Potion.potionTypes[this.potionID].isUsable() ? "(" + s + ")" : s;
188
    }
189
190
    public boolean equals(Object p_equals_1_)
191
    {
192
        if (!(p_equals_1_ instanceof PotionEffect))
193
        {
194
            return false;
195
        }
196
        else
197
        {
198
            PotionEffect potioneffect = (PotionEffect)p_equals_1_;
199
            return this.potionID == potioneffect.potionID && this.amplifier == potioneffect.amplifier && this.duration == potioneffect.duration && this.isSplashPotion == potioneffect.isSplashPotion && this.isAmbient == potioneffect.isAmbient;
200
        }
201
    }
202
203
    /**
204
     * Write a custom potion effect to a potion item's NBT data.
205
     */
206
    public NBTTagCompound writeCustomPotionEffectToNBT(NBTTagCompound nbt)
207
    {
208
        nbt.setByte("Id", (byte)this.getPotionID());
209
        nbt.setByte("Amplifier", (byte)this.getAmplifier());
210
        nbt.setInteger("Duration", this.getDuration());
211
        nbt.setBoolean("Ambient", this.getIsAmbient());
212
        nbt.setBoolean("ShowParticles", this.getIsShowParticles());
213
        return nbt;
214
    }
215
216
    /**
217
     * Read a custom potion effect from a potion item's NBT data.
218
     */
219
    public static PotionEffect readCustomPotionEffectFromNBT(NBTTagCompound nbt)
220
    {
221
        int i = nbt.getByte("Id");
222
223
        if (i >= 0 && i < Potion.potionTypes.length && Potion.potionTypes[i] != null)
224
        {
225
            int j = nbt.getByte("Amplifier");
226
            int k = nbt.getInteger("Duration");
227
            boolean flag = nbt.getBoolean("Ambient");
228
            boolean flag1 = true;
229
230
            if (nbt.hasKey("ShowParticles", 1))
231
            {
232
                flag1 = nbt.getBoolean("ShowParticles");
233
            }
234
235
            return new PotionEffect(i, k, j, flag, flag1);
236
        }
237
        else
238
        {
239
            return null;
240
        }
241
    }
242
243
    /**
244
     * Toggle the isPotionDurationMax field.
245
     */
246
    public void setPotionDurationMax(boolean maxDuration)
247
    {
248
        this.isPotionDurationMax = maxDuration;
249
    }
250
251
    public boolean getIsPotionDurationMax()
252
    {
253
        return this.isPotionDurationMax;
254
    }
255
}
256

Deobfuscated MCP 1.8.9 source of PotionEffect from Marcelektro/MavenMCP-1.8.9 (net/minecraft/potion/PotionEffect.java), stored verbatim.