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
|
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.effect.h"
#include "SharedConstants.h"
#include "JavaMath.h"
#include "ThrownPotion.h"
const double ThrownPotion::SPLASH_RANGE = 4.0;
const double ThrownPotion::SPLASH_RANGE_SQ = ThrownPotion::SPLASH_RANGE * ThrownPotion::SPLASH_RANGE;
void ThrownPotion::_init()
{
// 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
// the derived version of the function is called
this->defineSynchedData();
potionItem = nullptr;
}
ThrownPotion::ThrownPotion(Level *level) : Throwable(level)
{
_init();
}
ThrownPotion::ThrownPotion(Level *level, shared_ptr<LivingEntity> mob, int potionValue) : Throwable(level,mob)
{
_init();
potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, potionValue));
}
ThrownPotion::ThrownPotion(Level *level, shared_ptr<LivingEntity> mob, shared_ptr<ItemInstance> potion) : Throwable(level, mob)
{
_init();
potionItem = potion;
}
ThrownPotion::ThrownPotion(Level *level, double x, double y, double z, int potionValue) : Throwable(level,x,y,z)
{
_init();
potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, potionValue));
}
ThrownPotion::ThrownPotion(Level *level, double x, double y, double z, shared_ptr<ItemInstance> potion) : Throwable(level, x, y, z)
{
_init();
potionItem = potion;
}
float ThrownPotion::getGravity()
{
return 0.05f;
}
float ThrownPotion::getThrowPower()
{
return 0.5f;
}
float ThrownPotion::getThrowUpAngleOffset()
{
return -20;
}
void ThrownPotion::setPotionValue(int potionValue)
{
if (potionItem == NULL) potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, 0) );
potionItem->setAuxValue(potionValue);
}
int ThrownPotion::getPotionValue()
{
if (potionItem == NULL) potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, 0) );
return potionItem->getAuxValue();
}
void ThrownPotion::onHit(HitResult *res)
{
if (!level->isClientSide)
{
vector<MobEffectInstance *> *mobEffects = Item::potion->getMobEffects(potionItem);
if (mobEffects != NULL && !mobEffects->empty())
{
AABB *aoe = bb->grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE);
vector<shared_ptr<Entity> > *entitiesOfClass = level->getEntitiesOfClass(typeid(LivingEntity), aoe);
if (entitiesOfClass != NULL && !entitiesOfClass->empty())
{
for(auto & it : *entitiesOfClass)
{
shared_ptr<LivingEntity> e = dynamic_pointer_cast<LivingEntity>( it );
double dist = distanceToSqr(e);
if (dist < SPLASH_RANGE_SQ)
{
double scale = 1.0 - (sqrt(dist) / SPLASH_RANGE);
if (e == res->entity)
{
scale = 1;
}
//for (MobEffectInstance effect : mobEffects)
for(auto& effect : *mobEffects)
{
int id = effect->getId();
if (MobEffect::effects[id]->isInstantenous())
{
MobEffect::effects[id]->applyInstantenousEffect(getOwner(), e, effect->getAmplifier(), scale);
}
else
{
int duration = (int) (scale * (double) effect->getDuration() + .5);
if (duration > SharedConstants::TICKS_PER_SECOND)
{
e->addEffect(new MobEffectInstance(id, duration, effect->getAmplifier()));
}
}
}
}
}
}
delete entitiesOfClass;
}
level->levelEvent(LevelEvent::PARTICLES_POTION_SPLASH, (int) Math::round(x), (int) Math::round(y), (int) Math::round(z), getPotionValue() );
remove();
}
}
void ThrownPotion::readAdditionalSaveData(CompoundTag *tag)
{
Throwable::readAdditionalSaveData(tag);
if (tag->contains(L"Potion"))
{
potionItem = ItemInstance::fromTag(tag->getCompound(L"Potion"));
}
else
{
setPotionValue(tag->getInt(L"potionValue"));
}
if (potionItem == NULL) remove();
}
void ThrownPotion::addAdditonalSaveData(CompoundTag *tag)
{
Throwable::addAdditonalSaveData(tag);
if (potionItem != NULL) tag->putCompound(L"Potion", potionItem->save(new CompoundTag()));
}
|