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\JavaIntHash.h"
3#include "..\Minecraft.World\ChunkPos.h"
4class ServerPlayer;
5class ServerLevel;
6class MinecraftServer;
7class Packet;
8class TileEntity;
9using namespace std;
10
11class PlayerChunkMap
12{
13public:
14#ifdef _LARGE_WORLDS
15 static const int MAX_VIEW_DISTANCE = 30;
16#else
17 static const int MAX_VIEW_DISTANCE = 15;
18#endif
19 static const int MIN_VIEW_DISTANCE = 3;
20 static const int MAX_CHANGES_BEFORE_RESEND = 10;
21 static const int MIN_TICKS_BETWEEN_REGION_UPDATE = 10;
22
23 // 4J - added
24 class PlayerChunkAddRequest
25 {
26 public:
27 int x,z;
28 shared_ptr<ServerPlayer> player;
29 PlayerChunkAddRequest(int x, int z, shared_ptr<ServerPlayer> player ) : x(x), z(z), player(player) {}
30 };
31
32 class PlayerChunk
33 {
34 friend class PlayerChunkMap;
35 private:
36 PlayerChunkMap *parent; // 4J added
37 vector<shared_ptr<ServerPlayer> > players;
38 //int x, z;
39 ChunkPos pos;
40
41 shortArray changedTiles;
42 int changes;
43 int xChangeMin, xChangeMax;
44 int yChangeMin, yChangeMax;
45 int zChangeMin, zChangeMax;
46 int ticksToNextRegionUpdate; // 4J added
47 bool prioritised; // 4J added
48 __int64 firstInhabitedTime;
49
50 public:
51 PlayerChunk(int x, int z, PlayerChunkMap *pcm);
52 ~PlayerChunk();
53
54 // 4J Added sendPacket param so we can aggregate the initial send into one much smaller packet
55 void add(shared_ptr<ServerPlayer> player, bool sendPacket = true);
56 void remove(shared_ptr<ServerPlayer> player);
57 void updateInhabitedTime();
58
59 private:
60 void updateInhabitedTime(LevelChunk *chunk);
61
62 public:
63 void tileChanged(int x, int y, int z);
64 void prioritiseTileChanges(); // 4J added
65 void broadcast(shared_ptr<Packet> packet);
66 bool broadcastChanges(bool allowRegionUpdate); // 4J - added parm
67
68 private:
69 void broadcast(shared_ptr<TileEntity> te);
70 };
71
72public:
73 vector<shared_ptr<ServerPlayer> > players;
74 void flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFound); // 4J added
75private:
76 unordered_map<__int64,PlayerChunk *,LongKeyHash,LongKeyEq> chunks; // 4J - was LongHashMap
77 vector<PlayerChunk *> changedChunks;
78 vector<PlayerChunk *> knownChunks;
79 vector<PlayerChunkAddRequest> addRequests; // 4J added
80 void tickAddRequests(shared_ptr<ServerPlayer> player); // 4J added
81
82 ServerLevel *level;
83 int radius;
84 int dimension;
85 __int64 lastInhabitedUpdate;
86
87public:
88 PlayerChunkMap(ServerLevel *level, int dimension, int radius);
89 ~PlayerChunkMap();
90 ServerLevel *getLevel();
91 void tick();
92 bool hasChunk(int x, int z);
93private:
94 PlayerChunk *getChunk(int x, int z, bool create);
95 void getChunkAndAddPlayer(int x, int z, shared_ptr<ServerPlayer> player); // 4J added
96 void getChunkAndRemovePlayer(int x, int z, shared_ptr<ServerPlayer> player); // 4J added
97public:
98 void broadcastTileUpdate(shared_ptr<Packet> packet, int x, int y, int z);
99 void tileChanged(int x, int y, int z);
100 bool isTrackingTile(int x, int y, int z); // 4J added
101 void prioritiseTileChanges(int x, int y, int z); // 4J added
102 void add(shared_ptr<ServerPlayer> player);
103 void remove(shared_ptr<ServerPlayer> player);
104private:
105 bool chunkInRange(int x, int z, int xc, int zc);
106public:
107 void move(shared_ptr<ServerPlayer> player);
108 int getMaxRange();
109 bool isPlayerIn(shared_ptr<ServerPlayer> player, int xChunk, int zChunk);
110 static int convertChunkRangeToBlock(int radius);
111
112 // AP added for Vita
113 void setRadius(int newRadius);
114};