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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
#include "stdafx.h"
#include "net.minecraft.network.packet.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "TileEntity.h"
#include "PistonPieceEntity.h"
TileEntity::idToCreateMapType TileEntity::idCreateMap = unordered_map<wstring, tileEntityCreateFn>();
TileEntity::classToIdMapType TileEntity::classIdMap = unordered_map<eINSTANCEOF, wstring, eINSTANCEOFKeyHash, eINSTANCEOFKeyEq>();
void TileEntity::staticCtor()
{
TileEntity::setId(FurnaceTileEntity::create, eTYPE_FURNACETILEENTITY, L"Furnace");
TileEntity::setId(ChestTileEntity::create, eTYPE_CHESTTILEENTITY, L"Chest");
TileEntity::setId(EnderChestTileEntity::create, eTYPE_ENDERCHESTTILEENTITY, L"EnderChest");
TileEntity::setId(RecordPlayerTile::Entity::create, eTYPE_RECORDPLAYERTILE, L"RecordPlayer");
TileEntity::setId(DispenserTileEntity::create, eTYPE_DISPENSERTILEENTITY, L"Trap");
TileEntity::setId(SignTileEntity::create, eTYPE_SIGNTILEENTITY, L"Sign");
TileEntity::setId(MobSpawnerTileEntity::create, eTYPE_MOBSPAWNERTILEENTITY, L"MobSpawner");
TileEntity::setId(MusicTileEntity::create, eTYPE_MUSICTILEENTITY, L"Music");
TileEntity::setId(PistonPieceEntity::create, eTYPE_PISTONPIECEENTITY, L"Piston");
TileEntity::setId(BrewingStandTileEntity::create, eTYPE_BREWINGSTANDTILEENTITY, L"Cauldron");
TileEntity::setId(EnchantmentTableEntity::create, eTYPE_ENCHANTMENTTABLEENTITY, L"EnchantTable");
TileEntity::setId(TheEndPortalTileEntity::create, eTYPE_THEENDPORTALTILEENTITY, L"Airportal");
TileEntity::setId(SkullTileEntity::create,eTYPE_SKULLTILEENTITY, L"Skull");
}
void TileEntity::setId(tileEntityCreateFn createFn, eINSTANCEOF clas, wstring id)
{
// 4J Stu - Java has classIdMap.containsKey(id) which would never work as id is not of the type of the key in classIdMap
// I have changed to use idClassMap instead so that we can still search from the string key
// TODO 4J Stu - Exceptions
if (idCreateMap.find(id) != idCreateMap.end() ) {}//throw new IllegalArgumentException("Duplicate id: " + id);
idCreateMap.insert( idToCreateMapType::value_type(id, createFn) );
classIdMap.insert( classToIdMapType::value_type( clas, id ) );
}
TileEntity::TileEntity()
{
level = NULL;
x = y = z = 0;
remove = false;
data = -1;
tile = NULL;
renderRemoveStage = e_RenderRemoveStageKeep;
}
Level *TileEntity::getLevel()
{
return level;
}
void TileEntity::setLevel(Level *level)
{
this->level = level;
}
bool TileEntity::hasLevel()
{
return level != NULL;
}
void TileEntity::load(CompoundTag *tag)
{
x = tag->getInt(L"x");
y = tag->getInt(L"y");
z = tag->getInt(L"z");
}
void TileEntity::save(CompoundTag *tag)
{
AUTO_VAR(it, classIdMap.find( this->GetType() ));
if ( it == classIdMap.end() )
{
// TODO 4J Stu - Some sort of exception handling
//throw new RuntimeException(this->getClass() + " is missing a mapping! This is a bug!");
return;
}
tag->putString(L"id", ( (*it).second ) );
tag->putInt(L"x", x);
tag->putInt(L"y", y);
tag->putInt(L"z", z);
}
void TileEntity::tick()
{
}
shared_ptr<TileEntity> TileEntity::loadStatic(CompoundTag *tag)
{
shared_ptr<TileEntity> entity = nullptr;
//try
//{
AUTO_VAR(it, idCreateMap.find(tag->getString(L"id")));
if (it != idCreateMap.end() ) entity = shared_ptr<TileEntity>(it->second());
//}
//catch (Exception e)
//{
// TODO 4J Stu - Exception handling?
// e->printStackTrace();
//}
if (entity != NULL)
{
entity->load(tag);
}
else
{
#ifdef _DEBUG
app.DebugPrintf("Skipping TileEntity with id %ls.\n" , tag->getString(L"id").c_str() );
#endif
}
return entity;
}
int TileEntity::getData()
{
if (data == -1) data = level->getData(x, y, z);
return data;
}
void TileEntity::setData(int data)
{
this->data = data;
level->setData(x, y, z, data);
}
void TileEntity::setChanged()
{
if (level != NULL)
{
data = level->getData(x, y, z);
level->tileEntityChanged(x, y, z, shared_from_this());
}
}
double TileEntity::distanceToSqr(double xPlayer, double yPlayer, double zPlayer)
{
double xd = (x + 0.5) - xPlayer;
double yd = (y + 0.5) - yPlayer;
double zd = (z + 0.5) - zPlayer;
return xd * xd + yd * yd + zd * zd;
}
Tile *TileEntity::getTile()
{
if( tile == NULL ) tile = Tile::tiles[level->getTile(x, y, z)];
return tile;
}
shared_ptr<Packet> TileEntity::getUpdatePacket()
{
return nullptr;
}
bool TileEntity::isRemoved()
{
return remove;
}
void TileEntity::setRemoved()
{
remove = true;
}
void TileEntity::clearRemoved()
{
remove = false;
}
void TileEntity::triggerEvent(int b0, int b1)
{
}
void TileEntity::clearCache()
{
tile = NULL;
data = -1;
}
void TileEntity::setRenderRemoveStage( unsigned char stage )
{
renderRemoveStage = stage;
}
bool TileEntity::shouldRemoveForRender()
{
return (renderRemoveStage == e_RenderRemoveStageRemove);
}
void TileEntity::upgradeRenderRemoveStage()
{
if( renderRemoveStage == e_RenderRemoveStageFlaggedAtChunk )
{
renderRemoveStage = e_RenderRemoveStageRemove;
}
}
// 4J Added
void TileEntity::clone(shared_ptr<TileEntity> tileEntity)
{
tileEntity->level = this->level;
tileEntity->x = this->x;
tileEntity->y = this->y;
tileEntity->z = this->z;
tileEntity->data = this->data;
tileEntity->tile = this->tile;
}
|