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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#include "stdafx.h"
#include "net.minecraft.world.entity.ai.goal.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.level.h"
#include "SynchedEntityData.h"
#include "ParticleTypes.h"
#include "TamableAnimal.h"
TamableAnimal::TamableAnimal(Level *level) : Animal(level)
{
sitGoal = new SitGoal(this);
}
TamableAnimal::~TamableAnimal()
{
if(sitGoal != nullptr) delete sitGoal;
}
void TamableAnimal::defineSynchedData()
{
Animal::defineSynchedData();
entityData->define(DATA_FLAGS_ID, static_cast<byte>(0));
entityData->define(DATA_OWNERUUID_ID, L"");
}
void TamableAnimal::addAdditonalSaveData(CompoundTag *tag)
{
Animal::addAdditonalSaveData(tag);
#ifdef _XBOX_ONE
// 4J Stu Added from later Java version to remove owners from save transfer saves. We will probably want this on other platforms in the future
if (getOwnerUUID().empty())
{
tag->putString(L"OwnerUUID", L"");
}
else
{
tag->putString(L"OwnerUUID", getOwnerUUID());
}
#else
if (getOwnerUUID().empty())
{
tag->putString(L"Owner", L"");
}
else
{
tag->putString(L"Owner", getOwnerUUID());
}
#endif
tag->putBoolean(L"Sitting", isSitting());
}
void TamableAnimal::readAdditionalSaveData(CompoundTag *tag)
{
Animal::readAdditionalSaveData(tag);
#ifdef _XBOX_ONE
// 4J Stu Added from later Java version to remove owners from save transfer saves. We will probably want this on other platforms in the future
wstring owner = L"";
if(tag->contains(L"OwnerUUID") )
{
owner = tag->getString(L"OwnerUUID");
}
#else
wstring owner = tag->getString(L"Owner");
#endif
if (owner.length() > 0)
{
setOwnerUUID(owner);
setTame(true);
}
sitGoal->wantToSit(tag->getBoolean(L"Sitting"));
setSitting(tag->getBoolean(L"Sitting"));
}
void TamableAnimal::spawnTamingParticles(bool success)
{
ePARTICLE_TYPE particle = eParticleType_heart;
if (!success)
{
particle = eParticleType_smoke;
}
for (int i = 0; i < 7; i++)
{
double xa = random->nextGaussian() * 0.02;
double ya = random->nextGaussian() * 0.02;
double za = random->nextGaussian() * 0.02;
level->addParticle(particle, x + random->nextFloat() * bbWidth * 2 - bbWidth, y + .5f + random->nextFloat() * bbHeight, z + random->nextFloat() * bbWidth * 2 - bbWidth, xa, ya, za);
}
}
void TamableAnimal::handleEntityEvent(byte id)
{
if (id == EntityEvent::TAMING_SUCCEEDED)
{
spawnTamingParticles(true);
}
else if (id == EntityEvent::TAMING_FAILED)
{
spawnTamingParticles(false);
}
else
{
Animal::handleEntityEvent(id);
}
}
bool TamableAnimal::isTame()
{
return (entityData->getByte(DATA_FLAGS_ID) & 0x04) != 0;
}
void TamableAnimal::setTame(bool value)
{
byte current = entityData->getByte(DATA_FLAGS_ID);
if (value)
{
entityData->set(DATA_FLAGS_ID, static_cast<byte>(current | 0x04));
}
else
{
entityData->set(DATA_FLAGS_ID, static_cast<byte>(current & ~0x04));
}
}
bool TamableAnimal::isSitting()
{
return (entityData->getByte(DATA_FLAGS_ID) & 0x01) != 0;
}
void TamableAnimal::setSitting(bool value)
{
byte current = entityData->getByte(DATA_FLAGS_ID);
if (value)
{
entityData->set(DATA_FLAGS_ID, static_cast<byte>(current | 0x01));
}
else
{
entityData->set(DATA_FLAGS_ID, static_cast<byte>(current & ~0x01));
}
}
wstring TamableAnimal::getOwnerUUID()
{
return entityData->getString(DATA_OWNERUUID_ID);
}
void TamableAnimal::setOwnerUUID(const wstring &name)
{
entityData->set(DATA_OWNERUUID_ID, name);
}
shared_ptr<Entity> TamableAnimal::getOwner()
{
return level->getPlayerByUUID(getOwnerUUID());
}
SitGoal *TamableAnimal::getSitGoal()
{
return sitGoal;
}
bool TamableAnimal::wantsToAttack(shared_ptr<LivingEntity> target, shared_ptr<LivingEntity> owner)
{
return true;
}
Team *TamableAnimal::getTeam()
{
if (isTame())
{
shared_ptr<LivingEntity> owner = dynamic_pointer_cast<LivingEntity>(getOwner());
if (owner != nullptr)
{
return owner->getTeam();
}
}
return Animal::getTeam();
}
bool TamableAnimal::isAlliedTo(shared_ptr<LivingEntity> other)
{
if (isTame())
{
shared_ptr<LivingEntity> owner = dynamic_pointer_cast<LivingEntity>(getOwner());
if (other == owner)
{
return true;
}
if (owner != nullptr)
{
return owner->isAlliedTo(other);
}
}
return Animal::isAlliedTo(other);
}
|