Files
MinecraftConsoles/Minecraft.World/ChunkPos.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

76 lines
1.3 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.entity.h"
#include "ChunkPos.h"
ChunkPos::ChunkPos(int x, int z) : x( x ), z( z )
{
}
int64_t ChunkPos::hashCode(int x, int z)
{
int64_t xx = x;
int64_t zz = z;
return (xx & 0xffffffffl) | ((zz & 0xffffffffl) << 32l);
}
int ChunkPos::hashCode()
{
int64_t hash = hashCode(x, z);
const int h1 = static_cast<int>(hash);
const int h2 = static_cast<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"[" + std::to_wstring(x) + L", " + std::to_wstring(z) + L"]";
}
int64_t 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;
}