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
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "JukeboxEntity.h"
#include "../World.h"
#include "json/json.h"
cJukeboxEntity::cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
super(E_BLOCK_JUKEBOX, a_BlockX, a_BlockY, a_BlockZ, a_World),
m_Record(0)
{
}
cJukeboxEntity::~cJukeboxEntity()
{
EjectRecord();
}
void cJukeboxEntity::UsedBy(cPlayer * a_Player)
{
if (IsPlayingRecord())
{
EjectRecord();
}
else
{
const cItem & HeldItem = a_Player->GetEquippedItem();
if (PlayRecord(HeldItem.m_ItemType))
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
}
}
bool cJukeboxEntity::PlayRecord(int a_Record)
{
if (!IsRecordItem(a_Record))
{
// This isn't a Record Item
return false;
}
if (IsPlayingRecord())
{
// A Record is already in the Jukebox.
EjectRecord();
}
m_Record = a_Record;
m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, m_Record);
m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_ON);
return true;
}
bool cJukeboxEntity::EjectRecord(void)
{
if (!IsPlayingRecord())
{
// There's no record here
return false;
}
cItems Drops;
Drops.push_back(cItem(m_Record, 1, 0));
m_Record = 0;
m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8);
m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 0);
m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_OFF);
return true;
}
bool cJukeboxEntity::IsPlayingRecord(void)
{
return (m_Record != 0);
}
int cJukeboxEntity::GetRecord(void)
{
return m_Record;
}
void cJukeboxEntity::SetRecord(int a_Record)
{
m_Record = a_Record;
}
bool cJukeboxEntity::LoadFromJson(const Json::Value & a_Value)
{
m_PosX = a_Value.get("x", 0).asInt();
m_PosY = a_Value.get("y", 0).asInt();
m_PosZ = a_Value.get("z", 0).asInt();
m_Record = a_Value.get("Record", 0).asInt();
return true;
}
void cJukeboxEntity::SaveToJson(Json::Value & a_Value)
{
a_Value["x"] = m_PosX;
a_Value["y"] = m_PosY;
a_Value["z"] = m_PosZ;
a_Value["Record"] = m_Record;
}
|