-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathMultiplayerLocalPlayer.cpp
More file actions
163 lines (133 loc) · 4.31 KB
/
MultiplayerLocalPlayer.cpp
File metadata and controls
163 lines (133 loc) · 4.31 KB
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
#include "MultiplayerLocalPlayer.hpp"
#include "client/app/Minecraft.hpp"
#include "network/RakNetInstance.hpp"
#include "network/packets/AnimatePacket.hpp"
#include "network/packets/MovePlayerPacket.hpp"
#include "world/level/Level.hpp"
MultiplayerLocalPlayer::MultiplayerLocalPlayer(Minecraft* pMinecraft, Level* pLevel, User* pUser, GameType gameType, int dimensionId)
: LocalPlayer(pMinecraft, pLevel, pUser, gameType, dimensionId)
{
m_flashOnSetHealth = false;
m_pInventoryMenu->addSlotListener(this);
}
void MultiplayerLocalPlayer::reallyDrop(ItemEntity* itemEntity)
{
}
bool MultiplayerLocalPlayer::hurt(Entity* pAttacker, int damage)
{
// Java returns false
return false;
// Pulled from Mob::hurt(), modified to remove impact on health.
// @BUG: Will never work, because EntityEventPacket sets m_invulnerableTime
// before InteractPacket is received and calls this.
// If we remove the m_invulnerableTime check, the player can then be
// knocked back despite being invulnerable
/*if (isCreative())
return false;
bool var3 = true;
if (float(m_invulnerableTime) > float(m_invulnerableDuration) / 2.0f)
{
var3 = false;
}
else
{
m_invulnerableTime = m_invulnerableDuration;
m_hurtTime = m_hurtDuration = 10;
}
m_hurtDir = 0.0f;
if (var3)
{
markHurt();
if (pAttacker)
{
float xd = pAttacker->m_pos.x - m_pos.x;
float zd = pAttacker->m_pos.z - m_pos.z;
while (zd * zd + xd * xd < 0.0001f)
{
xd = 0.01f * (Mth::random() - Mth::random());
zd = 0.01f * (Mth::random() - Mth::random());
}
float ang = atan2f(zd, xd);
v020_field_104 = ang * (180.0f / float(M_PI)) - m_rot.x;
knockback(pAttacker, damage, xd, zd);
}
}
return true;*/
}
void MultiplayerLocalPlayer::heal(int health)
{
}
/*void MultiplayerLocalPlayer::drop()
{
// From Java
m_pLevel->m_pRakNetInstance->send(new PlayerActionPacket(PlayerActionPacket::DROP_ITEM))
}*/
void MultiplayerLocalPlayer::hurtTo(int newHealth)
{
if (m_flashOnSetHealth)
{
LocalPlayer::hurtTo(newHealth);
}
else
{
m_health = newHealth;
m_flashOnSetHealth = true;
}
}
void MultiplayerLocalPlayer::die(Entity* pCulprit)
{
#if NETWORK_PROTOCOL_VERSION >= 4
SendInventoryPacket* pPkt = new SendInventoryPacket();
pPkt->m_entityId = m_EntityID;
pPkt->m_bDropAll = true;
uint16_t size = m_pInventory->getContainerSize();
// 0.3.0
if (size > 9)
{
for (int i = 0; i < size; i++)
{
pPkt->m_items.push_back(m_pInventory->getItem(i));
}
}
m_pMinecraft->m_pRakNetInstance->send(pPkt);
#endif
LocalPlayer::die(pCulprit);
}
void MultiplayerLocalPlayer::drop(const ItemStack& item, bool randomly)
{
#if NETWORK_PROTOCOL_VERSION >= 4
m_pMinecraft->m_pRakNetInstance->send(new DropItemPacket(m_EntityID, item));
#endif
}
void MultiplayerLocalPlayer::closeContainer()
{
#if NETWORK_PROTOCOL_VERSION >= 5
m_pMinecraft->m_pRakNetInstance->send(new ContainerClosePacket(m_pContainerMenu->m_containerId));
#endif
LocalPlayer::closeContainer();
}
Player::BedSleepingProblem MultiplayerLocalPlayer::startSleepInBed(const TilePos& pos)
{
// Client players receive sleep command from server via InteractionPacket
// Just apply the sleep state locally - position will be set by MovePlayerPacket
return Player::startSleepInBed(pos);
}
void MultiplayerLocalPlayer::stopSleepInBed(bool resetCounter, bool update, bool setSpawn)
{
Player::stopSleepInBed(resetCounter, update, setSpawn);
// Send wake notification to server
if (m_pLevel && m_pLevel->m_pRakNetInstance)
{
m_pLevel->m_pRakNetInstance->send(new AnimatePacket(m_EntityID, AnimatePacket::WAKE_UP));
// Also send position update so server knows where we are after waking
m_pLevel->m_pRakNetInstance->send(new MovePlayerPacket(m_EntityID,
Vec3(m_pos.x, m_pos.y - m_heightOffset, m_pos.z), m_rot));
}
}
void MultiplayerLocalPlayer::refreshContainer(ContainerMenu* menu, const std::vector<ItemStack>& items)
{
}
void MultiplayerLocalPlayer::slotChanged(ContainerMenu* menu, int index, ItemStack& item, bool isResultSlot)
{
// @TODO: Replicate ContainerSetSlotPacket
}