the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.effect.h"
3
4void MobEffectInstance::_init(int id, int duration, int amplifier)
5{
6 this->id = id;
7 this->duration = duration;
8 this->amplifier = amplifier;
9
10 splash = false;
11 ambient = false;
12 noCounter = false;
13}
14
15MobEffectInstance::MobEffectInstance(int id)
16{
17 _init(id, 0, 0);
18}
19
20MobEffectInstance::MobEffectInstance(int id, int duration)
21{
22 _init(id, duration, 0);
23}
24
25MobEffectInstance::MobEffectInstance(int id, int duration, int amplifier)
26{
27 _init(id,duration,amplifier);
28}
29
30MobEffectInstance::MobEffectInstance(int id, int duration, int amplifier, bool ambient)
31{
32 _init(id,duration,amplifier);
33 this->ambient = ambient;
34}
35
36MobEffectInstance::MobEffectInstance(MobEffectInstance *copy)
37{
38 this->id = copy->id;
39 this->duration = copy->duration;
40 this->amplifier = copy->amplifier;
41 this->splash = copy->splash;
42 this->ambient = copy->ambient;
43 this->noCounter = copy->noCounter;
44}
45
46void MobEffectInstance::update(MobEffectInstance *takeOver)
47{
48 if (id != takeOver->id)
49 {
50 app.DebugPrintf("This method should only be called for matching effects!");
51 }
52 if (takeOver->amplifier > amplifier)
53 {
54 amplifier = takeOver->amplifier;
55 duration = takeOver->duration;
56 }
57 else if (takeOver->amplifier == amplifier && duration < takeOver->duration)
58 {
59 duration = takeOver->duration;
60 }
61 else if (!takeOver->ambient && ambient)
62 {
63 ambient = takeOver->ambient;
64 }
65}
66
67int MobEffectInstance::getId()
68{
69 return id;
70}
71
72int MobEffectInstance::getDuration()
73{
74 return duration;
75}
76
77int MobEffectInstance::getAmplifier()
78{
79 return amplifier;
80}
81
82bool MobEffectInstance::isSplash()
83{
84 return splash;
85}
86
87void MobEffectInstance::setSplash(bool splash)
88{
89 this->splash = splash;
90}
91
92bool MobEffectInstance::isAmbient()
93{
94 return ambient;
95}
96
97/**
98* Runs the effect on a Mob target.
99*
100* @param target
101* @return True if the effect is still active.
102*/
103bool MobEffectInstance::tick(shared_ptr<LivingEntity> target)
104{
105 if (duration > 0)
106 {
107 if (MobEffect::effects[id]->isDurationEffectTick(duration, amplifier))
108 {
109 applyEffect(target);
110 }
111 tickDownDuration();
112 }
113 return duration > 0;
114}
115
116int MobEffectInstance::tickDownDuration()
117{
118 return --duration;
119}
120
121void MobEffectInstance::applyEffect(shared_ptr<LivingEntity> mob)
122{
123 if (duration > 0)
124 {
125 MobEffect::effects[id]->applyEffectTick(mob, amplifier);
126 }
127}
128
129int MobEffectInstance::getDescriptionId()
130{
131 return MobEffect::effects[id]->getDescriptionId();
132}
133
134// 4J Added
135int MobEffectInstance::getPostfixDescriptionId()
136{
137 return MobEffect::effects[id]->getPostfixDescriptionId();
138}
139
140int MobEffectInstance::hashCode()
141{
142 //return id;
143
144 // 4J Stu - Changed this to return a value that represents id, amp and duration
145 return (id & 0xff) | ( (amplifier & 0xff) << 8) | ( (duration & 0xffff) << 16);
146}
147
148wstring MobEffectInstance::toString()
149{
150 wstring result = L"MobEffectInstance::toString - NON IMPLEMENTED OR LOCALISED FUNCTION";
151 //wstring result = "";
152 //if (getAmplifier() > 0)
153 //{
154 // result = getDescriptionId() + " x " + (getAmplifier() + 1) + ", Duration: " + getDuration();
155 //}
156 //else
157 //{
158 // result = getDescriptionId() + ", Duration: " + getDuration();
159 //}
160 //if (MobEffect.effects[id].isDisabled())
161 //{
162 // return "(" + result + ")";
163 //}
164 return result;
165}
166
167// Was bool equals(Object obj)
168bool MobEffectInstance::equals(MobEffectInstance *instance)
169{
170 return id == instance->id && amplifier == instance->amplifier && duration == instance->duration && splash == instance->splash && ambient == instance->ambient;
171}
172
173CompoundTag *MobEffectInstance::save(CompoundTag *tag)
174{
175 tag->putByte(L"Id", (byte) getId());
176 tag->putByte(L"Amplifier", (byte) getAmplifier());
177 tag->putInt(L"Duration", getDuration());
178 tag->putBoolean(L"Ambient", isAmbient());
179 return tag;
180}
181
182MobEffectInstance *MobEffectInstance::load(CompoundTag *tag)
183{
184 int id = tag->getByte(L"Id");
185 int amplifier = tag->getByte(L"Amplifier");
186 int duration = tag->getInt(L"Duration");
187 boolean ambient = tag->getBoolean(L"Ambient");
188 return new MobEffectInstance(id, duration, amplifier, ambient);
189}
190
191void MobEffectInstance::setNoCounter(bool noCounter)
192{
193 this->noCounter = noCounter;
194}
195
196bool MobEffectInstance::isNoCounter()
197{
198 return noCounter;
199}