diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/ChunkPos.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/ChunkPos.cpp')
| -rw-r--r-- | Minecraft.World/ChunkPos.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Minecraft.World/ChunkPos.cpp b/Minecraft.World/ChunkPos.cpp new file mode 100644 index 00000000..3f9674a7 --- /dev/null +++ b/Minecraft.World/ChunkPos.cpp @@ -0,0 +1,75 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.h" +#include "ChunkPos.h" + +ChunkPos::ChunkPos(int x, int z) : x( x ), z( z ) +{ +} + +__int64 ChunkPos::hashCode(int x, int z) +{ + __int64 xx = x; + __int64 zz = z; + return (xx & 0xffffffffl) | ((zz & 0xffffffffl) << 32l); +} + +int ChunkPos::hashCode() +{ + __int64 hash = hashCode(x, z); + int h1 = (int) (hash); + int h2 = (int) (hash >> 32l); + return h1 ^ h2; +} + +double ChunkPos::distanceToSqr(shared_ptr<Entity> e) +{ + double xPos = x * 16 + 8; + double zPos = z * 16 + 8; + + double xd = xPos - e->x; + double zd = zPos - e->z; + + return xd * xd + zd * zd; +} + +double ChunkPos::distanceToSqr(double px, double pz) +{ + double xPos = x * 16 + 8; + double zPos = z * 16 + 8; + + double xd = xPos - px; + double zd = zPos - pz; + + return xd * xd + zd * zd; +} + +int ChunkPos::getMiddleBlockX() +{ + return ( x << 4 ) + 8; +} + +int ChunkPos::getMiddleBlockZ() +{ + return ( z << 4 ) + 8; +} + +TilePos ChunkPos::getMiddleBlockPosition(int y) +{ + return TilePos(getMiddleBlockX(), y, getMiddleBlockZ()); +} + +wstring ChunkPos::toString() +{ + return L"[" + _toString<int>(x) + L", " + _toString<int>(z) + L"]"; +} + +__int64 ChunkPos::hash_fnct(const ChunkPos &k) +{ + return k.hashCode(k.x,k.z); +} + +bool ChunkPos::eq_test(const ChunkPos &x, const ChunkPos &y) +{ + return x.x == y.x && x.z == y.z; +} + |
