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
|
#include "stdafx.h"
#include "ServerLevelListener.h"
#include "EntityTracker.h"
#include "MinecraftServer.h"
#include "ServerLevel.h"
#include "ServerPlayer.h"
#include "PlayerList.h"
#include "PlayerChunkMap.h"
#include "PlayerConnection.h"
#include "..\Minecraft.World\net.minecraft.world.level.dimension.h"
#include "..\Minecraft.World\net.minecraft.network.packet.h"
#include "..\Minecraft.World\LevelData.h"
ServerLevelListener::ServerLevelListener(MinecraftServer *server, ServerLevel *level)
{
this->server = server;
this->level = level;
}
// 4J removed -
/*
void ServerLevelListener::addParticle(const wstring& name, double x, double y, double z, double xa, double ya, double za)
{
}
*/
void ServerLevelListener::addParticle(ePARTICLE_TYPE name, double x, double y, double z, double xa, double ya, double za)
{
}
void ServerLevelListener::allChanged()
{
}
void ServerLevelListener::entityAdded(shared_ptr<Entity> entity)
{
MemSect(10);
level->getTracker()->addEntity(entity);
MemSect(0);
}
void ServerLevelListener::entityRemoved(shared_ptr<Entity> entity)
{
level->getTracker()->removeEntity(entity);
}
// 4J added
void ServerLevelListener::playerRemoved(shared_ptr<Entity> entity)
{
dynamic_pointer_cast<ServerPlayer>(entity)->getLevel()->getTracker()->removePlayer(entity);
}
void ServerLevelListener::playSound(int iSound, double x, double y, double z, float volume, float pitch, float fClipSoundDist)
{
if(iSound < 0)
{
app.DebugPrintf("ServerLevelListener received request for sound less than 0, so ignoring\n");
}
else
{
// 4J-PB - I don't want to broadcast player sounds to my local machine, since we're already playing these in the LevelRenderer::playSound.
// The PC version does seem to do this and the result is I can stop walking , and then I'll hear my footstep sound with a delay
server->getPlayers()->broadcast(x, y, z, volume > 1 ? 16 * volume : 16, level->dimension->id, std::make_shared<LevelSoundPacket>(iSound, x, y, z, volume, pitch));
}
}
void ServerLevelListener::playSoundExceptPlayer(shared_ptr<Player> player, int iSound, double x, double y, double z, float volume, float pitch, float fSoundClipDist)
{
if(iSound < 0)
{
app.DebugPrintf("ServerLevelListener received request for sound less than 0, so ignoring\n");
}
else
{
// 4J-PB - I don't want to broadcast player sounds to my local machine, since we're already playing these in the LevelRenderer::playSound.
// The PC version does seem to do this and the result is I can stop walking , and then I'll hear my footstep sound with a delay
server->getPlayers()->broadcast(player,x, y, z, volume > 1 ? 16 * volume : 16, level->dimension->id, std::make_shared<LevelSoundPacket>(iSound, x, y, z, volume, pitch));
}
}
void ServerLevelListener::setTilesDirty(int x0, int y0, int z0, int x1, int y1, int z1, Level *level)
{
}
void ServerLevelListener::skyColorChanged()
{
}
void ServerLevelListener::tileChanged(int x, int y, int z)
{
level->getChunkMap()->tileChanged(x, y, z);
}
void ServerLevelListener::tileLightChanged(int x, int y, int z)
{
}
void ServerLevelListener::playStreamingMusic(const wstring& name, int x, int y, int z)
{
}
void ServerLevelListener::levelEvent(shared_ptr<Player> source, int type, int x, int y, int z, int data)
{
server->getPlayers()->broadcast(source, x, y, z, 64, level->dimension->id, std::make_shared<LevelEventPacket>( type, x, y, z, data, false ) );
}
void ServerLevelListener::globalLevelEvent(int type, int sourceX, int sourceY, int sourceZ, int data)
{
server->getPlayers()->broadcastAll( std::make_shared<LevelEventPacket>( type, sourceX, sourceY, sourceZ, data, true) );
}
void ServerLevelListener::destroyTileProgress(int id, int x, int y, int z, int progress)
{
//for (ServerPlayer p : server->getPlayers()->players)
for(auto& p : server->getPlayers()->players)
{
if (p == nullptr || p->level != level || p->entityId == id) continue;
double xd = static_cast<double>(x) - p->x;
double yd = static_cast<double>(y) - p->y;
double zd = static_cast<double>(z) - p->z;
if (xd * xd + yd * yd + zd * zd < 32 * 32)
{
p->connection->send(std::make_shared<TileDestructionPacket>(id, x, y, z, progress));
}
}
}
|