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.entity.ai.attributes.h"
3#include "net.minecraft.world.entity.player.h"
4#include "net.minecraft.world.entity.monster.h"
5#include "net.minecraft.world.entity.h"
6#include "net.minecraft.world.level.h"
7#include "net.minecraft.world.damagesource.h"
8#include "net.minecraft.world.food.h"
9#include "net.minecraft.world.effect.h"
10#include "SharedConstants.h"
11
12MobEffect *MobEffect::effects[NUM_EFFECTS];
13
14MobEffect *MobEffect::voidEffect;
15MobEffect *MobEffect::movementSpeed;
16MobEffect *MobEffect::movementSlowdown;
17MobEffect *MobEffect::digSpeed;
18MobEffect *MobEffect::digSlowdown;
19MobEffect *MobEffect::damageBoost;
20MobEffect *MobEffect::heal;
21MobEffect *MobEffect::harm;
22MobEffect *MobEffect::jump;
23MobEffect *MobEffect::confusion;
24MobEffect *MobEffect::regeneration;
25MobEffect *MobEffect::damageResistance;
26MobEffect *MobEffect::fireResistance;
27MobEffect *MobEffect::waterBreathing;
28MobEffect *MobEffect::invisibility;
29MobEffect *MobEffect::blindness;
30MobEffect *MobEffect::nightVision;
31MobEffect *MobEffect::hunger;
32MobEffect *MobEffect::weakness;
33MobEffect *MobEffect::poison;
34MobEffect *MobEffect::wither;
35MobEffect *MobEffect::healthBoost;
36MobEffect *MobEffect::absorption;
37MobEffect *MobEffect::saturation;
38MobEffect *MobEffect::reserved_24;
39MobEffect *MobEffect::reserved_25;
40MobEffect *MobEffect::reserved_26;
41MobEffect *MobEffect::reserved_27;
42MobEffect *MobEffect::reserved_28;
43MobEffect *MobEffect::reserved_29;
44MobEffect *MobEffect::reserved_30;
45MobEffect *MobEffect::reserved_31;
46
47void MobEffect::staticCtor()
48{
49 voidEffect = NULL;
50 movementSpeed = (new MobEffect(1, false, eMinecraftColour_Effect_MovementSpeed)) ->setDescriptionId(IDS_POTION_MOVESPEED) ->setPostfixDescriptionId(IDS_POTION_MOVESPEED_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Speed)->addAttributeModifier(SharedMonsterAttributes::MOVEMENT_SPEED, eModifierId_POTION_MOVESPEED, 0.2f, AttributeModifier::OPERATION_MULTIPLY_TOTAL); //setIcon(0, 0);
51 movementSlowdown = (new MobEffect(2, true, eMinecraftColour_Effect_MovementSlowDown)) ->setDescriptionId(IDS_POTION_MOVESLOWDOWN) ->setPostfixDescriptionId(IDS_POTION_MOVESLOWDOWN_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Slowness)->addAttributeModifier(SharedMonsterAttributes::MOVEMENT_SPEED, eModifierId_POTION_MOVESLOWDOWN, -0.15f, AttributeModifier::OPERATION_MULTIPLY_TOTAL); //->setIcon(1, 0);
52 digSpeed = (new MobEffect(3, false, eMinecraftColour_Effect_DigSpeed)) ->setDescriptionId(IDS_POTION_DIGSPEED) ->setPostfixDescriptionId(IDS_POTION_DIGSPEED_POSTFIX)->setDurationModifier(1.5)->setIcon(MobEffect::e_MobEffectIcon_Haste); //->setIcon(2, 0);
53 digSlowdown = (new MobEffect(4, true, eMinecraftColour_Effect_DigSlowdown)) ->setDescriptionId(IDS_POTION_DIGSLOWDOWN) ->setPostfixDescriptionId(IDS_POTION_DIGSLOWDOWN_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_MiningFatigue); //->setIcon(3, 0);
54 damageBoost = (new AttackDamageMobEffect(5, false, eMinecraftColour_Effect_DamageBoost)) ->setDescriptionId(IDS_POTION_DAMAGEBOOST) ->setPostfixDescriptionId(IDS_POTION_DAMAGEBOOST_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Strength)->addAttributeModifier(SharedMonsterAttributes::ATTACK_DAMAGE, eModifierId_POTION_DAMAGEBOOST, 3, AttributeModifier::OPERATION_MULTIPLY_TOTAL); //->setIcon(4, 0);
55 heal = (new InstantenousMobEffect(6, false, eMinecraftColour_Effect_Heal)) ->setDescriptionId(IDS_POTION_HEAL) ->setPostfixDescriptionId(IDS_POTION_HEAL_POSTFIX);
56 harm = (new InstantenousMobEffect(7, true, eMinecraftColour_Effect_Harm)) ->setDescriptionId(IDS_POTION_HARM) ->setPostfixDescriptionId(IDS_POTION_HARM_POSTFIX);
57 jump = (new MobEffect(8, false, eMinecraftColour_Effect_Jump)) ->setDescriptionId(IDS_POTION_JUMP) ->setPostfixDescriptionId(IDS_POTION_JUMP_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_JumpBoost); //->setIcon(2, 1);
58 confusion = (new MobEffect(9, true, eMinecraftColour_Effect_Confusion)) ->setDescriptionId(IDS_POTION_CONFUSION) ->setPostfixDescriptionId(IDS_POTION_CONFUSION_POSTFIX)->setDurationModifier(.25)->setIcon(MobEffect::e_MobEffectIcon_Nausea); //->setIcon(3, 1);
59 regeneration = (new MobEffect(10, false, eMinecraftColour_Effect_Regeneration)) ->setDescriptionId(IDS_POTION_REGENERATION) ->setPostfixDescriptionId(IDS_POTION_REGENERATION_POSTFIX)->setDurationModifier(.25)->setIcon(MobEffect::e_MobEffectIcon_Regeneration); //->setIcon(7, 0);
60 damageResistance = (new MobEffect(11, false, eMinecraftColour_Effect_DamageResistance)) ->setDescriptionId(IDS_POTION_RESISTANCE) ->setPostfixDescriptionId(IDS_POTION_RESISTANCE_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Resistance); //->setIcon(6, 1);
61 fireResistance = (new MobEffect(12, false, eMinecraftColour_Effect_FireResistance)) ->setDescriptionId(IDS_POTION_FIRERESISTANCE) ->setPostfixDescriptionId(IDS_POTION_FIRERESISTANCE_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_FireResistance); //->setIcon(7, 1);
62 waterBreathing = (new MobEffect(13, false, eMinecraftColour_Effect_WaterBreathing)) ->setDescriptionId(IDS_POTION_WATERBREATHING) ->setPostfixDescriptionId(IDS_POTION_WATERBREATHING_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_WaterBreathing); //->setIcon(0, 2);
63 invisibility = (new MobEffect(14, false, eMinecraftColour_Effect_Invisiblity)) ->setDescriptionId(IDS_POTION_INVISIBILITY) ->setPostfixDescriptionId(IDS_POTION_INVISIBILITY_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Invisiblity); //->setIcon(0, 1);
64 blindness = (new MobEffect(15, true, eMinecraftColour_Effect_Blindness)) ->setDescriptionId(IDS_POTION_BLINDNESS) ->setPostfixDescriptionId(IDS_POTION_BLINDNESS_POSTFIX)->setDurationModifier(.25)->setIcon(MobEffect::e_MobEffectIcon_Blindness); //->setIcon(5, 1);
65 nightVision = (new MobEffect(16, false, eMinecraftColour_Effect_NightVision)) ->setDescriptionId(IDS_POTION_NIGHTVISION) ->setPostfixDescriptionId(IDS_POTION_NIGHTVISION_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_NightVision); //->setIcon(4, 1);
66 hunger = (new MobEffect(17, true, eMinecraftColour_Effect_Hunger)) ->setDescriptionId(IDS_POTION_HUNGER) ->setPostfixDescriptionId(IDS_POTION_HUNGER_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Hunger); //->setIcon(1, 1);
67 weakness = (new AttackDamageMobEffect(18, true, eMinecraftColour_Effect_Weakness)) ->setDescriptionId(IDS_POTION_WEAKNESS) ->setPostfixDescriptionId(IDS_POTION_WEAKNESS_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Weakness)->addAttributeModifier(SharedMonsterAttributes::ATTACK_DAMAGE, eModifierId_POTION_WEAKNESS, 2, AttributeModifier::OPERATION_ADDITION); //->setIcon(5, 0);
68 poison = (new MobEffect(19, true, eMinecraftColour_Effect_Poison)) ->setDescriptionId(IDS_POTION_POISON) ->setPostfixDescriptionId(IDS_POTION_POISON_POSTFIX)->setDurationModifier(.25)->setIcon(MobEffect::e_MobEffectIcon_Poison); //->setIcon(6, 0);
69 wither = (new MobEffect(20, true, eMinecraftColour_Effect_Wither)) ->setDescriptionId(IDS_POTION_WITHER) ->setPostfixDescriptionId(IDS_POTION_WITHER_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Wither)->setDurationModifier(.25);
70 healthBoost = (new HealthBoostMobEffect(21, false, eMinecraftColour_Effect_HealthBoost)) ->setDescriptionId(IDS_POTION_HEALTHBOOST) ->setPostfixDescriptionId(IDS_POTION_HEALTHBOOST_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_HealthBoost)->addAttributeModifier(SharedMonsterAttributes::MAX_HEALTH, eModifierId_POTION_HEALTHBOOST, 4, AttributeModifier::OPERATION_ADDITION);
71 absorption = (new AbsoptionMobEffect(22, false, eMinecraftColour_Effect_Absoprtion)) ->setDescriptionId(IDS_POTION_ABSORPTION) ->setPostfixDescriptionId(IDS_POTION_ABSORPTION_POSTFIX)->setIcon(MobEffect::e_MobEffectIcon_Absorption);
72 saturation = (new InstantenousMobEffect(23, false, eMinecraftColour_Effect_Saturation)) ->setDescriptionId(IDS_POTION_SATURATION) ->setPostfixDescriptionId(IDS_POTION_SATURATION_POSTFIX);
73 reserved_24 = NULL;
74 reserved_25 = NULL;
75 reserved_26 = NULL;
76 reserved_27 = NULL;
77 reserved_28 = NULL;
78 reserved_29 = NULL;
79 reserved_30 = NULL;
80 reserved_31 = NULL;
81}
82
83MobEffect::MobEffect(int id, bool isHarmful, eMinecraftColour color) : id(id), _isHarmful(isHarmful), color(color)
84{
85 descriptionId = -1;
86 m_postfixDescriptionId = -1;
87 icon = e_MobEffectIcon_None;
88 _isDisabled = false;
89
90 effects[id] = this;
91
92 if (isHarmful)
93 {
94 durationModifier = .5;
95 }
96 else
97 {
98 durationModifier = 1.0;
99 }
100}
101
102// 4J Removed as using different value for icon
103//MobEffect *MobEffect::setIcon(int xPos, int yPos)
104//{
105// icon = xPos + yPos * 8;
106// return this;
107//}
108
109MobEffect *MobEffect::setIcon(EMobEffectIcon icon)
110{
111 this->icon = icon;
112 return this;
113}
114
115int MobEffect::getId()
116{
117 return id;
118}
119
120/**
121* This method should perform periodic updates on the player. Mainly used
122* for regeneration effects and the like. Other effects, such as blindness,
123* are in effect for the whole duration of the effect.
124*
125* @param mob
126* @param amplification
127*/
128void MobEffect::applyEffectTick(shared_ptr<LivingEntity> mob, int amplification)
129{
130 // Maybe move this to separate class implementations in the future?
131 if (id == regeneration->id)
132 {
133 if (mob->getHealth() < mob->getMaxHealth())
134 {
135 mob->heal(1);
136 }
137 }
138 else if (id == poison->id)
139 {
140 if (mob->getHealth() > 1)
141 {
142 mob->hurt(DamageSource::magic, 1);
143 }
144 }
145 else if (id == wither->id)
146 {
147 mob->hurt(DamageSource::wither, 1);
148 }
149 else if ( (id == hunger->id) && mob->instanceof(eTYPE_PLAYER) )
150 {
151 // every tick, cause the same amount of exhaustion as when removing
152 // a block, times amplification
153 dynamic_pointer_cast<Player>(mob)->causeFoodExhaustion(FoodConstants::EXHAUSTION_MINE * (amplification + 1));
154 }
155 else if ( (id == saturation->id) && mob->instanceof(eTYPE_PLAYER) )
156 {
157 if (!mob->level->isClientSide)
158 {
159 dynamic_pointer_cast<Player>(mob)->getFoodData()->eat(amplification + 1, FoodConstants::FOOD_SATURATION_MAX);
160 }
161 }
162 else if ((id == heal->id && !mob->isInvertedHealAndHarm()) || (id == harm->id && mob->isInvertedHealAndHarm()))
163 {
164 mob->heal(max(4 << amplification, 0));
165 }
166 else if ((id == harm->id && !mob->isInvertedHealAndHarm()) || (id == heal->id && mob->isInvertedHealAndHarm()))
167 {
168 mob->hurt(DamageSource::magic, 6 << amplification);
169 }
170}
171
172void MobEffect::applyInstantenousEffect(shared_ptr<LivingEntity> source, shared_ptr<LivingEntity> mob, int amplification, double scale)
173{
174 if ((id == heal->id && !mob->isInvertedHealAndHarm()) || (id == harm->id && mob->isInvertedHealAndHarm()))
175 {
176 int amount = (int) (scale * (double) (4 << amplification) + .5);
177 mob->heal(amount);
178 }
179 else if ((id == harm->id && !mob->isInvertedHealAndHarm()) || (id == heal->id && mob->isInvertedHealAndHarm()))
180 {
181 int amount = (int) (scale * (double) (6 << amplification) + .5);
182 if (source == NULL)
183 {
184 mob->hurt(DamageSource::magic, amount);
185 }
186 else
187 {
188 DamageSource *damageSource = DamageSource::indirectMagic(mob, source);
189 mob->hurt(damageSource, amount);
190 delete damageSource;
191 }
192 }
193}
194
195bool MobEffect::isInstantenous()
196{
197 return false;
198}
199
200/**
201* This parameter says if the applyEffect method should be called depending
202* on the remaining duration ticker. For instance, the regeneration will be
203* activated every 8 ticks, healing one point of health.
204*
205* @param remainingDuration
206* @param amplification
207* Effect amplification, starts at 0 (weakest)
208* @return
209*/
210bool MobEffect::isDurationEffectTick(int remainingDuration, int amplification)
211{
212
213 // Maybe move this to separate class implementations in the future?
214 if (id == regeneration->id)
215 {
216 // tick intervals are 50, 25, 12, 6..
217 int interval = 50 >> amplification;
218 if (interval > 0)
219 {
220 return (remainingDuration % interval) == 0;
221 }
222 return true;
223 }
224 else if (id == poison->id)
225 {
226 // tick intervals are 25, 12, 6..
227 int interval = 25 >> amplification;
228 if (interval > 0)
229 {
230 return (remainingDuration % interval) == 0;
231 }
232 return true;
233 }
234 else if (id == wither->id)
235 {
236 int interval = 40 >> amplification;
237 if (interval > 0)
238 {
239 return (remainingDuration % interval) == 0;
240 }
241 return true;
242 }
243 else if (id == hunger->id)
244 {
245 return true;
246 }
247
248 return false;
249}
250
251MobEffect *MobEffect::setDescriptionId(unsigned int id)
252{
253 descriptionId = id;
254 return this;
255}
256
257unsigned int MobEffect::getDescriptionId(int iData)
258{
259 return descriptionId;
260}
261
262MobEffect *MobEffect::setPostfixDescriptionId(unsigned int id)
263{
264 m_postfixDescriptionId = id;
265 return this;
266}
267
268unsigned int MobEffect::getPostfixDescriptionId(int iData)
269{
270 return m_postfixDescriptionId;
271}
272
273bool MobEffect::hasIcon()
274{
275 return icon != e_MobEffectIcon_None;
276}
277
278MobEffect::EMobEffectIcon MobEffect::getIcon()
279{
280 return icon;
281}
282
283bool MobEffect::isHarmful()
284{
285 return _isHarmful;
286}
287
288wstring MobEffect::formatDuration(MobEffectInstance *instance)
289{
290 if (instance->isNoCounter())
291 {
292 return L"**:**";
293 }
294 int duration = instance->getDuration();
295
296 int seconds = duration / SharedConstants::TICKS_PER_SECOND;
297 int minutes = seconds / 60;
298 seconds %= 60;
299
300 wchar_t temp[8];
301 ZeroMemory(&temp,8*(sizeof(wchar_t)));
302
303 if (seconds < 10)
304 {
305 swprintf(temp, 8, L"%d:0%d",minutes,seconds);
306 //return minutes + ":0" + seconds;
307 }
308 else
309 {
310 swprintf(temp, 8, L"%d:%d",minutes,seconds);
311 //return minutes + ":" + seconds;
312 }
313
314 return temp;
315}
316
317MobEffect *MobEffect::setDurationModifier(double durationModifier)
318{
319 this->durationModifier = durationModifier;
320 return this;
321}
322
323double MobEffect::getDurationModifier()
324{
325 return durationModifier;
326}
327
328MobEffect *MobEffect::setDisabled()
329{
330 _isDisabled = true;
331 return this;
332}
333
334bool MobEffect::isDisabled()
335{
336 return _isDisabled;
337}
338
339eMinecraftColour MobEffect::getColor()
340{
341 return color;
342}
343
344MobEffect *MobEffect::addAttributeModifier(Attribute *attribute, eMODIFIER_ID id, double amount, int operation)
345{
346 AttributeModifier *effect = new AttributeModifier(id, amount, operation);
347 attributeModifiers.insert(std::pair<Attribute*,AttributeModifier*>(attribute, effect));
348 return this;
349}
350
351unordered_map<Attribute *, AttributeModifier *> *MobEffect::getAttributeModifiers()
352{
353 return &attributeModifiers;
354}
355
356void MobEffect::removeAttributeModifiers(shared_ptr<LivingEntity> entity, BaseAttributeMap *attributes, int amplifier)
357{
358 for (AUTO_VAR(it, attributeModifiers.begin()); it != attributeModifiers.end(); ++it)
359 {
360 AttributeInstance *attribute = attributes->getInstance(it->first);
361
362 if (attribute != NULL)
363 {
364 attribute->removeModifier(it->second);
365 }
366 }
367}
368
369void MobEffect::addAttributeModifiers(shared_ptr<LivingEntity> entity, BaseAttributeMap *attributes, int amplifier)
370{
371 for (AUTO_VAR(it, attributeModifiers.begin()); it != attributeModifiers.end(); ++it)
372 {
373 AttributeInstance *attribute = attributes->getInstance(it->first);
374
375 if (attribute != NULL)
376 {
377 AttributeModifier *original = it->second;
378 attribute->removeModifier(original);
379 attribute->addModifier(new AttributeModifier(original->getId(), getAttributeModifierValue(amplifier, original), original->getOperation()));
380 }
381 }
382}
383
384double MobEffect::getAttributeModifierValue(int amplifier, AttributeModifier *original)
385{
386 return original->getAmount() * (amplifier + 1);
387}