chore: format Minecraft.Client

This commit is contained in:
Tropical
2026-03-13 17:10:10 -05:00
parent 33d0737d1d
commit e8424f2000
531 changed files with 67709 additions and 62690 deletions

View File

@@ -2,24 +2,17 @@
#include "DemoLevel.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.storage.h"
LevelSettings DemoLevel::DEMO_LEVEL_SETTINGS = LevelSettings(
DemoLevel::DEMO_LEVEL_SEED,
GameType::SURVIVAL,
false,
false,
false, LevelType::lvl_normal_1_1, LEVEL_MAX_WIDTH,
1.0
);
LevelSettings DemoLevel::DEMO_LEVEL_SETTINGS =
LevelSettings(DemoLevel::DEMO_LEVEL_SEED, GameType::SURVIVAL, false, false,
false, LevelType::lvl_normal_1_1, LEVEL_MAX_WIDTH, 1.0);
DemoLevel::DemoLevel(std::shared_ptr<LevelStorage> levelStorage, const std::wstring& levelName) : Level(levelStorage, levelName, &DEMO_LEVEL_SETTINGS)
{
}
DemoLevel::DemoLevel(std::shared_ptr<LevelStorage> levelStorage,
const std::wstring& levelName)
: Level(levelStorage, levelName, &DEMO_LEVEL_SETTINGS) {}
DemoLevel::DemoLevel(Level *level, Dimension *dimension): Level(level, dimension)
{
}
DemoLevel::DemoLevel(Level* level, Dimension* dimension)
: Level(level, dimension) {}
void DemoLevel::setInitialSpawn()
{
levelData->setSpawn(DEMO_SPAWN_X, DEMO_SPAWN_Y, DEMO_SPAWN_Z);
void DemoLevel::setInitialSpawn() {
levelData->setSpawn(DEMO_SPAWN_X, DEMO_SPAWN_Y, DEMO_SPAWN_Z);
}

View File

@@ -1,17 +1,20 @@
#pragma once
#include "../../Minecraft.World/Headers/net.minecraft.world.level.h"
class DemoLevel : public Level
{
class DemoLevel : public Level {
private:
static const __int64 DEMO_LEVEL_SEED = 0; // 4J - TODO - was "Don't Look Back".hashCode();
static const __int64 DEMO_LEVEL_SEED =
0; // 4J - TODO - was "Don't Look Back".hashCode();
static const int DEMO_SPAWN_X = 796;
static const int DEMO_SPAWN_Y = 72;
static const int DEMO_SPAWN_Z = -731;
static LevelSettings DEMO_LEVEL_SETTINGS;
public:
DemoLevel(std::shared_ptr<LevelStorage> levelStorage, const std::wstring& levelName);
DemoLevel(Level *level, Dimension *dimension);
DemoLevel(std::shared_ptr<LevelStorage> levelStorage,
const std::wstring& levelName);
DemoLevel(Level* level, Dimension* dimension);
protected:
virtual void setInitialSpawn();
virtual void setInitialSpawn();
};

View File

@@ -3,27 +3,28 @@
#include "../../Minecraft.World/Level/Storage/SavedDataStorage.h"
#include "../../Minecraft.World/Level/DerivedLevelData.h"
DerivedServerLevel::DerivedServerLevel(MinecraftServer *server, std::shared_ptr<LevelStorage> levelStorage, const std::wstring& levelName, int dimension, LevelSettings *levelSettings, ServerLevel *wrapped)
: ServerLevel(server, levelStorage, levelName, dimension, levelSettings)
{
// 4J-PB - we're going to override the savedDataStorage, so we need to delete the current one
if(this->savedDataStorage)
{
delete this->savedDataStorage;
this->savedDataStorage=NULL;
}
this->savedDataStorage = wrapped->savedDataStorage;
levelData = new DerivedLevelData(wrapped->getLevelData());
DerivedServerLevel::DerivedServerLevel(
MinecraftServer* server, std::shared_ptr<LevelStorage> levelStorage,
const std::wstring& levelName, int dimension, LevelSettings* levelSettings,
ServerLevel* wrapped)
: ServerLevel(server, levelStorage, levelName, dimension, levelSettings) {
// 4J-PB - we're going to override the savedDataStorage, so we need to
// delete the current one
if (this->savedDataStorage) {
delete this->savedDataStorage;
this->savedDataStorage = NULL;
}
this->savedDataStorage = wrapped->savedDataStorage;
levelData = new DerivedLevelData(wrapped->getLevelData());
}
DerivedServerLevel::~DerivedServerLevel()
{
// we didn't allocate savedDataStorage here, so we don't want the level destructor to delete it
this->savedDataStorage=NULL;
DerivedServerLevel::~DerivedServerLevel() {
// we didn't allocate savedDataStorage here, so we don't want the level
// destructor to delete it
this->savedDataStorage = NULL;
}
void DerivedServerLevel::saveLevelData()
{
// Do nothing?
// Do nothing!
void DerivedServerLevel::saveLevelData() {
// Do nothing?
// Do nothing!
}

View File

@@ -1,12 +1,14 @@
#pragma once
#include "ServerLevel.h"
class DerivedServerLevel : public ServerLevel
{
class DerivedServerLevel : public ServerLevel {
public:
DerivedServerLevel(MinecraftServer *server, std::shared_ptr<LevelStorage>levelStorage, const std::wstring& levelName, int dimension, LevelSettings *levelSettings, ServerLevel *wrapped);
~DerivedServerLevel();
DerivedServerLevel(MinecraftServer* server,
std::shared_ptr<LevelStorage> levelStorage,
const std::wstring& levelName, int dimension,
LevelSettings* levelSettings, ServerLevel* wrapped);
~DerivedServerLevel();
protected:
void saveLevelData();
void saveLevelData();
};

File diff suppressed because it is too large Load Diff

View File

@@ -8,95 +8,111 @@
class ClientConnection;
class MultiPlayerChunkCache;
class MultiPlayerLevel : public Level
{
class MultiPlayerLevel : public Level {
private:
static const int TICKS_BEFORE_RESET = 20 * 4;
static const int TICKS_BEFORE_RESET = 20 * 4;
class ResetInfo
{
public:
class ResetInfo {
public:
int x, y, z, ticks, tile, data;
ResetInfo(int x, int y, int z, int tile, int data);
};
std::vector<ResetInfo> updatesToReset; // 4J - was linked list but vector seems more appropriate
bool m_bEnableResetChanges; // 4J Added
std::vector<ResetInfo> updatesToReset; // 4J - was linked list but vector
// seems more appropriate
bool m_bEnableResetChanges; // 4J Added
public:
void unshareChunkAt(int x, int z); // 4J - added
void shareChunkAt(int x, int z); // 4J - added
void unshareChunkAt(int x, int z); // 4J - added
void shareChunkAt(int x, int z); // 4J - added
void enableResetChanges(bool enable) { m_bEnableResetChanges = enable; } // 4J Added
void enableResetChanges(bool enable) {
m_bEnableResetChanges = enable;
} // 4J Added
private:
int unshareCheckX; // 4J - added
int unshareCheckZ; // 4J - added
int compressCheckX; // 4J - added
int compressCheckZ; // 4J - added
std::vector<ClientConnection *> connections; // 4J Stu - Made this a vector as we can have more than one local connection
MultiPlayerChunkCache *chunkCache;
Minecraft *minecraft;
int unshareCheckX; // 4J - added
int unshareCheckZ; // 4J - added
int compressCheckX; // 4J - added
int compressCheckZ; // 4J - added
std::vector<ClientConnection*>
connections; // 4J Stu - Made this a vector as we can have more than
// one local connection
MultiPlayerChunkCache* chunkCache;
Minecraft* minecraft;
public:
MultiPlayerLevel(ClientConnection *connection, LevelSettings *levelSettings, int dimension, int difficulty);
virtual ~MultiPlayerLevel();
virtual void tick() ;
MultiPlayerLevel(ClientConnection* connection, LevelSettings* levelSettings,
int dimension, int difficulty);
virtual ~MultiPlayerLevel();
virtual void tick();
void clearResetRegion(int x0, int y0, int z0, int x1, int y1, int z1);
void clearResetRegion(int x0, int y0, int z0, int x1, int y1, int z1);
protected:
ChunkSource *createChunkSource(); // 4J - was virtual, but was called from parent ctor
ChunkSource*
createChunkSource(); // 4J - was virtual, but was called from parent ctor
public:
virtual void validateSpawn();
virtual void validateSpawn();
protected:
virtual void tickTiles();
virtual void tickTiles();
public:
void setChunkVisible(int x, int z, bool visible);
private:
std::unordered_map<int, std::shared_ptr<Entity>, IntKeyHash2, IntKeyEq> entitiesById; // 4J - was IntHashMap
std::unordered_map<int, std::shared_ptr<Entity>, IntKeyHash2, IntKeyEq>
entitiesById; // 4J - was IntHashMap
std::unordered_set<std::shared_ptr<Entity> > forced;
std::unordered_set<std::shared_ptr<Entity> > reEntries;
public:
virtual bool addEntity(std::shared_ptr<Entity> e);
virtual bool addEntity(std::shared_ptr<Entity> e);
virtual void removeEntity(std::shared_ptr<Entity> e);
protected:
virtual void entityAdded(std::shared_ptr<Entity> e);
virtual void entityAdded(std::shared_ptr<Entity> e);
virtual void entityRemoved(std::shared_ptr<Entity> e);
public:
void putEntity(int id, std::shared_ptr<Entity> e);
void putEntity(int id, std::shared_ptr<Entity> e);
std::shared_ptr<Entity> getEntity(int id);
std::shared_ptr<Entity> removeEntity(int id);
virtual void removeEntities(std::vector<std::shared_ptr<Entity> > *list); // 4J Added override
virtual void removeEntities(
std::vector<std::shared_ptr<Entity> >* list); // 4J Added override
virtual bool setDataNoUpdate(int x, int y, int z, int data);
virtual bool setTileAndDataNoUpdate(int x, int y, int z, int tile, int data);
virtual bool setTileAndDataNoUpdate(int x, int y, int z, int tile,
int data);
virtual bool setTileNoUpdate(int x, int y, int z, int tile);
bool doSetTileAndData(int x, int y, int z, int tile, int data);
virtual void disconnect(bool sendDisconnect = true);
void animateTick(int xt, int yt, int zt);
void animateTick(int xt, int yt, int zt);
protected:
virtual void tickWeather();
static const int ANIMATE_TICK_MAX_PARTICLES = 500;
virtual void tickWeather();
static const int ANIMATE_TICK_MAX_PARTICLES = 500;
public:
void animateTickDoWork(); // 4J added
std::unordered_set<int> chunksToAnimate; // 4J added
void animateTickDoWork(); // 4J added
std::unordered_set<int> chunksToAnimate; // 4J added
public:
void removeAllPendingEntityRemovals();
void removeAllPendingEntityRemovals();
virtual void playSound(std::shared_ptr<Entity> entity, int iSound, float volume, float pitch);
virtual void playSound(std::shared_ptr<Entity> entity, int iSound,
float volume, float pitch);
virtual void playLocalSound(double x, double y, double z, int iSound, float volume, float pitch, float fClipSoundDist=16.0f);
virtual void playLocalSound(double x, double y, double z, int iSound,
float volume, float pitch,
float fClipSoundDist = 16.0f);
// 4J Stu - Added so we can have multiple local connections
void addClientConnection(ClientConnection *c) { connections.push_back( c ); }
void removeClientConnection(ClientConnection *c, bool sendDisconnect);
// 4J Stu - Added so we can have multiple local connections
void addClientConnection(ClientConnection* c) { connections.push_back(c); }
void removeClientConnection(ClientConnection* c, bool sendDisconnect);
void tickAllConnections();
void tickAllConnections();
void dataReceivedForChunk(int x, int z); // 4J added
void removeUnusedTileEntitiesInRegion(int x0, int y0, int z0, int x1, int y1, int z1); // 4J added
void dataReceivedForChunk(int x, int z); // 4J added
void removeUnusedTileEntitiesInRegion(int x0, int y0, int z0, int x1,
int y1, int z1); // 4J added
};

File diff suppressed because it is too large Load Diff

View File

@@ -7,165 +7,193 @@ class Node;
class EntityTracker;
class PlayerChunkMap;
class ServerLevel : public Level
{
class ServerLevel : public Level {
private:
static const int EMPTY_TIME_NO_TICK = SharedConstants::TICKS_PER_SECOND * 3;
static const int EMPTY_TIME_NO_TICK = SharedConstants::TICKS_PER_SECOND * 3;
MinecraftServer *server;
EntityTracker *tracker;
PlayerChunkMap *chunkMap;
MinecraftServer* server;
EntityTracker* tracker;
PlayerChunkMap* chunkMap;
CRITICAL_SECTION m_tickNextTickCS; // 4J added
std::set<TickNextTickData, TickNextTickDataKeyCompare> tickNextTickList; // 4J Was TreeSet
std::unordered_set<TickNextTickData, TickNextTickDataKeyHash, TickNextTickDataKeyEq> tickNextTickSet; // 4J Was HashSet
CRITICAL_SECTION m_tickNextTickCS; // 4J added
std::set<TickNextTickData, TickNextTickDataKeyCompare>
tickNextTickList; // 4J Was TreeSet
std::unordered_set<TickNextTickData, TickNextTickDataKeyHash,
TickNextTickDataKeyEq>
tickNextTickSet; // 4J Was HashSet
std::vector<Pos *> m_queuedSendTileUpdates; // 4J added
CRITICAL_SECTION m_csQueueSendTileUpdates;
std::vector<Pos*> m_queuedSendTileUpdates; // 4J added
CRITICAL_SECTION m_csQueueSendTileUpdates;
protected:
int saveInterval;
int saveInterval;
public:
ServerChunkCache *cache;
ServerChunkCache* cache;
bool canEditSpawn;
bool noSave;
private:
bool allPlayersSleeping;
int emptyTime;
bool m_bAtLeastOnePlayerSleeping; // 4J Added
static WeighedTreasureArray RANDOM_BONUS_ITEMS; // 4J - brought forward from 1.3.2
std::vector<TileEventData> tileEvents[2];
int activeTileEventsList;
public:
static void staticCtor();
ServerLevel(MinecraftServer *server, std::shared_ptr<LevelStorage>levelStorage, const std::wstring& levelName, int dimension, LevelSettings *levelSettings);
~ServerLevel();
void tick();
Biome::MobSpawnerData *getRandomMobSpawnAt(MobCategory *mobCategory, int x, int y, int z);
void updateSleepingPlayerList();
protected:
void awakenAllPlayers();
private:
void stopWeather();
bool allPlayersSleeping;
int emptyTime;
bool m_bAtLeastOnePlayerSleeping; // 4J Added
static WeighedTreasureArray
RANDOM_BONUS_ITEMS; // 4J - brought forward from 1.3.2
std::vector<TileEventData> tileEvents[2];
int activeTileEventsList;
public:
bool allPlayersAreSleeping();
void validateSpawn();
static void staticCtor();
ServerLevel(MinecraftServer* server,
std::shared_ptr<LevelStorage> levelStorage,
const std::wstring& levelName, int dimension,
LevelSettings* levelSettings);
~ServerLevel();
void tick();
Biome::MobSpawnerData* getRandomMobSpawnAt(MobCategory* mobCategory, int x,
int y, int z);
void updateSleepingPlayerList();
protected:
void tickTiles();
void awakenAllPlayers();
private:
void stopWeather();
public:
void addToTickNextTick(int x, int y, int z, int tileId, int tickDelay);
void forceAddTileTick(int x, int y, int z, int tileId, int tickDelay);
void tickEntities();
bool tickPendingTicks(bool force);
std::vector<TickNextTickData> *fetchTicksInChunk(LevelChunk *chunk, bool remove);
bool allPlayersAreSleeping();
void validateSpawn();
protected:
void tickTiles();
public:
void addToTickNextTick(int x, int y, int z, int tileId, int tickDelay);
void forceAddTileTick(int x, int y, int z, int tileId, int tickDelay);
void tickEntities();
bool tickPendingTicks(bool force);
std::vector<TickNextTickData>* fetchTicksInChunk(LevelChunk* chunk,
bool remove);
virtual void tick(std::shared_ptr<Entity> e, bool actual);
void forceTick(std::shared_ptr<Entity> e, bool actual);
bool AllPlayersAreSleeping() { return allPlayersSleeping;} // 4J added for a message to other players
bool isAtLeastOnePlayerSleeping() { return m_bAtLeastOnePlayerSleeping;}
bool AllPlayersAreSleeping() {
return allPlayersSleeping;
} // 4J added for a message to other players
bool isAtLeastOnePlayerSleeping() { return m_bAtLeastOnePlayerSleeping; }
protected:
ChunkSource *createChunkSource(); // 4J - was virtual, but was called from parent ctor
ChunkSource*
createChunkSource(); // 4J - was virtual, but was called from parent ctor
public:
std::vector<std::shared_ptr<TileEntity> > *getTileEntitiesInRegion(int x0, int y0, int z0, int x1, int y1, int z1);
virtual bool mayInteract(std::shared_ptr<Player> player, int xt, int yt, int zt, int id);
std::vector<std::shared_ptr<TileEntity> >* getTileEntitiesInRegion(
int x0, int y0, int z0, int x1, int y1, int z1);
virtual bool mayInteract(std::shared_ptr<Player> player, int xt, int yt,
int zt, int id);
protected:
virtual void initializeLevel(LevelSettings *settings);
virtual void setInitialSpawn(LevelSettings *settings);
void generateBonusItemsNearSpawn(); // 4J - brought forward from 1.3.2
virtual void initializeLevel(LevelSettings* settings);
virtual void setInitialSpawn(LevelSettings* settings);
void generateBonusItemsNearSpawn(); // 4J - brought forward from 1.3.2
public:
Pos *getDimensionSpecificSpawn();
Pos* getDimensionSpecificSpawn();
void Suspend(); // 4j Added for XboxOne PLM
void Suspend(); // 4j Added for XboxOne PLM
void save(bool force, ProgressListener *progressListener, bool bAutosave=false);
void saveToDisc(ProgressListener *progressListener, bool autosave); // 4J Added
void save(bool force, ProgressListener* progressListener,
bool bAutosave = false);
void saveToDisc(ProgressListener* progressListener,
bool autosave); // 4J Added
private:
void saveLevelData();
void saveLevelData();
typedef std::unordered_map<int, std::shared_ptr<Entity> , IntKeyHash2, IntKeyEq> intEntityMap;
intEntityMap entitiesById; // 4J - was IntHashMap, using same hashing function as this uses
typedef std::unordered_map<int, std::shared_ptr<Entity>, IntKeyHash2,
IntKeyEq>
intEntityMap;
intEntityMap entitiesById; // 4J - was IntHashMap, using same hashing
// function as this uses
protected:
virtual void entityAdded(std::shared_ptr<Entity> e);
virtual void entityAdded(std::shared_ptr<Entity> e);
virtual void entityRemoved(std::shared_ptr<Entity> e);
public:
std::shared_ptr<Entity> getEntity(int id);
std::shared_ptr<Entity> getEntity(int id);
virtual bool addGlobalEntity(std::shared_ptr<Entity> e);
void broadcastEntityEvent(std::shared_ptr<Entity> e, uint8_t event);
virtual std::shared_ptr<Explosion> explode(std::shared_ptr<Entity> source, double x, double y, double z, float r, bool fire, bool destroyBlocks);
virtual std::shared_ptr<Explosion> explode(std::shared_ptr<Entity> source,
double x, double y, double z,
float r, bool fire,
bool destroyBlocks);
virtual void tileEvent(int x, int y, int z, int tile, int b0, int b1);
private:
void runTileEvents();
bool doTileEvent(TileEventData *te);
void runTileEvents();
bool doTileEvent(TileEventData* te);
public:
void closeLevelStorage();
protected:
virtual void tickWeather();
virtual void tickWeather();
public:
MinecraftServer *getServer();
EntityTracker *getTracker();
void setTimeAndAdjustTileTicks(__int64 newTime);
PlayerChunkMap *getChunkMap();
MinecraftServer* getServer();
EntityTracker* getTracker();
void setTimeAndAdjustTileTicks(__int64 newTime);
PlayerChunkMap* getChunkMap();
void queueSendTileUpdate(int x, int y, int z); // 4J Added
void queueSendTileUpdate(int x, int y, int z); // 4J Added
private:
void runQueuedSendTileUpdates();// 4J Added
void runQueuedSendTileUpdates(); // 4J Added
// 4J - added for implementation of finite limit to number of item entities, tnt and falling block entities
// 4J - added for implementation of finite limit to number of item entities,
// tnt and falling block entities
public:
static const int MAX_HANGING_ENTITIES = 400;
static const int MAX_ITEM_ENTITIES = 200;
static const int MAX_ARROW_ENTITIES = 200;
static const int MAX_EXPERIENCEORB_ENTITIES = 50;
static const int MAX_PRIMED_TNT = 20;
static const int MAX_FALLING_TILE = 20;
static const int MAX_HANGING_ENTITIES = 400;
static const int MAX_ITEM_ENTITIES = 200;
static const int MAX_ARROW_ENTITIES = 200;
static const int MAX_EXPERIENCEORB_ENTITIES = 50;
static const int MAX_PRIMED_TNT = 20;
static const int MAX_FALLING_TILE = 20;
int m_primedTntCount;
int m_fallingTileCount;
CRITICAL_SECTION m_limiterCS;
std::list<std::shared_ptr<Entity> > m_itemEntities;
std::list<std::shared_ptr<Entity> > m_hangingEntities;
std::list<std::shared_ptr<Entity> > m_arrowEntities;
std::list<std::shared_ptr<Entity> > m_experienceOrbEntities;
int m_primedTntCount;
int m_fallingTileCount;
CRITICAL_SECTION m_limiterCS;
std::list< std::shared_ptr<Entity> > m_itemEntities;
std::list< std::shared_ptr<Entity> > m_hangingEntities;
std::list< std::shared_ptr<Entity> > m_arrowEntities;
std::list< std::shared_ptr<Entity> > m_experienceOrbEntities;
virtual bool addEntity(std::shared_ptr<Entity> e);
void entityAddedExtra(std::shared_ptr<Entity> e);
void entityRemovedExtra(std::shared_ptr<Entity> e);
virtual bool addEntity(std::shared_ptr<Entity> e);
void entityAddedExtra(std::shared_ptr<Entity> e);
void entityRemovedExtra(std::shared_ptr<Entity> e);
virtual bool newPrimedTntAllowed();
virtual bool newFallingTileAllowed();
virtual bool newPrimedTntAllowed();
virtual bool newFallingTileAllowed();
void flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFound); // 4J added
void flagEntitiesToBeRemoved(unsigned int* flags,
bool* removedFound); // 4J added
// 4J added
static const int MAX_UPDATES = 256;
// 4J added
static const int MAX_UPDATES = 256;
// Each of these need to be duplicated for each level in the current game. As we currently only have 2 (over/nether), making this constant
static Level *m_level[3];
static int m_updateChunkX[3][LEVEL_CHUNKS_TO_UPDATE_MAX];
static int m_updateChunkZ[3][LEVEL_CHUNKS_TO_UPDATE_MAX];
static int m_updateChunkCount[3];
static int m_updateTileX[3][MAX_UPDATES];
static int m_updateTileY[3][MAX_UPDATES];
static int m_updateTileZ[3][MAX_UPDATES];
static int m_updateTileCount[3];
static int m_randValue[3];
// Each of these need to be duplicated for each level in the current game.
// As we currently only have 2 (over/nether), making this constant
static Level* m_level[3];
static int m_updateChunkX[3][LEVEL_CHUNKS_TO_UPDATE_MAX];
static int m_updateChunkZ[3][LEVEL_CHUNKS_TO_UPDATE_MAX];
static int m_updateChunkCount[3];
static int m_updateTileX[3][MAX_UPDATES];
static int m_updateTileY[3][MAX_UPDATES];
static int m_updateTileZ[3][MAX_UPDATES];
static int m_updateTileCount[3];
static int m_randValue[3];
static C4JThread::EventArray* m_updateTrigger;
static CRITICAL_SECTION m_updateCS[3];
static C4JThread* m_updateThread;
static int runUpdate(void* lpParam);
static C4JThread::EventArray* m_updateTrigger;
static CRITICAL_SECTION m_updateCS[3];
static C4JThread* m_updateThread;
static int runUpdate(void* lpParam);
};

View File

@@ -11,116 +11,120 @@
#include "../../Minecraft.World/Headers/net.minecraft.network.packet.h"
#include "../../Minecraft.World/Level/LevelData.h"
ServerLevelListener::ServerLevelListener(MinecraftServer *server, ServerLevel *level)
{
this->server = server;
this->level = level;
ServerLevelListener::ServerLevelListener(MinecraftServer* server,
ServerLevel* level) {
this->server = server;
this->level = level;
}
// 4J removed -
// 4J removed -
/*
void ServerLevelListener::addParticle(const std::wstring& name, double x, double y, double z, double xa, double ya, double za)
void ServerLevelListener::addParticle(const std::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::addParticle(ePARTICLE_TYPE name, double x, double y,
double z, double xa, double ya,
double za) {}
void ServerLevelListener::allChanged() {}
void ServerLevelListener::entityAdded(std::shared_ptr<Entity> entity) {
MemSect(10);
level->getTracker()->addEntity(entity);
MemSect(0);
}
void ServerLevelListener::allChanged()
{
}
void ServerLevelListener::entityAdded(std::shared_ptr<Entity> entity)
{
MemSect(10);
level->getTracker()->addEntity(entity);
MemSect(0);
}
void ServerLevelListener::entityRemoved(std::shared_ptr<Entity> entity)
{
level->getTracker()->removeEntity(entity);
void ServerLevelListener::entityRemoved(std::shared_ptr<Entity> entity) {
level->getTracker()->removeEntity(entity);
}
// 4J added
void ServerLevelListener::playerRemoved(std::shared_ptr<Entity> entity)
{
std::shared_ptr<ServerPlayer> player = std::dynamic_pointer_cast<ServerPlayer>(entity);
player->getLevel()->getTracker()->removePlayer(entity);
void ServerLevelListener::playerRemoved(std::shared_ptr<Entity> entity) {
std::shared_ptr<ServerPlayer> player =
std::dynamic_pointer_cast<ServerPlayer>(entity);
player->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::shared_ptr<LevelSoundPacket>(new LevelSoundPacket(iSound, x, y, z, volume, pitch)));
}
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::shared_ptr<LevelSoundPacket>(
new LevelSoundPacket(iSound, x, y, z, volume, pitch)));
}
}
void ServerLevelListener::playSound(std::shared_ptr<Entity> entity,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
std::shared_ptr<Player> player= std::dynamic_pointer_cast<Player>(entity);
server->getPlayers()->broadcast(player,x, y, z, volume > 1 ? 16 * volume : 16, level->dimension->id, std::shared_ptr<LevelSoundPacket>(new LevelSoundPacket(iSound, x, y, z, volume, pitch)));
}
void ServerLevelListener::playSound(std::shared_ptr<Entity> entity, 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
std::shared_ptr<Player> player =
std::dynamic_pointer_cast<Player>(entity);
server->getPlayers()->broadcast(
player, x, y, z, volume > 1 ? 16 * volume : 16,
level->dimension->id,
std::shared_ptr<LevelSoundPacket>(
new 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::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::skyColorChanged()
{
void ServerLevelListener::tileLightChanged(int x, int y, int z) {}
void ServerLevelListener::playStreamingMusic(const std::wstring& name, int x,
int y, int z) {}
void ServerLevelListener::levelEvent(std::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::shared_ptr<LevelEventPacket>(
new LevelEventPacket(type, x, y, z, data)));
}
void ServerLevelListener::tileChanged(int x, int y, int z)
{
level->getChunkMap()->tileChanged(x, y, z);
}
void ServerLevelListener::destroyTileProgress(int id, int x, int y, int z,
int progress) {
// for (ServerPlayer p : server->getPlayers()->players)
for (AUTO_VAR(it, server->getPlayers()->players.begin());
it != server->getPlayers()->players.end(); ++it) {
std::shared_ptr<ServerPlayer> p = *it;
if (p == NULL || p->level != level || p->entityId == id) continue;
double xd = (double)x - p->x;
double yd = (double)y - p->y;
double zd = (double)z - p->z;
void ServerLevelListener::tileLightChanged(int x, int y, int z)
{
}
void ServerLevelListener::playStreamingMusic(const std::wstring& name, int x, int y, int z)
{
}
void ServerLevelListener::levelEvent(std::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::shared_ptr<LevelEventPacket>( new LevelEventPacket(type, x, y, z, data) ) );
}
void ServerLevelListener::destroyTileProgress(int id, int x, int y, int z, int progress)
{
//for (ServerPlayer p : server->getPlayers()->players)
for(AUTO_VAR(it, server->getPlayers()->players.begin()); it != server->getPlayers()->players.end(); ++it)
{
std::shared_ptr<ServerPlayer> p = *it;
if (p == NULL || p->level != level || p->entityId == id) continue;
double xd = (double) x - p->x;
double yd = (double) y - p->y;
double zd = (double) z - p->z;
if (xd * xd + yd * yd + zd * zd < 32 * 32)
{
p->connection->send(std::shared_ptr<TileDestructionPacket>(new TileDestructionPacket(id, x, y, z, progress)));
}
}
if (xd * xd + yd * yd + zd * zd < 32 * 32) {
p->connection->send(std::shared_ptr<TileDestructionPacket>(
new TileDestructionPacket(id, x, y, z, progress)));
}
}
}

View File

@@ -7,27 +7,37 @@ class MinecraftServer;
class ServerLevel;
// 4J - renamed class to ServerLevelListener to avoid clash with LevelListener
class ServerLevelListener : public LevelListener
{
class ServerLevelListener : public LevelListener {
private:
MinecraftServer *server;
ServerLevel *level;
MinecraftServer* server;
ServerLevel* level;
public:
ServerLevelListener(MinecraftServer *server, ServerLevel *level);
// 4J removed - virtual void addParticle(const std::wstring& name, double x, double y, double z, double xa, double ya, double za);
virtual void addParticle(ePARTICLE_TYPE name, double x, double y, double z, double xa, double ya, double za); // 4J added
ServerLevelListener(MinecraftServer* server, ServerLevel* level);
// 4J removed - virtual void addParticle(const std::wstring& name, double x,
// double y, double z, double xa, double ya, double za);
virtual void addParticle(ePARTICLE_TYPE name, double x, double y, double z,
double xa, double ya, double za); // 4J added
virtual void allChanged();
virtual void entityAdded(std::shared_ptr<Entity> entity);
virtual void entityRemoved(std::shared_ptr<Entity> entity);
virtual void playerRemoved(std::shared_ptr<Entity> entity); // 4J added - for when a player is removed from the level's player array, not just the entity storage
virtual void playSound(int iSound, double x, double y, double z, float volume, float pitch, float fClipSoundDist);
virtual void playSound(std::shared_ptr<Entity> entity,int iSound, double x, double y, double z, float volume, float pitch, float fClipSoundDist);
virtual void setTilesDirty(int x0, int y0, int z0, int x1, int y1, int z1, Level *level); // 4J - added level param
virtual void playerRemoved(
std::shared_ptr<Entity>
entity); // 4J added - for when a player is removed from the
// level's player array, not just the entity storage
virtual void playSound(int iSound, double x, double y, double z,
float volume, float pitch, float fClipSoundDist);
virtual void playSound(std::shared_ptr<Entity> entity, int iSound, double x,
double y, double z, float volume, float pitch,
float fClipSoundDist);
virtual void setTilesDirty(int x0, int y0, int z0, int x1, int y1, int z1,
Level* level); // 4J - added level param
virtual void skyColorChanged();
virtual void tileChanged(int x, int y, int z);
virtual void tileLightChanged(int x, int y, int z);
virtual void playStreamingMusic(const std::wstring& name, int x, int y, int z);
virtual void levelEvent(std::shared_ptr<Player> source, int type, int x, int y, int z, int data);
virtual void destroyTileProgress(int id, int x, int y, int z, int progress);
virtual void tileLightChanged(int x, int y, int z);
virtual void playStreamingMusic(const std::wstring& name, int x, int y,
int z);
virtual void levelEvent(std::shared_ptr<Player> source, int type, int x,
int y, int z, int data);
virtual void destroyTileProgress(int id, int x, int y, int z, int progress);
};