refactor: remove heap-allocated AABBs

This commit is contained in:
orng 2026-03-28 02:58:56 -05:00
parent e48a05bb8f
commit 7101d03c6a
88 changed files with 353 additions and 387 deletions

View file

@ -1010,7 +1010,7 @@ void ClientConnection::handleMovePlayer(
player->xd = player->yd = player->zd = 0; player->xd = player->yd = player->zd = 0;
player->absMoveTo(x, y, z, yRot, xRot); player->absMoveTo(x, y, z, yRot, xRot);
packet->x = player->x; packet->x = player->x;
packet->y = player->bb->y0; packet->y = player->bb.y0;
packet->z = player->z; packet->z = player->z;
packet->yView = player->y; packet->yView = player->y;
connection->send(packet); connection->send(packet);

View file

@ -272,7 +272,7 @@ void PlayerConnection::handleMovePlayer(
*/ */
float r = 1 / 16.0f; float r = 1 / 16.0f;
AABB shrunk = player->bb->shrink(r, r, r); AABB shrunk = player->bb.shrink(r, r, r);
bool oldOk = bool oldOk =
level->getCubes(player, &shrunk) level->getCubes(player, &shrunk)
->empty(); ->empty();
@ -326,7 +326,7 @@ void PlayerConnection::handleMovePlayer(
player->absMoveTo(xt, yt, zt, yRotT, xRotT); player->absMoveTo(xt, yt, zt, yRotT, xRotT);
// TODO: check if this can be elided // TODO: check if this can be elided
shrunk = player->bb->shrink(r, r, r); shrunk = player->bb.shrink(r, r, r);
bool newOk = bool newOk =
level->getCubes(player, &shrunk) level->getCubes(player, &shrunk)
->empty(); ->empty();
@ -334,7 +334,7 @@ void PlayerConnection::handleMovePlayer(
teleport(xLastOk, yLastOk, zLastOk, yRotT, xRotT); teleport(xLastOk, yLastOk, zLastOk, yRotT, xRotT);
return; return;
} }
AABB testBox = (*player->bb).grow(r, r, r).expand(0, -0.55, 0); AABB testBox = player->bb.grow(r, r, r).expand(0, -0.55, 0);
// && server.level.getCubes(player, testBox).size() == 0 // && server.level.getCubes(player, testBox).size() == 0
if (!server->isFlightAllowed() && !player->gameMode->isCreative() && if (!server->isFlightAllowed() && !player->gameMode->isCreative() &&
!level->containsAnyBlocks(&testBox) && !player->isAllowedToFly()) { !level->containsAnyBlocks(&testBox) && !player->isAllowedToFly()) {

View file

@ -416,7 +416,7 @@ void PlayerList::validatePlayerSpawnPosition(
player->y, player->z, player->dimension); player->y, player->z, player->dimension);
ServerLevel* level = server->getLevel(player->dimension); ServerLevel* level = server->getLevel(player->dimension);
while (level->getCubes(player, player->bb)->size() != 0) { while (level->getCubes(player, &player->bb)->size() != 0) {
player->setPos(player->x, player->y + 1, player->z); player->setPos(player->x, player->y + 1, player->z);
} }
app.DebugPrintf("Final pos is %f, %f, %f in dimension %d\n", player->x, app.DebugPrintf("Final pos is %f, %f, %f in dimension %d\n", player->x,
@ -456,7 +456,7 @@ void PlayerList::validatePlayerSpawnPosition(
} }
delete bedPosition; delete bedPosition;
} }
while (level->getCubes(player, player->bb)->size() != 0) { while (level->getCubes(player, &player->bb)->size() != 0) {
player->setPos(player->x, player->y + 1, player->z); player->setPos(player->x, player->y + 1, player->z);
} }
@ -749,7 +749,7 @@ std::shared_ptr<ServerPlayer> PlayerList::respawn(
// Ensure the area the player is spawning in is loaded! // Ensure the area the player is spawning in is loaded!
level->cache->create(((int)player->x) >> 4, ((int)player->z) >> 4); level->cache->create(((int)player->x) >> 4, ((int)player->z) >> 4);
while (!level->getCubes(player, player->bb)->empty()) { while (!level->getCubes(player, &player->bb)->empty()) {
player->setPos(player->x, player->y + 1, player->z); player->setPos(player->x, player->y + 1, player->z);
} }

View file

@ -8,12 +8,13 @@
#include "ApplySchematicRuleDefinition.h" #include "ApplySchematicRuleDefinition.h"
#include "LevelGenerationOptions.h" #include "LevelGenerationOptions.h"
#include "ConsoleSchematicFile.h" #include "ConsoleSchematicFile.h"
#include "../../Minecraft.World/Util/AABB.h"
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition( ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
LevelGenerationOptions* levelGenOptions) { LevelGenerationOptions* levelGenOptions) {
m_levelGenOptions = levelGenOptions; m_levelGenOptions = levelGenOptions;
m_location = Vec3(0, 0, 0); m_location = Vec3(0, 0, 0);
m_locationBox = NULL; m_locationBox = std::nullopt;
m_totalBlocksChanged = 0; m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0; m_totalBlocksChangedLighting = 0;
m_rotation = ConsoleSchematicFile::eSchematicRot_0; m_rotation = ConsoleSchematicFile::eSchematicRot_0;
@ -130,7 +131,7 @@ void ApplySchematicRuleDefinition::updateLocationBox() {
if (m_schematic == NULL) if (m_schematic == NULL)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
m_locationBox = new AABB(0, 0, 0, 0, 0, 0); m_locationBox = AABB(0, 0, 0, 0, 0, 0);
m_locationBox->x0 = m_location.x; m_locationBox->x0 = m_location.x;
m_locationBox->y0 = m_location.y; m_locationBox->y0 = m_location.y;
@ -162,7 +163,7 @@ void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
if (m_schematic == NULL) if (m_schematic == NULL)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if (m_locationBox == NULL) updateLocationBox(); if (!m_locationBox.has_value()) updateLocationBox();
if (chunkBox->intersects(*m_locationBox)) { if (chunkBox->intersects(*m_locationBox)) {
m_locationBox->y1 = m_locationBox->y1 =
std::min((double)Level::maxBuildHeight, m_locationBox->y1); std::min((double)Level::maxBuildHeight, m_locationBox->y1);
@ -173,12 +174,12 @@ void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
#endif #endif
PIXBeginNamedEvent(0, "Applying blocks and data"); PIXBeginNamedEvent(0, "Applying blocks and data");
m_totalBlocksChanged += m_schematic->applyBlocksAndData( m_totalBlocksChanged += m_schematic->applyBlocksAndData(
chunk, chunkBox, m_locationBox, m_rotation); chunk, chunkBox, &*m_locationBox, m_rotation);
PIXEndNamedEvent(); PIXEndNamedEvent();
// Add the tileEntities // Add the tileEntities
PIXBeginNamedEvent(0, "Applying tile entities"); PIXBeginNamedEvent(0, "Applying tile entities");
m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox, m_schematic->applyTileEntities(chunk, chunkBox, &*m_locationBox,
m_rotation); m_rotation);
PIXEndNamedEvent(); PIXEndNamedEvent();
@ -206,7 +207,7 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
if (m_schematic == NULL) if (m_schematic == NULL)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if (m_locationBox == NULL) updateLocationBox(); if (!m_locationBox.has_value()) updateLocationBox();
if (chunkBox->intersects(*m_locationBox)) { if (chunkBox->intersects(*m_locationBox)) {
m_locationBox->y1 = m_locationBox->y1 =
std::min((double)Level::maxBuildHeight, m_locationBox->y1); std::min((double)Level::maxBuildHeight, m_locationBox->y1);
@ -217,7 +218,7 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
#endif #endif
PIXBeginNamedEvent(0, "Patching lighting"); PIXBeginNamedEvent(0, "Patching lighting");
m_totalBlocksChangedLighting += m_schematic->applyLighting( m_totalBlocksChangedLighting += m_schematic->applyLighting(
chunk, chunkBox, m_locationBox, m_rotation); chunk, chunkBox, &*m_locationBox, m_rotation);
PIXEndNamedEvent(); PIXEndNamedEvent();
// TODO This does not take into account things that go outside the // TODO This does not take into account things that go outside the
@ -237,12 +238,12 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0, bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0,
int x1, int y1, int z1) { int x1, int y1, int z1) {
if (m_locationBox == NULL) updateLocationBox(); if (!m_locationBox.has_value()) updateLocationBox();
return m_locationBox->intersects(x0, y0, z0, x1, y1, z1); return m_locationBox->intersects(x0, y0, z0, x1, y1, z1);
} }
int ApplySchematicRuleDefinition::getMinY() { int ApplySchematicRuleDefinition::getMinY() {
if (m_locationBox == NULL) updateLocationBox(); if (!m_locationBox.has_value()) updateLocationBox();
return m_locationBox->y0; return m_locationBox->y0;
} }

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <optional>
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
#include "ConsoleSchematicFile.h" #include "ConsoleSchematicFile.h"
#include "../../Minecraft.World/Util/AABB.h"
class AABB; class AABB;
class Vec3; class Vec3;
@ -14,7 +16,7 @@ private:
std::wstring m_schematicName; std::wstring m_schematicName;
ConsoleSchematicFile* m_schematic; ConsoleSchematicFile* m_schematic;
Vec3 m_location; Vec3 m_location;
AABB* m_locationBox; std::optional<AABB> m_locationBox;
ConsoleSchematicFile::ESchematicRotation m_rotation; ConsoleSchematicFile::ESchematicRotation m_rotation;
int m_dimension; int m_dimension;

View file

@ -5,11 +5,9 @@
NamedAreaRuleDefinition::NamedAreaRuleDefinition() { NamedAreaRuleDefinition::NamedAreaRuleDefinition() {
m_name = L""; m_name = L"";
m_area = new AABB(0, 0, 0, 0, 0, 0); m_area = AABB(0, 0, 0, 0, 0, 0);
} }
NamedAreaRuleDefinition::~NamedAreaRuleDefinition() { delete m_area; }
void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos, void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos,
unsigned int numAttributes) { unsigned int numAttributes) {
GameRuleDefinition::writeAttributes(dos, numAttributes + 7); GameRuleDefinition::writeAttributes(dos, numAttributes + 7);
@ -18,18 +16,18 @@ void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos,
dos->writeUTF(m_name); dos->writeUTF(m_name);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
dos->writeUTF(_toString(m_area->x0)); dos->writeUTF(_toString(m_area.x0));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0);
dos->writeUTF(_toString(m_area->y0)); dos->writeUTF(_toString(m_area.y0));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0);
dos->writeUTF(_toString(m_area->z0)); dos->writeUTF(_toString(m_area.z0));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1);
dos->writeUTF(_toString(m_area->x1)); dos->writeUTF(_toString(m_area.x1));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1);
dos->writeUTF(_toString(m_area->y1)); dos->writeUTF(_toString(m_area.y1));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1);
dos->writeUTF(_toString(m_area->z1)); dos->writeUTF(_toString(m_area.z1));
} }
void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName, void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName,
@ -41,31 +39,31 @@ void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName,
m_name.c_str()); m_name.c_str());
#endif #endif
} else if (attributeName.compare(L"x0") == 0) { } else if (attributeName.compare(L"x0") == 0) {
m_area->x0 = _fromString<int>(attributeValue); m_area.x0 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n", app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n",
m_area->x0); m_area.x0);
} else if (attributeName.compare(L"y0") == 0) { } else if (attributeName.compare(L"y0") == 0) {
m_area->y0 = _fromString<int>(attributeValue); m_area.y0 = _fromString<int>(attributeValue);
if (m_area->y0 < 0) m_area->y0 = 0; if (m_area.y0 < 0) m_area.y0 = 0;
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n", app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n",
m_area->y0); m_area.y0);
} else if (attributeName.compare(L"z0") == 0) { } else if (attributeName.compare(L"z0") == 0) {
m_area->z0 = _fromString<int>(attributeValue); m_area.z0 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n", app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n",
m_area->z0); m_area.z0);
} else if (attributeName.compare(L"x1") == 0) { } else if (attributeName.compare(L"x1") == 0) {
m_area->x1 = _fromString<int>(attributeValue); m_area.x1 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n", app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n",
m_area->x1); m_area.x1);
} else if (attributeName.compare(L"y1") == 0) { } else if (attributeName.compare(L"y1") == 0) {
m_area->y1 = _fromString<int>(attributeValue); m_area.y1 = _fromString<int>(attributeValue);
if (m_area->y1 < 0) m_area->y1 = 0; if (m_area.y1 < 0) m_area.y1 = 0;
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n", app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n",
m_area->y1); m_area.y1);
} else if (attributeName.compare(L"z1") == 0) { } else if (attributeName.compare(L"z1") == 0) {
m_area->z1 = _fromString<int>(attributeValue); m_area.z1 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n", app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n",
m_area->z1); m_area.z1);
} else { } else {
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }

View file

@ -1,15 +1,15 @@
#pragma once #pragma once
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
#include "../../Minecraft.World/Util/AABB.h"
class NamedAreaRuleDefinition : public GameRuleDefinition { class NamedAreaRuleDefinition : public GameRuleDefinition {
private: private:
std::wstring m_name; std::wstring m_name;
AABB* m_area; AABB m_area;
public: public:
NamedAreaRuleDefinition(); NamedAreaRuleDefinition();
~NamedAreaRuleDefinition();
virtual void writeAttributes(DataOutputStream* dos, virtual void writeAttributes(DataOutputStream* dos,
unsigned int numAttributes); unsigned int numAttributes);
@ -21,6 +21,6 @@ public:
virtual void addAttribute(const std::wstring& attributeName, virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue); const std::wstring& attributeValue);
AABB* getArea() { return m_area; } AABB* getArea() { return &m_area; }
std::wstring getName() { return m_name; } std::wstring getName() { return m_name; }
}; };

View file

@ -10,25 +10,19 @@ AreaConstraint::AreaConstraint(int descriptionId, double x0, double y0,
bool contains /*= true*/, bool contains /*= true*/,
bool restrictsMovement /*=true*/) bool restrictsMovement /*=true*/)
: TutorialConstraint(descriptionId) { : TutorialConstraint(descriptionId) {
messageArea = messageArea = AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2);
new AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2); movementArea = AABB(x0, y0, z0, x1, y1, z1);
movementArea = new AABB(x0, y0, z0, x1, y1, z1);
this->contains = contains; this->contains = contains;
m_restrictsMovement = restrictsMovement; m_restrictsMovement = restrictsMovement;
} }
AreaConstraint::~AreaConstraint() {
delete messageArea;
delete movementArea;
}
bool AreaConstraint::isConstraintSatisfied(int iPad) { bool AreaConstraint::isConstraintSatisfied(int iPad) {
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
// TODO: check if this can be elided // TODO: check if this can be elided
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1); Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
return messageArea->contains(ipad_player) == contains; return messageArea.contains(ipad_player) == contains;
} }
bool AreaConstraint::isConstraintRestrictive(int iPad) { bool AreaConstraint::isConstraintRestrictive(int iPad) {
@ -42,12 +36,12 @@ bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
Vec3 targetPos(xt, yt, zt); Vec3 targetPos(xt, yt, zt);
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
if (movementArea->contains(targetPos) == contains) { if (movementArea.contains(targetPos) == contains) {
return true; return true;
} }
Vec3 origPos(xo, yo, zo); Vec3 origPos(xo, yo, zo);
double currDist = origPos.distanceTo(movementArea); double currDist = origPos.distanceTo(&movementArea);
double targetDist = targetPos.distanceTo(movementArea); double targetDist = targetPos.distanceTo(&movementArea);
return targetDist < currDist; return targetDist < currDist;
} }

View file

@ -6,8 +6,8 @@ class AABB;
class AreaConstraint : public TutorialConstraint { class AreaConstraint : public TutorialConstraint {
private: private:
AABB* movementArea; AABB movementArea;
AABB* messageArea; AABB messageArea;
bool contains; // If true we must stay in this area, if false must stay out bool contains; // If true we must stay in this area, if false must stay out
// of this area // of this area
bool m_restrictsMovement; bool m_restrictsMovement;
@ -18,7 +18,6 @@ public:
AreaConstraint(int descriptionId, double x0, double y0, double z0, AreaConstraint(int descriptionId, double x0, double y0, double z0,
double x1, double y1, double z1, bool contains = true, double x1, double y1, double z1, bool contains = true,
bool restrictsMovement = true); bool restrictsMovement = true);
~AreaConstraint();
virtual bool isConstraintSatisfied(int iPad); virtual bool isConstraintSatisfied(int iPad);
virtual bool isConstraintRestrictive(int iPad); virtual bool isConstraintRestrictive(int iPad);

View file

@ -12,7 +12,7 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial,
double x1, double y1, double z1, bool allowFade /*= false*/, double x1, double y1, double z1, bool allowFade /*= false*/,
bool contains /*= true*/) bool contains /*= true*/)
: TutorialHint(id, tutorial, descriptionId, e_Hint_Area, allowFade) { : TutorialHint(id, tutorial, descriptionId, e_Hint_Area, allowFade) {
area = new AABB(x0, y0, z0, x1, y1, z1); area = AABB(x0, y0, z0, x1, y1, z1);
this->contains = contains; this->contains = contains;
@ -20,15 +20,13 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial,
m_completeState = completeState; m_completeState = completeState;
} }
AreaHint::~AreaHint() { delete area; }
int AreaHint::tick() { int AreaHint::tick() {
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
Vec3 player_pos = minecraft->player->getPos(1); Vec3 player_pos = minecraft->player->getPos(1);
if ((m_displayState == e_Tutorial_State_Any || if ((m_displayState == e_Tutorial_State_Any ||
m_tutorial->getCurrentState() == m_displayState) && m_tutorial->getCurrentState() == m_displayState) &&
m_hintNeeded && area->contains(player_pos) == contains) { m_hintNeeded && area.contains(player_pos) == contains) {
if (m_completeState == e_Tutorial_State_None) { if (m_completeState == e_Tutorial_State_None) {
m_hintNeeded = false; m_hintNeeded = false;
} else if (m_tutorial->isStateCompleted(m_completeState)) { } else if (m_tutorial->isStateCompleted(m_completeState)) {

View file

@ -6,7 +6,7 @@ class AABB;
class AreaHint : public TutorialHint { class AreaHint : public TutorialHint {
private: private:
AABB* area; AABB area;
bool contains; // If true we must stay in this area, if false must stay out bool contains; // If true we must stay in this area, if false must stay out
// of this area // of this area
@ -21,7 +21,6 @@ public:
eTutorial_State displayState, eTutorial_State completeState, eTutorial_State displayState, eTutorial_State completeState,
int descriptionId, double x0, double y0, double z0, double x1, int descriptionId, double x0, double y0, double z0, double x1,
double y1, double z1, bool allowFade = true, bool contains = true); double y1, double z1, bool allowFade = true, bool contains = true);
~AreaHint();
virtual int tick(); virtual int tick();
}; };

View file

@ -16,7 +16,7 @@ ChangeStateConstraint::ChangeStateConstraint(
bool contains /*= true*/, bool changeGameMode /*= false*/, bool contains /*= true*/, bool changeGameMode /*= false*/,
GameType* targetGameMode /*= 0*/) GameType* targetGameMode /*= 0*/)
: TutorialConstraint(-1) { : TutorialConstraint(-1) {
movementArea = new AABB(x0, y0, z0, x1, y1, z1); movementArea = AABB(x0, y0, z0, x1, y1, z1);
this->contains = contains; this->contains = contains;
@ -40,7 +40,6 @@ ChangeStateConstraint::ChangeStateConstraint(
} }
ChangeStateConstraint::~ChangeStateConstraint() { ChangeStateConstraint::~ChangeStateConstraint() {
delete movementArea;
if (m_sourceStatesCount > 0) delete[] m_sourceStates; if (m_sourceStatesCount > 0) delete[] m_sourceStates;
} }
@ -89,7 +88,7 @@ void ChangeStateConstraint::tick(int iPad) {
// TODO: check if this can be elided // TODO: check if this can be elided
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1); Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
if (!m_bHasChanged && inASourceState && if (!m_bHasChanged && inASourceState &&
movementArea->contains(ipad_player) == contains) { movementArea.contains(ipad_player) == contains) {
m_bHasChanged = true; m_bHasChanged = true;
m_changedFromState = m_tutorial->getCurrentState(); m_changedFromState = m_tutorial->getCurrentState();
m_tutorial->changeTutorialState(m_targetState); m_tutorial->changeTutorialState(m_targetState);
@ -127,7 +126,7 @@ void ChangeStateConstraint::tick(int iPad) {
} }
} }
} else if (m_bHasChanged && } else if (m_bHasChanged &&
movementArea->contains(ipad_player) != contains) { movementArea.contains(ipad_player) != contains) {
m_bHasChanged = false; m_bHasChanged = false;
m_tutorial->changeTutorialState(m_changedFromState); m_tutorial->changeTutorialState(m_changedFromState);

View file

@ -11,7 +11,7 @@ class GameType;
class ChangeStateConstraint : public TutorialConstraint { class ChangeStateConstraint : public TutorialConstraint {
private: private:
AABB* movementArea; AABB movementArea;
bool contains; // If true we must stay in this area, if false must stay out bool contains; // If true we must stay in this area, if false must stay out
// of this area // of this area
bool m_changeGameMode; bool m_changeGameMode;

View file

@ -245,10 +245,10 @@ void LocalPlayer::aiStep() {
if (ySlideOffset < 0.2f) ySlideOffset = 0.2f; if (ySlideOffset < 0.2f) ySlideOffset = 0.2f;
} }
checkInTile(x - bbWidth * 0.35, bb->y0 + 0.5, z + bbWidth * 0.35); checkInTile(x - bbWidth * 0.35, bb.y0 + 0.5, z + bbWidth * 0.35);
checkInTile(x - bbWidth * 0.35, bb->y0 + 0.5, z - bbWidth * 0.35); checkInTile(x - bbWidth * 0.35, bb.y0 + 0.5, z - bbWidth * 0.35);
checkInTile(x + bbWidth * 0.35, bb->y0 + 0.5, z - bbWidth * 0.35); checkInTile(x + bbWidth * 0.35, bb.y0 + 0.5, z - bbWidth * 0.35);
checkInTile(x + bbWidth * 0.35, bb->y0 + 0.5, z + bbWidth * 0.35); checkInTile(x + bbWidth * 0.35, bb.y0 + 0.5, z + bbWidth * 0.35);
bool enoughFoodToSprint = bool enoughFoodToSprint =
getFoodData()->getFoodLevel() > getFoodData()->getFoodLevel() >

View file

@ -140,7 +140,7 @@ void MultiplayerLocalPlayer::sendPosition() {
} }
double xdd = x - xLast; double xdd = x - xLast;
double ydd1 = bb->y0 - yLast1; double ydd1 = bb.y0 - yLast1;
double zdd = z - zLast; double zdd = z - zLast;
double rydd = yRot - yRotLast; double rydd = yRot - yRotLast;
@ -158,11 +158,11 @@ void MultiplayerLocalPlayer::sendPosition() {
if (move && rot) { if (move && rot) {
connection->send( connection->send(
std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::PosRot( std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::PosRot(
x, bb->y0, y, z, yRot, xRot, onGround, abilities.flying))); x, bb.y0, y, z, yRot, xRot, onGround, abilities.flying)));
} else if (move) { } else if (move) {
connection->send( connection->send(
std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Pos( std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Pos(
x, bb->y0, y, z, onGround, abilities.flying))); x, bb.y0, y, z, onGround, abilities.flying)));
} else if (rot) { } else if (rot) {
connection->send( connection->send(
std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Rot( std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Rot(
@ -178,7 +178,7 @@ void MultiplayerLocalPlayer::sendPosition() {
if (move) { if (move) {
xLast = x; xLast = x;
yLast1 = bb->y0; yLast1 = bb.y0;
yLast2 = y; yLast2 = y;
zLast = z; zLast = z;
positionReminder = 0; positionReminder = 0;

View file

@ -43,7 +43,8 @@ Chunk::Chunk(Level* level, LevelRenderer::rteMap& globalRenderableTileEntities,
: globalRenderableTileEntities(&globalRenderableTileEntities), : globalRenderableTileEntities(&globalRenderableTileEntities),
globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs) { globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs) {
clipChunk->visible = false; clipChunk->visible = false;
bb = NULL; const double g = 6;
bb = AABB(-g, -g, -g, XZSIZE + g, SIZE + g, XZSIZE + g);
id = 0; id = 0;
this->level = level; this->level = level;
@ -92,21 +93,13 @@ void Chunk::setPos(int x, int y, int z) {
#endif #endif
float g = 6.0f; float g = 6.0f;
// 4J - changed to just set the value rather than make a new one, if we've
// already created storage clipChunk->aabb[0] = bb.x0 + x;
if (bb == NULL) { clipChunk->aabb[1] = bb.y0 + y;
bb = new AABB(-g, -g, -g, XZSIZE + g, SIZE + g, XZSIZE + g); clipChunk->aabb[2] = bb.z0 + z;
} else { clipChunk->aabb[3] = bb.x1 + x;
// 4J MGH - bounds are relative to the position now, so the AABB will be clipChunk->aabb[4] = bb.y1 + y;
// setup already, either above, or from the tesselator bounds. clipChunk->aabb[5] = bb.z1 + z;
// bb->set(-g, -g, -g, SIZE+g, SIZE+g, SIZE+g);
}
clipChunk->aabb[0] = bb->x0 + x;
clipChunk->aabb[1] = bb->y0 + y;
clipChunk->aabb[2] = bb->z0 + z;
clipChunk->aabb[3] = bb->x1 + x;
clipChunk->aabb[4] = bb->y1 + y;
clipChunk->aabb[5] = bb->z1 + z;
assigned = true; assigned = true;
@ -508,11 +501,8 @@ void Chunk::rebuild() {
// 4J MGH - added this to take the bound from the value calc'd in the // 4J MGH - added this to take the bound from the value calc'd in the
// tesselator // tesselator
if (bb) { bb = {bounds.boundingBox[0], bounds.boundingBox[1], bounds.boundingBox[2],
*bb = {bounds.boundingBox[0], bounds.boundingBox[1], bounds.boundingBox[3], bounds.boundingBox[4], bounds.boundingBox[5]};
bounds.boundingBox[2], bounds.boundingBox[3],
bounds.boundingBox[4], bounds.boundingBox[5]};
}
delete tileRenderer; delete tileRenderer;
delete region; delete region;
@ -1033,7 +1023,7 @@ int Chunk::getList(int layer) {
return -1; return -1;
} }
void Chunk::cull(Culler* culler) { clipChunk->visible = culler->isVisible(bb); } void Chunk::cull(Culler* culler) { clipChunk->visible = culler->isVisible(&bb); }
void Chunk::renderBB() { void Chunk::renderBB() {
// glCallList(lists + 2); // 4J - removed - TODO put back in // glCallList(lists + 2); // 4J - removed - TODO put back in
@ -1064,8 +1054,6 @@ void Chunk::clearDirty() {
#endif #endif
} }
Chunk::~Chunk() { delete bb; }
bool Chunk::emptyFlagSet(int layer) { bool Chunk::emptyFlagSet(int layer) {
return levelRenderer->getGlobalChunkFlag( return levelRenderer->getGlobalChunkFlag(
x, y, z, level, LevelRenderer::CHUNK_FLAG_EMPTY0, layer); x, y, z, level, LevelRenderer::CHUNK_FLAG_EMPTY0, layer);

View file

@ -46,7 +46,7 @@ public:
int xRenderOffs, yRenderOffs, zRenderOffs; int xRenderOffs, yRenderOffs, zRenderOffs;
int xm, ym, zm; int xm, ym, zm;
AABB* bb; AABB bb;
ClipChunk* clipChunk; ClipChunk* clipChunk;
int id; int id;
@ -88,5 +88,4 @@ public:
void setDirty(); void setDirty();
void clearDirty(); // 4J added void clearDirty(); // 4J added
bool emptyFlagSet(int layer); bool emptyFlagSet(int layer);
~Chunk();
}; };

View file

@ -91,7 +91,7 @@ void EntityRenderer::renderFlame(std::shared_ptr<Entity> e, double x, double y,
float xo = 0.0f; float xo = 0.0f;
float h = e->bbHeight / s; float h = e->bbHeight / s;
float yo = (float)(e->y - e->bb->y0); float yo = (float)(e->y - e->bb.y0);
glRotatef(-entityRenderDispatcher->playerRotY, 0, 1, 0); glRotatef(-entityRenderDispatcher->playerRotY, 0, 1, 0);

View file

@ -78,7 +78,7 @@ void FireballRenderer::renderFlame(std::shared_ptr<Entity> e, double x,
// float yo = 0.0f; // float yo = 0.0f;
float h = e->bbHeight / s; float h = e->bbHeight / s;
float yo = (float)(e->y - e->bb->y0); float yo = (float)(e->y - e->bb.y0);
// glRotatef(-entityRenderDispatcher->playerRotY, 0, 1, 0); // glRotatef(-entityRenderDispatcher->playerRotY, 0, 1, 0);

View file

@ -310,7 +310,7 @@ void GameRenderer::pick(float a) {
hovered = nullptr; hovered = nullptr;
float overlap = 1; float overlap = 1;
AABB grown = mc->cameraTargetPlayer->bb AABB grown = 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); .grow(overlap, overlap, overlap);
std::vector<std::shared_ptr<Entity> >* objects = std::vector<std::shared_ptr<Entity> >* objects =
@ -323,7 +323,7 @@ void GameRenderer::pick(float a) {
if (!e->isPickable()) continue; if (!e->isPickable()) continue;
float rr = e->getPickRadius(); float rr = e->getPickRadius();
AABB bb = e->bb->grow(rr, rr, rr); AABB bb = e->bb.grow(rr, rr, rr);
HitResult* p = bb.clip(from, to); HitResult* p = bb.clip(from, to);
if (bb.contains(from)) { if (bb.contains(from)) {
if (0 < nearest || nearest == 0) { if (0 < nearest || nearest == 0) {

View file

@ -585,14 +585,14 @@ void LevelRenderer::renderEntities(Vec3* cam, Culler* culler, float a) {
bool shouldRender = bool shouldRender =
(entity->shouldRender(cam) && (entity->shouldRender(cam) &&
(entity->noCulling || culler->isVisible(entity->bb))); (entity->noCulling || culler->isVisible(&entity->bb)));
// Render the mob if the mob's leash holder is within the culler // Render the mob if the mob's leash holder is within the culler
if (!shouldRender && entity->instanceof(eTYPE_MOB)) { if (!shouldRender && entity->instanceof(eTYPE_MOB)) {
std::shared_ptr<Mob> mob = std::dynamic_pointer_cast<Mob>(entity); std::shared_ptr<Mob> mob = std::dynamic_pointer_cast<Mob>(entity);
if (mob->isLeashed() && (mob->getLeashHolder() != NULL)) { if (mob->isLeashed() && (mob->getLeashHolder() != NULL)) {
std::shared_ptr<Entity> leashHolder = mob->getLeashHolder(); std::shared_ptr<Entity> leashHolder = mob->getLeashHolder();
shouldRender = culler->isVisible(leashHolder->bb); shouldRender = culler->isVisible(&leashHolder->bb);
} }
} }

View file

@ -16,14 +16,14 @@ void CritParticle::_init(Level* level, std::shared_ptr<Entity> entity,
} }
CritParticle::CritParticle(Level* level, std::shared_ptr<Entity> entity) CritParticle::CritParticle(Level* level, std::shared_ptr<Entity> entity)
: Particle(level, entity->x, entity->bb->y0 + entity->bbHeight / 2, : Particle(level, entity->x, entity->bb.y0 + entity->bbHeight / 2,
entity->z, entity->xd, entity->yd, entity->zd) { entity->z, entity->xd, entity->yd, entity->zd) {
_init(level, entity, eParticleType_crit); _init(level, entity, eParticleType_crit);
} }
CritParticle::CritParticle(Level* level, std::shared_ptr<Entity> entity, CritParticle::CritParticle(Level* level, std::shared_ptr<Entity> entity,
ePARTICLE_TYPE type) ePARTICLE_TYPE type)
: Particle(level, entity->x, entity->bb->y0 + entity->bbHeight / 2, : Particle(level, entity->x, entity->bb.y0 + entity->bbHeight / 2,
entity->z, entity->xd, entity->yd, entity->zd) { entity->z, entity->xd, entity->yd, entity->zd) {
_init(level, entity, type); _init(level, entity, type);
} }
@ -43,7 +43,7 @@ void CritParticle::tick() {
if (xa * xa + ya * ya + za * za > 1) continue; if (xa * xa + ya * ya + za * za > 1) continue;
double x = entity->x + xa * entity->bbWidth / 4; double x = entity->x + xa * entity->bbWidth / 4;
double y = double y =
entity->bb->y0 + entity->bbHeight / 2 + ya * entity->bbHeight / 4; entity->bb.y0 + entity->bbHeight / 2 + ya * entity->bbHeight / 4;
double z = entity->z + za * entity->bbWidth / 4; double z = entity->z + za * entity->bbWidth / 4;
level->addParticle(particleName, x, y, z, xa, ya + 0.2, za); level->addParticle(particleName, x, y, z, xa, ya + 0.2, za);
} }

View file

@ -52,8 +52,8 @@ void PlayerCloudParticle::tick() {
zd *= 0.96f; zd *= 0.96f;
std::shared_ptr<Player> p = level->getNearestPlayer(shared_from_this(), 2); std::shared_ptr<Player> p = level->getNearestPlayer(shared_from_this(), 2);
if (p != NULL) { if (p != NULL) {
if (y > p->bb->y0) { if (y > p->bb.y0) {
y += (p->bb->y0 - y) * 0.2; y += (p->bb.y0 - y) * 0.2;
yd += (p->yd - yd) * 0.2; yd += (p->yd - yd) * 0.2;
setPos(x, y, z); setPos(x, y, z);
} }

View file

@ -20,7 +20,7 @@ void LookControl::setLookAt(std::shared_ptr<Entity> target, float yMax,
target->y + target->y +
std::dynamic_pointer_cast<LivingEntity>(target)->getHeadHeight(); std::dynamic_pointer_cast<LivingEntity>(target)->getHeadHeight();
else else
wantedY = (target->bb->y0 + target->bb->y1) / 2; wantedY = (target->bb.y0 + target->bb.y1) / 2;
wantedZ = target->z; wantedZ = target->z;
this->yMax = yMax; this->yMax = yMax;
this->xMax = xMax; this->xMax = xMax;

View file

@ -38,7 +38,7 @@ void MoveControl::tick() {
if (!_hasWanted) return; if (!_hasWanted) return;
_hasWanted = false; _hasWanted = false;
int yFloor = floor(mob->bb->y0 + .5f); int yFloor = floor(mob->bb.y0 + .5f);
double xd = wantedX - mob->x; double xd = wantedX - mob->x;
double zd = wantedZ - mob->z; double zd = wantedZ - mob->z;

View file

@ -53,7 +53,7 @@ bool AvoidPlayerGoal::canUse() {
mob->level->getNearestPlayer(mob->shared_from_this(), maxDist)); mob->level->getNearestPlayer(mob->shared_from_this(), maxDist));
if (toAvoid.lock() == NULL) return false; if (toAvoid.lock() == NULL) return false;
} else { } else {
AABB grown_bb = mob->bb->grow(maxDist, 3, maxDist); AABB grown_bb = mob->bb.grow(maxDist, 3, maxDist);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
mob->level->getEntitiesOfClass( mob->level->getEntitiesOfClass(
avoidType, &grown_bb, entitySelector); avoidType, &grown_bb, entitySelector);

View file

@ -48,7 +48,7 @@ void BreedGoal::tick() {
std::shared_ptr<Animal> BreedGoal::getFreePartner() { std::shared_ptr<Animal> BreedGoal::getFreePartner() {
float r = 8; float r = 8;
AABB grown_bb = animal->bb->grow(r, r, r); AABB grown_bb = animal->bb.grow(r, r, r);
std::vector<std::shared_ptr<Entity> >* others = std::vector<std::shared_ptr<Entity> >* others =
level->getEntitiesOfClass(typeid(*animal), &grown_bb); level->getEntitiesOfClass(typeid(*animal), &grown_bb);
double dist = std::numeric_limits<double>::max(); double dist = std::numeric_limits<double>::max();

View file

@ -17,7 +17,7 @@ FleeSunGoal::FleeSunGoal(PathfinderMob* mob, double speedModifier) {
bool FleeSunGoal::canUse() { bool FleeSunGoal::canUse() {
if (!level->isDay()) return false; if (!level->isDay()) return false;
if (!mob->isOnFire()) return false; if (!mob->isOnFire()) return false;
if (!level->canSeeSky(Mth::floor(mob->x), (int)mob->bb->y0, if (!level->canSeeSky(Mth::floor(mob->x), (int)mob->bb.y0,
Mth::floor(mob->z))) Mth::floor(mob->z)))
return false; return false;
@ -39,7 +39,7 @@ std::optional<Vec3> FleeSunGoal::getHidePos() {
Random* random = mob->getRandom(); Random* random = mob->getRandom();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
int xt = Mth::floor(mob->x + random->nextInt(20) - 10); int xt = Mth::floor(mob->x + random->nextInt(20) - 10);
int yt = Mth::floor(mob->bb->y0 + random->nextInt(6) - 3); int yt = Mth::floor(mob->bb.y0 + random->nextInt(6) - 3);
int zt = Mth::floor(mob->z + random->nextInt(20) - 10); int zt = Mth::floor(mob->z + random->nextInt(20) - 10);
if (!level->canSeeSky(xt, yt, zt) && if (!level->canSeeSky(xt, yt, zt) &&
mob->getWalkTargetValue(xt, yt, zt) < 0) mob->getWalkTargetValue(xt, yt, zt) < 0)

View file

@ -69,7 +69,7 @@ void FollowOwnerGoal::tick() {
// find a good spawn position nearby the owner // find a good spawn position nearby the owner
int sx = Mth::floor(owner.lock()->x) - 2; int sx = Mth::floor(owner.lock()->x) - 2;
int sz = Mth::floor(owner.lock()->z) - 2; int sz = Mth::floor(owner.lock()->z) - 2;
int y = Mth::floor(owner.lock()->bb->y0); int y = Mth::floor(owner.lock()->bb.y0);
for (int x = 0; x <= 4; x++) { for (int x = 0; x <= 4; x++) {
for (int z = 0; z <= 4; z++) { for (int z = 0; z <= 4; z++) {
if (x >= 1 && z >= 1 && x <= 3 && z <= 3) { if (x >= 1 && z >= 1 && x <= 3 && z <= 3) {

View file

@ -16,7 +16,7 @@ FollowParentGoal::FollowParentGoal(Animal* animal, double speedModifier) {
bool FollowParentGoal::canUse() { bool FollowParentGoal::canUse() {
if (animal->getAge() >= 0) return false; if (animal->getAge() >= 0) return false;
AABB grown_bb = animal->bb->grow(8, 4, 8); AABB grown_bb = animal->bb.grow(8, 4, 8);
std::vector<std::shared_ptr<Entity> >* parents = std::vector<std::shared_ptr<Entity> >* parents =
animal->level->getEntitiesOfClass(typeid(*animal), &grown_bb); animal->level->getEntitiesOfClass(typeid(*animal), &grown_bb);

View file

@ -37,10 +37,9 @@ bool LookAtPlayerGoal::canUse() {
lookAt = lookAt =
mob->level->getNearestPlayer(mob->shared_from_this(), lookDistance); mob->level->getNearestPlayer(mob->shared_from_this(), lookDistance);
} else { } else {
AABB mob_bb = mob->bb->grow(lookDistance, 3, lookDistance); AABB mob_bb = mob->bb.grow(lookDistance, 3, lookDistance);
lookAt = std::weak_ptr<Entity>(mob->level->getClosestEntityOfClass( lookAt = std::weak_ptr<Entity>(mob->level->getClosestEntityOfClass(
lookAtType, &mob_bb, lookAtType, &mob_bb, mob->shared_from_this()));
mob->shared_from_this()));
} }
return lookAt.lock() != NULL; return lookAt.lock() != NULL;
} }

View file

@ -29,10 +29,9 @@ bool MakeLoveGoal::canUse() {
if (village.lock() == NULL) return false; if (village.lock() == NULL) return false;
if (!villageNeedsMoreVillagers()) return false; if (!villageNeedsMoreVillagers()) return false;
AABB villager_bb = villager->bb->grow(8, 3, 8); AABB villager_bb = villager->bb.grow(8, 3, 8);
std::shared_ptr<Entity> mate = level->getClosestEntityOfClass( std::shared_ptr<Entity> mate = level->getClosestEntityOfClass(
typeid(Villager), &villager_bb, typeid(Villager), &villager_bb, villager->shared_from_this());
villager->shared_from_this());
if (mate == NULL) return false; if (mate == NULL) return false;
partner = partner =

View file

@ -41,7 +41,7 @@ bool MeleeAttackGoal::canUse() {
std::shared_ptr<LivingEntity> target = mob->getTarget(); std::shared_ptr<LivingEntity> target = mob->getTarget();
if (target == NULL) return false; if (target == NULL) return false;
if (!target->isAlive()) return false; if (!target->isAlive()) return false;
if (attackType != eTYPE_NOTSET && !target->instanceof (attackType)) if (attackType != eTYPE_NOTSET && !target->instanceof(attackType))
return false; return false;
path.reset(mob->getNavigation()->createPath(target)); path.reset(mob->getNavigation()->createPath(target));
return path != nullptr; return path != nullptr;
@ -79,7 +79,7 @@ void MeleeAttackGoal::tick() {
double meleeRadiusSqr = double meleeRadiusSqr =
(mob->bbWidth * 2) * (mob->bbWidth * 2) + target->bbWidth; (mob->bbWidth * 2) * (mob->bbWidth * 2) + target->bbWidth;
if (mob->distanceToSqr(target->x, target->bb->y0, target->z) > if (mob->distanceToSqr(target->x, target->bb.y0, target->z) >
meleeRadiusSqr) meleeRadiusSqr)
return; return;
if (attackTime > 0) return; if (attackTime > 0) return;

View file

@ -55,10 +55,9 @@ bool NearestAttackableTargetGoal::canUse() {
return false; return false;
double within = getFollowDistance(); double within = getFollowDistance();
AABB mob_bb = mob->bb->grow(within, 4, within); AABB mob_bb = mob->bb.grow(within, 4, within);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
mob->level->getEntitiesOfClass( mob->level->getEntitiesOfClass(targetType, &mob_bb, selector);
targetType, &mob_bb, selector);
bool result = false; bool result = false;
if (entities != NULL && !entities->empty()) { if (entities != NULL && !entities->empty()) {

View file

@ -40,7 +40,7 @@ void OcelotAttackGoal::tick() {
mob->getLookControl()->setLookAt(target.lock(), 30, 30); mob->getLookControl()->setLookAt(target.lock(), 30, 30);
double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2); double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2);
double distSqr = mob->distanceToSqr(target.lock()->x, target.lock()->bb->y0, double distSqr = mob->distanceToSqr(target.lock()->x, target.lock()->bb.y0,
target.lock()->z); target.lock()->z);
double speedModifier = Ocelot::WALK_SPEED_MOD; double speedModifier = Ocelot::WALK_SPEED_MOD;

View file

@ -15,10 +15,9 @@ OfferFlowerGoal::OfferFlowerGoal(VillagerGolem* golem) {
bool OfferFlowerGoal::canUse() { bool OfferFlowerGoal::canUse() {
if (!golem->level->isDay()) return false; if (!golem->level->isDay()) return false;
if (golem->getRandom()->nextInt(8000) != 0) return false; if (golem->getRandom()->nextInt(8000) != 0) return false;
AABB golem_bb = golem->bb->grow(6, 2, 6); AABB golem_bb = golem->bb.grow(6, 2, 6);
villager = std::weak_ptr<Villager>(std::dynamic_pointer_cast<Villager>( villager = std::weak_ptr<Villager>(std::dynamic_pointer_cast<Villager>(
golem->level->getClosestEntityOfClass(typeid(Villager), golem->level->getClosestEntityOfClass(typeid(Villager), &golem_bb,
&golem_bb,
golem->shared_from_this()))); golem->shared_from_this())));
return villager.lock() != NULL; return villager.lock() != NULL;
} }

View file

@ -23,10 +23,9 @@ bool PlayGoal::canUse() {
if (mob->getAge() >= 0) return false; if (mob->getAge() >= 0) return false;
if (mob->getRandom()->nextInt(400) != 0) return false; if (mob->getRandom()->nextInt(400) != 0) return false;
AABB mob_bb = mob->bb->grow(6, 3, 6); AABB mob_bb = mob->bb.grow(6, 3, 6);
std::vector<std::shared_ptr<Entity> >* children = std::vector<std::shared_ptr<Entity> >* children =
mob->level->getEntitiesOfClass(typeid(Villager), mob->level->getEntitiesOfClass(typeid(Villager), &mob_bb);
&mob_bb);
double closestDistSqr = std::numeric_limits<double>::max(); double closestDistSqr = std::numeric_limits<double>::max();
// for (Entity c : children) // for (Entity c : children)
for (AUTO_VAR(it, children->begin()); it != children->end(); ++it) { for (AUTO_VAR(it, children->begin()); it != children->end(); ++it) {

View file

@ -67,7 +67,7 @@ void RangedAttackGoal::tick() {
if (target.lock() == NULL) return; if (target.lock() == NULL) return;
double targetDistSqr = mob->distanceToSqr( double targetDistSqr = mob->distanceToSqr(
target.lock()->x, target.lock()->bb->y0, target.lock()->z); target.lock()->x, target.lock()->bb.y0, target.lock()->z);
bool canSee = mob->getSensing()->canSee(target.lock()); bool canSee = mob->getSensing()->canSee(target.lock());
if (canSee) { if (canSee) {

View file

@ -22,10 +22,10 @@ bool TakeFlowerGoal::canUse() {
if (villager->getAge() >= 0) return false; if (villager->getAge() >= 0) return false;
if (!villager->level->isDay()) return false; if (!villager->level->isDay()) return false;
AABB villager_bb = villager->bb->grow(6, 2, 6); AABB villager_bb = villager->bb.grow(6, 2, 6);
std::vector<std::shared_ptr<Entity> >* golems = std::vector<std::shared_ptr<Entity> >* golems =
villager->level->getEntitiesOfClass(typeid(VillagerGolem), villager->level->getEntitiesOfClass(typeid(VillagerGolem),
&villager_bb); &villager_bb);
if (golems->size() == 0) { if (golems->size() == 0) {
delete golems; delete golems;
return false; return false;

View file

@ -33,7 +33,7 @@ PathFinder::~PathFinder() {
} }
Path* PathFinder::findPath(Entity* from, Entity* to, float maxDist) { Path* PathFinder::findPath(Entity* from, Entity* to, float maxDist) {
return findPath(from, to->x, to->bb->y0, to->z, maxDist); return findPath(from, to->x, to->bb.y0, to->z, maxDist);
} }
Path* PathFinder::findPath(Entity* from, int x, int y, int z, float maxDist) { Path* PathFinder::findPath(Entity* from, int x, int y, int z, float maxDist) {
@ -46,9 +46,9 @@ Path* PathFinder::findPath(Entity* e, double xt, double yt, double zt,
nodes.clear(); nodes.clear();
bool resetAvoidWater = avoidWater; bool resetAvoidWater = avoidWater;
int startY = Mth::floor(e->bb->y0 + 0.5f); int startY = Mth::floor(e->bb.y0 + 0.5f);
if (canFloat && e->isInWater()) { if (canFloat && e->isInWater()) {
startY = (int)(e->bb->y0); startY = (int)(e->bb.y0);
int tileId = level->getTile((int)Mth::floor(e->x), startY, int tileId = level->getTile((int)Mth::floor(e->x), startY,
(int)Mth::floor(e->z)); (int)Mth::floor(e->z));
while (tileId == Tile::water_Id || tileId == Tile::calmWater_Id) { while (tileId == Tile::water_Id || tileId == Tile::calmWater_Id) {
@ -59,9 +59,9 @@ Path* PathFinder::findPath(Entity* e, double xt, double yt, double zt,
resetAvoidWater = avoidWater; resetAvoidWater = avoidWater;
avoidWater = false; avoidWater = false;
} else } else
startY = Mth::floor(e->bb->y0 + 0.5f); startY = Mth::floor(e->bb.y0 + 0.5f);
Node* from = getNode((int)floor(e->bb->x0), startY, (int)floor(e->bb->z0)); Node* from = getNode((int)floor(e->bb.x0), startY, (int)floor(e->bb.z0));
Node* to = getNode((int)floor(xt - e->bbWidth / 2), (int)floor(yt), Node* to = getNode((int)floor(xt - e->bbWidth / 2), (int)floor(yt),
(int)floor(zt - e->bbWidth / 2)); (int)floor(zt - e->bbWidth / 2));

View file

@ -188,9 +188,9 @@ Vec3 PathNavigation::getTempMobPos() {
} }
int PathNavigation::getSurfaceY() { int PathNavigation::getSurfaceY() {
if (!mob->isInWater() || !canFloat) return (int)(mob->bb->y0 + 0.5); if (!mob->isInWater() || !canFloat) return (int)(mob->bb.y0 + 0.5);
int surface = (int)(mob->bb->y0); int surface = (int)(mob->bb.y0);
int tileId = int tileId =
level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z)); level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z));
int steps = 0; int steps = 0;
@ -198,7 +198,7 @@ int PathNavigation::getSurfaceY() {
++surface; ++surface;
tileId = tileId =
level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z)); level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z));
if (++steps > 16) return (int)(mob->bb->y0); if (++steps > 16) return (int)(mob->bb.y0);
} }
return surface; return surface;
} }
@ -212,7 +212,7 @@ bool PathNavigation::isInLiquid() {
} }
void PathNavigation::trimPathFromSun() { void PathNavigation::trimPathFromSun() {
if (level->canSeeSky(Mth::floor(mob->x), (int)(mob->bb->y0 + 0.5), if (level->canSeeSky(Mth::floor(mob->x), (int)(mob->bb.y0 + 0.5),
Mth::floor(mob->z))) Mth::floor(mob->z)))
return; return;

View file

@ -168,7 +168,7 @@ void FallingTile::causeFallDamage(float distance) {
// entities (invalidating our iterator) // entities (invalidating our iterator)
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
new std::vector<std::shared_ptr<Entity> >( new std::vector<std::shared_ptr<Entity> >(
*level->getEntities(shared_from_this(), bb)); *level->getEntities(shared_from_this(), &bb));
DamageSource* source = tile == Tile::anvil_Id DamageSource* source = tile == Tile::anvil_Id
? DamageSource::anvil ? DamageSource::anvil
: DamageSource::fallingBlock; : DamageSource::fallingBlock;

View file

@ -268,7 +268,7 @@ void Entity::_init(bool useSmallId, Level* level) {
xd = yd = zd = 0.0; xd = yd = zd = 0.0;
yRot = xRot = 0.0f; yRot = xRot = 0.0f;
yRotO = xRotO = 0.0f; yRotO = xRotO = 0.0f;
bb = new AABB(0, 0, 0, 0, 0, 0); // 4J Was final bb = AABB(0, 0, 0, 0, 0, 0); // 4J Was final
onGround = false; onGround = false;
horizontalCollision = verticalCollision = false; horizontalCollision = verticalCollision = false;
collision = false; collision = false;
@ -376,7 +376,6 @@ Entity::Entity(Level* level,
Entity::~Entity() { Entity::~Entity() {
freeSmallId(entityId); freeSmallId(entityId);
delete random; delete random;
delete bb;
} }
std::shared_ptr<SynchedEntityData> Entity::getEntityData() { std::shared_ptr<SynchedEntityData> Entity::getEntityData() {
@ -402,7 +401,7 @@ void Entity::resetPos() {
std::shared_ptr<Entity> sharedThis = shared_from_this(); std::shared_ptr<Entity> sharedThis = shared_from_this();
while (true && y > 0) { while (true && y > 0) {
setPos(x, y, z); setPos(x, y, z);
if (level->getCubes(sharedThis, bb)->empty()) break; if (level->getCubes(sharedThis, &bb)->empty()) break;
y += 1; y += 1;
} }
@ -419,9 +418,9 @@ void Entity::setSize(float w, float h) {
bbWidth = w; bbWidth = w;
bbHeight = h; bbHeight = h;
bb->x1 = bb->x0 + bbWidth; bb.x1 = bb.x0 + bbWidth;
bb->z1 = bb->z0 + bbWidth; bb.z1 = bb.z0 + bbWidth;
bb->y1 = bb->y0 + bbHeight; bb.y1 = bb.y0 + bbHeight;
if (bbWidth > oldW && !firstTick && !level->isClientSide) { if (bbWidth > oldW && !firstTick && !level->isClientSide) {
move(oldW - bbWidth, 0, oldW - bbWidth); move(oldW - bbWidth, 0, oldW - bbWidth);
@ -463,7 +462,7 @@ void Entity::setPos(double x, double y, double z) {
this->z = z; this->z = z;
float w = bbWidth / 2; float w = bbWidth / 2;
float h = bbHeight; float h = bbHeight;
*bb = {x - w, y - heightOffset + ySlideOffset, z - w, x + w, bb = {x - w, y - heightOffset + ySlideOffset, z - w, x + w,
y - heightOffset + ySlideOffset + h, z + w}; y - heightOffset + ySlideOffset + h, z + w};
} }
@ -551,7 +550,7 @@ void Entity::baseTick() {
if (t > 0) { if (t > 0) {
level->addParticle(PARTICLE_TILECRACK(t, d), level->addParticle(PARTICLE_TILECRACK(t, d),
x + (random->nextFloat() - 0.5) * bbWidth, x + (random->nextFloat() - 0.5) * bbWidth,
bb->y0 + 0.1, bb.y0 + 0.1,
z + (random->nextFloat() - 0.5) * bbWidth, z + (random->nextFloat() - 0.5) * bbWidth,
-xd * 4, 1.5, -zd * 4); -xd * 4, 1.5, -zd * 4);
} }
@ -618,7 +617,7 @@ void Entity::clearFire() { onFire = 0; }
void Entity::outOfWorld() { remove(); } void Entity::outOfWorld() { remove(); }
bool Entity::isFree(float xa, float ya, float za, float grow) { bool Entity::isFree(float xa, float ya, float za, float grow) {
AABB box = bb->grow(grow, grow, grow).move(xa, ya, za); AABB box = bb.grow(grow, grow, grow).move(xa, ya, za);
AABBList* aABBs = level->getCubes(shared_from_this(), &box); AABBList* aABBs = level->getCubes(shared_from_this(), &box);
if (!aABBs->empty()) return false; if (!aABBs->empty()) return false;
if (level->containsAnyLiquid(&box)) return false; if (level->containsAnyLiquid(&box)) return false;
@ -626,7 +625,7 @@ bool Entity::isFree(float xa, float ya, float za, float grow) {
} }
bool Entity::isFree(double xa, double ya, double za) { bool Entity::isFree(double xa, double ya, double za) {
AABB box = bb->move(xa, ya, za); AABB box = bb.move(xa, ya, za);
AABBList* aABBs = level->getCubes(shared_from_this(), &box); AABBList* aABBs = level->getCubes(shared_from_this(), &box);
if (!aABBs->empty()) return false; if (!aABBs->empty()) return false;
if (level->containsAnyLiquid(&box)) return false; if (level->containsAnyLiquid(&box)) return false;
@ -637,10 +636,10 @@ void Entity::move(double xa, double ya, double za,
bool noEntityCubes) // 4J - added noEntityCubes parameter bool noEntityCubes) // 4J - added noEntityCubes parameter
{ {
if (noPhysics) { if (noPhysics) {
*bb = bb->move(xa, ya, za); bb = bb.move(xa, ya, za);
x = (bb->x0 + bb->x1) / 2.0f; x = (bb.x0 + bb.x1) / 2.0f;
y = bb->y0 + heightOffset - ySlideOffset; y = bb.y0 + heightOffset - ySlideOffset;
z = (bb->z0 + bb->z1) / 2.0f; z = (bb.z0 + bb.z1) / 2.0f;
return; return;
} }
@ -665,15 +664,13 @@ void Entity::move(double xa, double ya, double za,
double yaOrg = ya; double yaOrg = ya;
double zaOrg = za; double zaOrg = za;
AABB bbOrg = *bb;
bool isPlayerSneaking = bool isPlayerSneaking =
onGround && isSneaking() && instanceof(eTYPE_PLAYER); onGround && isSneaking() && instanceof(eTYPE_PLAYER);
if (isPlayerSneaking) { if (isPlayerSneaking) {
double d = 0.05; double d = 0.05;
AABB translated_bb = bb->move(xa, -1.0, 0.0); AABB translated_bb = bb.move(xa, -1.0, 0.0);
while (xa != 0 && while (xa != 0 &&
level->getCubes(shared_from_this(), &translated_bb)->empty()) { level->getCubes(shared_from_this(), &translated_bb)->empty()) {
if (xa < d && xa >= -d) if (xa < d && xa >= -d)
@ -685,7 +682,7 @@ void Entity::move(double xa, double ya, double za,
xaOrg = xa; xaOrg = xa;
} }
translated_bb = bb->move(0, -1.0, za); translated_bb = bb.move(0, -1.0, za);
while (za != 0 && while (za != 0 &&
level->getCubes(shared_from_this(), &translated_bb)->empty()) { level->getCubes(shared_from_this(), &translated_bb)->empty()) {
if (za < d && za >= -d) if (za < d && za >= -d)
@ -697,7 +694,7 @@ void Entity::move(double xa, double ya, double za,
zaOrg = za; zaOrg = za;
} }
translated_bb = bb->move(xa, -1.0, za); translated_bb = bb.move(xa, -1.0, za);
while (xa != 0 && za != 0 && while (xa != 0 && za != 0 &&
level->getCubes(shared_from_this(), &translated_bb)->empty()) { level->getCubes(shared_from_this(), &translated_bb)->empty()) {
if (xa < d && xa >= -d) if (xa < d && xa >= -d)
@ -717,7 +714,7 @@ void Entity::move(double xa, double ya, double za,
} }
} }
AABB expanded = bb->expand(xa, ya, za); AABB expanded = bb.expand(xa, ya, za);
AABBList* aABBs = AABBList* aABBs =
level->getCubes(shared_from_this(), &expanded, noEntityCubes, true); level->getCubes(shared_from_this(), &expanded, noEntityCubes, true);
@ -733,8 +730,8 @@ void Entity::move(double xa, double ya, double za,
// But if we don't have the chunk data then all the collision info will // But if we don't have the chunk data then all the collision info will
// be incorrect as well // be incorrect as well
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
ya = it->clipYCollide(*bb, ya); ya = it->clipYCollide(bb, ya);
*bb = bb->move(0, ya, 0); bb = bb.move(0, ya, 0);
} }
if (!slide && yaOrg != ya) { if (!slide && yaOrg != ya) {
@ -745,9 +742,9 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end(); itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
xa = it->clipXCollide(*bb, xa); xa = it->clipXCollide(bb, xa);
*bb = bb->move(xa, 0, 0); bb = bb.move(xa, 0, 0);
if (!slide && xaOrg != xa) { if (!slide && xaOrg != xa) {
xa = ya = za = 0; xa = ya = za = 0;
@ -755,8 +752,8 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end(); itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
za = it->clipZCollide(*bb, za); za = it->clipZCollide(bb, za);
*bb = bb->move(0, 0, za); bb = bb.move(0, 0, za);
if (!slide && zaOrg != za) { if (!slide && zaOrg != za) {
xa = ya = za = 0; xa = ya = za = 0;
@ -772,13 +769,11 @@ void Entity::move(double xa, double ya, double za,
ya = footSize; ya = footSize;
za = zaOrg; za = zaOrg;
AABB normal = *bb;
*bb = bbOrg;
// 4J - added extra expand, as if we don't move up by footSize by // 4J - added extra expand, as if we don't move up by footSize by
// hitting a block above us, then overall we could be trying to move as // hitting a block above us, then overall we could be trying to move as
// much as footSize downwards, so we'd better include cubes under our // much as footSize downwards, so we'd better include cubes under our
// feet in this list of things we might possibly collide with // feet in this list of things we might possibly collide with
AABB expanded = bb->expand(xa, ya, za).expand(0, -ya, 0); AABB expanded = bb.expand(xa, ya, za).expand(0, -ya, 0);
aABBs = level->getCubes(shared_from_this(), &expanded, false, true); aABBs = level->getCubes(shared_from_this(), &expanded, false, true);
// LAND FIRST, then x and z // LAND FIRST, then x and z
@ -789,8 +784,8 @@ void Entity::move(double xa, double ya, double za,
// all! But if we don't have the chunk data then all the collision // all! But if we don't have the chunk data then all the collision
// info will be incorrect as well // info will be incorrect as well
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
ya = it->clipYCollide(*bb, ya); ya = it->clipYCollide(bb, ya);
*bb = bb->move(0, ya, 0); bb = bb.move(0, ya, 0);
} }
if (!slide && yaOrg != ya) { if (!slide && yaOrg != ya) {
@ -799,8 +794,8 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end(); itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
xa = it->clipXCollide(*bb, xa); xa = it->clipXCollide(bb, xa);
*bb = bb->move(xa, 0, 0); bb = bb.move(xa, 0, 0);
if (!slide && xaOrg != xa) { if (!slide && xaOrg != xa) {
xa = ya = za = 0; xa = ya = za = 0;
@ -808,8 +803,8 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end(); itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
za = it->clipZCollide(*bb, za); za = it->clipZCollide(bb, za);
*bb = bb->move(0, 0, za); bb = bb.move(0, 0, za);
if (!slide && zaOrg != za) { if (!slide && zaOrg != za) {
xa = ya = za = 0; xa = ya = za = 0;
@ -822,21 +817,20 @@ void Entity::move(double xa, double ya, double za,
// LAND FIRST, then x and z // LAND FIRST, then x and z
itEndAABB = aABBs->end(); itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
ya = it->clipYCollide(*bb, ya); ya = it->clipYCollide(bb, ya);
*bb = bb->move(0, ya, 0); bb = bb.move(0, ya, 0);
} }
if (xaN * xaN + zaN * zaN >= xa * xa + za * za) { if (xaN * xaN + zaN * zaN >= xa * xa + za * za) {
xa = xaN; xa = xaN;
ya = yaN; ya = yaN;
za = zaN; za = zaN;
*bb = normal;
} }
} }
x = (bb->x0 + bb->x1) / 2.0f; x = (bb.x0 + bb.x1) / 2.0f;
y = bb->y0 + heightOffset - ySlideOffset; y = bb.y0 + heightOffset - ySlideOffset;
z = (bb->z0 + bb->z1) / 2.0f; z = (bb.z0 + bb.z1) / 2.0f;
horizontalCollision = (xaOrg != xa) || (zaOrg != za); horizontalCollision = (xaOrg != xa) || (zaOrg != za);
verticalCollision = !m_ignoreVerticalCollisions && (yaOrg != ya); verticalCollision = !m_ignoreVerticalCollisions && (yaOrg != ya);
@ -891,8 +885,8 @@ void Entity::move(double xa, double ya, double za,
checkInsideTiles(); checkInsideTiles();
bool water = isInWaterOrRain(); bool water = isInWaterOrRain();
const AABB& shrunk = bb->shrink(0.001, 0.001, 0.001); const AABB& shrunk = bb.shrink(0.001, 0.001, 0.001);
if (level->containsFireTile(bb)) { if (level->containsFireTile(&bb)) {
burn(1); burn(1);
if (!water) { if (!water) {
onFire++; onFire++;
@ -912,12 +906,12 @@ void Entity::move(double xa, double ya, double za,
} }
void Entity::checkInsideTiles() { void Entity::checkInsideTiles() {
int x0 = Mth::floor(bb->x0 + 0.001); int x0 = Mth::floor(bb.x0 + 0.001);
int y0 = Mth::floor(bb->y0 + 0.001); int y0 = Mth::floor(bb.y0 + 0.001);
int z0 = Mth::floor(bb->z0 + 0.001); int z0 = Mth::floor(bb.z0 + 0.001);
int x1 = Mth::floor(bb->x1 - 0.001); int x1 = Mth::floor(bb.x1 - 0.001);
int y1 = Mth::floor(bb->y1 - 0.001); int y1 = Mth::floor(bb.y1 - 0.001);
int z1 = Mth::floor(bb->z1 - 0.001); int z1 = Mth::floor(bb.z1 - 0.001);
if (level->hasChunksAt(x0, y0, z0, x1, y1, z1)) { if (level->hasChunksAt(x0, y0, z0, x1, y1, z1)) {
for (int x = x0; x <= x1; x++) for (int x = x0; x <= x1; x++)
@ -1000,7 +994,7 @@ bool Entity::isInWaterOrRain() {
bool Entity::isInWater() { return wasInWater; } bool Entity::isInWater() { return wasInWater; }
bool Entity::updateInWaterState() { bool Entity::updateInWaterState() {
AABB shrunk = bb->grow(0, -0.4, 0).shrink(0.001, 0.001, 0.001); AABB shrunk = bb.grow(0, -0.4, 0).shrink(0.001, 0.001, 0.001);
if (level->checkAndHandleWater(&shrunk, Material::water, if (level->checkAndHandleWater(&shrunk, Material::water,
shared_from_this())) { shared_from_this())) {
if (!wasInWater && !firstTick && canCreateParticles()) { if (!wasInWater && !firstTick && canCreateParticles()) {
@ -1011,7 +1005,7 @@ bool Entity::updateInWaterState() {
playSound(eSoundType_RANDOM_SPLASH, speed, playSound(eSoundType_RANDOM_SPLASH, speed,
1 + (random->nextFloat() - random->nextFloat()) * 0.4f); 1 + (random->nextFloat() - random->nextFloat()) * 0.4f);
MemSect(0); MemSect(0);
float yt = (float)Mth::floor(bb->y0); float yt = (float)Mth::floor(bb.y0);
for (int i = 0; i < 1 + bbWidth * 20; i++) { for (int i = 0; i < 1 + bbWidth * 20; i++) {
float xo = (random->nextFloat() * 2 - 1) * bbWidth; float xo = (random->nextFloat() * 2 - 1) * bbWidth;
float zo = (random->nextFloat() * 2 - 1) * bbWidth; float zo = (random->nextFloat() * 2 - 1) * bbWidth;
@ -1052,7 +1046,7 @@ bool Entity::isUnderLiquid(Material* material) {
float Entity::getHeadHeight() { return 0; } float Entity::getHeadHeight() { return 0; }
bool Entity::isInLava() { bool Entity::isInLava() {
AABB mat_bounds = bb->grow(-0.1, -0.4, -0.1); AABB mat_bounds = bb.grow(-0.1, -0.4, -0.1);
return level->containsMaterial(&mat_bounds, Material::lava); return level->containsMaterial(&mat_bounds, Material::lava);
} }
@ -1079,7 +1073,7 @@ int Entity::getLightColor(float a) {
int zTile = Mth::floor(z); int zTile = Mth::floor(z);
if (level->hasChunkAt(xTile, 0, zTile)) { if (level->hasChunkAt(xTile, 0, zTile)) {
double hh = (bb->y1 - bb->y0) * 0.66; double hh = (bb.y1 - bb.y0) * 0.66;
int yTile = Mth::floor(y - heightOffset + hh); int yTile = Mth::floor(y - heightOffset + hh);
return level->getLightColor(xTile, yTile, zTile, 0); return level->getLightColor(xTile, yTile, zTile, 0);
} }
@ -1091,7 +1085,7 @@ float Entity::getBrightness(float a) {
int xTile = Mth::floor(x); int xTile = Mth::floor(x);
int zTile = Mth::floor(z); int zTile = Mth::floor(z);
if (level->hasChunkAt(xTile, 0, zTile)) { if (level->hasChunkAt(xTile, 0, zTile)) {
double hh = (bb->y1 - bb->y0) * 0.66; double hh = (bb.y1 - bb.y0) * 0.66;
int yTile = Mth::floor(y - heightOffset + hh); int yTile = Mth::floor(y - heightOffset + hh);
return level->getBrightness(xTile, yTile, zTile); return level->getBrightness(xTile, yTile, zTile);
} }
@ -1200,7 +1194,7 @@ bool Entity::hurt(DamageSource* source, float damage) {
bool Entity::intersects(double x0, double y0, double z0, double x1, double y1, bool Entity::intersects(double x0, double y0, double z0, double x1, double y1,
double z1) { double z1) {
return bb->intersects(x0, y0, z0, x1, y1, z1); return bb.intersects(x0, y0, z0, x1, y1, z1);
} }
bool Entity::isPickable() { return false; } bool Entity::isPickable() { return false; }
@ -1220,7 +1214,7 @@ bool Entity::shouldRender(Vec3* c) {
} }
bool Entity::shouldRenderAtSqrDistance(double distance) { bool Entity::shouldRenderAtSqrDistance(double distance) {
double size = bb->getSize(); double size = bb.getSize();
size *= 64.0f * viewScale; size *= 64.0f * viewScale;
return distance < size * size; return distance < size * size;
} }
@ -1497,7 +1491,7 @@ void Entity::ride(std::shared_ptr<Entity> e) {
// 4J Stu - Position should already be updated before the // 4J Stu - Position should already be updated before the
// SetEntityLinkPacket comes in // SetEntityLinkPacket comes in
if (!level->isClientSide) if (!level->isClientSide)
moveTo(riding->x, riding->bb->y0 + riding->bbHeight, riding->z, moveTo(riding->x, riding->bb.y0 + riding->bbHeight, riding->z,
yRot, xRot); yRot, xRot);
riding->rider = std::weak_ptr<Entity>(); riding->rider = std::weak_ptr<Entity>();
} }
@ -1520,7 +1514,7 @@ void Entity::lerpTo(double x, double y, double z, float yRot, float xRot,
// its definitely bad news for arrows as they are actually Meant to // its definitely bad news for arrows as they are actually Meant to
// intersect the geometry they land in slightly. // intersect the geometry they land in slightly.
if (GetType() != eTYPE_ARROW) { if (GetType() != eTYPE_ARROW) {
AABB shrunk = bb->shrink(1 / 32.0, 0.0, 1 / 32.0); AABB shrunk = bb.shrink(1 / 32.0, 0.0, 1 / 32.0);
AABBList* collisions = level->getCubes(shared_from_this(), &shrunk); AABBList* collisions = level->getCubes(shared_from_this(), &shrunk);
if (!collisions->empty()) { if (!collisions->empty()) {
double yTop = 0; double yTop = 0;
@ -1529,7 +1523,7 @@ void Entity::lerpTo(double x, double y, double z, float yRot, float xRot,
if (it->y1 > yTop) yTop = it->y1; if (it->y1 > yTop) yTop = it->y1;
} }
y += yTop - bb->y0; y += yTop - bb.y0;
setPos(x, y, z); setPos(x, y, z);
} }
} }
@ -1667,7 +1661,7 @@ bool Entity::checkInTile(double x, double y, double z) {
double yd = y - (yTile); double yd = y - (yTile);
double zd = z - (zTile); double zd = z - (zTile);
auto* cubes = level->getTileCubes(bb); auto* cubes = level->getTileCubes(&bb);
if ((cubes && !cubes->empty()) || if ((cubes && !cubes->empty()) ||
level->isFullAABBTile(xTile, yTile, zTile)) { level->isFullAABBTile(xTile, yTile, zTile)) {
bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile); bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile);

View file

@ -5,6 +5,7 @@
#include "../IO/NBT/FloatTag.h" #include "../IO/NBT/FloatTag.h"
#include "../Util/Vec3.h" #include "../Util/Vec3.h"
#include "../Util/Definitions.h" #include "../Util/Definitions.h"
#include "../Util/AABB.h"
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
@ -72,7 +73,7 @@ public:
double xd, yd, zd; double xd, yd, zd;
float yRot, xRot; float yRot, xRot;
float yRotO, xRotO; float yRotO, xRotO;
/*const*/ AABB* bb; // 4J Was final /*const*/ AABB bb; // 4J Was final
bool onGround; bool onGround;
bool horizontalCollision, verticalCollision; bool horizontalCollision, verticalCollision;
bool collision; bool collision;

View file

@ -34,7 +34,7 @@ void FlyingMob::travel(float xa, float ya) {
float friction = 0.91f; float friction = 0.91f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.91f; friction = 0.6f * 0.91f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1,
Mth::floor(z)); Mth::floor(z));
if (t > 0) { if (t > 0) {
friction = Tile::tiles[t]->friction * 0.91f; friction = Tile::tiles[t]->friction * 0.91f;
@ -48,7 +48,7 @@ void FlyingMob::travel(float xa, float ya) {
friction = 0.91f; friction = 0.91f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.91f; friction = 0.6f * 0.91f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1,
Mth::floor(z)); Mth::floor(z));
if (t > 0) { if (t > 0) {
friction = Tile::tiles[t]->friction * 0.91f; friction = Tile::tiles[t]->friction * 0.91f;

View file

@ -74,8 +74,8 @@ void HangingEntity::setDir(int dir) {
float y1 = y + h + ss; float y1 = y + h + ss;
float z0 = z - d - ss; float z0 = z - d - ss;
float z1 = z + d + ss; float z1 = z + d + ss;
*bb = {std::min(x0, x1), std::min(y0, y1), std::min(z0, z1), bb = {std::min(x0, x1), std::min(y0, y1), std::min(z0, z1),
std::max(x0, x1), std::max(y0, y1), std::max(z0, z1)}; std::max(x0, x1), std::max(y0, y1), std::max(z0, z1)};
} }
float HangingEntity::offs(int w) { float HangingEntity::offs(int w) {
@ -98,7 +98,7 @@ void HangingEntity::tick() {
} }
bool HangingEntity::survives() { bool HangingEntity::survives() {
if (level->getCubes(shared_from_this(), bb)->size() != 0) // isEmpty()) if (level->getCubes(shared_from_this(), &bb)->size() != 0) // isEmpty())
{ {
return false; return false;
} else { } else {
@ -128,7 +128,7 @@ bool HangingEntity::survives() {
} }
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
level->getEntities(shared_from_this(), bb); level->getEntities(shared_from_this(), &bb);
if (entities != NULL && entities->size() > 0) { if (entities != NULL && entities->size() > 0) {
AUTO_VAR(itEnd, entities->end()); AUTO_VAR(itEnd, entities->end());

View file

@ -68,7 +68,7 @@ void ItemEntity::tick() {
zo = z; zo = z;
yd -= 0.04f; yd -= 0.04f;
noPhysics = checkInTile(x, (bb->y0 + bb->y1) / 2, z); noPhysics = checkInTile(x, (bb.y0 + bb.y1) / 2, z);
// 4J - added parameter here so that these don't care about colliding with // 4J - added parameter here so that these don't care about colliding with
// other entities // other entities
@ -96,7 +96,7 @@ void ItemEntity::tick() {
float friction = 0.98f; float friction = 0.98f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.98f; friction = 0.6f * 0.98f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1,
Mth::floor(z)); Mth::floor(z));
if (t > 0) { if (t > 0) {
friction = Tile::tiles[t]->friction * 0.98f; friction = Tile::tiles[t]->friction * 0.98f;
@ -119,7 +119,7 @@ void ItemEntity::tick() {
} }
void ItemEntity::mergeWithNeighbours() { void ItemEntity::mergeWithNeighbours() {
AABB grown = bb->grow(0.5, 0, 0.5); AABB grown = bb.grow(0.5, 0, 0.5);
std::vector<std::shared_ptr<Entity> >* neighbours = std::vector<std::shared_ptr<Entity> >* neighbours =
level->getEntitiesOfClass(typeid(*this), &grown); level->getEntitiesOfClass(typeid(*this), &grown);
for (AUTO_VAR(it, neighbours->begin()); it != neighbours->end(); ++it) { for (AUTO_VAR(it, neighbours->begin()); it != neighbours->end(); ++it) {
@ -164,7 +164,7 @@ void ItemEntity::setShortLifeTime() {
} }
bool ItemEntity::updateInWaterState() { bool ItemEntity::updateInWaterState() {
return level->checkAndHandleWater(bb, Material::water, shared_from_this()); return level->checkAndHandleWater(&bb, Material::water, shared_from_this());
} }
void ItemEntity::burn(int dmg) { hurt(DamageSource::inFire, dmg); } void ItemEntity::burn(int dmg) { hurt(DamageSource::inFire, dmg); }

View file

@ -897,7 +897,7 @@ void LivingEntity::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) {
bool LivingEntity::onLadder() { bool LivingEntity::onLadder() {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
int zt = Mth::floor(z); int zt = Mth::floor(z);
// 4J-PB - TU9 - add climbable vines // 4J-PB - TU9 - add climbable vines
@ -1166,7 +1166,7 @@ void LivingEntity::teleportTo(double x, double y, double z) {
void LivingEntity::findStandUpPosition(std::shared_ptr<Entity> vehicle) { void LivingEntity::findStandUpPosition(std::shared_ptr<Entity> vehicle) {
AABB boundingBox; AABB boundingBox;
double fallbackX = vehicle->x; double fallbackX = vehicle->x;
double fallbackY = vehicle->bb->y0 + vehicle->bbHeight; double fallbackY = vehicle->bb.y0 + vehicle->bbHeight;
double fallbackZ = vehicle->z; double fallbackZ = vehicle->z;
for (double xDiff = -1.5; xDiff < 2; xDiff += 1.5) { for (double xDiff = -1.5; xDiff < 2; xDiff += 1.5) {
@ -1177,7 +1177,7 @@ void LivingEntity::findStandUpPosition(std::shared_ptr<Entity> vehicle) {
int xToInt = (int)(x + xDiff); int xToInt = (int)(x + xDiff);
int zToInt = (int)(z + zDiff); int zToInt = (int)(z + zDiff);
boundingBox = bb->move(xDiff, 1, zDiff); boundingBox = bb.move(xDiff, 1, zDiff);
if (level->getTileCubes(&boundingBox, true)->empty()) { if (level->getTileCubes(&boundingBox, true)->empty()) {
if (level->isTopSolidBlocking(xToInt, (int)y, zToInt)) { if (level->isTopSolidBlocking(xToInt, (int)y, zToInt)) {
@ -1259,7 +1259,7 @@ void LivingEntity::travel(float xa, float ya) {
float friction = 0.91f; float friction = 0.91f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.91f; friction = 0.6f * 0.91f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1,
Mth::floor(z)); Mth::floor(z));
if (t > 0) { if (t > 0) {
friction = Tile::tiles[t]->friction * 0.91f; friction = Tile::tiles[t]->friction * 0.91f;
@ -1281,7 +1281,7 @@ void LivingEntity::travel(float xa, float ya) {
friction = 0.91f; friction = 0.91f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.91f; friction = 0.6f * 0.91f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1,
Mth::floor(z)); Mth::floor(z));
if (t > 0) { if (t > 0) {
friction = Tile::tiles[t]->friction * 0.91f; friction = Tile::tiles[t]->friction * 0.91f;
@ -1337,13 +1337,13 @@ void LivingEntity::travel(float xa, float ya) {
// and out of lit areas, for example when bobbing in the water. // and out of lit areas, for example when bobbing in the water.
int LivingEntity::getLightColor(float a) { int LivingEntity::getLightColor(float a) {
float accum[2] = {0, 0}; float accum[2] = {0, 0};
float totVol = (bb->x1 - bb->x0) * (bb->y1 - bb->y0) * (bb->z1 - bb->z0); float totVol = (bb.x1 - bb.x0) * (bb.y1 - bb.y0) * (bb.z1 - bb.z0);
int xmin = Mth::floor(bb->x0); int xmin = Mth::floor(bb.x0);
int xmax = Mth::floor(bb->x1); int xmax = Mth::floor(bb.x1);
int ymin = Mth::floor(bb->y0); int ymin = Mth::floor(bb.y0);
int ymax = Mth::floor(bb->y1); int ymax = Mth::floor(bb.y1);
int zmin = Mth::floor(bb->z0); int zmin = Mth::floor(bb.z0);
int zmax = Mth::floor(bb->z1); int zmax = Mth::floor(bb.z1);
for (int xt = xmin; xt <= xmax; xt++) for (int xt = xmin; xt <= xmax; xt++)
for (int yt = ymin; yt <= ymax; yt++) for (int yt = ymin; yt <= ymax; yt++)
for (int zt = zmin; zt <= zmax; zt++) { for (int zt = zmin; zt <= zmax; zt++) {
@ -1353,12 +1353,12 @@ int LivingEntity::getLightColor(float a) {
float tileymax = (float)(yt + 1); float tileymax = (float)(yt + 1);
float tilezmin = (float)zt; float tilezmin = (float)zt;
float tilezmax = (float)(zt + 1); float tilezmax = (float)(zt + 1);
if (tilexmin < bb->x0) tilexmin = bb->x0; if (tilexmin < bb.x0) tilexmin = bb.x0;
if (tilexmax > bb->x1) tilexmax = bb->x1; if (tilexmax > bb.x1) tilexmax = bb.x1;
if (tileymin < bb->y0) tileymin = bb->y0; if (tileymin < bb.y0) tileymin = bb.y0;
if (tileymax > bb->y1) tileymax = bb->y1; if (tileymax > bb.y1) tileymax = bb.y1;
if (tilezmin < bb->z0) tilezmin = bb->z0; if (tilezmin < bb.z0) tilezmin = bb.z0;
if (tilezmax > bb->z1) tilezmax = bb->z1; if (tilezmax > bb.z1) tilezmax = bb.z1;
float tileVol = (tilexmax - tilexmin) * (tileymax - tileymin) * float tileVol = (tilexmax - tilexmin) * (tileymax - tileymin) *
(tilezmax - tilezmin); (tilezmax - tilezmin);
float frac = tileVol / totVol; float frac = tileVol / totVol;
@ -1508,10 +1508,10 @@ void LivingEntity::aiStep() {
// 4J - this collision is carried out to try and stop the lerping push // 4J - this collision is carried out to try and stop the lerping push
// the mob through the floor, in which case gravity can then carry on // the mob through the floor, in which case gravity can then carry on
// moving the mob because the collision just won't work anymore. BB for // moving the mob because the collision just won't work anymore. BB for
// collision used to be calculated as: bb->shrink(1 / 32.0, 0, 1 / 32.0) // collision used to be calculated as: bb.shrink(1 / 32.0, 0, 1 / 32.0)
// now using a reduced BB to try and get rid of some issues where mobs // now using a reduced BB to try and get rid of some issues where mobs
// pop up the sides of walls, undersides of trees etc. // pop up the sides of walls, undersides of trees etc.
AABB shrinkbb = bb->shrink(0.1, 0, 0.1); AABB shrinkbb = bb.shrink(0.1, 0, 0.1);
shrinkbb.y1 = shrinkbb.y0 + 0.1; shrinkbb.y1 = shrinkbb.y0 + 0.1;
AABBList* collisions = level->getCubes(shared_from_this(), &shrinkbb); AABBList* collisions = level->getCubes(shared_from_this(), &shrinkbb);
if (collisions->size() > 0) { if (collisions->size() > 0) {
@ -1521,7 +1521,7 @@ void LivingEntity::aiStep() {
if (it->y1 > yTop) yTop = it->y1; if (it->y1 > yTop) yTop = it->y1;
} }
yt += yTop - bb->y0; yt += yTop - bb.y0;
setPos(xt, yt, zt); setPos(xt, yt, zt);
} }
} else if (!isEffectiveAi()) { } else if (!isEffectiveAi()) {
@ -1581,7 +1581,7 @@ void LivingEntity::aiStep() {
void LivingEntity::newServerAiStep() {} void LivingEntity::newServerAiStep() {}
void LivingEntity::pushEntities() { void LivingEntity::pushEntities() {
AABB grown = bb->grow(0.2, 0, 0.2); AABB grown = bb.grow(0.2, 0, 0.2);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
if (entities != NULL && !entities->empty()) { if (entities != NULL && !entities->empty()) {

View file

@ -85,7 +85,7 @@ void MinecartHopper::tick() {
bool MinecartHopper::suckInItems() { bool MinecartHopper::suckInItems() {
if (HopperTileEntity::suckInItems(this)) return true; if (HopperTileEntity::suckInItems(this)) return true;
AABB grown = bb->grow(0.25, 0, 0.25); AABB grown = bb.grow(0.25, 0, 0.25);
std::vector<std::shared_ptr<Entity> >* items = std::vector<std::shared_ptr<Entity> >* items =
level->getEntitiesOfClass(typeid(ItemEntity), &grown, level->getEntitiesOfClass(typeid(ItemEntity), &grown,
EntitySelector::ENTITY_STILL_ALIVE); EntitySelector::ENTITY_STILL_ALIVE);

View file

@ -301,7 +301,7 @@ void Mob::aiStep() {
if (!level->isClientSide && canPickUpLoot() && !dead && if (!level->isClientSide && canPickUpLoot() && !dead &&
level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) { level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) {
AABB grown = bb->grow(1, 0, 1); AABB grown = bb.grow(1, 0, 1);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
level->getEntitiesOfClass(typeid(ItemEntity), &grown); level->getEntitiesOfClass(typeid(ItemEntity), &grown);
for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) {
@ -499,7 +499,7 @@ void Mob::lookAt(std::shared_ptr<Entity> e, float yMax, float xMax) {
std::dynamic_pointer_cast<LivingEntity>(e); std::dynamic_pointer_cast<LivingEntity>(e);
yd = (mob->y + mob->getHeadHeight()) - (y + getHeadHeight()); yd = (mob->y + mob->getHeadHeight()) - (y + getHeadHeight());
} else { } else {
yd = (e->bb->y0 + e->bb->y1) / 2 - (y + getHeadHeight()); yd = (e->bb.y0 + e->bb.y1) / 2 - (y + getHeadHeight());
} }
double sd = Mth::sqrt(xd * xd + zd * zd); double sd = Mth::sqrt(xd * xd + zd * zd);
@ -527,9 +527,9 @@ float Mob::rotlerp(float a, float b, float max) {
bool Mob::canSpawn() { bool Mob::canSpawn() {
// 4J - altered to use special containsAnyLiquid variant // 4J - altered to use special containsAnyLiquid variant
return level->isUnobstructed(bb) && return level->isUnobstructed(&bb) &&
level->getCubes(shared_from_this(), bb)->empty() && level->getCubes(shared_from_this(), &bb)->empty() &&
!level->containsAnyLiquid_NoLoad(bb); !level->containsAnyLiquid_NoLoad(&bb);
} }
float Mob::getSizeScale() { return 1.0f; } float Mob::getSizeScale() { return 1.0f; }
@ -848,7 +848,7 @@ void Mob::restoreLeashFromSave() {
if (_isLeashed && leashInfoTag != NULL) { if (_isLeashed && leashInfoTag != NULL) {
if (leashInfoTag->contains(L"UUID")) { if (leashInfoTag->contains(L"UUID")) {
std::wstring leashUuid = leashInfoTag->getString(L"UUID"); std::wstring leashUuid = leashInfoTag->getString(L"UUID");
AABB grown = bb->grow(10, 10, 10); AABB grown = bb.grow(10, 10, 10);
std::vector<std::shared_ptr<Entity> >* livingEnts = std::vector<std::shared_ptr<Entity> >* livingEnts =
level->getEntitiesOfClass(typeid(LivingEntity), level->getEntitiesOfClass(typeid(LivingEntity),
&grown); &grown);
@ -889,9 +889,9 @@ void Mob::restoreLeashFromSave() {
// resolve bug 10327 :Gameplay: NPCs can spawn over chunks that have not yet // resolve bug 10327 :Gameplay: NPCs can spawn over chunks that have not yet
// been streamed and display jitter. // been streamed and display jitter.
bool Mob::shouldRender(Vec3* c) { bool Mob::shouldRender(Vec3* c) {
if (!level->reallyHasChunksAt(Mth::floor(bb->x0), Mth::floor(bb->y0), if (!level->reallyHasChunksAt(Mth::floor(bb.x0), Mth::floor(bb.y0),
Mth::floor(bb->z0), Mth::floor(bb->x1), Mth::floor(bb.z0), Mth::floor(bb.x1),
Mth::floor(bb->y1), Mth::floor(bb->z1))) { Mth::floor(bb.y1), Mth::floor(bb.z1))) {
return false; return false;
} }
return Entity::shouldRender(c); return Entity::shouldRender(c);

View file

@ -216,7 +216,7 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
float r = 8; float r = 8;
if (getInLoveValue() > 0) { if (getInLoveValue() > 0) {
AABB grown = bb->grow(r, r, r); AABB grown = bb.grow(r, r, r);
std::vector<std::shared_ptr<Entity> >* others = std::vector<std::shared_ptr<Entity> >* others =
level->getEntitiesOfClass(typeid(*this), &grown); level->getEntitiesOfClass(typeid(*this), &grown);
// for (int i = 0; i < others->size(); i++) // for (int i = 0; i < others->size(); i++)
@ -230,7 +230,7 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
delete others; delete others;
} else { } else {
if (getAge() == 0) { if (getAge() == 0) {
AABB grown = bb->grow(r, r, r); AABB grown = bb.grow(r, r, r);
std::vector<std::shared_ptr<Entity> >* players = std::vector<std::shared_ptr<Entity> >* players =
level->getEntitiesOfClass(typeid(Player), &grown); level->getEntitiesOfClass(typeid(Player), &grown);
// for (int i = 0; i < players.size(); i++) // for (int i = 0; i < players.size(); i++)
@ -247,7 +247,7 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
} }
delete players; delete players;
} else if (getAge() > 0) { } else if (getAge() > 0) {
AABB grown = bb->grow(r, r, r); AABB grown = bb.grow(r, r, r);
std::vector<std::shared_ptr<Entity> >* others = std::vector<std::shared_ptr<Entity> >* others =
level->getEntitiesOfClass(typeid(*this), &grown); level->getEntitiesOfClass(typeid(*this), &grown);
// for (int i = 0; i < others.size(); i++) // for (int i = 0; i < others.size(); i++)
@ -267,7 +267,7 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
bool Animal::canSpawn() { bool Animal::canSpawn() {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
int zt = Mth::floor(z); int zt = Mth::floor(z);
return level->getTile(xt, yt - 1, zt) == Tile::grass_Id && return level->getTile(xt, yt - 1, zt) == Tile::grass_Id &&
level->getDaytimeRawBrightness(xt, yt, zt) > 8 && level->getDaytimeRawBrightness(xt, yt, zt) > 8 &&

View file

@ -230,7 +230,7 @@ void Arrow::tick() {
} }
std::shared_ptr<Entity> hitEntity = nullptr; std::shared_ptr<Entity> hitEntity = nullptr;
AABB grown = bb->expand(xd, yd, zd).grow(1, 1, 1); AABB grown = bb.expand(xd, yd, zd).grow(1, 1, 1);
std::vector<std::shared_ptr<Entity> >* objects = std::vector<std::shared_ptr<Entity> >* objects =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
double nearest = 0; double nearest = 0;
@ -240,7 +240,7 @@ void Arrow::tick() {
if (!e->isPickable() || (e == owner && flightTime < 5)) continue; if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
float rr = 0.3f; float rr = 0.3f;
AABB bb = e->bb->grow(rr, rr, rr); AABB bb = e->bb.grow(rr, rr, rr);
HitResult* p = bb.clip(from, to); HitResult* p = bb.clip(from, to);
if (p != NULL) { if (p != NULL) {
double dd = from.distanceTo(p->pos); double dd = from.distanceTo(p->pos);

View file

@ -185,7 +185,7 @@ void Bat::addAdditonalSaveData(CompoundTag* entityTag) {
} }
bool Bat::canSpawn() { bool Bat::canSpawn() {
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
if (yt >= level->seaLevel) return false; if (yt >= level->seaLevel) return false;
int xt = Mth::floor(x); int xt = Mth::floor(x);

View file

@ -93,14 +93,14 @@ void Blaze::aiStep() {
} }
void Blaze::checkHurtTarget(std::shared_ptr<Entity> target, float d) { void Blaze::checkHurtTarget(std::shared_ptr<Entity> target, float d) {
if (attackTime <= 0 && d < 2.0f && target->bb->y1 > bb->y0 && if (attackTime <= 0 && d < 2.0f && target->bb.y1 > bb.y0 &&
target->bb->y0 < bb->y1) { target->bb.y0 < bb.y1) {
attackTime = 20; attackTime = 20;
doHurtTarget(target); doHurtTarget(target);
} else if (d < 30) { } else if (d < 30) {
double xd = target->x - x; double xd = target->x - x;
double yd = double yd =
(target->bb->y0 + target->bbHeight / 2) - (y + bbHeight / 2); (target->bb.y0 + target->bbHeight / 2) - (y + bbHeight / 2);
double zd = target->z - z; double zd = target->z - z;
if (attackTime == 0) { if (attackTime == 0) {

View file

@ -44,10 +44,10 @@ void Boat::defineSynchedData() {
} }
AABB* Boat::getCollideAgainstBox(std::shared_ptr<Entity> entity) { AABB* Boat::getCollideAgainstBox(std::shared_ptr<Entity> entity) {
return entity->bb; return &entity->bb;
} }
AABB* Boat::getCollideBox() { return bb; } AABB* Boat::getCollideBox() { return &bb; }
bool Boat::isPushable() { return true; } bool Boat::isPushable() { return true; }
@ -165,9 +165,9 @@ void Boat::tick() {
int steps = 5; int steps = 5;
double waterPercentage = 0; double waterPercentage = 0;
for (int i = 0; i < steps; i++) { for (int i = 0; i < steps; i++) {
double y0 = bb->y0 + (bb->y1 - bb->y0) * (i + 0) / steps - 2 / 16.0f; double y0 = bb.y0 + (bb.y1 - bb.y0) * (i + 0) / steps - 2 / 16.0f;
double y1 = bb->y0 + (bb->y1 - bb->y0) * (i + 1) / steps - 2 / 16.0f; double y1 = bb.y0 + (bb.y1 - bb.y0) * (i + 1) / steps - 2 / 16.0f;
AABB bb2(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); AABB bb2(bb.x0, y0, bb.z0, bb.x1, y1, bb.z1);
if (level->containsLiquid(&bb2, Material::water)) { if (level->containsLiquid(&bb2, Material::water)) {
waterPercentage += 1.0 / steps; waterPercentage += 1.0 / steps;
} }
@ -345,7 +345,7 @@ void Boat::tick() {
if (level->isClientSide) return; if (level->isClientSide) return;
AABB grown = bb->grow(0.2, 0, 0.2); AABB grown = bb.grow(0.2, 0, 0.2);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
if (entities != NULL && !entities->empty()) { if (entities != NULL && !entities->empty()) {

View file

@ -29,7 +29,7 @@ DragonFireball::DragonFireball(Level* level, double x, double y, double z,
void DragonFireball::onHit(HitResult* res) { void DragonFireball::onHit(HitResult* res) {
if (!level->isClientSide) { if (!level->isClientSide) {
AABB aoe = bb->grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE); AABB aoe = bb.grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE);
std::vector<std::shared_ptr<Entity> >* entitiesOfClass = std::vector<std::shared_ptr<Entity> >* entitiesOfClass =
level->getEntitiesOfClass(typeid(LivingEntity), &aoe); level->getEntitiesOfClass(typeid(LivingEntity), &aoe);

View file

@ -73,7 +73,7 @@ void EnderDragon::_init() {
m_actionTicks = 0; m_actionTicks = 0;
m_sittingDamageReceived = 0; m_sittingDamageReceived = 0;
m_headYRot = 0.0; m_headYRot = 0.0;
m_acidArea = new AABB(-4, -10, -3, 6, 3, 3); m_acidArea = AABB(-4, -10, -3, 6, 3, 3);
m_flameAttacks = 0; m_flameAttacks = 0;
for (int i = 0; i < positionsLength; i++) { for (int i = 0; i < positionsLength; i++) {
@ -324,7 +324,7 @@ void EnderDragon::aiStep() {
{ {
xP = head->x; // - vN->x * d; xP = head->x; // - vN->x * d;
yP = yP =
head->bb->y0 + head->bb.y0 +
head->bbHeight / head->bbHeight /
2; // - vN->y * d; //head->y + 2; // - vN->y * d; //head->y +
// head->bbHeight / 2 + 0.5f - v->y * d; // head->bbHeight / 2 + 0.5f - v->y * d;
@ -346,7 +346,7 @@ void EnderDragon::aiStep() {
for (unsigned int j = 0; j < 6; ++j) { for (unsigned int j = 0; j < 6; ++j) {
xP = head->x; // - vN->x * d; xP = head->x; // - vN->x * d;
yP = yP =
head->bb->y0 + head->bb.y0 +
head->bbHeight / head->bbHeight /
2; // - vN->y * d; //head->y + 2; // - vN->y * d; //head->y +
// head->bbHeight / 2 + 0.5f - v->y * d; // head->bbHeight / 2 + 0.5f - v->y * d;
@ -462,7 +462,7 @@ void EnderDragon::aiStep() {
getSynchedAction() == e_EnderdragonAction_Landing) { getSynchedAction() == e_EnderdragonAction_Landing) {
if (m_actionTicks < (FLAME_TICKS - 10)) { if (m_actionTicks < (FLAME_TICKS - 10)) {
std::vector<std::shared_ptr<Entity> >* targets = std::vector<std::shared_ptr<Entity> >* targets =
level->getEntities(shared_from_this(), m_acidArea); level->getEntities(shared_from_this(), &m_acidArea);
for (AUTO_VAR(it, targets->begin()); it != targets->end(); for (AUTO_VAR(it, targets->begin()); it != targets->end();
++it) { ++it) {
@ -491,7 +491,7 @@ void EnderDragon::aiStep() {
if (angleDegs < 0 || angleDegs > 10) { if (angleDegs < 0 || angleDegs > 10) {
double xdd = attackTarget->x - head->x; double xdd = attackTarget->x - head->x;
// double ydd = (attackTarget->bb->y0 + // double ydd = (attackTarget->bb.y0 +
// attackTarget->bbHeight / 2) - (head->y + head->bbHeight / // attackTarget->bbHeight / 2) - (head->y + head->bbHeight /
// 2); // 2);
double zdd = attackTarget->z - head->z; double zdd = attackTarget->z - head->z;
@ -541,7 +541,7 @@ void EnderDragon::aiStep() {
double sd = sqrt(xd * xd + zd * zd); double sd = sqrt(xd * xd + zd * zd);
double ho = 0.4f + sd / 80.0f - 1; double ho = 0.4f + sd / 80.0f - 1;
if (ho > 10) ho = 10; if (ho > 10) ho = 10;
yTarget = attackTarget->bb->y0 + ho; yTarget = attackTarget->bb.y0 + ho;
} else { } else {
// xTarget += random->nextGaussian() * 2; // xTarget += random->nextGaussian() * 2;
// zTarget += random->nextGaussian() * 2; // zTarget += random->nextGaussian() * 2;
@ -646,13 +646,13 @@ void EnderDragon::aiStep() {
if (!level->isClientSide) checkAttack(); if (!level->isClientSide) checkAttack();
if (!level->isClientSide && hurtDuration == 0) { if (!level->isClientSide && hurtDuration == 0) {
AABB wing_mov = wing1->bb->grow(4, 2, 4).move(0, -2, 0); AABB wing_mov = wing1->bb.grow(4, 2, 4).move(0, -2, 0);
knockBack(level->getEntities(shared_from_this(), &wing_mov)); knockBack(level->getEntities(shared_from_this(), &wing_mov));
wing_mov = wing2->bb->grow(4, 2, 4).move(0, -2, 0); wing_mov = wing2->bb.grow(4, 2, 4).move(0, -2, 0);
knockBack(level->getEntities(shared_from_this(), &wing_mov)); knockBack(level->getEntities(shared_from_this(), &wing_mov));
AABB neck_bb = neck->bb->grow(1, 1, 1); AABB neck_bb = neck->bb.grow(1, 1, 1);
AABB head_bb = head->bb->grow(1, 1, 1); AABB head_bb = head->bb.grow(1, 1, 1);
hurt(level->getEntities(shared_from_this(), &neck_bb)); hurt(level->getEntities(shared_from_this(), &neck_bb));
hurt(level->getEntities(shared_from_this(), &head_bb)); hurt(level->getEntities(shared_from_this(), &head_bb));
} }
@ -687,19 +687,19 @@ void EnderDragon::aiStep() {
double acidX = x + ss * 9.5f * ccTilt; double acidX = x + ss * 9.5f * ccTilt;
double acidY = y + yOffset + ssTilt * 10.5f; double acidY = y + yOffset + ssTilt * 10.5f;
double acidZ = z - cc * 9.5f * ccTilt; double acidZ = z - cc * 9.5f * ccTilt;
*m_acidArea = {acidX - 5, acidY - 17, acidZ - 5, m_acidArea = {acidX - 5, acidY - 17, acidZ - 5,
acidX + 5, acidY + 4, acidZ + 5}; acidX + 5, acidY + 4, acidZ + 5};
// app.DebugPrintf("\nDragon is %s, yRot = %f, yRotA = %f, ss = %f, cc = // app.DebugPrintf("\nDragon is %s, yRot = %f, yRotA = %f, ss = %f, cc =
// %f, ccTilt = %f\n",level->isClientSide?"client":"server", yRot, // %f, ccTilt = %f\n",level->isClientSide?"client":"server", yRot,
// yRotA, ss, cc, ccTilt); app.DebugPrintf("Body (%f,%f,%f) to // yRotA, ss, cc, ccTilt); app.DebugPrintf("Body (%f,%f,%f) to
// (%f,%f,%f)\n", body->bb->x0, body->bb->y0, body->bb->z0, // (%f,%f,%f)\n", body->bb.x0, body->bb.y0, body->bb.z0,
// body->bb->x1, body->bb->y1, body->bb->z1); app.DebugPrintf("Neck // body->bb.x1, body->bb.y1, body->bb.z1); app.DebugPrintf("Neck
// (%f,%f,%f) to (%f,%f,%f)\n", neck->bb->x0, neck->bb->y0, // (%f,%f,%f) to (%f,%f,%f)\n", neck->bb.x0, neck->bb.y0,
// neck->bb->z0, neck->bb->x1, neck->bb->y1, neck->bb->z1); // neck->bb.z0, neck->bb.x1, neck->bb.y1, neck->bb.z1);
// app.DebugPrintf("Head (%f,%f,%f) to (%f,%f,%f)\n", head->bb->x0, // app.DebugPrintf("Head (%f,%f,%f) to (%f,%f,%f)\n", head->bb.x0,
// head->bb->y0, head->bb->z0, head->bb->x1, head->bb->y1, // head->bb.y0, head->bb.z0, head->bb.x1, head->bb.y1,
// head->bb->z1); app.DebugPrintf("Acid (%f,%f,%f) to (%f,%f,%f)\n\n", // head->bb.z1); app.DebugPrintf("Acid (%f,%f,%f) to (%f,%f,%f)\n\n",
// m_acidArea->x0, m_acidArea->y0, m_acidArea->z0, m_acidArea->x1, // m_acidArea->x0, m_acidArea->y0, m_acidArea->z0, m_acidArea->x1,
// m_acidArea->y1, m_acidArea->z1); // m_acidArea->y1, m_acidArea->z1);
} }
@ -757,7 +757,7 @@ void EnderDragon::aiStep() {
double xdd = attackTarget->x - startingX; double xdd = attackTarget->x - startingX;
double ydd = double ydd =
(attackTarget->bb->y0 + attackTarget->bbHeight / 2) - (attackTarget->bb.y0 + attackTarget->bbHeight / 2) -
(startingY + head->bbHeight / 2); (startingY + head->bbHeight / 2);
double zdd = attackTarget->z - startingZ; double zdd = attackTarget->z - startingZ;
@ -795,7 +795,7 @@ void EnderDragon::aiStep() {
if (!level->isClientSide) { if (!level->isClientSide) {
inWall = inWall =
checkWalls(head->bb) | checkWalls(neck->bb) | checkWalls(body->bb); checkWalls(&head->bb) | checkWalls(&neck->bb) | checkWalls(&body->bb);
} }
} }
@ -814,7 +814,7 @@ void EnderDragon::checkCrystals() {
if (random->nextInt(10) == 0) { if (random->nextInt(10) == 0) {
float maxDist = 32; float maxDist = 32;
AABB grown = bb->grow(maxDist, maxDist, maxDist); AABB grown = bb.grow(maxDist, maxDist, maxDist);
std::vector<std::shared_ptr<Entity> >* crystals = std::vector<std::shared_ptr<Entity> >* crystals =
level->getEntitiesOfClass(typeid(EnderCrystal), &grown); level->getEntitiesOfClass(typeid(EnderCrystal), &grown);
@ -851,9 +851,9 @@ void EnderDragon::checkAttack() {
} }
void EnderDragon::knockBack(std::vector<std::shared_ptr<Entity> >* entities) { void EnderDragon::knockBack(std::vector<std::shared_ptr<Entity> >* entities) {
double xm = (body->bb->x0 + body->bb->x1) / 2; double xm = (body->bb.x0 + body->bb.x1) / 2;
// double ym = (body.bb.y0 + body.bb.y1) / 2; // double ym = (body.bb.y0 + body.bb.y1) / 2;
double zm = (body->bb->z0 + body->bb->z1) / 2; double zm = (body->bb.z0 + body->bb.z1) / 2;
// for (Entity e : entities) // for (Entity e : entities)
for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) {
@ -1475,7 +1475,7 @@ void EnderDragon::strafeAttackTarget() {
double sd = sqrt(xd * xd + zd * zd); double sd = sqrt(xd * xd + zd * zd);
double ho = 0.4f + sd / 80.0f - 1; double ho = 0.4f + sd / 80.0f - 1;
if (ho > 10) ho = 10; if (ho > 10) ho = 10;
int finalYTarget = attackTarget->bb->y0 + ho; int finalYTarget = attackTarget->bb.y0 + ho;
Node finalNode(finalXTarget, finalYTarget, finalZTarget); Node finalNode(finalXTarget, finalYTarget, finalZTarget);

View file

@ -59,7 +59,7 @@ private:
int m_iGrowlTimer; int m_iGrowlTimer;
double m_headYRot; double m_headYRot;
AABB* m_acidArea; AABB m_acidArea;
NodeArray* m_nodes; NodeArray* m_nodes;
int m_nodeAdjacency[24]; int m_nodeAdjacency[24];

View file

@ -117,7 +117,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
Vec3 look = player->getViewVector(1).normalize(); Vec3 look = player->getViewVector(1).normalize();
Vec3 dir{x - player->x, Vec3 dir{x - player->x,
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), (bb.y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
z - player->z}; z - player->z};
double dist = dir.length(); double dist = dir.length();
@ -250,7 +250,7 @@ bool EnderMan::teleport() {
} }
bool EnderMan::teleportTowards(std::shared_ptr<Entity> e) { bool EnderMan::teleportTowards(std::shared_ptr<Entity> e) {
Vec3 dir{x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(), Vec3 dir{x - e->x, bb.y0 + bbHeight / 2 - e->y + e->getHeadHeight(),
z - e->z}; z - e->z};
dir = dir.normalize(); dir = dir.normalize();
double d = 16; double d = 16;
@ -286,8 +286,8 @@ bool EnderMan::teleport(double xx, double yy, double zz) {
} }
if (landed) { if (landed) {
setPos(x, y, z); setPos(x, y, z);
if (level->getCubes(shared_from_this(), bb)->empty() && if (level->getCubes(shared_from_this(), &bb)->empty() &&
!level->containsAnyLiquid(bb)) { !level->containsAnyLiquid(&bb)) {
ok = true; ok = true;
} }
} }

View file

@ -420,7 +420,7 @@ std::shared_ptr<EntityHorse> EntityHorse::getClosestMommy(
double closestDistance = std::numeric_limits<double>::max(); double closestDistance = std::numeric_limits<double>::max();
std::shared_ptr<Entity> mommy = nullptr; std::shared_ptr<Entity> mommy = nullptr;
AABB expanded = baby->bb->expand(searchRadius, searchRadius, searchRadius); AABB expanded = baby->bb.expand(searchRadius, searchRadius, searchRadius);
std::vector<std::shared_ptr<Entity> >* list = std::vector<std::shared_ptr<Entity> >* list =
level->getEntities(baby, &expanded, PARENT_HORSE_SELECTOR); level->getEntities(baby, &expanded, PARENT_HORSE_SELECTOR);

View file

@ -84,7 +84,7 @@ void ExperienceOrb::tick() {
playSound(eSoundType_RANDOM_FIZZ, 0.4f, playSound(eSoundType_RANDOM_FIZZ, 0.4f,
2.0f + random->nextFloat() * 0.4f); 2.0f + random->nextFloat() * 0.4f);
} }
checkInTile(x, (bb->y0 + bb->y1) / 2, z); checkInTile(x, (bb.y0 + bb.y1) / 2, z);
double maxDist = 8; double maxDist = 8;
// 4J - PC Comment // 4J - PC Comment
@ -121,7 +121,7 @@ void ExperienceOrb::tick() {
float friction = 0.98f; float friction = 0.98f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.98f; friction = 0.6f * 0.98f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1,
Mth::floor(z)); Mth::floor(z));
if (t > 0) { if (t > 0) {
friction = Tile::tiles[t]->friction * 0.98f; friction = Tile::tiles[t]->friction * 0.98f;
@ -145,7 +145,7 @@ void ExperienceOrb::tick() {
} }
bool ExperienceOrb::updateInWaterState() { bool ExperienceOrb::updateInWaterState() {
return level->checkAndHandleWater(bb, Material::water, shared_from_this()); return level->checkAndHandleWater(&bb, Material::water, shared_from_this());
} }
void ExperienceOrb::burn(int dmg) { hurt(DamageSource::inFire, dmg); } void ExperienceOrb::burn(int dmg) { hurt(DamageSource::inFire, dmg); }

View file

@ -28,7 +28,7 @@ EyeOfEnderSignal::EyeOfEnderSignal(Level* level) : Entity(level) {
void EyeOfEnderSignal::defineSynchedData() {} void EyeOfEnderSignal::defineSynchedData() {}
bool EyeOfEnderSignal::shouldRenderAtSqrDistance(double distance) { bool EyeOfEnderSignal::shouldRenderAtSqrDistance(double distance) {
double size = bb->getSize() * 4; double size = bb.getSize() * 4;
size *= 64.0f; size *= 64.0f;
return distance < size * size; return distance < size * size;
} }

View file

@ -39,7 +39,7 @@ Fireball::Fireball(Level* level) : Entity(level) {
void Fireball::defineSynchedData() {} void Fireball::defineSynchedData() {}
bool Fireball::shouldRenderAtSqrDistance(double distance) { bool Fireball::shouldRenderAtSqrDistance(double distance) {
double size = bb->getSize() * 4; double size = bb.getSize() * 4;
size *= 64.0f; size *= 64.0f;
return distance < size * size; return distance < size * size;
} }
@ -176,7 +176,7 @@ void Fireball::tick() {
to = Vec3{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::shared_ptr<Entity> hitEntity = nullptr;
AABB grown = bb->expand(xd, yd, zd).grow(1, 1, 1); AABB grown = bb.expand(xd, yd, zd).grow(1, 1, 1);
std::vector<std::shared_ptr<Entity> >* objects = std::vector<std::shared_ptr<Entity> >* objects =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
double nearest = 0; double nearest = 0;
@ -188,7 +188,7 @@ void Fireball::tick() {
// && flightTime < 25)) continue; // && flightTime < 25)) continue;
float rr = 0.3f; float rr = 0.3f;
AABB bb = e->bb->grow(rr, rr, rr); AABB bb = e->bb.grow(rr, rr, rr);
HitResult* p = bb.clip(from, to); HitResult* p = bb.clip(from, to);
if (p != NULL) { if (p != NULL) {
double dd = from.distanceTo(p->pos); double dd = from.distanceTo(p->pos);

View file

@ -88,7 +88,7 @@ FishingHook::FishingHook(Level* level, std::shared_ptr<Player> mob)
void FishingHook::defineSynchedData() {} void FishingHook::defineSynchedData() {}
bool FishingHook::shouldRenderAtSqrDistance(double distance) { bool FishingHook::shouldRenderAtSqrDistance(double distance) {
double size = bb->getSize() * 4; double size = bb.getSize() * 4;
size *= 64.0f; size *= 64.0f;
return distance < size * size; return distance < size * size;
} }
@ -175,7 +175,7 @@ void FishingHook::tick() {
hookedIn = nullptr; hookedIn = nullptr;
else { else {
x = hookedIn->x; x = hookedIn->x;
y = hookedIn->bb->y0 + hookedIn->bbHeight * 0.8; y = hookedIn->bb.y0 + hookedIn->bbHeight * 0.8;
z = hookedIn->z; z = hookedIn->z;
return; return;
} }
@ -213,7 +213,7 @@ void FishingHook::tick() {
to = Vec3(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::shared_ptr<Entity> hitEntity = nullptr;
AABB grown = bb->expand(xd, yd, zd).grow(1, 1, 1); AABB grown = bb.expand(xd, yd, zd).grow(1, 1, 1);
std::vector<std::shared_ptr<Entity> >* objects = std::vector<std::shared_ptr<Entity> >* objects =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
double nearest = 0; double nearest = 0;
@ -223,7 +223,7 @@ void FishingHook::tick() {
if (!e->isPickable() || (e == owner && flightTime < 5)) continue; if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
float rr = 0.3f; float rr = 0.3f;
AABB bb = e->bb->grow(rr, rr, rr); AABB bb = e->bb.grow(rr, rr, rr);
HitResult* p = bb.clip(from, to); HitResult* p = bb.clip(from, to);
if (p != NULL) { if (p != NULL) {
double dd = from.distanceTo(p->pos); double dd = from.distanceTo(p->pos);
@ -284,11 +284,11 @@ void FishingHook::tick() {
int steps = 5; int steps = 5;
double waterPercentage = 0; double waterPercentage = 0;
for (int i = 0; i < steps; i++) { for (int i = 0; i < steps; i++) {
double y0 = bb->y0 + (bb->y1 - bb->y0) * (i + 0) / steps - 2 / 16.0f + double y0 = bb.y0 + (bb.y1 - bb.y0) * (i + 0) / steps - 2 / 16.0f +
2 / 16.0f; 2 / 16.0f;
double y1 = bb->y0 + (bb->y1 - bb->y0) * (i + 1) / steps - 2 / 16.0f + double y1 = bb.y0 + (bb.y1 - bb.y0) * (i + 1) / steps - 2 / 16.0f +
2 / 16.0f; 2 / 16.0f;
AABB bb2(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); AABB bb2(bb.x0, y0, bb.z0, bb.x1, y1, bb.z1);
if (level->containsLiquid(&bb2, Material::water)) { if (level->containsLiquid(&bb2, Material::water)) {
waterPercentage += 1.0 / steps; waterPercentage += 1.0 / steps;
} }
@ -309,7 +309,7 @@ void FishingHook::tick() {
playSound( playSound(
eSoundType_RANDOM_SPLASH, 0.25f, eSoundType_RANDOM_SPLASH, 0.25f,
1 + (random->nextFloat() - random->nextFloat()) * 0.4f); 1 + (random->nextFloat() - random->nextFloat()) * 0.4f);
float yt = (float)Mth::floor(bb->y0); float yt = (float)Mth::floor(bb.y0);
for (int i = 0; i < 1 + bbWidth * 20; i++) { for (int i = 0; i < 1 + bbWidth * 20; i++) {
float xo = (random->nextFloat() * 2 - 1) * bbWidth; float xo = (random->nextFloat() * 2 - 1) * bbWidth;
float zo = (random->nextFloat() * 2 - 1) * bbWidth; float zo = (random->nextFloat() * 2 - 1) * bbWidth;

View file

@ -119,7 +119,7 @@ void Ghast::serverAiStep() {
target->distanceToSqr(shared_from_this()) < maxDist * maxDist) { target->distanceToSqr(shared_from_this()) < maxDist * maxDist) {
double xdd = target->x - x; double xdd = target->x - x;
double ydd = double ydd =
(target->bb->y0 + target->bbHeight / 2) - (y + bbHeight / 2); (target->bb.y0 + target->bbHeight / 2) - (y + bbHeight / 2);
double zdd = target->z - z; double zdd = target->z - z;
yBodyRot = yRot = -(float)atan2(xdd, zdd) * 180 / PI; yBodyRot = yRot = -(float)atan2(xdd, zdd) * 180 / PI;
@ -170,7 +170,6 @@ bool Ghast::canReach(double xt, double yt, double zt, double dist) {
double yd = (yTarget - y) / dist; double yd = (yTarget - y) / dist;
double zd = (zTarget - z) / dist; double zd = (zTarget - z) / dist;
AABB bb = *this->bb;
for (int d = 1; d < dist; d++) { for (int d = 1; d < dist; d++) {
bb.move(xd, yd, zd); bb.move(xd, yd, zd);
if (!level->getCubes(shared_from_this(), &bb)->empty()) return false; if (!level->getCubes(shared_from_this(), &bb)->empty()) return false;

View file

@ -27,9 +27,9 @@ void LavaSlime::registerAttributes() {
bool LavaSlime::canSpawn() { bool LavaSlime::canSpawn() {
return level->difficulty > Difficulty::PEACEFUL && return level->difficulty > Difficulty::PEACEFUL &&
level->isUnobstructed(bb) && level->isUnobstructed(&bb) &&
level->getCubes(shared_from_this(), bb)->empty() && level->getCubes(shared_from_this(), &bb)->empty() &&
!level->containsAnyLiquid(bb); !level->containsAnyLiquid(&bb);
} }
int LavaSlime::getArmorValue() { return getSize() * 3; } int LavaSlime::getArmorValue() { return getSize() * 3; }

View file

@ -98,7 +98,7 @@ void Minecart::defineSynchedData() {
AABB* Minecart::getCollideAgainstBox(std::shared_ptr<Entity> entity) { AABB* Minecart::getCollideAgainstBox(std::shared_ptr<Entity> entity) {
if (entity->isPushable()) { if (entity->isPushable()) {
return entity->bb; return &entity->bb;
} }
return NULL; return NULL;
} }
@ -305,7 +305,7 @@ void Minecart::tick() {
} }
setRot(yRot, xRot); setRot(yRot, xRot);
AABB grown = bb->grow(0.2, 0, 0.2); AABB grown = bb.grow(0.2, 0, 0.2);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
if (entities != NULL && !entities->empty()) { if (entities != NULL && !entities->empty()) {

View file

@ -67,7 +67,7 @@ bool MushroomCow::mobInteract(std::shared_ptr<Player> player) {
// already really // already really
bool MushroomCow::canSpawn() { bool MushroomCow::canSpawn() {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
int zt = Mth::floor(z); int zt = Mth::floor(z);
return (level->getTile(xt, yt - 1, zt) == Tile::grass_Id || return (level->getTile(xt, yt - 1, zt) == Tile::grass_Id ||
level->getTile(xt, yt - 1, zt) == Tile::mycel_Id) && level->getTile(xt, yt - 1, zt) == Tile::mycel_Id) &&

View file

@ -240,11 +240,11 @@ bool Ocelot::canSpawn() {
if (level->random->nextInt(3) == 0) { if (level->random->nextInt(3) == 0) {
return false; return false;
} }
if (level->isUnobstructed(bb) && if (level->isUnobstructed(&bb) &&
level->getCubes(shared_from_this(), bb)->empty() && level->getCubes(shared_from_this(), &bb)->empty() &&
!level->containsAnyLiquid(bb)) { !level->containsAnyLiquid(&bb)) {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
int zt = Mth::floor(z); int zt = Mth::floor(z);
if (yt < level->seaLevel) { if (yt < level->seaLevel) {
return false; return false;

View file

@ -69,9 +69,9 @@ void PigZombie::tick() {
bool PigZombie::canSpawn() { bool PigZombie::canSpawn() {
return level->difficulty > Difficulty::PEACEFUL && return level->difficulty > Difficulty::PEACEFUL &&
level->isUnobstructed(bb) && level->isUnobstructed(&bb) &&
level->getCubes(shared_from_this(), bb)->empty() && level->getCubes(shared_from_this(), &bb)->empty() &&
!level->containsAnyLiquid(bb); !level->containsAnyLiquid(&bb);
} }
void PigZombie::addAdditonalSaveData(CompoundTag* tag) { void PigZombie::addAdditonalSaveData(CompoundTag* tag) {
@ -100,7 +100,7 @@ std::shared_ptr<Entity> PigZombie::findAttackTarget() {
bool PigZombie::hurt(DamageSource* source, float dmg) { bool PigZombie::hurt(DamageSource* source, float dmg) {
std::shared_ptr<Entity> sourceEntity = source->getEntity(); std::shared_ptr<Entity> sourceEntity = source->getEntity();
if (sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER)) { if (sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER)) {
AABB grown = bb->grow(32, 32, 32); AABB grown = bb.grow(32, 32, 32);
std::vector<std::shared_ptr<Entity> >* nearby = std::vector<std::shared_ptr<Entity> >* nearby =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
AUTO_VAR(itEnd, nearby->end()); AUTO_VAR(itEnd, nearby->end());

View file

@ -69,8 +69,8 @@ bool Silverfish::hurt(DamageSource* source, float dmg) {
void Silverfish::checkHurtTarget(std::shared_ptr<Entity> target, float d) { void Silverfish::checkHurtTarget(std::shared_ptr<Entity> target, float d) {
// super.checkHurtTarget(target, d); // super.checkHurtTarget(target, d);
if (attackTime <= 0 && d < 1.2f && target->bb->y1 > bb->y0 && if (attackTime <= 0 && d < 1.2f && target->bb.y1 > bb.y0 &&
target->bb->y0 < bb->y1) { target->bb.y0 < bb.y1) {
attackTime = 20; attackTime = 20;
doHurtTarget(target); doHurtTarget(target);
} }

View file

@ -91,7 +91,7 @@ void Slime::tick() {
float d = random->nextFloat() * 0.5f + 0.5f; float d = random->nextFloat() * 0.5f + 0.5f;
float xd = Mth::sin(dir) * size * 0.5f * d; float xd = Mth::sin(dir) * size * 0.5f * d;
float zd = Mth::cos(dir) * size * 0.5f * d; float zd = Mth::cos(dir) * size * 0.5f * d;
level->addParticle(getParticleName(), x + xd, bb->y0, z + zd, 0, 0, level->addParticle(getParticleName(), x + xd, bb.y0, z + zd, 0, 0,
0); 0);
} }

View file

@ -65,7 +65,7 @@ void Squid::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) {
} }
bool Squid::isInWater() { bool Squid::isInWater() {
AABB grown = bb->grow(0, -0.6, 0); AABB grown = bb.grow(0, -0.6, 0);
return level->checkAndHandleWater(&grown, Material::water, return level->checkAndHandleWater(&grown, Material::water,
shared_from_this()); shared_from_this());
} }

View file

@ -82,7 +82,7 @@ void ThrownPotion::onHit(HitResult* res) {
Item::potion->getMobEffects(potionItem); Item::potion->getMobEffects(potionItem);
if (mobEffects != NULL && !mobEffects->empty()) { if (mobEffects != NULL && !mobEffects->empty()) {
AABB aoe = bb->grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE); AABB aoe = bb.grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE);
std::vector<std::shared_ptr<Entity> >* entitiesOfClass = std::vector<std::shared_ptr<Entity> >* entitiesOfClass =
level->getEntitiesOfClass(typeid(LivingEntity), &aoe); level->getEntitiesOfClass(typeid(LivingEntity), &aoe);

View file

@ -113,7 +113,7 @@ void VillagerGolem::aiStep() {
if (t > 0) { if (t > 0) {
level->addParticle(PARTICLE_TILECRACK(t, d), level->addParticle(PARTICLE_TILECRACK(t, d),
x + (random->nextFloat() - 0.5) * bbWidth, x + (random->nextFloat() - 0.5) * bbWidth,
bb->y0 + 0.1, bb.y0 + 0.1,
z + (random->nextFloat() - 0.5) * bbWidth, z + (random->nextFloat() - 0.5) * bbWidth,
4 * (random->nextFloat() - 0.5), .5, 4 * (random->nextFloat() - 0.5), .5,
(random->nextFloat() - 0.5) * 4); (random->nextFloat() - 0.5) * 4);

View file

@ -153,7 +153,7 @@ void Witch::handleEntityEvent(uint8_t id) {
for (int i = 0; i < random->nextInt(35) + 10; i++) { for (int i = 0; i < random->nextInt(35) + 10; i++) {
level->addParticle(eParticleType_witchMagic, level->addParticle(eParticleType_witchMagic,
x + random->nextGaussian() * .13f, x + random->nextGaussian() * .13f,
bb->y1 + 0.5f + random->nextGaussian() * .13f, bb.y1 + 0.5f + random->nextGaussian() * .13f,
z + random->nextGaussian() * .13f, 0, 0, 0); z + random->nextGaussian() * .13f, 0, 0, 0);
} }
} else { } else {

View file

@ -252,7 +252,7 @@ void WitherBoss::newServerAiStep() {
idleHeadUpdates[i - 1] = 0; idleHeadUpdates[i - 1] = 0;
} }
} else { } else {
AABB grown = bb->grow(20, 8, 20); AABB grown = bb.grow(20, 8, 20);
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =
level->getEntitiesOfClass(typeid(LivingEntity), &grown, level->getEntitiesOfClass(typeid(LivingEntity), &grown,
livingEntitySelector); livingEntitySelector);

View file

@ -182,7 +182,7 @@ void Wolf::tick() {
} }
if (shakeAnim > 0.4f) { if (shakeAnim > 0.4f) {
float yt = (float)bb->y0; float yt = (float)bb.y0;
int shakeCount = int shakeCount =
(int)(Mth::sin((shakeAnim - 0.4f) * PI) * 7.0f); (int)(Mth::sin((shakeAnim - 0.4f) * PI) * 7.0f);
for (int i = 0; i < shakeCount; i++) { for (int i = 0; i < shakeCount; i++) {

View file

@ -176,10 +176,10 @@ bool Zombie::hurt(DamageSource* source, float dmg) {
level->getRawBrightness(xt, yt, zt) < 10) { level->getRawBrightness(xt, yt, zt) < 10) {
reinforcement->setPos(xt, yt, zt); reinforcement->setPos(xt, yt, zt);
if (level->isUnobstructed(reinforcement->bb) && if (level->isUnobstructed(&reinforcement->bb) &&
level->getCubes(reinforcement, reinforcement->bb) level->getCubes(reinforcement, &reinforcement->bb)
->empty() && ->empty() &&
!level->containsAnyLiquid(reinforcement->bb)) { !level->containsAnyLiquid(&reinforcement->bb)) {
level->addEntity(reinforcement); level->addEntity(reinforcement);
reinforcement->setTarget(target); reinforcement->setTarget(target);
reinforcement->finalizeMobSpawn(NULL); reinforcement->finalizeMobSpawn(NULL);

View file

@ -113,8 +113,8 @@ bool Monster::doHurtTarget(std::shared_ptr<Entity> target) {
} }
void Monster::checkHurtTarget(std::shared_ptr<Entity> target, float distance) { void Monster::checkHurtTarget(std::shared_ptr<Entity> target, float distance) {
if (attackTime <= 0 && distance < 2.0f && target->bb->y1 > bb->y0 && if (attackTime <= 0 && distance < 2.0f && target->bb.y1 > bb.y0 &&
target->bb->y0 < bb->y1) { target->bb.y0 < bb.y1) {
attackTime = 20; attackTime = 20;
doHurtTarget(target); doHurtTarget(target);
} }
@ -126,7 +126,7 @@ float Monster::getWalkTargetValue(int x, int y, int z) {
bool Monster::isDarkEnoughToSpawn() { bool Monster::isDarkEnoughToSpawn() {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
int zt = Mth::floor(z); int zt = Mth::floor(z);
if (level->getBrightness(LightLayer::Sky, xt, yt, zt) > random->nextInt(32)) if (level->getBrightness(LightLayer::Sky, xt, yt, zt) > random->nextInt(32))
return false; return false;

View file

@ -109,7 +109,7 @@ void PathfinderMob::serverAiStep() {
// protected. // protected.
considerForExtraWandering(isDespawnProtected()); considerForExtraWandering(isDespawnProtected());
int yFloor = Mth::floor(bb->y0 + 0.5f); int yFloor = Mth::floor(bb.y0 + 0.5f);
bool inWater = isInWater(); bool inWater = isInWater();
bool inLava = isInLava(); bool inLava = isInLava();
@ -226,7 +226,7 @@ std::shared_ptr<Entity> PathfinderMob::findAttackTarget() {
bool PathfinderMob::canSpawn() { bool PathfinderMob::canSpawn() {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(bb->y0); int yt = Mth::floor(bb.y0);
int zt = Mth::floor(z); int zt = Mth::floor(z);
return this->Mob::canSpawn() && getWalkTargetValue(xt, yt, zt) >= 0; return this->Mob::canSpawn() && getWalkTargetValue(xt, yt, zt) >= 0;
} }

View file

@ -27,7 +27,7 @@ Throwable::Throwable(Level* level) : Entity(level) {
void Throwable::defineSynchedData() {} void Throwable::defineSynchedData() {}
bool Throwable::shouldRenderAtSqrDistance(double distance) { bool Throwable::shouldRenderAtSqrDistance(double distance) {
double size = bb->getSize() * 4; double size = bb.getSize() * 4;
size *= 64.0f; size *= 64.0f;
return distance < size * size; return distance < size * size;
} }
@ -147,7 +147,7 @@ void Throwable::tick() {
if (!level->isClientSide) { if (!level->isClientSide) {
std::shared_ptr<Entity> hitEntity = nullptr; std::shared_ptr<Entity> hitEntity = nullptr;
AABB grown = bb->expand(xd, yd, zd).grow(1, 1, 1); AABB grown = bb.expand(xd, yd, zd).grow(1, 1, 1);
std::vector<std::shared_ptr<Entity> >* objects = std::vector<std::shared_ptr<Entity> >* objects =
level->getEntities(shared_from_this(), &grown); level->getEntities(shared_from_this(), &grown);
double nearest = 0; double nearest = 0;
@ -157,7 +157,7 @@ void Throwable::tick() {
if (!e->isPickable() || (e == owner && flightTime < 5)) continue; if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
float rr = 0.3f; float rr = 0.3f;
AABB bb = e->bb->grow(rr, rr, rr); AABB bb = e->bb.grow(rr, rr, rr);
HitResult* p = bb.clip(from, to); HitResult* p = bb.clip(from, to);
if (p != NULL) { if (p != NULL) {
double dd = from.distanceTo(p->pos); double dd = from.distanceTo(p->pos);

View file

@ -18,7 +18,7 @@ bool WaterAnimal::isWaterMob() {
return true; // prevent drowning return true; // prevent drowning
} }
bool WaterAnimal::canSpawn() { return level->isUnobstructed(bb); } bool WaterAnimal::canSpawn() { return level->isUnobstructed(&bb); }
int WaterAnimal::getAmbientSoundInterval() { return 20 * 6; } int WaterAnimal::getAmbientSoundInterval() { return 20 * 6; }

View file

@ -83,7 +83,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
Vec3 b = player->getViewVector(a); Vec3 b = player->getViewVector(a);
bool hitEntity = false; bool hitEntity = false;
float overlap = 1; float overlap = 1;
AABB grown = player->bb->expand(b.x * (range), b.y * (range), b.z * (range)) AABB grown = player->bb.expand(b.x * (range), b.y * (range), b.z * (range))
.grow(overlap, overlap, overlap); .grow(overlap, overlap, overlap);
std::vector<std::shared_ptr<Entity> >* objects = std::vector<std::shared_ptr<Entity> >* objects =
level->getEntities(player, &grown); level->getEntities(player, &grown);
@ -93,7 +93,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
if (!e->isPickable()) continue; if (!e->isPickable()) continue;
float rr = e->getPickRadius(); float rr = e->getPickRadius();
AABB bb = e->bb->grow(rr, rr, rr); AABB bb = e->bb.grow(rr, rr, rr);
if (bb.contains(from)) { if (bb.contains(from)) {
hitEntity = true; hitEntity = true;
} }
@ -116,7 +116,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
boat->yRot = boat->yRot =
((Mth::floor(player->yRot * 4.0F / 360.0F + 0.5) & 0x3) - 1) * ((Mth::floor(player->yRot * 4.0F / 360.0F + 0.5) & 0x3) - 1) *
90; 90;
AABB grown = boat->bb->grow(-0.1, -0.1, -0.1); AABB grown = boat->bb.grow(-0.1, -0.1, -0.1);
if (!level->getCubes(boat, &grown)->empty()) { if (!level->getCubes(boat, &grown)->empty()) {
return itemInstance; return itemInstance;
} }

View file

@ -118,7 +118,7 @@ void Explosion::explode() {
// walls // walls
bool canDamage = false; bool canDamage = false;
for (AUTO_VAR(it2, toBlow.begin()); it2 != toBlow.end(); ++it2) { for (AUTO_VAR(it2, toBlow.begin()); it2 != toBlow.end(); ++it2) {
if (e->bb->intersects(it2->x, it2->y, it2->z, it2->x + 1, if (e->bb.intersects(it2->x, it2->y, it2->z, it2->x + 1,
it2->y + 1, it2->z + 1)) { it2->y + 1, it2->z + 1)) {
canDamage = true; canDamage = true;
break; break;
@ -144,7 +144,7 @@ void Explosion::explode() {
za /= da; za /= da;
} }
double sp = level->getSeenPercent(&center, e->bb); double sp = level->getSeenPercent(&center, &e->bb);
double pow = (1 - dist) * sp; double pow = (1 - dist) * sp;
if (canDamage) if (canDamage)
e->hurt(DamageSource::explosion(this), e->hurt(DamageSource::explosion(this),

View file

@ -1691,7 +1691,7 @@ void LevelChunk::getEntities(std::shared_ptr<Entity> except, AABB* bb,
AUTO_VAR(itEnd, entities->end()); AUTO_VAR(itEnd, entities->end());
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) { for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
std::shared_ptr<Entity> e = *it; // entities->at(i); std::shared_ptr<Entity> e = *it; // entities->at(i);
if (e != except && e->bb->intersects(*bb) && if (e != except && e->bb.intersects(*bb) &&
(selector == NULL || selector->matches(e))) { (selector == NULL || selector->matches(e))) {
es.push_back(e); es.push_back(e);
std::vector<std::shared_ptr<Entity> >* subs = std::vector<std::shared_ptr<Entity> >* subs =
@ -1699,7 +1699,7 @@ void LevelChunk::getEntities(std::shared_ptr<Entity> except, AABB* bb,
if (subs != NULL) { if (subs != NULL) {
for (int j = 0; j < subs->size(); j++) { for (int j = 0; j < subs->size(); j++) {
e = subs->at(j); e = subs->at(j);
if (e != except && e->bb->intersects(*bb) && if (e != except && e->bb.intersects(*bb) &&
(selector == NULL || selector->matches(e))) { (selector == NULL || selector->matches(e))) {
es.push_back(e); es.push_back(e);
} }
@ -1765,7 +1765,7 @@ void LevelChunk::getEntitiesOfClass(const std::type_info& ec, AABB* bb,
else if (Entity* entity = e.get(); else if (Entity* entity = e.get();
entity != NULL && ec == typeid(*entity)) entity != NULL && ec == typeid(*entity))
isAssignableFrom = true; isAssignableFrom = true;
if (isAssignableFrom && e->bb->intersects(*bb)) { if (isAssignableFrom && e->bb.intersects(*bb)) {
if (selector == NULL || selector->matches(e)) { if (selector == NULL || selector->matches(e)) {
es.push_back(e); es.push_back(e);
} }

View file

@ -965,9 +965,9 @@ void Player::aiStep() {
if (riding != NULL && !riding->removed) { if (riding != NULL && !riding->removed) {
// if the player is riding, also touch entities under the // if the player is riding, also touch entities under the
// pig/horse // pig/horse
pickupArea = bb->minmax(*riding->bb).grow(1, 0, 1); pickupArea = bb.minmax(riding->bb).grow(1, 0, 1);
} else { } else {
pickupArea = bb->grow(1, .5, 1); pickupArea = bb.grow(1, .5, 1);
} }
std::vector<std::shared_ptr<Entity> >* entities = std::vector<std::shared_ptr<Entity> >* entities =

View file

@ -19,7 +19,7 @@ void CombatTracker::prepareForDamage() {
if (mob->onLadder()) { if (mob->onLadder()) {
int type = mob->level->getTile( int type = mob->level->getTile(
Mth::floor(mob->x), Mth::floor(mob->bb->y0), Mth::floor(mob->z)); Mth::floor(mob->x), Mth::floor(mob->bb.y0), Mth::floor(mob->z));
if (type == Tile::ladder->id) { if (type == Tile::ladder->id) {
nextLocation = eLocation_LADDER; nextLocation = eLocation_LADDER;