Merge branch 'dev' into dev

This commit is contained in:
Tropical 2026-03-27 18:20:24 -05:00 committed by GitHub
commit 293590ef77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
128 changed files with 8396 additions and 8452 deletions

View file

@ -1112,13 +1112,13 @@ std::shared_ptr<Explosion> ServerLevel::explode(std::shared_ptr<Entity> source,
}
if (player->distanceToSqr(x, y, z) < 64 * 64) {
Vec3* knockbackVec = explosion->getHitPlayerKnockback(player);
Vec3 knockbackVec = explosion->getHitPlayerKnockback(player);
// app.DebugPrintf("Sending %s with knockback (%f,%f,%f)\n",
// knockbackOnly?"knockbackOnly":"allExplosion",knockbackVec->x,knockbackVec->y,knockbackVec->z);
// If the player is not the primary on the system, then we only
// want to send info for the knockback
player->connection->send(std::shared_ptr<ExplodePacket>(
new ExplodePacket(x, y, z, r, &explosion->toBlow, knockbackVec,
new ExplodePacket(x, y, z, r, &explosion->toBlow, &knockbackVec,
knockbackOnly)));
sentTo.push_back(player);
}
@ -1584,4 +1584,4 @@ void ServerLevel::flagEntitiesToBeRemoved(unsigned int* flags,
if (chunkMap) {
chunkMap->flagEntitiesToBeRemoved(flags, removedFound);
}
}
}

View file

@ -724,7 +724,6 @@ void Minecraft::run()
// try { // 4J - removed try/catch
// if (minecraftApplet != null && !minecraftApplet.isActive()) break; // 4J - removed
AABB::resetPool();
Vec3::resetPool();
// if (parent == NULL && Display.isCloseRequested()) { // 4J - removed
// stop();
@ -1281,7 +1280,6 @@ void Minecraft::run_middle() {
// if (minecraftApplet != null &&
// !minecraftApplet.isActive()) break; // 4J - removed
AABB::resetPool();
Vec3::resetPool();
// if (parent == NULL && Display.isCloseRequested()) {
// // 4J - removed
@ -2223,7 +2221,6 @@ void Minecraft::emergencySave() {
// 4J - lots of try/catches removed here, and garbage collector things
levelRenderer->clear();
AABB::clearPool();
Vec3::clearPool();
setLevel(NULL);
}
@ -2400,7 +2397,6 @@ void Minecraft::levelTickUpdateFunc(void* pParam) {
void Minecraft::levelTickThreadInitFunc() {
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::UseDefaultThreadStorage();
}
@ -2750,7 +2746,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
// 4J-PB - Call the useItemOn with the TestOnly flag set
bool bUseItemOn = gameMode->useItemOn(
player, level, itemInstance, x, y, z, face,
hitResult->pos, true);
&hitResult->pos, true);
/* 4J-Jev:
* Moved this here so we have item tooltips to
@ -3900,7 +3896,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
bool usedItem = false;
gameMode->useItemOn(player, level, nullptr, hitResult->x,
hitResult->y, hitResult->z, 0,
hitResult->pos, false, &usedItem);
&hitResult->pos, false, &usedItem);
} else {
ui.PlayUISFX(eSFX_Press);
app.LoadCrafting2x2Menu(iPad, player);

View file

@ -315,7 +315,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
Entity::useSmallIds(); // This thread can end up spawning entities as
// resources
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::UseDefaultThreadStorage();
Level::enableLightingCache();
Tile::CreateNewThreadStorage();
@ -365,7 +364,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
// #endif //__PS3__
Tile::ReleaseThreadStorage();
AABB::ReleaseThreadStorage();
Vec3::ReleaseThreadStorage();
Level::destroyLightingCache();
ShutdownManager::HasFinished(ShutdownManager::ePostProcessThread);
@ -1651,7 +1649,6 @@ void MinecraftServer::tick() {
}
AABB::resetPool();
Vec3::resetPool();
tickCount++;

View file

@ -1551,7 +1551,8 @@ void PlayerConnection::handlePlayerAbilities(
// StringBuilder result = new StringBuilder();
// for (String candidate : server.getAutoCompletions(player,
//packet.getMessage())) { if (result.length() > 0) result.append("\0");
// packet.getMessage())) { if (result.length() > 0)
// result.append("\0");
// result.append(candidate);
// }

View file

@ -4706,7 +4706,6 @@ int CMinecraftApp::SignoutExitWorldThreadProc(void* lpParameter) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
// app.SetGameStarted(false);
@ -6332,7 +6331,7 @@ int CMinecraftApp::WarningTrialTexturePackReturned(
DLCPack *pDLCPack=pDLCTexPack->getDLCInfoParentPack();//tPack->getDLCPack();
const char *pchPackName=wstringtofilename(pDLCPack->getName());
app.DebugPrintf("Texture Pack - %s\n",pchPackName);
SONYDLC *pSONYDLCInfo=app.GetSONYDLCInfo((char *)pchPackName);
SONYDLC *pSONYDLCInfo=app.GetSONYDLCInfo((char *)pchPackName);
if(pSONYDLCInfo!=NULL)
{
@ -6353,14 +6352,14 @@ int CMinecraftApp::WarningTrialTexturePackReturned(
#if defined __ORBIS__ || defined __PSVITA__ || defined __PS3__
if(app.CheckForEmptyStore(iPad)==false)
#endif
{
{
if(app.DLCAlreadyPurchased(chSkuID))
{
app.DownloadAlreadyPurchased(chSkuID);
}
else
{
app.Checkout(chSkuID);
app.Checkout(chSkuID);
}
}
}
@ -7698,7 +7697,6 @@ int CMinecraftApp::RemoteSaveThreadProc(void* lpParameter) {
// The game should be stopped while we are doing this, but the connections
// ticks may try to create some AABB's or Vec3's
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
// 4J-PB - Xbox 360 - 163153 - [CRASH] TU17: Code: Multiplayer: During the
@ -10355,4 +10353,4 @@ std::wstring CMinecraftApp::getRootPath(std::uint32_t packId,
void CMinecraftApp::SetReachedMainMenu() { m_hasReachedMainMenu = true; }
bool CMinecraftApp::HasReachedMainMenu() { return m_hasReachedMainMenu; }
#endif
#endif

View file

@ -12,7 +12,7 @@
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
LevelGenerationOptions* levelGenOptions) {
m_levelGenOptions = levelGenOptions;
m_location = Vec3::newPermanent(0, 0, 0);
m_location = Vec3(0, 0, 0);
m_locationBox = NULL;
m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0;
@ -26,7 +26,6 @@ ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() {
app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n");
if (!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName);
m_schematic = NULL;
delete m_location;
}
void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
@ -36,11 +35,11 @@ void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename);
dos->writeUTF(m_schematicName);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
dos->writeUTF(_toString(m_location->x));
dos->writeUTF(_toString(m_location.x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
dos->writeUTF(_toString(m_location->y));
dos->writeUTF(_toString(m_location.y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
dos->writeUTF(_toString(m_location->z));
dos->writeUTF(_toString(m_location.z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
switch (m_rotation) {
@ -76,19 +75,19 @@ void ApplySchematicRuleDefinition::addAttribute(
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
}
} else if (attributeName.compare(L"x") == 0) {
m_location->x = _fromString<int>(attributeValue);
if (((int)abs(m_location->x)) % 2 != 0) m_location->x -= 1;
m_location.x = _fromString<int>(attributeValue);
if (((int)abs(m_location.x)) % 2 != 0) m_location.x -= 1;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// x=%f\n",m_location->x);
} else if (attributeName.compare(L"y") == 0) {
m_location->y = _fromString<int>(attributeValue);
if (((int)abs(m_location->y)) % 2 != 0) m_location->y -= 1;
if (m_location->y < 0) m_location->y = 0;
m_location.y = _fromString<int>(attributeValue);
if (((int)abs(m_location.y)) % 2 != 0) m_location.y -= 1;
if (m_location.y < 0) m_location.y = 0;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// y=%f\n",m_location->y);
} else if (attributeName.compare(L"z") == 0) {
m_location->z = _fromString<int>(attributeValue);
if (((int)abs(m_location->z)) % 2 != 0) m_location->z -= 1;
m_location.z = _fromString<int>(attributeValue);
if (((int)abs(m_location.z)) % 2 != 0) m_location.z -= 1;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// z=%f\n",m_location->z);
} else if (attributeName.compare(L"rot") == 0) {
@ -133,23 +132,23 @@ void ApplySchematicRuleDefinition::updateLocationBox() {
m_locationBox = AABB::newPermanent(0, 0, 0, 0, 0, 0);
m_locationBox->x0 = m_location->x;
m_locationBox->y0 = m_location->y;
m_locationBox->z0 = m_location->z;
m_locationBox->x0 = m_location.x;
m_locationBox->y0 = m_location.y;
m_locationBox->z0 = m_location.z;
m_locationBox->y1 = m_location->y + m_schematic->getYSize();
m_locationBox->y1 = m_location.y + m_schematic->getYSize();
switch (m_rotation) {
case ConsoleSchematicFile::eSchematicRot_90:
case ConsoleSchematicFile::eSchematicRot_270:
m_locationBox->x1 = m_location->x + m_schematic->getZSize();
m_locationBox->z1 = m_location->z + m_schematic->getXSize();
m_locationBox->x1 = m_location.x + m_schematic->getZSize();
m_locationBox->z1 = m_location.z + m_schematic->getXSize();
break;
case ConsoleSchematicFile::eSchematicRot_0:
case ConsoleSchematicFile::eSchematicRot_180:
default:
m_locationBox->x1 = m_location->x + m_schematic->getXSize();
m_locationBox->z1 = m_location->z + m_schematic->getZSize();
m_locationBox->x1 = m_location.x + m_schematic->getXSize();
m_locationBox->z1 = m_location.z + m_schematic->getZSize();
break;
};
}
@ -251,4 +250,4 @@ void ApplySchematicRuleDefinition::reset() {
m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0;
m_completed = false;
}
}

View file

@ -13,7 +13,7 @@ private:
LevelGenerationOptions* m_levelGenOptions;
std::wstring m_schematicName;
ConsoleSchematicFile* m_schematic;
Vec3* m_location;
Vec3 m_location;
AABB* m_locationBox;
ConsoleSchematicFile::ESchematicRotation m_rotation;
int m_dimension;
@ -51,4 +51,4 @@ public:
* Reset any state to how it should be before a new game.
*/
void reset();
};
};

View file

@ -155,8 +155,8 @@ void ConsoleSchematicFile::load(DataInputStream* dis) {
// app.DebugPrintf(1,"Loaded entity type %d at
// (%f,%f,%f)\n",(int)type,x,y,z);
#endif
m_entities.push_back(std::pair<Vec3*, CompoundTag*>(
Vec3::newPermanent(x, y, z), (CompoundTag*)eTag->copy()));
m_entities.push_back(std::pair<Vec3, CompoundTag*>(
Vec3(x, y, z), (CompoundTag*)eTag->copy()));
}
}
delete tag;
@ -463,8 +463,8 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
schematicCoordToChunkCoord(destinationBox, te->x, te->z, rot, targetX,
targetZ);
Vec3* pos = Vec3::newTemp(targetX, targetY, targetZ);
if (chunkBox->containsIncludingLowerBound(pos)) {
Vec3 pos(targetX, targetY, targetZ);
if (chunkBox->containsIncludingLowerBound(&pos)) {
std::shared_ptr<TileEntity> teCopy = chunk->getTileEntity(
(int)targetX & 15, (int)targetY & 15, (int)targetZ & 15);
@ -500,19 +500,18 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
}
}
for (AUTO_VAR(it, m_entities.begin()); it != m_entities.end();) {
Vec3* source = it->first;
Vec3 source = it->first;
double targetX = source->x;
double targetY = source->y + destinationBox->y0;
double targetZ = source->z;
schematicCoordToChunkCoord(destinationBox, source->x, source->z, rot,
double targetX = source.x;
double targetY = source.y + destinationBox->y0;
double targetZ = source.z;
schematicCoordToChunkCoord(destinationBox, source.x, source.z, rot,
targetX, targetZ);
// Add 0.01 as the AABB::contains function returns false if a value is
// <= the lower bound
Vec3* pos =
Vec3::newTemp(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
if (!chunkBox->containsIncludingLowerBound(pos)) {
Vec3 pos(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
if (!chunkBox->containsIncludingLowerBound(&pos)) {
++it;
continue;
}
@ -800,8 +799,8 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
// if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH)
//{
// byteArray blockData = byteArray(data->data + blocksP,
//Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); blocksP +=
//blockData.length;
// Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData);
// blocksP += blockData.length;
// byteArray dataData = byteArray(data->data + dataP, 16384);
// chunk->getBlockLightData(dataData);

View file

@ -54,7 +54,7 @@ public:
private:
int m_xSize, m_ySize, m_zSize;
std::vector<std::shared_ptr<TileEntity> > m_tileEntities;
std::vector<std::pair<Vec3*, CompoundTag*> > m_entities;
std::vector<std::pair<Vec3, CompoundTag*> > m_entities;
public:
byteArray m_data;

View file

@ -948,7 +948,6 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
Tile::CreateNewThreadStorage();
@ -1008,7 +1007,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
SetThreadName(-1, "Minecraft Server thread");
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::UseDefaultThreadStorage();
OldChunkStorage::UseDefaultThreadStorage();
Entity::useSmallIds();
@ -1022,7 +1020,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
Tile::ReleaseThreadStorage();
AABB::ReleaseThreadStorage();
Vec3::ReleaseThreadStorage();
Level::destroyLightingCache();
if (lpParameter != NULL) delete (NetworkGameInitData*)lpParameter;
@ -1034,7 +1031,6 @@ int CGameNetworkManager::ExitAndJoinFromInviteThreadProc(void* lpParam) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
// app.SetGameStarted(false);
@ -1187,7 +1183,6 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
Minecraft* pMinecraft = Minecraft::GetInstance();

View file

@ -25,8 +25,8 @@ AreaConstraint::~AreaConstraint() {
bool AreaConstraint::isConstraintSatisfied(int iPad) {
Minecraft* minecraft = Minecraft::GetInstance();
return messageArea->contains(minecraft->localplayers[iPad]->getPos(1)) ==
contains;
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
return messageArea->contains(&ipad_player) == contains;
}
bool AreaConstraint::isConstraintRestrictive(int iPad) {
@ -37,15 +37,15 @@ bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
double xt, double yt, double zt) {
if (!m_restrictsMovement) return true;
Vec3* targetPos = Vec3::newTemp(xt, yt, zt);
Vec3 targetPos(xt, yt, zt);
Minecraft* minecraft = Minecraft::GetInstance();
if (movementArea->contains(targetPos) == contains) {
if (movementArea->contains(&targetPos) == contains) {
return true;
}
Vec3* origPos = Vec3::newTemp(xo, yo, zo);
Vec3 origPos(xo, yo, zo);
double currDist = origPos->distanceTo(movementArea);
double targetDist = targetPos->distanceTo(movementArea);
double currDist = origPos.distanceTo(movementArea);
double targetDist = targetPos.distanceTo(movementArea);
return targetDist < currDist;
}

View file

@ -24,10 +24,11 @@ AreaHint::~AreaHint() { delete area; }
int AreaHint::tick() {
Minecraft* minecraft = Minecraft::GetInstance();
Vec3 player_pos = minecraft->player->getPos(1);
if ((m_displayState == e_Tutorial_State_Any ||
m_tutorial->getCurrentState() == m_displayState) &&
m_hintNeeded &&
area->contains(minecraft->player->getPos(1)) == contains) {
m_hintNeeded && area->contains(&player_pos) == contains) {
if (m_completeState == e_Tutorial_State_None) {
m_hintNeeded = false;
} else if (m_tutorial->isStateCompleted(m_completeState)) {

View file

@ -85,9 +85,9 @@ void ChangeStateConstraint::tick(int iPad) {
break;
}
}
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
if (!m_bHasChanged && inASourceState &&
movementArea->contains(minecraft->localplayers[iPad]->getPos(1)) ==
contains) {
movementArea->contains(&ipad_player) == contains) {
m_bHasChanged = true;
m_changedFromState = m_tutorial->getCurrentState();
m_tutorial->changeTutorialState(m_targetState);
@ -125,8 +125,7 @@ void ChangeStateConstraint::tick(int iPad) {
}
}
} else if (m_bHasChanged &&
movementArea->contains(
minecraft->localplayers[iPad]->getPos(1)) != contains) {
movementArea->contains(&ipad_player) != contains) {
m_bHasChanged = false;
m_tutorial->changeTutorialState(m_changedFromState);

View file

@ -381,7 +381,6 @@ int IUIScene_PauseMenu::SaveWorldThreadProc(void* lpParameter) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
Minecraft* pMinecraft = Minecraft::GetInstance();
@ -419,7 +418,6 @@ int IUIScene_PauseMenu::ExitWorldThreadProc(void* lpParameter) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
// app.SetGameStarted(false);

View file

@ -19,13 +19,13 @@ UIScene_DebugSetCamera::UIScene_DebugSetCamera(int iPad, void* initData,
Minecraft* pMinecraft = Minecraft::GetInstance();
if (pMinecraft != NULL) {
Vec3* vec = pMinecraft->localplayers[playerNo]->getPos(1.0);
Vec3 vec = pMinecraft->localplayers[playerNo]->getPos(1.0);
currentPosition->m_camX = vec->x;
currentPosition->m_camX = vec.x;
currentPosition->m_camY =
vec->y -
vec.y -
1.62; // pMinecraft->localplayers[playerNo]->getHeadHeight();
currentPosition->m_camZ = vec->z;
currentPosition->m_camZ = vec.z;
currentPosition->m_yRot = pMinecraft->localplayers[playerNo]->yRot;
currentPosition->m_elev = pMinecraft->localplayers[playerNo]->xRot;

View file

@ -220,7 +220,6 @@ HRESULT CScene_Death::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) {
int CScene_Death::RespawnThreadProc(void* lpParameter) {
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
size_t iPad = (size_t)lpParameter;
@ -246,4 +245,4 @@ HRESULT CScene_Death::OnCustomMessage_Splitscreenplayer(bool bJoining,
bHandled = true;
return app.AdjustSplitscreenScene_PlayerChanged(m_hObj, &m_OriginalPosition,
m_iPad, bJoining);
}
}

View file

@ -1074,7 +1074,6 @@ int UIScene_PauseMenu::SaveWorldThreadProc(LPVOID lpParameter) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
Minecraft* pMinecraft = Minecraft::GetInstance();
@ -1107,7 +1106,6 @@ int UIScene_PauseMenu::ExitWorldThreadProc(void* lpParameter) {
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
// as we don't tick the main thread whilst this thread is running
AABB::UseDefaultThreadStorage();
Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage();
// app.SetGameStarted(false);
@ -1326,4 +1324,4 @@ void UIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) {
void UIScene_PauseMenu::SetIgnoreInput(bool ignoreInput) {
m_bIgnoreInput = ignoreInput;
}
}

View file

@ -795,7 +795,6 @@ void oldWinMainInit() {
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
Tile::CreateNewThreadStorage();
@ -1143,9 +1142,6 @@ void oldWinMainTick() {
}
// Fix for #7318 - Title crashes after short soak in the leaderboards menu
// A memory leak was caused because the icon renderer kept creating new
// Vec3's because the pool wasn't reset
Vec3::resetPool();
}
#ifdef MEMORY_TRACKING

View file

@ -711,7 +711,6 @@ void CleanupDevice() {
#endif
int StartMinecraftThreadProc(void* lpParameter) {
Vec3::UseDefaultThreadStorage();
AABB::UseDefaultThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024);
RenderManager.InitialiseContext();
@ -868,7 +867,6 @@ return -1;
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
@ -1103,9 +1101,6 @@ PIXEndNamedEvent();
}
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
} // end game loop
// Graceful shutdown: destroy GL context and GLFW before any C++ dtors run.

View file

@ -1040,7 +1040,6 @@ void RegisterAwardsWithProfileManager() {
}
int StartMinecraftThreadProc(void* lpParameter) {
Vec3::UseDefaultThreadStorage();
AABB::UseDefaultThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024);
RenderManager.InitialiseContext();
@ -1378,7 +1377,6 @@ int main(int argc, const char* argv[]) {
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
@ -1737,9 +1735,6 @@ int main(int argc, const char* argv[]) {
app.PatchAvailableDialogTick();
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
// Free resources, unregister custom classes, and exit.

View file

@ -27,373 +27,359 @@
#include <boost/foreach.hpp>
namespace boost { namespace spirit { namespace lex { namespace lexertl
{
///////////////////////////////////////////////////////////////////////////
namespace detail
{
///////////////////////////////////////////////////////////////////////
// The must_escape function checks if the given character value needs
// to be preceded by a backslash character to disable its special
// meaning in the context of a regular expression
///////////////////////////////////////////////////////////////////////
template <typename Char>
inline bool must_escape(Char c)
{
// FIXME: more needed?
switch (c) {
case '+': case '/': case '*': case '?':
case '|':
case '(': case ')':
case '[': case ']':
case '{': case '}':
case '.':
case '^': case '$':
case '\\':
case '"':
return true;
namespace boost {
namespace spirit {
namespace lex {
namespace lexertl {
///////////////////////////////////////////////////////////////////////////
namespace detail {
///////////////////////////////////////////////////////////////////////
// The must_escape function checks if the given character value needs
// to be preceded by a backslash character to disable its special
// meaning in the context of a regular expression
///////////////////////////////////////////////////////////////////////
template <typename Char>
inline bool must_escape(Char c) {
// FIXME: more needed?
switch (c) {
case '+':
case '/':
case '*':
case '?':
case '|':
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '.':
case '^':
case '$':
case '\\':
case '"':
return true;
default:
break;
}
return false;
}
default:
break;
}
return false;
}
///////////////////////////////////////////////////////////////////////
// The escape function returns the string representation of the given
// character value, possibly escaped with a backslash character, to
// allow it being safely used in a regular expression definition.
///////////////////////////////////////////////////////////////////////
template <typename Char>
inline std::basic_string<Char> escape(Char ch)
{
std::basic_string<Char> result(1, ch);
if (detail::must_escape(ch))
{
typedef typename std::basic_string<Char>::size_type size_type;
result.insert((size_type)0, 1, '\\');
}
return result;
}
///////////////////////////////////////////////////////////////////////
// The escape function returns the string representation of the given
// character value, possibly escaped with a backslash character, to
// allow it being safely used in a regular expression definition.
///////////////////////////////////////////////////////////////////////
template <typename Char>
inline std::basic_string<Char> escape(Char ch) {
std::basic_string<Char> result(1, ch);
if (detail::must_escape(ch)) {
typedef typename std::basic_string<Char>::size_type size_type;
result.insert((size_type)0, 1, '\\');
}
return result;
}
///////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////
inline boost::lexer::regex_flags map_flags(unsigned int flags)
{
unsigned int retval = boost::lexer::none;
if (flags & match_flags::match_not_dot_newline)
retval |= boost::lexer::dot_not_newline;
if (flags & match_flags::match_icase)
retval |= boost::lexer::icase;
///////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////
inline boost::lexer::regex_flags map_flags(unsigned int flags) {
unsigned int retval = boost::lexer::none;
if (flags & match_flags::match_not_dot_newline)
retval |= boost::lexer::dot_not_newline;
if (flags & match_flags::match_icase) retval |= boost::lexer::icase;
return boost::lexer::regex_flags(retval);
}
return boost::lexer::regex_flags(retval);
}
} // namespace detail
///////////////////////////////////////////////////////////////////////////
template <typename Lexer, typename F>
bool generate_static(Lexer const&,
std::basic_ostream<typename Lexer::char_type>&,
typename Lexer::char_type const*, F);
///////////////////////////////////////////////////////////////////////////
//
// Every lexer type to be used as a lexer for Spirit has to conform to
// the following public interface:
//
// typedefs:
// iterator_type The type of the iterator exposed by this lexer.
// token_type The type of the tokens returned from the exposed
// iterators.
//
// functions:
// default constructor
// Since lexers are instantiated as base classes
// only it might be a good idea to make this
// constructor protected.
// begin, end Return a pair of iterators, when dereferenced
// returning the sequence of tokens recognized in
// the input stream given as the parameters to the
// begin() function.
// add_token Should add the definition of a token to be
// recognized by this lexer.
// clear Should delete all current token definitions
// associated with the given state of this lexer
// object.
//
// template parameters:
// Iterator The type of the iterator used to access the
// underlying character stream.
// Token The type of the tokens to be returned from the
// exposed token iterator.
// Functor The type of the InputPolicy to use to instantiate
// the multi_pass iterator type to be used as the
// token iterator (returned from begin()/end()).
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
// The lexer class is a implementation of a Spirit.Lex lexer on
// top of Ben Hanson's lexertl library as outlined above (For more
// information about lexertl go here: http://www.benhanson.net/lexertl.html).
//
// This class is supposed to be used as the first and only template
// parameter while instantiating instances of a lex::lexer class.
//
///////////////////////////////////////////////////////////////////////////
template <typename Token = token<>,
typename Iterator = typename Token::iterator_type,
typename Functor = functor<Token, lexertl::detail::data, Iterator> >
class lexer {
private:
struct dummy {
void true_() {}
};
typedef void (dummy::*safe_bool)();
static std::size_t const all_states_id = static_cast<std::size_t>(-2);
public:
operator safe_bool() const { return initialized_dfa_ ? &dummy::true_ : 0; }
typedef
typename boost::detail::iterator_traits<Iterator>::value_type char_type;
typedef std::basic_string<char_type> string_type;
typedef boost::lexer::basic_rules<char_type> basic_rules_type;
// Every lexer type to be used as a lexer for Spirit has to conform to
// a public interface .
typedef Token token_type;
typedef typename Token::id_type id_type;
typedef iterator<Functor> iterator_type;
private:
// this type is purely used for the iterator_type construction below
struct iterator_data_type {
typedef typename Functor::semantic_actions_type semantic_actions_type;
iterator_data_type(
boost::lexer::basic_state_machine<char_type> const& sm,
boost::lexer::basic_rules<char_type> const& rules,
semantic_actions_type const& actions)
: state_machine_(sm), rules_(rules), actions_(actions) {}
boost::lexer::basic_state_machine<char_type> const& state_machine_;
boost::lexer::basic_rules<char_type> const& rules_;
semantic_actions_type const& actions_;
private:
// silence MSVC warning C4512: assignment operator could not be
// generated
iterator_data_type& operator=(iterator_data_type const&);
};
public:
// Return the start iterator usable for iterating over the generated
// tokens.
iterator_type begin(Iterator& first, Iterator const& last,
char_type const* initial_state = 0) const {
if (!init_dfa()) // never minimize DFA for dynamic lexers
return iterator_type();
iterator_data_type iterator_data(state_machine_, rules_, actions_);
return iterator_type(iterator_data, first, last, initial_state);
}
///////////////////////////////////////////////////////////////////////////
template <typename Lexer, typename F>
bool generate_static(Lexer const&
, std::basic_ostream<typename Lexer::char_type>&
, typename Lexer::char_type const*, F);
// Return the end iterator usable to stop iterating over the generated
// tokens.
iterator_type end() const { return iterator_type(); }
///////////////////////////////////////////////////////////////////////////
//
// Every lexer type to be used as a lexer for Spirit has to conform to
// the following public interface:
//
// typedefs:
// iterator_type The type of the iterator exposed by this lexer.
// token_type The type of the tokens returned from the exposed
// iterators.
//
// functions:
// default constructor
// Since lexers are instantiated as base classes
// only it might be a good idea to make this
// constructor protected.
// begin, end Return a pair of iterators, when dereferenced
// returning the sequence of tokens recognized in
// the input stream given as the parameters to the
// begin() function.
// add_token Should add the definition of a token to be
// recognized by this lexer.
// clear Should delete all current token definitions
// associated with the given state of this lexer
// object.
//
// template parameters:
// Iterator The type of the iterator used to access the
// underlying character stream.
// Token The type of the tokens to be returned from the
// exposed token iterator.
// Functor The type of the InputPolicy to use to instantiate
// the multi_pass iterator type to be used as the
// token iterator (returned from begin()/end()).
//
///////////////////////////////////////////////////////////////////////////
protected:
// Lexer instances can be created by means of a derived class only.
lexer(unsigned int flags)
: flags_(detail::map_flags(flags)),
rules_(flags_),
initialized_dfa_(false) {}
///////////////////////////////////////////////////////////////////////////
//
// The lexer class is a implementation of a Spirit.Lex lexer on
// top of Ben Hanson's lexertl library as outlined above (For more
// information about lexertl go here: http://www.benhanson.net/lexertl.html).
//
// This class is supposed to be used as the first and only template
// parameter while instantiating instances of a lex::lexer class.
//
///////////////////////////////////////////////////////////////////////////
template <typename Token = token<>
, typename Iterator = typename Token::iterator_type
, typename Functor = functor<Token, lexertl::detail::data, Iterator> >
class lexer
{
private:
struct dummy { void true_() {} };
typedef void (dummy::*safe_bool)();
public:
// interface for token definition management
std::size_t add_token(char_type const* state, char_type tokendef,
std::size_t token_id, char_type const* targetstate) {
add_state(state);
initialized_dfa_ = false;
if (state == all_states())
return rules_.add(state, detail::escape(tokendef), token_id,
rules_.dot());
static std::size_t const all_states_id = static_cast<std::size_t>(-2);
if (0 == targetstate)
targetstate = state;
else
add_state(targetstate);
return rules_.add(state, detail::escape(tokendef), token_id,
targetstate);
}
std::size_t add_token(char_type const* state, string_type const& tokendef,
std::size_t token_id, char_type const* targetstate) {
add_state(state);
initialized_dfa_ = false;
if (state == all_states())
return rules_.add(state, tokendef, token_id, rules_.dot());
public:
operator safe_bool() const
{ return initialized_dfa_ ? &dummy::true_ : 0; }
if (0 == targetstate)
targetstate = state;
else
add_state(targetstate);
return rules_.add(state, tokendef, token_id, targetstate);
}
typedef typename boost::detail::iterator_traits<Iterator>::value_type
char_type;
typedef std::basic_string<char_type> string_type;
// interface for pattern definition management
void add_pattern(char_type const* state, string_type const& name,
string_type const& patterndef) {
add_state(state);
rules_.add_macro(name.c_str(), patterndef);
initialized_dfa_ = false;
}
typedef boost::lexer::basic_rules<char_type> basic_rules_type;
boost::lexer::rules const& get_rules() const { return rules_; }
// Every lexer type to be used as a lexer for Spirit has to conform to
// a public interface .
typedef Token token_type;
typedef typename Token::id_type id_type;
typedef iterator<Functor> iterator_type;
void clear(char_type const* state) {
std::size_t s = rules_.state(state);
if (boost::lexer::npos != s) rules_.clear(state);
initialized_dfa_ = false;
}
std::size_t add_state(char_type const* state) {
if (state == all_states()) return all_states_id;
private:
// this type is purely used for the iterator_type construction below
struct iterator_data_type
{
typedef typename Functor::semantic_actions_type semantic_actions_type;
iterator_data_type(
boost::lexer::basic_state_machine<char_type> const& sm
, boost::lexer::basic_rules<char_type> const& rules
, semantic_actions_type const& actions)
: state_machine_(sm), rules_(rules), actions_(actions)
{}
boost::lexer::basic_state_machine<char_type> const& state_machine_;
boost::lexer::basic_rules<char_type> const& rules_;
semantic_actions_type const& actions_;
private:
// silence MSVC warning C4512: assignment operator could not be generated
iterator_data_type& operator= (iterator_data_type const&);
};
public:
// Return the start iterator usable for iterating over the generated
// tokens.
iterator_type begin(Iterator& first, Iterator const& last
, char_type const* initial_state = 0) const
{
if (!init_dfa()) // never minimize DFA for dynamic lexers
return iterator_type();
iterator_data_type iterator_data(state_machine_, rules_, actions_);
return iterator_type(iterator_data, first, last, initial_state);
}
// Return the end iterator usable to stop iterating over the generated
// tokens.
iterator_type end() const
{
return iterator_type();
}
protected:
// Lexer instances can be created by means of a derived class only.
lexer(unsigned int flags)
: flags_(detail::map_flags(flags))
, rules_(flags_)
, initialized_dfa_(false)
{}
public:
// interface for token definition management
std::size_t add_token(char_type const* state, char_type tokendef,
std::size_t token_id, char_type const* targetstate)
{
add_state(state);
initialized_dfa_ = false;
if (state == all_states())
return rules_.add(state, detail::escape(tokendef), token_id, rules_.dot());
if (0 == targetstate)
targetstate = state;
else
add_state(targetstate);
return rules_.add(state, detail::escape(tokendef), token_id, targetstate);
}
std::size_t add_token(char_type const* state, string_type const& tokendef,
std::size_t token_id, char_type const* targetstate)
{
add_state(state);
initialized_dfa_ = false;
if (state == all_states())
return rules_.add(state, tokendef, token_id, rules_.dot());
if (0 == targetstate)
targetstate = state;
else
add_state(targetstate);
return rules_.add(state, tokendef, token_id, targetstate);
}
// interface for pattern definition management
void add_pattern (char_type const* state, string_type const& name,
string_type const& patterndef)
{
add_state(state);
rules_.add_macro(name.c_str(), patterndef);
std::size_t stateid = rules_.state(state);
if (boost::lexer::npos == stateid) {
stateid = rules_.add_state(state);
initialized_dfa_ = false;
}
return stateid;
}
string_type initial_state() const { return string_type(rules_.initial()); }
string_type all_states() const { return string_type(rules_.all_states()); }
boost::lexer::rules const& get_rules() const { return rules_; }
void clear(char_type const* state)
{
std::size_t s = rules_.state(state);
if (boost::lexer::npos != s)
rules_.clear(state);
initialized_dfa_ = false;
}
std::size_t add_state(char_type const* state)
{
if (state == all_states())
return all_states_id;
std::size_t stateid = rules_.state(state);
if (boost::lexer::npos == stateid) {
stateid = rules_.add_state(state);
initialized_dfa_ = false;
}
return stateid;
}
string_type initial_state() const
{
return string_type(rules_.initial());
}
string_type all_states() const
{
return string_type(rules_.all_states());
}
// Register a semantic action with the given id
template <typename F>
void add_action(std::size_t unique_id, std::size_t state, F act)
{
// If you see an error here stating add_action is not a member of
// fusion::unused_type then you are probably having semantic actions
// attached to at least one token in the lexer definition without
// using the lex::lexertl::actor_lexer<> as its base class.
typedef typename Functor::wrap_action_type wrapper_type;
if (state == all_states_id) {
// add the action to all known states
typedef typename
basic_rules_type::string_size_t_map::value_type
// Register a semantic action with the given id
template <typename F>
void add_action(std::size_t unique_id, std::size_t state, F act) {
// If you see an error here stating add_action is not a member of
// fusion::unused_type then you are probably having semantic actions
// attached to at least one token in the lexer definition without
// using the lex::lexertl::actor_lexer<> as its base class.
typedef typename Functor::wrap_action_type wrapper_type;
if (state == all_states_id) {
// add the action to all known states
typedef typename basic_rules_type::string_size_t_map::value_type
state_type;
std::size_t states = rules_.statemap().size();
BOOST_FOREACH(state_type const& s, rules_.statemap()) {
for (std::size_t j = 0; j < states; ++j)
actions_.add_action(unique_id + j, s.second, wrapper_type::call(act));
}
}
else {
actions_.add_action(unique_id, state, wrapper_type::call(act));
std::size_t states = rules_.statemap().size();
BOOST_FOREACH (state_type const& s, rules_.statemap()) {
for (std::size_t j = 0; j < states; ++j)
actions_.add_action(unique_id + j, s.second,
wrapper_type::call(act));
}
} else {
actions_.add_action(unique_id, state, wrapper_type::call(act));
}
// template <typename F>
// void add_action(std::size_t unique_id, char_type const* state, F act)
// {
// typedef typename Functor::wrap_action_type wrapper_type;
// actions_.add_action(unique_id, add_state(state), wrapper_type::call(act));
// }
}
// template <typename F>
// void add_action(std::size_t unique_id, char_type const* state, F
// act)
// {
// typedef typename Functor::wrap_action_type wrapper_type;
// actions_.add_action(unique_id, add_state(state),
// wrapper_type::call(act));
// }
// We do not minimize the state machine by default anymore because
// Ben said: "If you can afford to generate a lexer at runtime, there
// is little point in calling minimise."
// Go figure.
bool init_dfa(bool minimize = false) const
{
if (!initialized_dfa_) {
state_machine_.clear();
typedef boost::lexer::basic_generator<char_type> generator;
generator::build (rules_, state_machine_);
if (minimize)
generator::minimise (state_machine_);
// We do not minimize the state machine by default anymore because
// Ben said: "If you can afford to generate a lexer at runtime, there
// is little point in calling minimise."
// Go figure.
bool init_dfa(bool minimize = false) const {
if (!initialized_dfa_) {
state_machine_.clear();
typedef boost::lexer::basic_generator<char_type> generator;
generator::build(rules_, state_machine_);
if (minimize) generator::minimise(state_machine_);
#if defined(BOOST_SPIRIT_LEXERTL_DEBUG)
boost::lexer::debug::dump(state_machine_, std::cerr);
boost::lexer::debug::dump(state_machine_, std::cerr);
#endif
initialized_dfa_ = true;
initialized_dfa_ = true;
// // release memory held by rules description
// basic_rules_type rules;
// rules.init_state_info(rules_); // preserve states
// std::swap(rules, rules_);
}
return true;
// // release memory held by rules description
// basic_rules_type rules;
// rules.init_state_info(rules_); // preserve
// states std::swap(rules, rules_);
}
return true;
}
private:
// lexertl specific data
mutable boost::lexer::basic_state_machine<char_type> state_machine_;
boost::lexer::regex_flags flags_;
/*mutable*/ basic_rules_type rules_;
private:
// lexertl specific data
mutable boost::lexer::basic_state_machine<char_type> state_machine_;
boost::lexer::regex_flags flags_;
/*mutable*/ basic_rules_type rules_;
typename Functor::semantic_actions_type actions_;
mutable bool initialized_dfa_;
typename Functor::semantic_actions_type actions_;
mutable bool initialized_dfa_;
// generator functions must be able to access members directly
template <typename Lexer, typename F>
friend bool generate_static(Lexer const&
, std::basic_ostream<typename Lexer::char_type>&
, typename Lexer::char_type const*, F);
};
// generator functions must be able to access members directly
template <typename Lexer, typename F>
friend bool generate_static(Lexer const&,
std::basic_ostream<typename Lexer::char_type>&,
typename Lexer::char_type const*, F);
};
///////////////////////////////////////////////////////////////////////////
//
// The actor_lexer class is another implementation of a Spirit.Lex
// lexer on top of Ben Hanson's lexertl library as outlined above (For
// more information about lexertl go here:
// http://www.benhanson.net/lexertl.html).
//
// The only difference to the lexer class above is that token_def
// definitions may have semantic (lexer) actions attached while being
// defined:
//
// int w;
// token_def word = "[^ \t\n]+";
// self = word[++ref(w)]; // see example: word_count_lexer
//
// This class is supposed to be used as the first and only template
// parameter while instantiating instances of a lex::lexer class.
//
///////////////////////////////////////////////////////////////////////////
template <typename Token = token<>
, typename Iterator = typename Token::iterator_type
, typename Functor = functor<Token, lexertl::detail::data, Iterator, mpl::true_> >
class actor_lexer : public lexer<Token, Iterator, Functor>
{
protected:
// Lexer instances can be created by means of a derived class only.
actor_lexer(unsigned int flags)
: lexer<Token, Iterator, Functor>(flags) {}
};
///////////////////////////////////////////////////////////////////////////
//
// The actor_lexer class is another implementation of a Spirit.Lex
// lexer on top of Ben Hanson's lexertl library as outlined above (For
// more information about lexertl go here:
// http://www.benhanson.net/lexertl.html).
//
// The only difference to the lexer class above is that token_def
// definitions may have semantic (lexer) actions attached while being
// defined:
//
// int w;
// token_def word = "[^ \t\n]+";
// self = word[++ref(w)]; // see example: word_count_lexer
//
// This class is supposed to be used as the first and only template
// parameter while instantiating instances of a lex::lexer class.
//
///////////////////////////////////////////////////////////////////////////
template <typename Token = token<>,
typename Iterator = typename Token::iterator_type,
typename Functor =
functor<Token, lexertl::detail::data, Iterator, mpl::true_> >
class actor_lexer : public lexer<Token, Iterator, Functor> {
protected:
// Lexer instances can be created by means of a derived class only.
actor_lexer(unsigned int flags) : lexer<Token, Iterator, Functor>(flags) {}
};
}}}}
} // namespace lexertl
} // namespace lex
} // namespace spirit
} // namespace boost
#endif

View file

@ -1211,7 +1211,6 @@ int main() {
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
Tile::CreateNewThreadStorage();
@ -1547,7 +1546,6 @@ int main() {
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
// Free resources, unregister custom classes, and exit.

View file

@ -661,7 +661,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Level::enableLightingCache();
Minecraft::main();
@ -961,9 +960,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
#endif
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
// Free resources, unregister custom classes, and exit.

View file

@ -896,7 +896,6 @@ int main() {
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
@ -1250,9 +1249,6 @@ int main() {
app.SaveDataTick();
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
// sceRazorCpuSync();
#ifndef _CONTENT_PACKAGE

View file

@ -941,7 +941,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
@ -1269,9 +1268,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
}
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
// Free resources, unregister custom classes, and exit.

View file

@ -700,7 +700,6 @@ int __cdecl main() {
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
@ -1029,9 +1028,6 @@ int __cdecl main() {
}
// Fix for #7318 - Title crashes after short soak in the leaderboards
// menu A memory leak was caused because the icon renderer kept creating
// new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
// Free resources, unregister custom classes, and exit.

View file

@ -404,25 +404,25 @@ void LocalPlayer::aiStep() {
if (abilities.flying) // minecraft->options->isFlying )
{
Vec3* viewVector = getViewVector(1.0f);
Vec3 viewVector = getViewVector(1.0f);
// 4J-PB - To let the player build easily while flying, we need to
// change this
#ifdef _DEBUG_MENUS_ENABLED
if (abilities.debugflying) {
flyX = (float)viewVector->x * input->ya;
flyY = (float)viewVector->y * input->ya;
flyZ = (float)viewVector->z * input->ya;
flyX = (float)viewVector.x * input->ya;
flyY = (float)viewVector.y * input->ya;
flyZ = (float)viewVector.z * input->ya;
} else
#endif
{
if (isSprinting()) {
// Accelrate up to full speed if we are sprinting, moving in the
// direction of the view vector
flyX = (float)viewVector->x * input->ya;
flyY = (float)viewVector->y * input->ya;
flyZ = (float)viewVector->z * input->ya;
flyX = (float)viewVector.x * input->ya;
flyY = (float)viewVector.y * input->ya;
flyZ = (float)viewVector.z * input->ya;
float scale = ((float)(SPRINT_DURATION - sprintTime)) / 10.0f;
scale = scale * scale;
@ -550,7 +550,8 @@ void LocalPlayer::closeContainer() {
void LocalPlayer::openTextEdit(std::shared_ptr<TileEntity> tileEntity) {
#ifdef ENABLE_JAVA_GUIS
if (tileEntity->GetType() == eTYPE_SIGNTILEENTITY) {
minecraft->setScreen(new TextEditScreen(std::dynamic_pointer_cast<SignTileEntity>(tileEntity)));
minecraft->setScreen(new TextEditScreen(
std::dynamic_pointer_cast<SignTileEntity>(tileEntity)));
bool success = true;
}
#else
@ -782,8 +783,7 @@ void LocalPlayer::awardStat(Stat* stat, byteArray param) {
// storage device, so needs a primary player, and the player may not
// have been a primary player when they first 'got' the award so let the
// award manager figure it out
if (!minecraft->stats[m_iPad]->hasTaken(ach))
{
if (!minecraft->stats[m_iPad]->hasTaken(ach)) {
// 4J-PB - Don't display the java popup
#ifdef ENABLE_JAVA_GUIS
minecraft->achievementPopup->popup(ach);
@ -1506,7 +1506,7 @@ bool LocalPlayer::handleMouseClick(int button) {
bool usedItem = false;
if (minecraft->gameMode->useItemOn(
minecraft->localplayers[GetXboxPad()], level, item, x, y, z,
face, minecraft->hitResult->pos, false, &usedItem)) {
face, &minecraft->hitResult->pos, false, &usedItem)) {
// Presume that if we actually used the held item, then we've
// placed it
if (usedItem) {

View file

@ -91,10 +91,11 @@ zPlayerOffs = position->get(2);
TilePos* Camera::getCameraTilePos(std::shared_ptr<LivingEntity> player,
double alpha) {
return new TilePos(getCameraPos(player, alpha));
Vec3 cam_pos = getCameraPos(player, alpha);
return new TilePos(&cam_pos);
}
Vec3* Camera::getCameraPos(std::shared_ptr<LivingEntity> player, double alpha) {
Vec3 Camera::getCameraPos(std::shared_ptr<LivingEntity> player, double alpha) {
double xx = player->xo + (player->x - player->xo) * alpha;
double yy =
player->yo + (player->y - player->yo) * alpha + player->getHeadHeight();
@ -104,21 +105,21 @@ Vec3* Camera::getCameraPos(std::shared_ptr<LivingEntity> player, double alpha) {
double yt = yy + Camera::yPlayerOffs * 1;
double zt = zz + Camera::zPlayerOffs * 1;
return Vec3::newTemp(xt, yt, zt);
return Vec3(xt, yt, zt);
}
int Camera::getBlockAt(Level* level, std::shared_ptr<LivingEntity> player,
float alpha) {
Vec3* p = Camera::getCameraPos(player, alpha);
TilePos tp = TilePos(p);
Vec3 p = Camera::getCameraPos(player, alpha);
TilePos tp = TilePos(&p);
int t = level->getTile(tp.x, tp.y, tp.z);
if (t != 0 && Tile::tiles[t]->material->isLiquid()) {
float hh =
LiquidTile::getHeight(level->getData(tp.x, tp.y, tp.z)) - 1 / 9.0f;
float h = tp.y + 1 - hh;
if (p->y >= h) {
if (p.y >= h) {
t = level->getTile(tp.x, tp.y + 1, tp.z);
}
}
return t;
}
}

View file

@ -26,8 +26,8 @@ public:
static TilePos* getCameraTilePos(std::shared_ptr<LivingEntity> player,
double alpha);
static Vec3* getCameraPos(std::shared_ptr<LivingEntity> player,
double alpha);
static Vec3 getCameraPos(std::shared_ptr<LivingEntity> player,
double alpha);
static int getBlockAt(Level* level, std::shared_ptr<LivingEntity> player,
float alpha);
};
};

View file

@ -23,4 +23,4 @@ bool DirtyChunkSorter::operator()(const Chunk* c0, const Chunk* c1) const {
if (d0 > d1) return true;
return c0->id >= c1->id; // 4J - was c0.id < c1.id ? 1 : -1
}
}

View file

@ -58,22 +58,22 @@ void FishingHookRenderer::render(std::shared_ptr<Entity> _hook, double x,
float swing = hook->owner->getAttackAnim(a);
float swing2 = (float)Mth::sin(sqrt(swing) * PI);
Vec3* vv = Vec3::newTemp(-0.5, 0.03, 0.8);
vv->xRot(-(hook->owner->xRotO +
(hook->owner->xRot - hook->owner->xRotO) * a) *
PI / 180);
vv->yRot(-(hook->owner->yRotO +
(hook->owner->yRot - hook->owner->yRotO) * a) *
PI / 180);
vv->yRot(swing2 * 0.5f);
vv->xRot(-swing2 * 0.7f);
Vec3 vv(-0.5, 0.03, 0.8);
vv.xRot(-(hook->owner->xRotO +
(hook->owner->xRot - hook->owner->xRotO) * a) *
PI / 180);
vv.yRot(-(hook->owner->yRotO +
(hook->owner->yRot - hook->owner->yRotO) * a) *
PI / 180);
vv.yRot(swing2 * 0.5f);
vv.xRot(-swing2 * 0.7f);
double xp =
hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv->x;
hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv.x;
double yp =
hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv->y;
hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv.y;
double zp =
hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv->z;
hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv.z;
double yOffset = hook->owner == std::dynamic_pointer_cast<Player>(
Minecraft::GetInstance()->player)
? 0

View file

@ -613,4 +613,4 @@ void LivingEntityRenderer::renderNameTag(std::shared_ptr<LivingEntity> mob,
glDisable(GL_BLEND);
glColor4f(1, 1, 1, 1);
glPopMatrix();
}
}

View file

@ -1,5 +1,6 @@
#include "../../Platform/stdafx.h"
#include "MinecartRenderer.h"
#include <optional>
#include "../Models/MinecartModel.h"
#include "../../Textures/TextureAtlas.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.entity.item.h"
@ -40,26 +41,27 @@ void MinecartRenderer::render(std::shared_ptr<Entity> _cart, double x, double y,
double r = 0.3f;
Vec3* p = cart->getPos(xx, yy, zz);
std::optional<Vec3> p = cart->getPos(xx, yy, zz);
float xRot = cart->xRotO + (cart->xRot - cart->xRotO) * a;
if (p != NULL) {
Vec3* p0 = cart->getPosOffs(xx, yy, zz, r);
Vec3* p1 = cart->getPosOffs(xx, yy, zz, -r);
if (p0 == NULL) p0 = p;
if (p1 == NULL) p1 = p;
if (p.has_value()) {
auto p0 = cart->getPosOffs(xx, yy, zz, r);
auto p1 = cart->getPosOffs(xx, yy, zz, -r);
if (!p0.has_value()) p0 = p;
if (!p1.has_value()) p1 = p;
x += p->x - xx;
y += (p0->y + p1->y) / 2 - yy;
z += p->z - zz;
Vec3* dir = p1->add(-p0->x, -p0->y, -p0->z);
if (dir->length() == 0) {
Vec3 dir(-p0->x, -p0->y, -p0->z);
dir = dir.add(p1->x, p1->y, p1->z);
if (dir.length() == 0) {
} else {
dir = dir->normalize();
rot = (float)(atan2(dir->z, dir->x) * 180 / PI);
xRot = (float)(atan(dir->y) * 73);
dir = dir.normalize();
rot = (float)(atan2(dir.z, dir.x) * 180 / PI);
xRot = (float)(atan(dir.y) * 73);
}
}
glTranslatef((float)x, (float)y, (float)z);
@ -146,4 +148,4 @@ void MinecartRenderer::renderMinecartContents(std::shared_ptr<Minecart> cart,
glPushMatrix();
renderer->renderTile(tile, tileData, brightness);
glPopMatrix();
}
}

View file

@ -1,6 +1,7 @@
#include "../../Platform/stdafx.h"
#include "TileRenderer.h"
#include <array>
#include "../GameRenderer.h"
#include "../../Minecraft.h"
#include "../../Textures/Textures.h"
@ -1045,9 +1046,8 @@ bool TileRenderer::tesselateAnvilInWorld(AnvilTile* tt, int x, int y, int z,
float TileRenderer::tesselateAnvilPiece(AnvilTile* tt, int x, int y, int z,
int part, float bottom, float width,
float height, float length,
bool rotate, bool render,
int data) {
float height, float length, bool rotate,
bool render, int data) {
if (rotate) {
float swap = width;
width = length;
@ -1818,58 +1818,58 @@ bool TileRenderer::tesselateLeverInWorld(Tile* tt, int x, int y, int z) {
float u1 = tex->getU1(true);
float v1 = tex->getV1(true);
Vec3* corners[8];
std::array<Vec3, 8> corners;
float xv = 1.0f / 16.0f;
float zv = 1.0f / 16.0f;
float yv = 10.0f / 16.0f;
corners[0] = Vec3::newTemp(-xv, -0, -zv);
corners[1] = Vec3::newTemp(+xv, -0, -zv);
corners[2] = Vec3::newTemp(+xv, -0, +zv);
corners[3] = Vec3::newTemp(-xv, -0, +zv);
corners[4] = Vec3::newTemp(-xv, +yv, -zv);
corners[5] = Vec3::newTemp(+xv, +yv, -zv);
corners[6] = Vec3::newTemp(+xv, +yv, +zv);
corners[7] = Vec3::newTemp(-xv, +yv, +zv);
corners[0] = Vec3(-xv, -0, -zv);
corners[1] = Vec3(+xv, -0, -zv);
corners[2] = Vec3(+xv, -0, +zv);
corners[3] = Vec3(-xv, -0, +zv);
corners[4] = Vec3(-xv, +yv, -zv);
corners[5] = Vec3(+xv, +yv, -zv);
corners[6] = Vec3(+xv, +yv, +zv);
corners[7] = Vec3(-xv, +yv, +zv);
for (int i = 0; i < 8; i++) {
if (flipped) {
corners[i]->z -= 1 / 16.0f;
corners[i]->xRot(40 * PI / 180);
corners[i].z -= 1 / 16.0f;
corners[i].xRot(40 * PI / 180);
} else {
corners[i]->z += 1 / 16.0f;
corners[i]->xRot(-40 * PI / 180);
corners[i].z += 1 / 16.0f;
corners[i].xRot(-40 * PI / 180);
}
if (dir == 0 || dir == 7) {
corners[i]->zRot(180 * PI / 180);
corners[i].zRot(180 * PI / 180);
}
if (dir == 6 || dir == 0) {
corners[i]->yRot(90 * PI / 180);
corners[i].yRot(90 * PI / 180);
}
if (dir > 0 && dir < 5) {
corners[i]->y -= 6 / 16.0f;
corners[i]->xRot(90 * PI / 180);
corners[i].y -= 6 / 16.0f;
corners[i].xRot(90 * PI / 180);
if (dir == 4) corners[i]->yRot(0 * PI / 180);
if (dir == 3) corners[i]->yRot(180 * PI / 180);
if (dir == 2) corners[i]->yRot(90 * PI / 180);
if (dir == 1) corners[i]->yRot(-90 * PI / 180);
if (dir == 4) corners[i].yRot(0 * PI / 180);
if (dir == 3) corners[i].yRot(180 * PI / 180);
if (dir == 2) corners[i].yRot(90 * PI / 180);
if (dir == 1) corners[i].yRot(-90 * PI / 180);
corners[i]->x += x + 0.5;
corners[i]->y += y + 8 / 16.0f;
corners[i]->z += z + 0.5;
corners[i].x += x + 0.5;
corners[i].y += y + 8 / 16.0f;
corners[i].z += z + 0.5;
} else if (dir == 0 || dir == 7) {
corners[i]->x += x + 0.5;
corners[i]->y += y + 14 / 16.0f;
corners[i]->z += z + 0.5;
corners[i].x += x + 0.5;
corners[i].y += y + 14 / 16.0f;
corners[i].z += z + 0.5;
} else {
corners[i]->x += x + 0.5;
corners[i]->y += y + 2 / 16.0f;
corners[i]->z += z + 0.5;
corners[i].x += x + 0.5;
corners[i].y += y + 2 / 16.0f;
corners[i].z += z + 0.5;
}
}
Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;
Vec3 c0, c1, c2, c3;
for (int i = 0; i < 6; i++) {
if (i == 0) {
u0 = tex->getU(7, true);
@ -1913,13 +1913,13 @@ bool TileRenderer::tesselateLeverInWorld(Tile* tt, int x, int y, int z) {
c2 = corners[7];
c3 = corners[4];
}
t->vertexUV((float)(c0->x), (float)(c0->y), (float)(c0->z), (float)(u0),
t->vertexUV((float)(c0.x), (float)(c0.y), (float)(c0.z), (float)(u0),
(float)(v1));
t->vertexUV((float)(c1->x), (float)(c1->y), (float)(c1->z), (float)(u1),
t->vertexUV((float)(c1.x), (float)(c1.y), (float)(c1.z), (float)(u1),
(float)(v1));
t->vertexUV((float)(c2->x), (float)(c2->y), (float)(c2->z), (float)(u1),
t->vertexUV((float)(c2.x), (float)(c2.y), (float)(c2.z), (float)(u1),
(float)(v0));
t->vertexUV((float)(c3->x), (float)(c3->y), (float)(c3->z), (float)(u0),
t->vertexUV((float)(c3.x), (float)(c3.y), (float)(c3.z), (float)(u0),
(float)(v0));
}
return true;
@ -1977,46 +1977,46 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y,
double u1 = tex->getU1();
double v1 = tex->getV1();
Vec3* corners[8];
std::array<Vec3, 8> corners;
float stickWidth = 0.75f / 16.0f;
float stickHeight = 0.75f / 16.0f;
float stickLength = 5 / 16.0f;
corners[0] = Vec3::newTemp(-stickWidth, -0, -stickHeight);
corners[1] = Vec3::newTemp(+stickWidth, -0, -stickHeight);
corners[2] = Vec3::newTemp(+stickWidth, -0, +stickHeight);
corners[3] = Vec3::newTemp(-stickWidth, -0, +stickHeight);
corners[4] = Vec3::newTemp(-stickWidth, +stickLength, -stickHeight);
corners[5] = Vec3::newTemp(+stickWidth, +stickLength, -stickHeight);
corners[6] = Vec3::newTemp(+stickWidth, +stickLength, +stickHeight);
corners[7] = Vec3::newTemp(-stickWidth, +stickLength, +stickHeight);
corners[0] = Vec3(-stickWidth, -0, -stickHeight);
corners[1] = Vec3(+stickWidth, -0, -stickHeight);
corners[2] = Vec3(+stickWidth, -0, +stickHeight);
corners[3] = Vec3(-stickWidth, -0, +stickHeight);
corners[4] = Vec3(-stickWidth, +stickLength, -stickHeight);
corners[5] = Vec3(+stickWidth, +stickLength, -stickHeight);
corners[6] = Vec3(+stickWidth, +stickLength, +stickHeight);
corners[7] = Vec3(-stickWidth, +stickLength, +stickHeight);
for (int i = 0; i < 8; i++) {
corners[i]->z += 1 / 16.0f;
corners[i].z += 1 / 16.0f;
if (powered) {
corners[i]->xRot(30 * PI / 180);
corners[i]->y -= 7 / 16.0f;
corners[i].xRot(30 * PI / 180);
corners[i].y -= 7 / 16.0f;
} else if (attached) {
corners[i]->xRot(5 * PI / 180);
corners[i]->y -= 7 / 16.0f;
corners[i].xRot(5 * PI / 180);
corners[i].y -= 7 / 16.0f;
} else {
corners[i]->xRot(-40 * PI / 180);
corners[i]->y -= 6 / 16.0f;
corners[i].xRot(-40 * PI / 180);
corners[i].y -= 6 / 16.0f;
}
corners[i]->xRot(90 * PI / 180);
corners[i].xRot(90 * PI / 180);
if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180);
if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180);
if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180);
if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180);
if (dir == Direction::NORTH) corners[i].yRot(0 * PI / 180);
if (dir == Direction::SOUTH) corners[i].yRot(180 * PI / 180);
if (dir == Direction::WEST) corners[i].yRot(90 * PI / 180);
if (dir == Direction::EAST) corners[i].yRot(-90 * PI / 180);
corners[i]->x += x + 0.5;
corners[i]->y += y + 5 / 16.0f;
corners[i]->z += z + 0.5;
corners[i].x += x + 0.5;
corners[i].y += y + 5 / 16.0f;
corners[i].z += z + 0.5;
}
Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;
Vec3 c0, c1, c2, c3;
int stickX0 = 7;
int stickX1 = 9;
int stickY0 = 9;
@ -2062,47 +2062,47 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y,
c2 = corners[7];
c3 = corners[4];
}
t->vertexUV(c0->x, c0->y, c0->z, u0, v1);
t->vertexUV(c1->x, c1->y, c1->z, u1, v1);
t->vertexUV(c2->x, c2->y, c2->z, u1, v0);
t->vertexUV(c3->x, c3->y, c3->z, u0, v0);
t->vertexUV(c0.x, c0.y, c0.z, u0, v1);
t->vertexUV(c1.x, c1.y, c1.z, u1, v1);
t->vertexUV(c2.x, c2.y, c2.z, u1, v0);
t->vertexUV(c3.x, c3.y, c3.z, u0, v0);
}
float hoopWidth = 1.5f / 16.0f;
float hoopHeight = 1.5f / 16.0f;
float hoopLength = 0.5f / 16.0f;
corners[0] = Vec3::newTemp(-hoopWidth, -0, -hoopHeight);
corners[1] = Vec3::newTemp(+hoopWidth, -0, -hoopHeight);
corners[2] = Vec3::newTemp(+hoopWidth, -0, +hoopHeight);
corners[3] = Vec3::newTemp(-hoopWidth, -0, +hoopHeight);
corners[4] = Vec3::newTemp(-hoopWidth, +hoopLength, -hoopHeight);
corners[5] = Vec3::newTemp(+hoopWidth, +hoopLength, -hoopHeight);
corners[6] = Vec3::newTemp(+hoopWidth, +hoopLength, +hoopHeight);
corners[7] = Vec3::newTemp(-hoopWidth, +hoopLength, +hoopHeight);
corners[0] = Vec3(-hoopWidth, -0, -hoopHeight);
corners[1] = Vec3(+hoopWidth, -0, -hoopHeight);
corners[2] = Vec3(+hoopWidth, -0, +hoopHeight);
corners[3] = Vec3(-hoopWidth, -0, +hoopHeight);
corners[4] = Vec3(-hoopWidth, +hoopLength, -hoopHeight);
corners[5] = Vec3(+hoopWidth, +hoopLength, -hoopHeight);
corners[6] = Vec3(+hoopWidth, +hoopLength, +hoopHeight);
corners[7] = Vec3(-hoopWidth, +hoopLength, +hoopHeight);
for (int i = 0; i < 8; i++) {
corners[i]->z += 3.5f / 16.0f;
corners[i].z += 3.5f / 16.0f;
if (powered) {
corners[i]->y -= 1.5 / 16.0f;
corners[i]->z -= 2.6 / 16.0f;
corners[i]->xRot(0 * PI / 180);
corners[i].y -= 1.5 / 16.0f;
corners[i].z -= 2.6 / 16.0f;
corners[i].xRot(0 * PI / 180);
} else if (attached) {
corners[i]->y += 0.25 / 16.0f;
corners[i]->z -= 2.75 / 16.0f;
corners[i]->xRot(10 * PI / 180);
corners[i].y += 0.25 / 16.0f;
corners[i].z -= 2.75 / 16.0f;
corners[i].xRot(10 * PI / 180);
} else {
corners[i]->xRot(50 * PI / 180);
corners[i].xRot(50 * PI / 180);
}
if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180);
if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180);
if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180);
if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180);
if (dir == Direction::NORTH) corners[i].yRot(0 * PI / 180);
if (dir == Direction::SOUTH) corners[i].yRot(180 * PI / 180);
if (dir == Direction::WEST) corners[i].yRot(90 * PI / 180);
if (dir == Direction::EAST) corners[i].yRot(-90 * PI / 180);
corners[i]->x += x + 0.5;
corners[i]->y += y + 5 / 16.0f;
corners[i]->z += z + 0.5;
corners[i].x += x + 0.5;
corners[i].y += y + 5 / 16.0f;
corners[i].z += z + 0.5;
}
int hoopX0 = 5;
@ -2150,14 +2150,14 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y,
c2 = corners[7];
c3 = corners[4];
}
t->vertexUV(c0->x, c0->y, c0->z, u0, v1);
t->vertexUV(c1->x, c1->y, c1->z, u1, v1);
t->vertexUV(c2->x, c2->y, c2->z, u1, v0);
t->vertexUV(c3->x, c3->y, c3->z, u0, v0);
t->vertexUV(c0.x, c0.y, c0.z, u0, v1);
t->vertexUV(c1.x, c1.y, c1.z, u1, v1);
t->vertexUV(c2.x, c2.y, c2.z, u1, v0);
t->vertexUV(c3.x, c3.y, c3.z, u0, v0);
}
if (attached) {
double hoopBottomY = corners[0]->y;
double hoopBottomY = corners[0].y;
float width = 0.5f / 16.0f;
float top = 0.5f - (width / 2);
float bottom = top + width;
@ -4068,9 +4068,11 @@ bool TileRenderer::tesselateCrossInWorld(Tile* tt, int x, int y, int z) {
float zt = (float)z;
if (tt == Tile::tallgrass) {
// 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed = ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) + ((uint64_t)seed * 11ULL));
// 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed =
((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) +
((uint64_t)seed * 11ULL));
xt += ((((seed >> 16) & 0xf) / 15.0f) - 0.5f) * 0.5f;
yt += ((((seed >> 20) & 0xf) / 15.0f) - 1.0f) * 0.2f;
@ -4326,8 +4328,10 @@ bool TileRenderer::tesselateLilypadInWorld(Tile* tt, int x, int y, int z) {
float v1 = tex->getV1(true);
// 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed = ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) + ((uint64_t)seed * 11ULL));
int64_t seed =
((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) +
((uint64_t)seed * 11ULL));
int dir = (int)((seed >> 16) & 0x3);

View file

@ -90,7 +90,7 @@ GameRenderer::GameRenderer(Minecraft* mc) {
tickSmoothYO = 0;
lastTickA = 0;
cameraPos = Vec3::newPermanent(0.0f, 0.0f, 0.0f);
cameraPos = Vec3(0.0f, 0.0f, 0.0f);
fovOffset = 0;
fovOffsetO = 0;
@ -291,7 +291,7 @@ void GameRenderer::pick(float a) {
}
double dist = range;
Vec3* from = mc->cameraTargetPlayer->getPos(a);
Vec3 from = mc->cameraTargetPlayer->getPos(a);
if (mc->gameMode->hasFarPickRange()) {
dist = range = 6;
@ -301,17 +301,18 @@ void GameRenderer::pick(float a) {
}
if (mc->hitResult != NULL) {
dist = mc->hitResult->pos->distanceTo(from);
dist = mc->hitResult->pos.distanceTo(from);
}
Vec3* b = mc->cameraTargetPlayer->getViewVector(a);
Vec3* to = from->add(b->x * range, b->y * range, b->z * range);
Vec3 b = mc->cameraTargetPlayer->getViewVector(a);
Vec3 to(b.x * range, b.y * range, b.z * range);
to = to.add(from.x, from.y, from.z);
hovered = nullptr;
float overlap = 1;
std::vector<std::shared_ptr<Entity> >* objects = mc->level->getEntities(
mc->cameraTargetPlayer,
mc->cameraTargetPlayer->bb
->expand(b->x * (range), b->y * (range), b->z * (range))
->expand(b.x * (range), b.y * (range), b.z * (range))
->grow(overlap, overlap, overlap));
double nearest = dist;
@ -322,14 +323,14 @@ void GameRenderer::pick(float a) {
float rr = e->getPickRadius();
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
if (bb->contains(from)) {
HitResult* p = bb->clip(&from, &to);
if (bb->contains(&from)) {
if (0 < nearest || nearest == 0) {
hovered = e;
nearest = 0;
}
} else if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
std::shared_ptr<Entity> ridingEntity =
mc->cameraTargetPlayer->riding;
// 4jcraft: compare the mounted entity explicitly so riding the hit
@ -523,11 +524,12 @@ void GameRenderer::moveCameraToPlayer(float a) {
// 4J - corrected bug here where zo was also added to x
// component
HitResult* hr = mc->level->clip(
Vec3::newTemp(x + xo, y + yo, z + zo),
Vec3::newTemp(x - xd + xo, y - yd + yo, z - zd + zo));
Vec3 a(x + xo, y + yo, z + zo);
Vec3 b(x - xd + xo, y - yd + yo, z - zd + zo);
HitResult* hr = mc->level->clip(&a, &b);
if (hr != NULL) {
double dist = hr->pos->distanceTo(Vec3::newTemp(x, y, z));
Vec3 p(x, y, z);
double dist = hr->pos.distanceTo(p);
if (dist < cameraDist) cameraDist = dist;
delete hr;
}
@ -1113,7 +1115,6 @@ void GameRenderer::FinishedReassigning() {
int GameRenderer::runUpdate(void* lpParam) {
Minecraft* minecraft = Minecraft::GetInstance();
Vec3::CreateNewThreadStorage();
AABB::CreateNewThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024);
Compression::UseDefaultThreadStorage();
@ -1194,7 +1195,6 @@ int GameRenderer::runUpdate(void* lpParam) {
// PIXEndNamedEvent();
AABB::resetPool();
Vec3::resetPool();
m_updateEvents->Set(eUpdateEventIsFinished);
}
@ -1369,11 +1369,11 @@ void GameRenderer::renderLevel(float a, int64_t until) {
// storing the camera position Fix for #77745 - TU9: Content:
// Gameplay: Items and mobs not belonging to end world are
// disappearing when Enderdragon is damaged.
Vec3* cameraPosTemp = cameraEntity->getPos(a);
cameraPos->x = cameraPosTemp->x;
cameraPos->y = cameraPosTemp->y;
cameraPos->z = cameraPosTemp->z;
levelRenderer->renderEntities(cameraPos, frustum, a);
Vec3 cameraPosTemp = cameraEntity->getPos(a);
cameraPos.x = cameraPosTemp.x;
cameraPos.y = cameraPosTemp.y;
cameraPos.z = cameraPosTemp.z;
levelRenderer->renderEntities(&cameraPos, frustum, a);
#ifdef __PSVITA__
// AP - make sure we're using the Alpha cut out effect for particles
glEnable(GL_ALPHA_TEST);
@ -1853,21 +1853,20 @@ void GameRenderer::setupClearColor(float a) {
float whiteness = 1.0f / (4 - mc->options->viewDistance);
whiteness = 1 - (float)pow((double)whiteness, 0.25);
Vec3* skyColor = level->getSkyColor(mc->cameraTargetPlayer, a);
float sr = (float)skyColor->x;
float sg = (float)skyColor->y;
float sb = (float)skyColor->z;
Vec3 skyColor = level->getSkyColor(mc->cameraTargetPlayer, a);
float sr = (float)skyColor.x;
float sg = (float)skyColor.y;
float sb = (float)skyColor.z;
Vec3* fogColor = level->getFogColor(a);
fr = (float)fogColor->x;
fg = (float)fogColor->y;
fb = (float)fogColor->z;
Vec3 fogColor = level->getFogColor(a);
fr = (float)fogColor.x;
fg = (float)fogColor.y;
fb = (float)fogColor.z;
if (mc->options->viewDistance < 2) {
Vec3* sunAngle = Mth::sin(level->getSunAngle(a)) > 0
? Vec3::newTemp(-1, 0, 0)
: Vec3::newTemp(1, 0, 0);
float d = (float)player->getViewVector(a)->dot(sunAngle);
Vec3 sunAngle = Mth::sin(level->getSunAngle(a)) > 0 ? Vec3(-1, 0, 0)
: Vec3(1, 0, 0);
float d = (float)player->getViewVector(a).dot(sunAngle);
if (d < 0) d = 0;
if (d > 0) {
float* c =
@ -1903,10 +1902,10 @@ void GameRenderer::setupClearColor(float a) {
int t = Camera::getBlockAt(mc->level, player, a);
if (isInClouds) {
Vec3* cc = level->getCloudColor(a);
fr = (float)cc->x;
fg = (float)cc->y;
fb = (float)cc->z;
Vec3 cc = level->getCloudColor(a);
fr = (float)cc.x;
fg = (float)cc.y;
fb = (float)cc.z;
} else if (t != 0 && Tile::tiles[t]->material == Material::water) {
float clearness = EnchantmentHelper::getOxygenBonus(player) * 0.2f;

View file

@ -50,7 +50,7 @@ private:
float thirdTiltO;
float accumulatedSmoothXO, accumulatedSmoothYO;
float tickSmoothXO, tickSmoothYO, lastTickA;
Vec3* cameraPos; // 4J added
Vec3 cameraPos; // 4J added
// fov modification
float fovOffset;

View file

@ -1035,10 +1035,10 @@ void LevelRenderer::renderSky(float alpha) {
glDisable(GL_TEXTURE_2D);
int playerIndex = mc->player->GetXboxPad();
Vec3* sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha);
float sr = (float)sc->x;
float sg = (float)sc->y;
float sb = (float)sc->z;
Vec3 sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha);
float sr = (float)sc.x;
float sg = (float)sc.y;
float sb = (float)sc.z;
if (mc->options->anaglyph3d) {
float srr = (sr * 30 + sg * 59 + sb * 11) / 100;
@ -1185,7 +1185,7 @@ void LevelRenderer::renderSky(float alpha) {
glColor3f(0, 0, 0);
double yy =
mc->player->getPos(alpha)->y -
mc->player->getPos(alpha).y -
level[playerIndex]->getHorizonHeight(); // 4J - getHorizonHeight moved
// forward from 1.2.3
if (yy < 0) {
@ -1259,10 +1259,10 @@ void LevelRenderer::renderHaloRing(float alpha) {
int playerIndex = mc->player->GetXboxPad();
Vec3* sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha);
float sr = (float)sc->x;
float sg = (float)sc->y;
float sb = (float)sc->z;
Vec3 sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha);
float sr = (float)sc.x;
float sg = (float)sc.y;
float sb = (float)sc.z;
// Rough lumninance calculation
float Y = (sr + sr + sb + sg + sg + sg) / 6;
@ -1335,10 +1335,10 @@ void LevelRenderer::renderClouds(float alpha) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Vec3* cc = level[playerIndex]->getCloudColor(alpha);
float cr = (float)cc->x;
float cg = (float)cc->y;
float cb = (float)cc->z;
Vec3 cc = level[playerIndex]->getCloudColor(alpha);
float cr = (float)cc.x;
float cg = (float)cc.y;
float cb = (float)cc.z;
if (mc->options->anaglyph3d) {
float crr = (cr * 30 + cg * 59 + cb * 11) / 100;
@ -1632,10 +1632,10 @@ void LevelRenderer::renderAdvancedClouds(float alpha) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Vec3* cc = level[playerIndex]->getCloudColor(alpha);
float cr = (float)cc->x;
float cg = (float)cc->y;
float cb = (float)cc->z;
Vec3 cc = level[playerIndex]->getCloudColor(alpha);
float cr = (float)cc.x;
float cg = (float)cc.y;
float cb = (float)cc.z;
if (mc->options->anaglyph3d) {
float crr = (cr * 30 + cg * 59 + cb * 11) / 100;
@ -4039,7 +4039,6 @@ void LevelRenderer::staticCtor() {
}
int LevelRenderer::rebuildChunkThreadProc(void* lpParam) {
Vec3::CreateNewThreadStorage();
AABB::CreateNewThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024);
RenderManager.InitialiseContext();

View file

@ -22,14 +22,16 @@ void Lighting::turnOn() {
float d = 0.6f;
float s = 0.0f;
Vec3* l = Vec3::newTemp(0.2f, 1.0f, -0.7f)->normalize();
glLight(GL_LIGHT0, GL_POSITION, getBuffer(l->x, l->y, l->z, 0));
Vec3 l(0.2f, 1.0f, -0.7f);
l = l.normalize();
glLight(GL_LIGHT0, GL_POSITION, getBuffer(l.x, l.y, l.z, 0));
glLight(GL_LIGHT0, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT0, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT0, GL_SPECULAR, getBuffer(s, s, s, 1.0f));
l = Vec3::newTemp(-0.2f, 1.0f, 0.7f)->normalize();
glLight(GL_LIGHT1, GL_POSITION, getBuffer(l->x, l->y, l->z, 0));
l = Vec3(-0.2f, 1.0f, 0.7f);
l = l.normalize();
glLight(GL_LIGHT1, GL_POSITION, getBuffer(l.x, l.y, l.z, 0));
glLight(GL_LIGHT1, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT1, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT1, GL_SPECULAR, getBuffer(s, s, s, 1.0f));
@ -55,4 +57,4 @@ void Lighting::turnOnGui() {
glRotatef(165, 1, 0, 0);
turnOn();
glPopMatrix();
}
}

View file

@ -45,21 +45,21 @@ void _Polygon::mirror() {
}
void _Polygon::render(Tesselator* t, float scale) {
Vec3* v0 = vertices[1]->pos->vectorTo(vertices[0]->pos);
Vec3* v1 = vertices[1]->pos->vectorTo(vertices[2]->pos);
Vec3* n = v1->cross(v0)->normalize();
Vec3 v0 = vertices[1]->pos.vectorTo(vertices[0]->pos);
Vec3 v1 = vertices[1]->pos.vectorTo(vertices[2]->pos);
Vec3 n = v1.cross(v0).normalize();
t->begin();
if (_flipNormal) {
t->normal(-(float)n->x, -(float)n->y, -(float)n->z);
t->normal(-(float)n.x, -(float)n.y, -(float)n.z);
} else {
t->normal((float)n->x, (float)n->y, (float)n->z);
t->normal((float)n.x, (float)n.y, (float)n.z);
}
for (int i = 0; i < 4; i++) {
Vertex* v = vertices[i];
t->vertexUV((float)(v->pos->x * scale), (float)(v->pos->y * scale),
(float)(v->pos->z * scale), (float)(v->u), (float)(v->v));
t->vertexUV((float)(v->pos.x * scale), (float)(v->pos.y * scale),
(float)(v->pos.z * scale), (float)(v->u), (float)(v->v));
}
t->end();
}
@ -67,4 +67,4 @@ void _Polygon::render(Tesselator* t, float scale) {
_Polygon* _Polygon::flipNormal() {
_flipNormal = true;
return this;
}
}

View file

@ -2,7 +2,7 @@
#include "Vertex.h"
Vertex::Vertex(float x, float y, float z, float u, float v) {
this->pos = Vec3::newPermanent(x, y, z);
this->pos = Vec3(x, y, z);
this->u = u;
this->v = v;
}
@ -16,7 +16,7 @@ Vertex::Vertex(Vertex* vertex, float u, float v) {
}
Vertex::Vertex(Vec3* pos, float u, float v) {
this->pos = pos;
this->pos = *pos;
this->u = u;
this->v = v;
}
}

View file

@ -3,7 +3,7 @@
class Vertex {
public:
Vec3* pos;
Vec3 pos;
float u, v;
public:
@ -11,4 +11,4 @@ public:
Vertex* remap(float u, float v);
Vertex(Vertex* vertex, float u, float v);
Vertex(Vec3* pos, float u, float v);
};
};

View file

@ -64,18 +64,18 @@ bool AvoidPlayerGoal::canUse() {
delete entities;
}
Vec3* pos = RandomPos::getPosAvoid(
Vec3 avoid_pos(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z);
auto pos = RandomPos::getPosAvoid(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7,
Vec3::newTemp(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z));
if (pos == NULL) return false;
7, &avoid_pos);
if (!pos.has_value()) return false;
if (toAvoid.lock()->distanceToSqr(pos->x, pos->y, pos->z) <
toAvoid.lock()->distanceToSqr(mob->shared_from_this()))
return false;
delete path;
path = pathNav->createPath(pos->x, pos->y, pos->z);
if (path == NULL) return false;
if (!path->endsInXZ(pos)) return false;
if (!path->endsInXZ(&*pos)) return false;
return true;
}
@ -95,4 +95,4 @@ void AvoidPlayerGoal::tick() {
mob->getNavigation()->setSpeedModifier(sprintSpeedModifier);
else
mob->getNavigation()->setSpeedModifier(walkSpeedModifier);
}
}

View file

@ -54,4 +54,4 @@ bool BegGoal::playerHoldingInteresting(std::shared_ptr<Player> player) {
if (item == NULL) return false;
if (!wolf->isTame() && item->id == Item::bone_Id) return true;
return wolf->isFood(item);
}
}

View file

@ -5,6 +5,7 @@
#include "../../Headers/net.minecraft.world.level.h"
#include "../../Headers/net.minecraft.world.phys.h"
#include "FleeSunGoal.h"
#include <optional>
FleeSunGoal::FleeSunGoal(PathfinderMob* mob, double speedModifier) {
this->mob = mob;
@ -20,8 +21,8 @@ bool FleeSunGoal::canUse() {
Mth::floor(mob->z)))
return false;
Vec3* pos = getHidePos();
if (pos == NULL) return false;
auto pos = getHidePos();
if (!pos.has_value()) return false;
wantedX = pos->x;
wantedY = pos->y;
wantedZ = pos->z;
@ -34,7 +35,7 @@ void FleeSunGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
}
Vec3* FleeSunGoal::getHidePos() {
std::optional<Vec3> FleeSunGoal::getHidePos() {
Random* random = mob->getRandom();
for (int i = 0; i < 10; i++) {
int xt = Mth::floor(mob->x + random->nextInt(20) - 10);
@ -42,7 +43,7 @@ Vec3* FleeSunGoal::getHidePos() {
int zt = Mth::floor(mob->z + random->nextInt(20) - 10);
if (!level->canSeeSky(xt, yt, zt) &&
mob->getWalkTargetValue(xt, yt, zt) < 0)
return Vec3::newTemp(xt, yt, zt);
return Vec3(xt, yt, zt);
}
return NULL;
}
return std::nullopt;
}

View file

@ -1,5 +1,8 @@
#pragma once
#include <optional>
#include "../../Util/Vec3.h"
#include "Goal.h"
class FleeSunGoal : public Goal {
@ -17,10 +20,10 @@ public:
virtual void start();
private:
Vec3* getHidePos();
std::optional<Vec3> getHidePos();
public:
// 4J Added override to update ai elements when loading entity from
// schematics
virtual void setLevel(Level* level) { this->level = level; }
};
};

View file

@ -85,4 +85,4 @@ void FollowOwnerGoal::tick() {
}
}
}
}
}

View file

@ -34,4 +34,4 @@ void LeapAtTargetGoal::start() {
mob->xd += (xdd / dd * 0.5f) * 0.8f + mob->xd * 0.2f;
mob->zd += (zdd / dd * 0.5f) * 0.8f + mob->zd * 0.2f;
mob->yd = yd;
}
}

View file

@ -62,4 +62,4 @@ void LookAtPlayerGoal::tick() {
lookAt.lock()->x, lookAt.lock()->y + lookAt.lock()->getHeadHeight(),
lookAt.lock()->z, 10, mob->getMaxHeadXRot());
--lookTime;
}
}

View file

@ -44,13 +44,12 @@ void MoveIndoorsGoal::start() {
}
if (mob->distanceToSqr(_doorInfo->getIndoorX(), _doorInfo->y,
_doorInfo->getIndoorZ()) > 16 * 16) {
Vec3* pos = RandomPos::getPosTowards(
Vec3 towards(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(),
_doorInfo->getIndoorZ() + 0.5);
auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()),
14, 3,
Vec3::newTemp(_doorInfo->getIndoorX() + 0.5,
_doorInfo->getIndoorY(),
_doorInfo->getIndoorZ() + 0.5));
if (pos != NULL)
14, 3, &towards);
if (pos.has_value())
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, 1.0f);
} else
mob->getNavigation()->moveTo(_doorInfo->getIndoorX() + 0.5,
@ -68,4 +67,4 @@ void MoveIndoorsGoal::stop() {
insideX = _doorInfo->getIndoorX();
insideZ = _doorInfo->getIndoorZ();
doorInfo = std::weak_ptr<DoorInfo>();
}
}

View file

@ -47,10 +47,11 @@ bool MoveThroughVillageGoal::canUse() {
mob->getNavigation()->setCanOpenDoors(oldCanOpenDoors);
if (path != NULL) return true;
Vec3* pos = RandomPos::getPosTowards(
Vec3 towards(_doorInfo->x, _doorInfo->y, _doorInfo->z);
auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10,
7, Vec3::newTemp(_doorInfo->x, _doorInfo->y, _doorInfo->z));
if (pos == NULL) return false;
7, &towards);
if (!pos.has_value()) return false;
mob->getNavigation()->setCanOpenDoors(false);
delete path;
path = mob->getNavigation()->createPath(pos->x, pos->y, pos->z);

View file

@ -17,11 +17,12 @@ MoveTowardsRestrictionGoal::MoveTowardsRestrictionGoal(PathfinderMob* mob,
bool MoveTowardsRestrictionGoal::canUse() {
if (mob->isWithinRestriction()) return false;
Pos* towards = mob->getRestrictCenter();
Vec3* pos = RandomPos::getPosTowards(
Pos* toward = mob->getRestrictCenter();
Vec3 towards(toward->x, toward->y, toward->z);
auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, Vec3::newTemp(towards->x, towards->y, towards->z));
if (pos == NULL) return false;
7, &towards);
if (!pos.has_value()) return false;
wantedX = pos->x;
wantedY = pos->y;
wantedZ = pos->z;
@ -34,4 +35,4 @@ bool MoveTowardsRestrictionGoal::canContinueToUse() {
void MoveTowardsRestrictionGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
}
}

View file

@ -20,10 +20,11 @@ bool MoveTowardsTargetGoal::canUse() {
if (target.lock() == NULL) return false;
if (target.lock()->distanceToSqr(mob->shared_from_this()) > within * within)
return false;
Vec3* pos = RandomPos::getPosTowards(
Vec3 towards(target.lock()->x, target.lock()->y, target.lock()->z);
auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, Vec3::newTemp(target.lock()->x, target.lock()->y, target.lock()->z));
if (pos == NULL) return false;
7, &towards);
if (!pos.has_value()) return false;
wantedX = pos->x;
wantedY = pos->y;
wantedZ = pos->z;
@ -41,4 +42,4 @@ void MoveTowardsTargetGoal::stop() { target = std::weak_ptr<Mob>(); }
void MoveTowardsTargetGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
}
}

View file

@ -74,4 +74,4 @@ bool NearestAttackableTargetGoal::canUse() {
void NearestAttackableTargetGoal::start() {
mob->setTarget(target.lock());
TargetGoal::start();
}
}

View file

@ -57,4 +57,4 @@ void OcelotAttackGoal::tick() {
if (attackTime > 0) return;
attackTime = 20;
mob->doHurtTarget(target.lock());
}
}

View file

@ -22,10 +22,10 @@ bool PanicGoal::canUse() {
const int panicDuration = random.nextInt(41) + 60;
if (mob->tickCount - hurtTimeout > panicDuration) return false;
Vec3* pos = RandomPos::getPos(
auto pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5,
4);
if (pos == NULL) return false;
if (!pos.has_value()) return false;
posX = pos->x;
posY = pos->y;
posZ = pos->z;
@ -36,4 +36,4 @@ void PanicGoal::start() {
mob->getNavigation()->moveTo(posX, posY, posZ, speedModifier);
}
bool PanicGoal::canContinueToUse() { return !mob->getNavigation()->isDone(); }
bool PanicGoal::canContinueToUse() { return !mob->getNavigation()->isDone(); }

View file

@ -43,10 +43,10 @@ bool PlayGoal::canUse() {
delete children;
if (followFriend.lock() == NULL) {
Vec3* pos = RandomPos::getPos(
auto pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()),
16, 3);
if (pos == NULL) return false;
if (!pos.has_value()) return false;
}
return true;
}
@ -72,11 +72,11 @@ void PlayGoal::tick() {
mob->getNavigation()->moveTo(followFriend.lock(), speedModifier);
} else {
if (mob->getNavigation()->isDone()) {
Vec3* pos =
auto pos =
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
mob->shared_from_this()),
16, 3);
if (pos == NULL) return;
if (!pos.has_value()) return;
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier);
}
}

View file

@ -20,11 +20,11 @@ bool RandomStrollGoal::canUse() {
// fenced-off region far enough to determine we can despawn them
if (mob->getNoActionTime() < SharedConstants::TICKS_PER_SECOND * 5) {
if (mob->getRandom()->nextInt(120) == 0) {
Vec3* pos =
auto pos =
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
mob->shared_from_this()),
10, 7);
if (pos == NULL) return false;
if (!pos.has_value()) return false;
wantedX = pos->x;
wantedY = pos->y;
wantedZ = pos->z;
@ -38,11 +38,11 @@ bool RandomStrollGoal::canUse() {
// a given area and so waiting around is just wasting time
if (mob->isExtraWanderingEnabled()) {
Vec3* pos =
auto pos =
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
mob->shared_from_this()),
10, 7, mob->getWanderingQuadrant());
if (pos == NULL) return false;
if (!pos.has_value()) return false;
wantedX = pos->x;
wantedY = pos->y;
wantedZ = pos->z;
@ -58,4 +58,4 @@ bool RandomStrollGoal::canContinueToUse() {
void RandomStrollGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
}
}

View file

@ -17,10 +17,10 @@ RunAroundLikeCrazyGoal::RunAroundLikeCrazyGoal(EntityHorse* mob,
bool RunAroundLikeCrazyGoal::canUse() {
if (horse->isTamed() || horse->rider.lock() == NULL) return false;
Vec3* pos = RandomPos::getPos(
auto pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(horse->shared_from_this()), 5,
4);
if (pos == NULL) return false;
if (!pos.has_value()) return false;
posX = pos->x;
posY = pos->y;
posZ = pos->z;
@ -57,4 +57,4 @@ void RunAroundLikeCrazyGoal::tick() {
horse->level->broadcastEntityEvent(horse->shared_from_this(),
EntityEvent::TAMING_FAILED);
}
}
}

View file

@ -38,4 +38,4 @@ void SitGoal::start() {
void SitGoal::stop() { mob->setSitting(false); }
void SitGoal::wantToSit(bool _wantToSit) { this->_wantToSit = _wantToSit; }
void SitGoal::wantToSit(bool _wantToSit) { this->_wantToSit = _wantToSit; }

View file

@ -72,4 +72,4 @@ void TakeFlowerGoal::tick() {
villager->getNavigation()->stop();
}
}
}
}

View file

@ -115,4 +115,4 @@ bool TargetGoal::canReach(std::shared_ptr<LivingEntity> target) {
int zz = last->z - Mth::floor(target->z);
delete path;
return xx * xx + zz * zz <= 1.5 * 1.5;
}
}

View file

@ -84,4 +84,4 @@ void TemptGoal::tick() {
mob->getNavigation()->moveTo(player.lock(), speedModifier);
}
bool TemptGoal::isRunning() { return _isRunning; }
bool TemptGoal::isRunning() { return _isRunning; }

View file

@ -38,4 +38,4 @@ bool TradeWithPlayerGoal::canUse() {
void TradeWithPlayerGoal::start() { mob->getNavigation()->stop(); }
void TradeWithPlayerGoal::stop() { mob->setTradingPlayer(nullptr); }
void TradeWithPlayerGoal::stop() { mob->setTradingPlayer(nullptr); }

View file

@ -48,17 +48,17 @@ int Path::getIndex() { return index; }
void Path::setIndex(int index) { this->index = index; }
Vec3* Path::getPos(std::shared_ptr<Entity> e, int index) {
Vec3 Path::getPos(std::shared_ptr<Entity> e, int index) {
double x = nodes[index]->x + (int)(e->bbWidth + 1) * 0.5;
double y = nodes[index]->y;
double z = nodes[index]->z + (int)(e->bbWidth + 1) * 0.5;
return Vec3::newTemp(x, y, z);
return Vec3(x, y, z);
}
Vec3* Path::currentPos(std::shared_ptr<Entity> e) { return getPos(e, index); }
Vec3 Path::currentPos(std::shared_ptr<Entity> e) { return getPos(e, index); }
Vec3* Path::currentPos() {
return Vec3::newTemp(nodes[index]->x, nodes[index]->y, nodes[index]->z);
Vec3 Path::currentPos() {
return Vec3(nodes[index]->x, nodes[index]->y, nodes[index]->z);
}
bool Path::sameAs(Path* path) {
@ -83,4 +83,4 @@ bool Path::endsInXZ(Vec3* pos) {
Node* lastNode = last();
if (lastNode == NULL) return false;
return lastNode->x == (int)pos->x && lastNode->z == (int)pos->z;
}
}

View file

@ -20,10 +20,10 @@ public:
void setSize(int length);
int getIndex();
void setIndex(int index);
Vec3* getPos(std::shared_ptr<Entity> e, int index);
Vec3 getPos(std::shared_ptr<Entity> e, int index);
NodeArray Getarray();
Vec3* currentPos(std::shared_ptr<Entity> e);
Vec3* currentPos();
Vec3 currentPos(std::shared_ptr<Entity> e);
Vec3 currentPos();
bool sameAs(Path* path);
bool endsIn(Vec3* pos);
bool endsInXZ(Vec3* pos);

View file

@ -283,4 +283,4 @@ Path* PathFinder::reconstruct_path(Node* from, Node* to) {
Path* ret = new Path(nodes);
delete[] nodes.data;
return ret;
}
}

View file

@ -20,7 +20,7 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
avoidSun = false;
_tick = 0;
lastStuckCheck = 0;
lastStuckCheckPos = Vec3::newPermanent(0, 0, 0);
lastStuckCheckPos = Vec3(0, 0, 0);
_canPassDoors = true;
_canOpenDoors = false;
avoidWater = false;
@ -29,7 +29,6 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
PathNavigation::~PathNavigation() {
if (path != NULL) delete path;
delete lastStuckCheckPos;
}
void PathNavigation::setAvoidWater(bool avoidWater) {
@ -110,11 +109,11 @@ bool PathNavigation::moveTo(Path* newPath, double speedModifier) {
if (path->getSize() == 0) return false;
this->speedModifier = speedModifier;
Vec3* mobPos = getTempMobPos();
Vec3 mobPos = getTempMobPos();
lastStuckCheck = _tick;
lastStuckCheckPos->x = mobPos->x;
lastStuckCheckPos->y = mobPos->y;
lastStuckCheckPos->z = mobPos->z;
lastStuckCheckPos.x = mobPos.x;
lastStuckCheckPos.y = mobPos.y;
lastStuckCheckPos.z = mobPos.z;
return true;
}
@ -127,20 +126,19 @@ void PathNavigation::tick() {
if (canUpdatePath()) updatePath();
if (isDone()) return;
Vec3* target = path->currentPos(mob->shared_from_this());
if (target == NULL) return;
Vec3 target = path->currentPos(mob->shared_from_this());
mob->getMoveControl()->setWantedPosition(target->x, target->y, target->z,
mob->getMoveControl()->setWantedPosition(target.x, target.y, target.z,
speedModifier);
}
void PathNavigation::updatePath() {
Vec3* mobPos = getTempMobPos();
Vec3 mobPos = getTempMobPos();
// find first elevations in path
int firstElevation = path->getSize();
for (int i = path->getIndex(); path != NULL && i < path->getSize(); ++i) {
if ((int)path->get(i)->y != (int)mobPos->y) {
if ((int)path->get(i)->y != (int)mobPos.y) {
firstElevation = i;
break;
}
@ -150,8 +148,8 @@ void PathNavigation::updatePath() {
// check canWalkDirectly also) possibly only check next as well
float waypointRadiusSqr = mob->bbWidth * mob->bbWidth;
for (int i = path->getIndex(); i < firstElevation; ++i) {
Vec3* pathPos = path->getPos(mob->shared_from_this(), i);
if (mobPos->distanceToSqr(pathPos) < waypointRadiusSqr) {
Vec3 pathPos = path->getPos(mob->shared_from_this(), i);
if (mobPos.distanceToSqr(pathPos) < waypointRadiusSqr) {
path->setIndex(i + 1);
}
}
@ -161,8 +159,8 @@ void PathNavigation::updatePath() {
int sy = (int)mob->bbHeight + 1;
int sz = sx;
for (int i = firstElevation - 1; i >= path->getIndex(); --i) {
if (canMoveDirectly(mobPos, path->getPos(mob->shared_from_this(), i),
sx, sy, sz)) {
Vec3 mob_pos = path->getPos(mob->shared_from_this(), i);
if (canMoveDirectly(&mobPos, &mob_pos, sx, sy, sz)) {
path->setIndex(i);
break;
}
@ -170,11 +168,11 @@ void PathNavigation::updatePath() {
// stuck detection (probably pushed off path)
if (_tick - lastStuckCheck > 100) {
if (mobPos->distanceToSqr(lastStuckCheckPos) < 1.5 * 1.5) stop();
if (mobPos.distanceToSqr(lastStuckCheckPos) < 1.5 * 1.5) stop();
lastStuckCheck = _tick;
lastStuckCheckPos->x = mobPos->x;
lastStuckCheckPos->y = mobPos->y;
lastStuckCheckPos->z = mobPos->z;
lastStuckCheckPos.x = mobPos.x;
lastStuckCheckPos.y = mobPos.y;
lastStuckCheckPos.z = mobPos.z;
}
}
@ -185,8 +183,8 @@ void PathNavigation::stop() {
path = NULL;
}
Vec3* PathNavigation::getTempMobPos() {
return Vec3::newTemp(mob->x, getSurfaceY(), mob->z);
Vec3 PathNavigation::getTempMobPos() {
return Vec3(mob->x, getSurfaceY(), mob->z);
}
int PathNavigation::getSurfaceY() {
@ -329,4 +327,4 @@ bool PathNavigation::canWalkAbove(int startX, int startY, int startZ, int sx,
return true;
}
void PathNavigation::setLevel(Level* level) { this->level = level; }
void PathNavigation::setLevel(Level* level) { this->level = level; }

View file

@ -14,7 +14,7 @@ private:
bool avoidSun;
int _tick;
int lastStuckCheck;
Vec3* lastStuckCheckPos;
Vec3 lastStuckCheckPos;
bool _canPassDoors;
bool _canOpenDoors;
@ -52,7 +52,7 @@ public:
void stop();
private:
Vec3* getTempMobPos();
Vec3 getTempMobPos();
int getSurfaceY();
bool canUpdatePath();
bool isInLiquid();
@ -67,4 +67,4 @@ public:
// 4J Added override to update ai elements when loading entity from
// schematics
void setLevel(Level* level);
};
};

View file

@ -2,34 +2,38 @@
#include "../../Headers/net.minecraft.world.entity.h"
#include "../../Headers/net.minecraft.world.phys.h"
#include "RandomPos.h"
#include <optional>
Vec3* RandomPos::tempDir = Vec3::newPermanent(0, 0, 0);
Vec3 RandomPos::tempDir = Vec3(0, 0, 0);
Vec3* RandomPos::getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, int quadrant /*=-1*/) // 4J - added quadrant
std::optional<Vec3> RandomPos::getPos(
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist,
int quadrant /*=-1*/) // 4J - added quadrant
{
return generateRandomPos(mob, xzDist, yDist, NULL, quadrant);
}
Vec3* RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* towardsPos) {
tempDir->x = towardsPos->x - mob->x;
tempDir->y = towardsPos->y - mob->y;
tempDir->z = towardsPos->z - mob->z;
return generateRandomPos(mob, xzDist, yDist, tempDir);
std::optional<Vec3> RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* towardsPos) {
tempDir.x = towardsPos->x - mob->x;
tempDir.y = towardsPos->y - mob->y;
tempDir.z = towardsPos->z - mob->z;
return generateRandomPos(mob, xzDist, yDist, &tempDir);
}
Vec3* RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* avoidPos) {
tempDir->x = mob->x - avoidPos->x;
tempDir->y = mob->y - avoidPos->y;
tempDir->z = mob->z - avoidPos->z;
return generateRandomPos(mob, xzDist, yDist, tempDir);
std::optional<Vec3> RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* avoidPos) {
tempDir.x = mob->x - avoidPos->x;
tempDir.y = mob->y - avoidPos->y;
tempDir.z = mob->z - avoidPos->z;
return generateRandomPos(mob, xzDist, yDist, &tempDir);
}
Vec3* RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist, Vec3* dir,
int quadrant /*=-1*/) // 4J - added quadrant
std::optional<Vec3> RandomPos::generateRandomPos(
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3* dir,
int quadrant /*=-1*/) // 4J - added quadrant
{
Random* random = mob->getRandom();
bool hasBest = false;
@ -81,8 +85,8 @@ Vec3* RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
}
}
if (hasBest) {
return Vec3::newTemp(xBest, yBest, zBest);
return Vec3(xBest, yBest, zBest);
}
return NULL;
}
return std::nullopt;
}

View file

@ -1,21 +1,25 @@
#pragma once
#include <optional>
class PathfinderMob;
class RandomPos {
private:
static Vec3* tempDir;
static Vec3 tempDir;
public:
static Vec3* getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, int quadrant = -1); // 4J added quadrant
static Vec3* getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* towardsPos);
static Vec3* getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* avoidPos);
static std::optional<Vec3> getPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
int quadrant = -1); // 4J added quadrant
static std::optional<Vec3> getPosTowards(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* towardsPos);
static std::optional<Vec3> getPosAvoid(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* avoidPos);
private:
static Vec3* generateRandomPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist, Vec3* dir,
int quadrant = -1); // 4J added quadrant
};
static std::optional<Vec3> generateRandomPos(
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3* dir,
int quadrant = -1); // 4J added quadrant
};

View file

@ -7,6 +7,7 @@
#include "LiquidTile.h"
#include "../Util/Facing.h"
#include "../Util/SoundTypes.h"
#include "Blocks/Material.h"
const std::wstring LiquidTile::TEXTURE_LAVA_STILL = L"lava";
const std::wstring LiquidTile::TEXTURE_WATER_STILL = L"water";
@ -116,8 +117,8 @@ int LiquidTile::getResource(int data, Random* random, int playerBonusLevel) {
int LiquidTile::getResourceCount(Random* random) { return 0; }
Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) {
Vec3* flow = Vec3::newTemp(0, 0, 0);
Vec3 LiquidTile::getFlow(LevelSource* level, int x, int y, int z) {
Vec3 flow(0, 0, 0);
int mid = getRenderedDepth(level, x, y, z);
for (int d = 0; d < 4; d++) {
int xt = x;
@ -135,15 +136,14 @@ Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) {
t = getRenderedDepth(level, xt, yt - 1, zt);
if (t >= 0) {
int dir = t - (mid - 8);
flow = flow->add((xt - x) * dir, (yt - y) * dir,
(zt - z) * dir);
flow = flow.add((xt - x) * dir, (yt - y) * dir,
(zt - z) * dir);
}
}
} else {
if (t >= 0) {
int dir = t - mid;
flow =
flow->add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir);
flow = flow.add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir);
}
}
}
@ -157,18 +157,19 @@ Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) {
if (ok || isSolidFace(level, x, y + 1, z + 1, 3)) ok = true;
if (ok || isSolidFace(level, x - 1, y + 1, z, 4)) ok = true;
if (ok || isSolidFace(level, x + 1, y + 1, z, 5)) ok = true;
if (ok) flow = flow->normalize()->add(0, -6, 0);
if (ok) flow = flow.normalize().add(0, -6, 0);
}
flow = flow->normalize();
flow = flow.normalize();
return flow;
}
void LiquidTile::handleEntityInside(Level* level, int x, int y, int z,
std::shared_ptr<Entity> e, Vec3* current) {
Vec3* flow = getFlow(level, x, y, z);
current->x += flow->x;
current->y += flow->y;
current->z += flow->z;
Vec3 flow = getFlow(level, x, y, z);
current->x += flow.x;
current->y += flow.y;
current->z += flow.z;
}
int LiquidTile::getTickDelay(Level* level) {
@ -305,13 +306,11 @@ void LiquidTile::animateTick(Level* level, int x, int y, int z,
double LiquidTile::getSlopeAngle(LevelSource* level, int x, int y, int z,
Material* m) {
Vec3* flow = NULL;
if (m == Material::water)
flow = ((LiquidTile*)Tile::water)->getFlow(level, x, y, z);
if (m == Material::lava)
flow = ((LiquidTile*)Tile::lava)->getFlow(level, x, y, z);
if (flow->x == 0 && flow->z == 0) return -1000;
return atan2(flow->z, flow->x) - PI / 2;
Vec3 flow;
if (m == Material::water) flow = Tile::water->getFlow(level, x, y, z);
if (m == Material::lava) flow = Tile::lava->getFlow(level, x, y, z);
if (flow.x == 0 && flow.z == 0) return -1000;
return atan2(flow.z, flow.x) - PI / 2;
}
void LiquidTile::onPlace(Level* level, int x, int y, int z) {

View file

@ -46,7 +46,7 @@ public:
virtual int getResourceCount(Random* random);
private:
virtual Vec3* getFlow(LevelSource* level, int x, int y, int z);
virtual Vec3 getFlow(LevelSource* level, int x, int y, int z);
public:
virtual void handleEntityInside(Level* level, int x, int y, int z,
@ -72,4 +72,4 @@ protected:
public:
void registerIcons(IconRegister* iconRegister);
static Icon* getTexture(const std::wstring& name);
};
};

View file

@ -443,7 +443,7 @@ HitResult* StairTile::clip(Level* level, int xt, int yt, int zt, Vec3* a,
for (unsigned int i = 0; i < 8; ++i) {
HitResult* result = results[i];
if (result != NULL) {
double dist = result->pos->distanceToSqr(b);
double dist = result->pos.distanceToSqr(*b);
if (dist > closestDist) {
closest = result;

View file

@ -15,7 +15,9 @@
#include "../Headers/net.minecraft.world.food.h"
#include "../Headers/net.minecraft.world.h"
#include "../Headers/net.minecraft.h"
#include "Util/Vec3.h"
#include "Tile.h"
#include <optional>
std::wstring Tile::TILE_DESCRIPTION_PREFIX = L"Tile.";
@ -2120,41 +2122,52 @@ float Tile::getExplosionResistance(std::shared_ptr<Entity> source) {
HitResult* Tile::clip(Level* level, int xt, int yt, int zt, Vec3* a, Vec3* b) {
updateShape(level, xt, yt, zt);
a = a->add(-xt, -yt, -zt);
b = b->add(-xt, -yt, -zt);
*a = a->add(-xt, -yt, -zt);
*b = b->add(-xt, -yt, -zt);
ThreadStorage* tls = m_tlsShape;
Vec3* xh0 = a->clipX(b, tls->xx0);
Vec3* xh1 = a->clipX(b, tls->xx1);
auto xh0 = a->clipX(*b, tls->xx0);
auto xh1 = a->clipX(*b, tls->xx1);
Vec3* yh0 = a->clipY(b, tls->yy0);
Vec3* yh1 = a->clipY(b, tls->yy1);
auto yh0 = a->clipY(*b, tls->yy0);
auto yh1 = a->clipY(*b, tls->yy1);
Vec3* zh0 = a->clipZ(b, tls->zz0);
Vec3* zh1 = a->clipZ(b, tls->zz1);
auto zh0 = a->clipZ(*b, tls->zz0);
auto zh1 = a->clipZ(*b, tls->zz1);
Vec3* closest = NULL;
std::optional<Vec3> closest = std::nullopt;
if (containsX(xh0) &&
(closest == NULL || a->distanceToSqr(xh0) < a->distanceToSqr(closest)))
if (xh0.has_value() and containsX(&*xh0) and
(!closest.has_value() or
a->distanceToSqr(*xh0) < a->distanceToSqr(*closest)))
closest = xh0;
if (containsX(xh1) &&
(closest == NULL || a->distanceToSqr(xh1) < a->distanceToSqr(closest)))
if (xh1.has_value() and containsX(&*xh1) and
(!closest.has_value() or
a->distanceToSqr(*xh1) < a->distanceToSqr(*closest)))
closest = xh1;
if (containsY(yh0) &&
(closest == NULL || a->distanceToSqr(yh0) < a->distanceToSqr(closest)))
if (yh0.has_value() and containsY(&*yh0) and
(!closest.has_value() or
a->distanceToSqr(*yh0) < a->distanceToSqr(*closest)))
closest = yh0;
if (containsY(yh1) &&
(closest == NULL || a->distanceToSqr(yh1) < a->distanceToSqr(closest)))
if (yh1.has_value() and containsY(&*yh1) and
(!closest.has_value() or
a->distanceToSqr(*yh1) < a->distanceToSqr(*closest)))
closest = yh1;
if (containsZ(zh0) &&
(closest == NULL || a->distanceToSqr(zh0) < a->distanceToSqr(closest)))
if (zh0.has_value() and containsZ(&*zh0) and
(!closest.has_value() or
a->distanceToSqr(*zh0) < a->distanceToSqr(*closest)))
closest = zh0;
if (containsZ(zh1) &&
(closest == NULL || a->distanceToSqr(zh1) < a->distanceToSqr(closest)))
if (zh1.has_value() and containsZ(&*zh1) and
(!closest.has_value() or
a->distanceToSqr(*zh1) < a->distanceToSqr(*closest)))
closest = zh1;
if (closest == NULL) return NULL;
if (!closest.has_value()) return nullptr;
int face = -1;
@ -2165,7 +2178,8 @@ HitResult* Tile::clip(Level* level, int xt, int yt, int zt, Vec3* a, Vec3* b) {
if (closest == zh0) face = Facing::NORTH;
if (closest == zh1) face = Facing::SOUTH;
return new HitResult(xt, yt, zt, face, closest->add(xt, yt, zt));
Vec3 res = closest->add(xt, yt, zt);
return new HitResult(xt, yt, zt, face, res);
}
bool Tile::containsX(Vec3* v) {

View file

@ -113,4 +113,4 @@ void HorseInventoryMenu::removed(std::shared_ptr<Player> player) {
std::shared_ptr<Container> HorseInventoryMenu::getContainer() {
return horseContainer;
}
}

View file

@ -23,6 +23,7 @@
#include "../../Minecraft.Client/Level/MultiPlayerLevel.h"
#include "../../Minecraft.Client/Player/MultiPlayerLocalPlayer.h"
#include <cstdint>
#include <optional>
#include "../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Minecraft.Client/Network/PlayerList.h"
@ -1533,7 +1534,7 @@ void Entity::lerpTo(double x, double y, double z, float yRot, float xRot,
float Entity::getPickRadius() { return 0.1f; }
Vec3* Entity::getLookAngle() { return NULL; }
std::optional<Vec3> Entity::getLookAngle() { return std::nullopt; }
void Entity::handleInsidePortal() {
if (changingDimensionDelay > 0) {
@ -1874,4 +1875,4 @@ unsigned int Entity::getAnimOverrideBitmask() {
}
return m_uiAnimOverrideBitmask;
}
}

View file

@ -6,6 +6,7 @@
#include "../Util/Vec3.h"
#include "../Util/Definitions.h"
#include <cstdint>
#include <optional>
class LivingEntity;
class LightningBolt;
@ -342,7 +343,7 @@ public:
virtual void lerpTo(double x, double y, double z, float yRot, float xRot,
int steps);
virtual float getPickRadius();
virtual Vec3* getLookAngle();
virtual std::optional<Vec3> getLookAngle();
virtual void handleInsidePortal();
virtual int getDimensionChangingDelay();
virtual void lerpMotion(double xd, double yd, double zd);
@ -424,6 +425,7 @@ private:
static int extraWanderTicks;
static thread_local bool m_tlsUseSmallIds;
public:
static void tickExtraWandering();
static void countFlagsForPIX();

View file

@ -24,6 +24,7 @@
#include "../Headers/net.minecraft.world.scores.h"
#include "../Headers/com.mojang.nbt.h"
#include "LivingEntity.h"
#include <optional>
#include "../../Minecraft.Client/Textures/Textures.h"
#include "../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Minecraft.Client/Player/EntityTracker.h"
@ -31,6 +32,7 @@
#include "../Util/ParticleTypes.h"
#include "../Stats/GenericStats.h"
#include "ItemEntity.h"
#include "Util/Vec3.h"
const double LivingEntity::MIN_MOVEMENT_DISTANCE = 0.005;
@ -791,18 +793,18 @@ void LivingEntity::breakItem(std::shared_ptr<ItemInstance> itemInstance) {
0.8f + level->random->nextFloat() * 0.4f);
for (int i = 0; i < 5; i++) {
Vec3* d = Vec3::newTemp((random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0);
d->xRot(-xRot * PI / 180);
d->yRot(-yRot * PI / 180);
Vec3 d = Vec3((random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0);
d.xRot(-xRot * PI / 180);
d.yRot(-yRot * PI / 180);
Vec3* p = Vec3::newTemp((random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6);
p->xRot(-xRot * PI / 180);
p->yRot(-yRot * PI / 180);
p = p->add(x, y + getHeadHeight(), z);
Vec3 p = Vec3((random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6);
p.xRot(-xRot * PI / 180);
p.yRot(-yRot * PI / 180);
p = p.add(x, y + getHeadHeight(), z);
level->addParticle(PARTICLE_ICONCRACK(itemInstance->getItem()->id, 0),
p->x, p->y, p->z, d->x, d->y + 0.05, d->z);
p.x, p.y, p.z, d.x, d.y + 0.05, d.z);
}
}
@ -1640,25 +1642,25 @@ void LivingEntity::take(std::shared_ptr<Entity> e, int orgCount) {
}
bool LivingEntity::canSee(std::shared_ptr<Entity> target) {
HitResult* hres = level->clip(
Vec3::newTemp(x, y + getHeadHeight(), z),
Vec3::newTemp(target->x, target->y + target->getHeadHeight(),
target->z));
Vec3 a{x, y + getHeadHeight(), z};
Vec3 b{target->x, target->y + target->getHeadHeight(), target->z};
HitResult* hres = level->clip(&a, &b);
bool retVal = (hres == NULL);
delete hres;
return retVal;
}
Vec3* LivingEntity::getLookAngle() { return getViewVector(1); }
std::optional<Vec3> LivingEntity::getLookAngle() { return getViewVector(1); }
Vec3* LivingEntity::getViewVector(float a) {
Vec3 LivingEntity::getViewVector(float a) {
if (a == 1) {
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI);
float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD);
return Vec3::newTemp(ySin * xCos, xSin, yCos * xCos);
return Vec3(ySin * xCos, xSin, yCos * xCos);
}
float xRot = xRotO + (this->xRot - xRotO) * a;
float yRot = yRotO + (this->yRot - yRotO) * a;
@ -1668,7 +1670,7 @@ Vec3* LivingEntity::getViewVector(float a) {
float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD);
return Vec3::newTemp(ySin * xCos, xSin, yCos * xCos);
return Vec3(ySin * xCos, xSin, yCos * xCos);
}
float LivingEntity::getAttackAnim(float a) {
@ -1677,22 +1679,23 @@ float LivingEntity::getAttackAnim(float a) {
return oAttackAnim + diff * a;
}
Vec3* LivingEntity::getPos(float a) {
Vec3 LivingEntity::getPos(float a) {
if (a == 1) {
return Vec3::newTemp(x, y, z);
return Vec3(x, y, z);
}
double x = xo + (this->x - xo) * a;
double y = yo + (this->y - yo) * a;
double z = zo + (this->z - zo) * a;
return Vec3::newTemp(x, y, z);
return Vec3(x, y, z);
}
HitResult* LivingEntity::pick(double range, float a) {
Vec3* from = getPos(a);
Vec3* b = getViewVector(a);
Vec3* to = from->add(b->x * range, b->y * range, b->z * range);
return level->clip(from, to);
Vec3 from = getPos(a);
Vec3 b = getViewVector(a);
Vec3 to{b.x * range, b.y * range, b.z * range};
to = to.add(from.x, from.y, from.z);
return level->clip(&from, &to);
}
bool LivingEntity::isEffectiveAi() { return !level->isClientSide; }

View file

@ -1,5 +1,6 @@
#pragma once
#include <optional>
#include "Entity.h"
#include "MobType.h"
#include "../AI/Goals/GoalSelector.h"
@ -304,10 +305,10 @@ public:
virtual bool canSee(std::shared_ptr<Entity> target);
public:
virtual Vec3* getLookAngle();
virtual Vec3* getViewVector(float a);
virtual std::optional<Vec3> getLookAngle();
virtual Vec3 getViewVector(float a);
virtual float getAttackAnim(float a);
virtual Vec3* getPos(float a);
virtual Vec3 getPos(float a);
virtual HitResult* pick(double range, float a);
virtual bool isEffectiveAi();

View file

@ -210,4 +210,4 @@ void MinecartContainer::applyNaturalSlowdown() {
xd *= keep;
yd *= 0;
zd *= keep;
}
}

View file

@ -184,7 +184,8 @@ void Arrow::tick() {
if (t > 0) {
Tile::tiles[t]->updateShape(level, xTile, yTile, zTile);
AABB* aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile);
if (aabb != NULL && aabb->contains(Vec3::newTemp(x, y, z))) {
Vec3 pos{x, y, z};
if (aabb != NULL && aabb->contains(&pos)) {
inGround = true;
}
}
@ -217,15 +218,17 @@ void Arrow::tick() {
flightTime++;
}
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to, false, true);
Vec3 from{x, y, z};
Vec3 to{x + xd, y + yd, z + zd};
HitResult* res = level->clip(&from, &to, false, true);
from = Vec3{x, y, z};
to = Vec3{x + xd, y + yd, z + zd};
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z);
to = Vec3{res->pos.x, res->pos.y, res->pos.z};
}
std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
shared_from_this(), this->bb->expand(xd, yd, zd)->grow(1, 1, 1));
@ -237,9 +240,9 @@ void Arrow::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) {
hitEntity = e;
nearest = dd;
@ -359,9 +362,9 @@ void Arrow::tick() {
zTile = res->z;
lastTile = level->getTile(xTile, yTile, zTile);
lastData = level->getData(xTile, yTile, zTile);
xd = (float)(res->pos->x - x);
yd = (float)(res->pos->y - y);
zd = (float)(res->pos->z - z);
xd = (float)(res->pos.x - x);
yd = (float)(res->pos.y - y);
zd = (float)(res->pos.z - z);
float dd = (float)sqrt(xd * xd + yd * yd + zd * zd);
// 4J added check - zero dd here was creating NaNs
if (dd > 0.0001f) {

View file

@ -67,4 +67,4 @@ ePARTICLE_TYPE DragonFireball::getTrailParticleType() {
return eParticleType_dragonbreath;
}
bool DragonFireball::shouldBurn() { return false; }
bool DragonFireball::shouldBurn() { return false; }

View file

@ -14,6 +14,7 @@
#include "../../Util/SharedConstants.h"
#include "EnderDragon.h"
#include <limits>
#include <optional>
#define PRINT_DRAGON_STATE_CHANGE_MESSAGES 1
@ -309,13 +310,14 @@ void EnderDragon::aiStep() {
double xP = 0.0;
double yP = 0.0;
double zP = 0.0;
Vec3* v = getHeadLookVector(1); // getViewVector(1);
Vec3 v = getHeadLookVector(1); // getViewVector(1);
// app.DebugPrintf("View vector is (%f,%f,%f) - lsteps %d\n", v->x,
// v->y, v->z, lSteps); unsigned int d = 0; for(unsigned int d = 1;
// d < 3; ++d)
{
Vec3* vN = v->normalize();
vN->yRot(-PI / 4);
Vec3 vN = Vec3{v.x, v.y, v.z}.normalize();
vN.yRot(-PI / 4);
for (unsigned int i = 0; i < 8; ++i) {
if (getSynchedAction() == e_EnderdragonAction_Landing) {
// for(unsigned int j = 0; j < 6; ++j)
@ -334,9 +336,9 @@ void EnderDragon::aiStep() {
zP += (level->random->nextBoolean() ? 1 : -1) *
level->random->nextFloat() / 2;
level->addParticle(eParticleType_dragonbreath, xP,
yP, zP, (-vN->x * 0.08) + xd,
(-vN->y * 0.3) + yd,
(-vN->z * 0.08) + zd);
yP, zP, (-vN.x * 0.08) + xd,
(-vN.y * 0.3) + yd,
(-vN.z * 0.08) + zd);
}
} else {
double yVelocity = 0.6;
@ -356,12 +358,12 @@ void EnderDragon::aiStep() {
zP += (level->random->nextBoolean() ? 1 : -1) *
level->random->nextFloat() / 2;
level->addParticle(eParticleType_dragonbreath, xP,
yP, zP, -vN->x * xzVelocity * j,
-vN->y * yVelocity,
-vN->z * xzVelocity * j);
yP, zP, -vN.x * xzVelocity * j,
-vN.y * yVelocity,
-vN.z * xzVelocity * j);
}
}
vN->yRot(PI / (2 * 8));
vN.yRot(PI / (2 * 8));
}
}
} else if (getSynchedAction() ==
@ -477,13 +479,13 @@ void EnderDragon::aiStep() {
// No movement
} else if (getSynchedAction() == e_EnderdragonAction_Sitting_Scanning) {
if (attackTarget != NULL) {
Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0,
(attackTarget->z - z))
->normalize();
Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0,
-cos(yRot * PI / 180))
->normalize();
float dot = (float)dir->dot(aim);
Vec3 aim = Vec3((attackTarget->x - x), 0, (attackTarget->z - z))
.normalize();
Vec3 dir = Vec3(sin(yRot * PI / 180), 0, -cos(yRot * PI / 180))
.normalize();
float dot = (float)dir.dot(aim);
float angleDegs = acos(dot) * 180 / PI;
angleDegs = angleDegs + 0.5f;
@ -561,13 +563,12 @@ void EnderDragon::aiStep() {
if (yRotD > 50) yRotD = 50;
if (yRotD < -50) yRotD = -50;
Vec3* aim =
Vec3::newTemp((xTarget - x), (yTarget - y), (zTarget - z))
->normalize();
Vec3* dir =
Vec3::newTemp(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180))
->normalize();
float dot = (float)(dir->dot(aim) + 0.5f) / 1.5f;
Vec3 aim =
Vec3((xTarget - x), (yTarget - y), (zTarget - z)).normalize();
Vec3 dir = Vec3(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180))
.normalize();
float dot = (float)(dir.dot(aim) + 0.5f) / 1.5f;
if (dot < 0) dot = 0;
yRotA *= 0.80f;
@ -591,8 +592,8 @@ void EnderDragon::aiStep() {
move(xd, yd, zd);
}
Vec3* actual = Vec3::newTemp(xd, yd, zd)->normalize();
float slide = (float)(actual->dot(dir) + 1) / 2.0f;
Vec3 actual = Vec3(xd, yd, zd).normalize();
float slide = (float)(actual.dot(dir) + 1) / 2.0f;
slide = 0.8f + 0.15f * slide;
xd *= slide;
@ -733,23 +734,23 @@ void EnderDragon::aiStep() {
maxDist * maxDist) {
if (this->canSee(attackTarget)) {
m_fireballCharge++;
Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0,
(attackTarget->z - z))
->normalize();
Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0,
-cos(yRot * PI / 180))
->normalize();
float dot = (float)dir->dot(aim);
Vec3 aim = Vec3((attackTarget->x - x), 0, (attackTarget->z - z))
.normalize();
Vec3 dir = Vec3(sin(yRot * PI / 180), 0, -cos(yRot * PI / 180))
.normalize();
float dot = (float)dir.dot(aim);
float angleDegs = acos(dot) * 180 / PI;
angleDegs = angleDegs + 0.5f;
if (m_fireballCharge >= 20 &&
(angleDegs >= 0 && angleDegs < 10)) {
double d = 1;
Vec3* v = getViewVector(1);
float startingX = head->x - v->x * d;
Vec3 v = getViewVector(1);
float startingX = head->x - v.x * d;
float startingY = head->y + head->bbHeight / 2 + 0.5f;
float startingZ = head->z - v->z * d;
float startingZ = head->z - v.z * d;
double xdd = attackTarget->x - startingX;
double ydd =
@ -978,13 +979,13 @@ void EnderDragon::findNewTarget() {
int targetNodeIndex = 0;
if (playerNearestToEgg != NULL) {
Vec3* aim = Vec3::newTemp(playerNearestToEgg->x, 0,
playerNearestToEgg->z)
->normalize();
Vec3 aim = Vec3(playerNearestToEgg->x, 0, playerNearestToEgg->z)
.normalize();
// app.DebugPrintf("Final marker node near (%f,%d,%f)\n",
// -aim->x*40,105,-aim->z*40 );
targetNodeIndex =
findClosestNode(-aim->x * 40, 105.0, -aim->z * 40);
findClosestNode(-aim.x * 40, 105.0, -aim.z * 40);
} else {
targetNodeIndex = findClosestNode(40.0, eggHeight, 0.0);
}
@ -1022,9 +1023,8 @@ void EnderDragon::findNewTarget() {
// !m_holdingPatternClockwise;
if (getSynchedAction() == e_EnderdragonAction_Takeoff) {
Vec3* v = getHeadLookVector(1);
targetNodeIndex =
findClosestNode(-v->x * 40, 105.0, -v->z * 40);
Vec3 v = getHeadLookVector(1);
targetNodeIndex = findClosestNode(-v.x * 40, 105.0, -v.z * 40);
} else {
if (random->nextInt(8) == 0) {
m_holdingPatternClockwise = !m_holdingPatternClockwise;
@ -1488,24 +1488,24 @@ void EnderDragon::strafeAttackTarget() {
void EnderDragon::navigateToNextPathNode() {
if (m_currentPath != NULL && !m_currentPath->isDone()) {
Vec3* curr = m_currentPath->currentPos();
Vec3 curr = m_currentPath->currentPos();
m_currentPath->next();
xTarget = curr->x;
xTarget = curr.x;
if (getSynchedAction() == e_EnderdragonAction_LandingApproach &&
m_currentPath->isDone()) {
// When heading to the last node on the landing approach, we want
// the yCoord to be exact
yTarget = curr->y;
yTarget = curr.y;
} else {
do {
yTarget = curr->y + random->nextFloat() * 20;
} while (yTarget < (curr->y));
yTarget = curr.y + random->nextFloat() * 20;
} while (yTarget < (curr.y));
}
zTarget = curr->z;
app.DebugPrintf("Path node pos is (%f,%f,%f)\n", curr->x, curr->y,
curr->z);
zTarget = curr.z;
app.DebugPrintf("Path node pos is (%f,%f,%f)\n", curr.x, curr.y,
curr.z);
app.DebugPrintf("Setting new target to (%f,%f,%f)\n", xTarget, yTarget,
zTarget);
}
@ -1846,8 +1846,8 @@ double EnderDragon::getHeadPartYRotDiff(int partIndex, doubleArray bodyPos,
return result;
}
Vec3* EnderDragon::getHeadLookVector(float a) {
Vec3* result = NULL;
Vec3 EnderDragon::getHeadLookVector(float a) {
Vec3 result;
if (getSynchedAction() == e_EnderdragonAction_Landing ||
getSynchedAction() == e_EnderdragonAction_Takeoff) {
@ -1888,5 +1888,6 @@ Vec3* EnderDragon::getHeadLookVector(float a) {
} else {
result = getViewVector(a);
}
return result;
}

View file

@ -188,7 +188,7 @@ public:
doubleArray partPos);
double getHeadPartYRotDiff(int partIndex, doubleArray bodyPos,
doubleArray partPos);
Vec3* getHeadLookVector(float a);
Vec3 getHeadLookVector(float a);
virtual std::wstring getAName() { return app.GetString(IDS_ENDERDRAGON); };
virtual float getHealth() { return LivingEntity::getHealth(); };

View file

@ -114,14 +114,15 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
std::shared_ptr<ItemInstance> helmet = player->inventory->armor[3];
if (helmet != NULL && helmet->id == Tile::pumpkin_Id) return false;
Vec3* look = player->getViewVector(1)->normalize();
Vec3* dir = Vec3::newTemp(
x - player->x,
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
z - player->z);
double dist = dir->length();
dir = dir->normalize();
double dot = look->dot(dir);
Vec3 look = player->getViewVector(1).normalize();
Vec3 dir{x - player->x,
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
z - player->z};
double dist = dir.length();
dir = dir.normalize();
double dot = look.dot(dir);
if (dot > 1 - 0.025 / dist) {
return player->canSee(shared_from_this());
}
@ -249,13 +250,13 @@ bool EnderMan::teleport() {
}
bool EnderMan::teleportTowards(std::shared_ptr<Entity> e) {
Vec3* dir = Vec3::newTemp(
x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(), z - e->z);
dir = dir->normalize();
Vec3 dir{x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(),
z - e->z};
dir = dir.normalize();
double d = 16;
double xx = x + (random->nextDouble() - 0.5) * 8 - dir->x * d;
double yy = y + (random->nextInt(16) - 8) - dir->y * d;
double zz = z + (random->nextDouble() - 0.5) * 8 - dir->z * d;
double xx = x + (random->nextDouble() - 0.5) * 8 - dir.x * d;
double yy = y + (random->nextInt(16) - 8) - dir.y * d;
double zz = z + (random->nextDouble() - 0.5) * 8 - dir.z * d;
return teleport(xx, yy, zz);
}
@ -378,4 +379,4 @@ bool EnderMan::isCreepy() { return entityData->getByte(DATA_CREEPY) > 0; }
void EnderMan::setCreepy(bool creepy) {
entityData->set(DATA_CREEPY, (uint8_t)(creepy ? 1 : 0));
}
}

View file

@ -265,4 +265,4 @@ bool ExperienceOrb::shouldRender(Vec3* c) {
if (distance < 4) return false;
return Entity::shouldRender(c);
}
}

View file

@ -166,14 +166,14 @@ void Fireball::tick() {
}
MemSect(41);
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to);
Vec3 from(x, y, z);
Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
from = Vec3(x, y, z);
to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z);
to = Vec3{res->pos.x, res->pos.y, res->pos.z};
}
std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
@ -188,9 +188,9 @@ void Fireball::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) {
hitEntity = e;
nearest = dd;
@ -300,8 +300,8 @@ bool Fireball::hurt(DamageSource* source, float damage) {
markHurt();
if (source->getEntity() != NULL) {
Vec3* lookAngle = source->getEntity()->getLookAngle();
if (lookAngle != NULL) {
auto lookAngle = source->getEntity()->getLookAngle();
if (lookAngle.has_value()) {
xd = lookAngle->x;
yd = lookAngle->y;
zd = lookAngle->z;
@ -309,6 +309,7 @@ bool Fireball::hurt(DamageSource* source, float damage) {
yPower = yd * 0.1;
zPower = zd * 0.1;
}
if (source->getEntity()->instanceof(eTYPE_LIVINGENTITY)) {
owner =
std::dynamic_pointer_cast<LivingEntity>(source->getEntity());
@ -326,4 +327,4 @@ int Fireball::getLightColor(float a) { return 15 << 20 | 15 << 4; }
ePARTICLE_TYPE Fireball::getTrailParticleType() { return eParticleType_smoke; }
bool Fireball::shouldBurn() { return true; }
bool Fireball::shouldBurn() { return true; }

View file

@ -203,14 +203,14 @@ void FishingHook::tick() {
flightTime++;
}
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to);
Vec3 from(x, y, z);
Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
from = Vec3(x, y, z);
to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z);
to = Vec3(res->pos.x, res->pos.y, res->pos.z);
}
std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
@ -223,9 +223,9 @@ void FishingHook::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) {
hitEntity = e;
nearest = dd;
@ -412,4 +412,4 @@ int FishingHook::retrieve() {
void FishingHook::remove() {
Entity::remove();
if (owner != NULL) owner->fishing = nullptr;
}
}

View file

@ -141,10 +141,10 @@ void Ghast::serverAiStep() {
ydd, zdd));
ie->explosionPower = explosionPower;
double d = 4;
Vec3* v = getViewVector(1);
ie->x = x + v->x * d;
Vec3 v = getViewVector(1);
ie->x = x + v.x * d;
ie->y = y + bbHeight / 2 + 0.5f;
ie->z = z + v->z * d;
ie->z = z + v.z * d;
level->addEntity(ie);
charge = -40;
}
@ -217,4 +217,4 @@ void Ghast::readAdditionalSaveData(CompoundTag* tag) {
FlyingMob::readAdditionalSaveData(tag);
if (tag->contains(L"ExplosionPower"))
explosionPower = tag->getInt(L"ExplosionPower");
}
}

View file

@ -13,6 +13,8 @@
#include "../../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Headers/com.mojang.nbt.h"
#include "Minecart.h"
#include <cstddef>
#include <optional>
#include "../../Util/SharedConstants.h"
const int Minecart::EXITS[][2][3] = {
@ -129,10 +131,9 @@ bool Minecart::hurt(DamageSource* source, float hurtDamage) {
if (dynamic_cast<EntityDamageSource*>(source) != NULL) {
std::shared_ptr<Entity> attacker = source->getDirectEntity();
if (attacker->instanceof
(eTYPE_PLAYER) &&
!std::dynamic_pointer_cast<Player>(attacker)
->isAllowedToHurtEntity(shared_from_this())) {
if (attacker->instanceof(eTYPE_PLAYER) &&
!std::dynamic_pointer_cast<Player>(attacker)->isAllowedToHurtEntity(
shared_from_this())) {
return false;
}
}
@ -149,9 +150,9 @@ bool Minecart::hurt(DamageSource* source, float hurtDamage) {
if (rider.lock() != NULL && rider.lock() == source->getEntity())
hurtDamage += 1;
bool creativePlayer =
source->getEntity() != NULL && source->getEntity()->instanceof
(eTYPE_PLAYER) && std::dynamic_pointer_cast<Player>(source->getEntity())
bool creativePlayer = source->getEntity() != NULL &&
source->getEntity()->instanceof(eTYPE_PLAYER) &&
std::dynamic_pointer_cast<Player>(source->getEntity())
->abilities.instabuild;
if (creativePlayer || getDamage() > 20 * 2) {
@ -310,8 +311,8 @@ void Minecart::tick() {
AUTO_VAR(itEnd, entities->end());
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
std::shared_ptr<Entity> e = (*it); // entities->at(i);
if (e != rider.lock() && e->isPushable() && e->instanceof
(eTYPE_MINECART)) {
if (e != rider.lock() && e->isPushable() &&
e->instanceof(eTYPE_MINECART)) {
std::shared_ptr<Minecart> cart =
std::dynamic_pointer_cast<Minecart>(e);
cart->m_bHasPushedCartThisTick = false;
@ -362,7 +363,7 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed,
double slideSpeed, int tile, int data) {
fallDistance = 0;
Vec3* oldPos = getPos(x, y, z);
auto oldPos = getPos(x, y, z);
y = yt;
bool powerTrack = false;
@ -405,7 +406,7 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed,
xd = pow * xD / dd;
zd = pow * zD / dd;
if (rider.lock() != NULL && rider.lock()->instanceof (eTYPE_LIVINGENTITY)) {
if (rider.lock() != NULL && rider.lock()->instanceof(eTYPE_LIVINGENTITY)) {
std::shared_ptr<LivingEntity> living =
std::dynamic_pointer_cast<LivingEntity>(rider.lock());
@ -490,8 +491,8 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed,
applyNaturalSlowdown();
Vec3* newPos = getPos(x, y, z);
if (newPos != NULL && oldPos != NULL) {
auto newPos = getPos(x, y, z);
if (newPos.has_value() && oldPos.has_value()) {
double speed = (oldPos->y - newPos->y) * 0.05;
pow = sqrt(xd * xd + zd * zd);
@ -550,7 +551,8 @@ void Minecart::applyNaturalSlowdown() {
}
}
Vec3* Minecart::getPosOffs(double x, double y, double z, double offs) {
std::optional<Vec3> Minecart::getPosOffs(double x, double y, double z,
double offs) {
int xt = Mth::floor(x);
int yt = Mth::floor(y);
int zt = Mth::floor(z);
@ -595,10 +597,11 @@ Vec3* Minecart::getPosOffs(double x, double y, double z, double offs) {
return getPos(x, y, z);
}
return NULL;
return std::nullopt;
}
Vec3* Minecart::getPos(double x, double y, double z) {
std::optional<Vec3> Minecart::getPos(double x, double y, double z) {
int xt = Mth::floor(x);
int yt = Mth::floor(y);
int zt = Mth::floor(z);
@ -654,9 +657,10 @@ Vec3* Minecart::getPos(double x, double y, double z) {
z = z0 + zD * progress;
if (yD < 0) y += 1;
if (yD > 0) y += 0.5;
return Vec3::newTemp(x, y, z);
return Vec3(x, y, z);
}
return NULL;
return std::nullopt;
}
void Minecart::readAdditionalSaveData(CompoundTag* tag) {
@ -689,10 +693,9 @@ void Minecart::push(std::shared_ptr<Entity> e) {
if (level->isClientSide) return;
if (e == rider.lock()) return;
if (e->instanceof (eTYPE_LIVINGENTITY) && !e->instanceof
(eTYPE_PLAYER) && !e->instanceof
(eTYPE_VILLAGERGOLEM) && (getType() == TYPE_RIDEABLE) &&
(xd * xd + zd * zd > 0.01)) {
if (e->instanceof(eTYPE_LIVINGENTITY) && !e->instanceof(eTYPE_PLAYER) &&
!e->instanceof(eTYPE_VILLAGERGOLEM) && (getType() == TYPE_RIDEABLE) &&
(xd * xd + zd * zd > 0.01)) {
if ((rider.lock() == NULL) && (e->riding == NULL)) {
e->ride(shared_from_this());
}
@ -718,7 +721,7 @@ void Minecart::push(std::shared_ptr<Entity> e) {
xa *= 0.5;
za *= 0.5;
if (e->instanceof (eTYPE_MINECART)) {
if (e->instanceof(eTYPE_MINECART)) {
double xo = e->x - x;
double zo = e->z - z;
@ -726,12 +729,13 @@ void Minecart::push(std::shared_ptr<Entity> e) {
// other
// Fix for #38882 - TU5: Gameplay: Minecart with furnace is not
// able to move another minecart on the rail.
Vec3* dir = Vec3::newTemp(xo, 0, zo)->normalize();
Vec3* facing =
Vec3::newTemp(cos(yRot * PI / 180), 0, sin(yRot * PI / 180))
->normalize();
Vec3 dir(xo, 0, zo);
dir = dir.normalize();
double dot = abs(dir->dot(facing));
Vec3 facing(cos(yRot * PI / 180), 0, sin(yRot * PI / 180));
facing = facing.normalize();
double dot = abs(dir.dot(facing));
if (dot < 0.8f) {
return;

View file

@ -1,4 +1,5 @@
#pragma once
#include <optional>
#include "../Entity.h"
class DamageSource;
@ -77,8 +78,9 @@ protected:
virtual void moveAlongTrack(int xt, int yt, int zt, double maxSpeed,
double slideSpeed, int tile, int data);
virtual void applyNaturalSlowdown();
virtual Vec3* getPosOffs(double x, double y, double z, double offs);
virtual Vec3* getPos(double x, double y, double z);
virtual std::optional<Vec3> getPosOffs(double x, double y, double z,
double offs);
virtual std::optional<Vec3> getPos(double x, double y, double z);
protected:
virtual void addAdditonalSaveData(CompoundTag* base);

View file

@ -305,4 +305,4 @@ void Ocelot::setSittingOnTile(bool val) {
bool Ocelot::isSittingOnTile() {
uint8_t current = entityData->getByte(DATA_FLAGS_ID);
return (current & 0x02) > 0;
}
}

View file

@ -248,4 +248,4 @@ int Slime::getMaxHeadXRot() { return 0; }
bool Slime::doPlayJumpSound() { return getSize() > 0; }
bool Slime::doPlayLandSound() { return getSize() > 2; }
bool Slime::doPlayLandSound() { return getSize() > 2; }

View file

@ -151,4 +151,4 @@ void ThrownPotion::addAdditonalSaveData(CompoundTag* tag) {
if (potionItem != NULL)
tag->putCompound(L"Potion", potionItem->save(new CompoundTag()));
}
}

View file

@ -212,4 +212,4 @@ void Witch::performRangedAttack(std::shared_ptr<LivingEntity> target,
potion->shoot(xd, yd + dist * 0.2f, zd, 0.75f, 8);
level->addEntity(potion);
}
}

View file

@ -506,4 +506,4 @@ bool WitherBoss::isPowered() { return getHealth() <= getMaxHealth() / 2; }
MobType WitherBoss::getMobType() { return UNDEAD; }
void WitherBoss::ride(std::shared_ptr<Entity> e) { riding = nullptr; }
void WitherBoss::ride(std::shared_ptr<Entity> e) { riding = nullptr; }

View file

@ -120,18 +120,20 @@ void PathfinderMob::serverAiStep() {
return;
}
Vec3* target = path->currentPos(shared_from_this());
Vec3 target = path->currentPos(shared_from_this());
double r = bbWidth * 2;
while (target != NULL && target->distanceToSqr(x, target->y, z) < r * r) {
while (target.distanceToSqr(x, target.y, z) < r * r) {
path->next();
if (path->isDone()) {
target = NULL;
setPath(NULL); // 4J - changed to setPath from path =
break;
} else
target = path->currentPos(shared_from_this());
}
jumping = false;
// 4jcraft - refactoring Vec3 shows this branch never hits
/*
if (target != NULL) {
double xd = target->x - x;
double zd = target->z - z;
@ -165,6 +167,7 @@ void PathfinderMob::serverAiStep() {
jumping = true;
}
}
*/
if (attackTarget != NULL) {
lookAt(attackTarget, 30, 30);
@ -328,4 +331,4 @@ void PathfinderMob::onLeashDistance(float distanceToLeashHolder) {}
bool PathfinderMob::couldWander() {
return (noActionTime < SharedConstants::TICKS_PER_SECOND * 5) ||
(isExtraWanderingEnabled());
}
}

View file

@ -135,14 +135,14 @@ void Throwable::tick() {
flightTime++;
}
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to);
Vec3 from(x, y, z);
Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
from = Vec3(x, y, z);
to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z);
to = Vec3(res->pos.x, res->pos.y, res->pos.z);
}
if (!level->isClientSide) {
@ -157,9 +157,9 @@ void Throwable::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
delete p;
if (dd < nearest || nearest == 0) {
hitEntity = e;
@ -256,4 +256,4 @@ std::shared_ptr<LivingEntity> Throwable::getOwner() {
owner = level->getPlayerByName(ownerName);
}
return owner;
}
}

Some files were not shown because too many files have changed in this diff Show more