the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#pragma once
2#include "..\Minecraft.World\net.minecraft.world.level.h"
3#include "..\Minecraft.World\JavaIntHash.h"
4class ServerChunkCache;
5class MinecraftServer;
6class Node;
7class EntityTracker;
8class PlayerChunkMap;
9using namespace std;
10
11class ServerLevel : public Level
12{
13private:
14 static const int EMPTY_TIME_NO_TICK = SharedConstants::TICKS_PER_SECOND * 60;
15
16 MinecraftServer *server;
17 EntityTracker *tracker;
18 PlayerChunkMap *chunkMap;
19
20 CRITICAL_SECTION m_tickNextTickCS; // 4J added
21 set<TickNextTickData, TickNextTickDataKeyCompare> tickNextTickList; // 4J Was TreeSet
22 unordered_set<TickNextTickData, TickNextTickDataKeyHash, TickNextTickDataKeyEq> tickNextTickSet; // 4J Was HashSet
23
24 vector<Pos *> m_queuedSendTileUpdates; // 4J added
25 CRITICAL_SECTION m_csQueueSendTileUpdates;
26
27protected:
28 int saveInterval;
29
30public:
31 ServerChunkCache *cache;
32 bool canEditSpawn;
33 bool noSave;
34private:
35 bool allPlayersSleeping;
36 PortalForcer *portalForcer;
37 MobSpawner *mobSpawner;
38 int emptyTime;
39 bool m_bAtLeastOnePlayerSleeping; // 4J Added
40 static WeighedTreasureArray RANDOM_BONUS_ITEMS; // 4J - brought forward from 1.3.2
41
42 vector<TileEventData> tileEvents[2];
43 int activeTileEventsList;
44public:
45 static void staticCtor();
46 ServerLevel(MinecraftServer *server, shared_ptr<LevelStorage>levelStorage, const wstring& levelName, int dimension, LevelSettings *levelSettings);
47 ~ServerLevel();
48 void tick();
49 Biome::MobSpawnerData *getRandomMobSpawnAt(MobCategory *mobCategory, int x, int y, int z);
50 void updateSleepingPlayerList();
51protected:
52 void awakenAllPlayers();
53
54private:
55 void stopWeather();
56
57public:
58 bool allPlayersAreSleeping();
59 void validateSpawn();
60
61protected:
62 void tickTiles();
63
64private:
65 vector<TickNextTickData> toBeTicked;
66
67public:
68 bool isTileToBeTickedAt(int x, int y, int z, int tileId);
69 void addToTickNextTick(int x, int y, int z, int tileId, int tickDelay);
70 void addToTickNextTick(int x, int y, int z, int tileId, int tickDelay, int priorityTilt);
71 void forceAddTileTick(int x, int y, int z, int tileId, int tickDelay, int prioTilt);
72 void tickEntities();
73 void resetEmptyTime();
74 bool tickPendingTicks(bool force);
75 vector<TickNextTickData> *fetchTicksInChunk(LevelChunk *chunk, bool remove);
76 virtual void tick(shared_ptr<Entity> e, bool actual);
77 void forceTick(shared_ptr<Entity> e, bool actual);
78 bool AllPlayersAreSleeping() { return allPlayersSleeping;} // 4J added for a message to other players
79 bool isAtLeastOnePlayerSleeping() { return m_bAtLeastOnePlayerSleeping;}
80protected:
81 ChunkSource *createChunkSource(); // 4J - was virtual, but was called from parent ctor
82public:
83 vector<shared_ptr<TileEntity> > *getTileEntitiesInRegion(int x0, int y0, int z0, int x1, int y1, int z1);
84 virtual bool mayInteract(shared_ptr<Player> player, int xt, int yt, int zt, int content);
85protected:
86 virtual void initializeLevel(LevelSettings *settings);
87 virtual void setInitialSpawn(LevelSettings *settings);
88 void generateBonusItemsNearSpawn(); // 4J - brought forward from 1.3.2
89
90public:
91 Pos *getDimensionSpecificSpawn();
92
93 void Suspend(); // 4j Added for XboxOne PLM
94
95 void save(bool force, ProgressListener *progressListener, bool bAutosave=false);
96 void saveToDisc(ProgressListener *progressListener, bool autosave); // 4J Added
97
98private:
99 void saveLevelData();
100
101 typedef unordered_map<int, shared_ptr<Entity> , IntKeyHash2, IntKeyEq> intEntityMap;
102 intEntityMap entitiesById; // 4J - was IntHashMap, using same hashing function as this uses
103protected:
104 virtual void entityAdded(shared_ptr<Entity> e);
105 virtual void entityRemoved(shared_ptr<Entity> e);
106public:
107 shared_ptr<Entity> getEntity(int id);
108 virtual bool addGlobalEntity(shared_ptr<Entity> e);
109 void broadcastEntityEvent(shared_ptr<Entity> e, byte event);
110 virtual shared_ptr<Explosion> explode(shared_ptr<Entity> source, double x, double y, double z, float r, bool fire, bool destroyBlocks);
111 virtual void tileEvent(int x, int y, int z, int tile, int b0, int b1);
112
113private:
114 void runTileEvents();
115 bool doTileEvent(TileEventData *te);
116
117public:
118 void closeLevelStorage();
119protected:
120 virtual void tickWeather();
121
122public:
123 MinecraftServer *getServer();
124 EntityTracker *getTracker();
125 void setTimeAndAdjustTileTicks(__int64 newTime);
126 PlayerChunkMap *getChunkMap();
127 PortalForcer *getPortalForcer();
128 void sendParticles(const wstring &name, double x, double y, double z, int count);
129 void sendParticles(const wstring &name, double x, double y, double z, int count, double xDist, double yDist, double zDist, double speed);
130
131 void queueSendTileUpdate(int x, int y, int z); // 4J Added
132private:
133 void runQueuedSendTileUpdates();// 4J Added
134
135 // 4J - added for implementation of finite limit to number of item entities, tnt and falling block entities
136public:
137
138 static const int MAX_HANGING_ENTITIES = 400;
139 static const int MAX_ITEM_ENTITIES = 200;
140 static const int MAX_ARROW_ENTITIES = 200;
141 static const int MAX_EXPERIENCEORB_ENTITIES = 50;
142 static const int MAX_PRIMED_TNT = 20;
143 static const int MAX_FALLING_TILE = 20;
144
145 int m_primedTntCount;
146 int m_fallingTileCount;
147 CRITICAL_SECTION m_limiterCS;
148 list< shared_ptr<Entity> > m_itemEntities;
149 list< shared_ptr<Entity> > m_hangingEntities;
150 list< shared_ptr<Entity> > m_arrowEntities;
151 list< shared_ptr<Entity> > m_experienceOrbEntities;
152
153 virtual bool addEntity(shared_ptr<Entity> e);
154 void entityAddedExtra(shared_ptr<Entity> e);
155 void entityRemovedExtra(shared_ptr<Entity> e);
156
157 bool atEntityLimit(shared_ptr<Entity> e); // 4J: Added
158
159 virtual bool newPrimedTntAllowed();
160 virtual bool newFallingTileAllowed();
161
162 void flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFound); // 4J added
163
164 // 4J added
165 static const int MAX_UPDATES = 256;
166
167 // 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
168 static Level *m_level[3];
169 static int m_updateChunkX[3][LEVEL_CHUNKS_TO_UPDATE_MAX];
170 static int m_updateChunkZ[3][LEVEL_CHUNKS_TO_UPDATE_MAX];
171 static int m_updateChunkCount[3];
172 static int m_updateTileX[3][MAX_UPDATES];
173 static int m_updateTileY[3][MAX_UPDATES];
174 static int m_updateTileZ[3][MAX_UPDATES];
175 static int m_updateTileCount[3];
176 static int m_randValue[3];
177
178 static C4JThread::EventArray* m_updateTrigger;
179 static CRITICAL_SECTION m_updateCS[3];
180
181 static C4JThread* m_updateThread;
182 static int runUpdate(void* lpParam);
183
184};