From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.Client/PlayerChunkMap.h | 105 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Minecraft.Client/PlayerChunkMap.h (limited to 'Minecraft.Client/PlayerChunkMap.h') diff --git a/Minecraft.Client/PlayerChunkMap.h b/Minecraft.Client/PlayerChunkMap.h new file mode 100644 index 00000000..61324272 --- /dev/null +++ b/Minecraft.Client/PlayerChunkMap.h @@ -0,0 +1,105 @@ +#pragma once +#include "..\Minecraft.World\JavaIntHash.h" +#include "..\Minecraft.World\ChunkPos.h" +class ServerPlayer; +class ServerLevel; +class MinecraftServer; +class Packet; +class TileEntity; +using namespace std; + +class PlayerChunkMap +{ +public: +#ifdef _LARGE_WORLDS + static const int MAX_VIEW_DISTANCE = 30; +#else + static const int MAX_VIEW_DISTANCE = 15; +#endif + static const int MIN_VIEW_DISTANCE = 3; + static const int MAX_CHANGES_BEFORE_RESEND = 10; + static const int MIN_TICKS_BETWEEN_REGION_UPDATE = 10; + + // 4J - added + class PlayerChunkAddRequest + { + public: + int x,z; + shared_ptr player; + PlayerChunkAddRequest(int x, int z, shared_ptr player ) : x(x), z(z), player(player) {} + }; + + class PlayerChunk + { + friend class PlayerChunkMap; + private: + PlayerChunkMap *parent; // 4J added + vector > players; + //int x, z; + ChunkPos pos; + + shortArray changedTiles; + int changes; + int xChangeMin, xChangeMax; + int yChangeMin, yChangeMax; + int zChangeMin, zChangeMax; + int ticksToNextRegionUpdate; // 4J added + bool prioritised; // 4J added + + public: + PlayerChunk(int x, int z, PlayerChunkMap *pcm); + ~PlayerChunk(); + + // 4J Added sendPacket param so we can aggregate the initial send into one much smaller packet + void add(shared_ptr player, bool sendPacket = true); + void remove(shared_ptr player); + void tileChanged(int x, int y, int z); + void prioritiseTileChanges(); // 4J added + void broadcast(shared_ptr packet); + bool broadcastChanges(bool allowRegionUpdate); // 4J - added parm + + private: + void broadcast(shared_ptr te); + }; + +public: + vector > players; + void flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFound); // 4J added +private: + unordered_map<__int64,PlayerChunk *,LongKeyHash,LongKeyEq> chunks; // 4J - was LongHashMap + vector changedChunks; + vector addRequests; // 4J added + void tickAddRequests(shared_ptr player); // 4J added + + ServerLevel *level; + int radius; + int dimension; + +public: + PlayerChunkMap(ServerLevel *level, int dimension, int radius); + ~PlayerChunkMap(); + ServerLevel *getLevel(); + void tick(); + bool hasChunk(int x, int z); +private: + PlayerChunk *getChunk(int x, int z, bool create); + void getChunkAndAddPlayer(int x, int z, shared_ptr player); // 4J added + void getChunkAndRemovePlayer(int x, int z, shared_ptr player); // 4J added +public: + void broadcastTileUpdate(shared_ptr packet, int x, int y, int z); + void tileChanged(int x, int y, int z); + bool isTrackingTile(int x, int y, int z); // 4J added + void prioritiseTileChanges(int x, int y, int z); // 4J added + void add(shared_ptr player); + void remove(shared_ptr player); +private: + bool chunkInRange(int x, int z, int xc, int zc); +public: + void move(shared_ptr player); + int getMaxRange(); + bool isPlayerIn(shared_ptr player, int xChunk, int zChunk); + static int convertChunkRangeToBlock(int radius); + + // AP added for Vita + void setRadius(int newRadius); +}; -- cgit v1.2.3