summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/MobEffect.java
blob: 726a447a692b6602f9a4eea654f18c079fba331c (plain)
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
package net.minecraft.server;

public class MobEffect {

    private int effectId;
    private int duration;
    private int amplification;
    private boolean splash;
    private boolean ambient;

    public MobEffect(int i, int j) {
        this(i, j, 0);
    }

    public MobEffect(int i, int j, int k) {
        this(i, j, k, false);
    }

    public MobEffect(int i, int j, int k, boolean flag) {
        this.effectId = i;
        this.duration = j;
        this.amplification = k;
        this.ambient = flag;
    }

    public MobEffect(MobEffect mobeffect) {
        this.effectId = mobeffect.effectId;
        this.duration = mobeffect.duration;
        this.amplification = mobeffect.amplification;
    }

    public void a(MobEffect mobeffect) {
        if (this.effectId != mobeffect.effectId) {
            System.err.println("This method should only be called for matching effects!");
        }

        if (mobeffect.amplification > this.amplification) {
            this.amplification = mobeffect.amplification;
            this.duration = mobeffect.duration;
        } else if (mobeffect.amplification == this.amplification && this.duration < mobeffect.duration) {
            this.duration = mobeffect.duration;
        } else if (!mobeffect.ambient && this.ambient) {
            this.ambient = mobeffect.ambient;
        }
    }

    public int getEffectId() {
        return this.effectId;
    }

    public int getDuration() {
        return this.duration;
    }

    public int getAmplifier() {
        return this.amplification;
    }

    public boolean isSplash() {
        return this.splash;
    }

    public void setSplash(boolean flag) {
        this.splash = flag;
    }

    public boolean isAmbient() {
        return this.ambient;
    }

    public boolean tick(EntityLiving entityliving) {
        if (this.duration > 0) {
            if (MobEffectList.byId[this.effectId].a(this.duration, this.amplification)) {
                this.b(entityliving);
            }

            this.h();
        }

        return this.duration > 0;
    }

    private int h() {
        return --this.duration;
    }

    public void b(EntityLiving entityliving) {
        if (this.duration > 0) {
            MobEffectList.byId[this.effectId].tick(entityliving, this.amplification);
        }
    }

    public String f() {
        return MobEffectList.byId[this.effectId].a();
    }

    public int hashCode() {
        return this.effectId;
    }

    public String toString() {
        String s = "";

        if (this.getAmplifier() > 0) {
            s = this.f() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration();
        } else {
            s = this.f() + ", Duration: " + this.getDuration();
        }

        if (this.splash) {
            s = s + ", Splash: true";
        }

        return MobEffectList.byId[this.effectId].i() ? "(" + s + ")" : s;
    }

    public boolean equals(Object object) {
        if (!(object instanceof MobEffect)) {
            return false;
        } else {
            MobEffect mobeffect = (MobEffect) object;

            return this.effectId == mobeffect.effectId && this.amplification == mobeffect.amplification && this.duration == mobeffect.duration && this.splash == mobeffect.splash && this.ambient == mobeffect.ambient;
        }
    }

    public NBTTagCompound a(NBTTagCompound nbttagcompound) {
        nbttagcompound.setByte("Id", (byte) this.getEffectId());
        nbttagcompound.setByte("Amplifier", (byte) this.getAmplifier());
        nbttagcompound.setInt("Duration", this.getDuration());
        nbttagcompound.setBoolean("Ambient", this.isAmbient());
        return nbttagcompound;
    }

    public static MobEffect b(NBTTagCompound nbttagcompound) {
        byte b0 = nbttagcompound.getByte("Id");
        byte b1 = nbttagcompound.getByte("Amplifier");
        int i = nbttagcompound.getInt("Duration");
        boolean flag = nbttagcompound.getBoolean("Ambient");

        return new MobEffect(b0, i, b1, flag);
    }
}