mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-13 04:07:12 +00:00
refactor: modernize AABB class
This commit is contained in:
parent
da7cbcb4b6
commit
79217ca8e3
|
|
@ -272,8 +272,9 @@ void PlayerConnection::handleMovePlayer(
|
|||
*/
|
||||
|
||||
float r = 1 / 16.0f;
|
||||
AABB shrunk = player->bb->shrink(r, r, r);
|
||||
bool oldOk =
|
||||
level->getCubes(player, player->bb->copy()->shrink(r, r, r))
|
||||
level->getCubes(player, &shrunk)
|
||||
->empty();
|
||||
|
||||
if (player->onGround && !packet->onGround && yDist > 0) {
|
||||
|
|
@ -324,17 +325,19 @@ void PlayerConnection::handleMovePlayer(
|
|||
}
|
||||
player->absMoveTo(xt, yt, zt, yRotT, xRotT);
|
||||
|
||||
// TODO: check if this can be elided
|
||||
shrunk = player->bb->shrink(r, r, r);
|
||||
bool newOk =
|
||||
level->getCubes(player, player->bb->copy()->shrink(r, r, r))
|
||||
level->getCubes(player, &shrunk)
|
||||
->empty();
|
||||
if (oldOk && (fail || !newOk) && !player->isSleeping()) {
|
||||
teleport(xLastOk, yLastOk, zLastOk, yRotT, xRotT);
|
||||
return;
|
||||
}
|
||||
AABB* testBox = player->bb->copy()->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
|
||||
if (!server->isFlightAllowed() && !player->gameMode->isCreative() &&
|
||||
!level->containsAnyBlocks(testBox) && !player->isAllowedToFly()) {
|
||||
!level->containsAnyBlocks(&testBox) && !player->isAllowedToFly()) {
|
||||
if (oyDist >= (-0.5f / 16.0f)) {
|
||||
aboveGroundTickCount++;
|
||||
if (aboveGroundTickCount > 80) {
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
|
|||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
|
||||
if (m_locationBox == NULL) updateLocationBox();
|
||||
if (chunkBox->intersects(m_locationBox)) {
|
||||
if (chunkBox->intersects(*m_locationBox)) {
|
||||
m_locationBox->y1 =
|
||||
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
|
|||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
|
||||
if (m_locationBox == NULL) updateLocationBox();
|
||||
if (chunkBox->intersects(m_locationBox)) {
|
||||
if (chunkBox->intersects(*m_locationBox)) {
|
||||
m_locationBox->y1 =
|
||||
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
|
||||
|
||||
|
|
|
|||
|
|
@ -464,7 +464,7 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
|
|||
targetZ);
|
||||
|
||||
Vec3 pos(targetX, targetY, targetZ);
|
||||
if (chunkBox->containsIncludingLowerBound(&pos)) {
|
||||
if (chunkBox->containsIncludingLowerBound(pos)) {
|
||||
std::shared_ptr<TileEntity> teCopy = chunk->getTileEntity(
|
||||
(int)targetX & 15, (int)targetY & 15, (int)targetZ & 15);
|
||||
|
||||
|
|
@ -511,7 +511,7 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
|
|||
// Add 0.01 as the AABB::contains function returns false if a value is
|
||||
// <= the lower bound
|
||||
Vec3 pos(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
|
||||
if (!chunkBox->containsIncludingLowerBound(&pos)) {
|
||||
if (!chunkBox->containsIncludingLowerBound(pos)) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,10 @@ AreaConstraint::~AreaConstraint() {
|
|||
|
||||
bool AreaConstraint::isConstraintSatisfied(int iPad) {
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
|
||||
// TODO: check if this can be elided
|
||||
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) {
|
||||
|
|
@ -40,7 +42,7 @@ bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
|
|||
Vec3 targetPos(xt, yt, zt);
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
|
||||
if (movementArea->contains(&targetPos) == contains) {
|
||||
if (movementArea->contains(targetPos) == contains) {
|
||||
return true;
|
||||
}
|
||||
Vec3 origPos(xo, yo, zo);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ int AreaHint::tick() {
|
|||
|
||||
if ((m_displayState == e_Tutorial_State_Any ||
|
||||
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) {
|
||||
m_hintNeeded = false;
|
||||
} else if (m_tutorial->isStateCompleted(m_completeState)) {
|
||||
|
|
|
|||
|
|
@ -85,9 +85,11 @@ void ChangeStateConstraint::tick(int iPad) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check if this can be elided
|
||||
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
|
||||
if (!m_bHasChanged && inASourceState &&
|
||||
movementArea->contains(&ipad_player) == contains) {
|
||||
movementArea->contains(ipad_player) == contains) {
|
||||
m_bHasChanged = true;
|
||||
m_changedFromState = m_tutorial->getCurrentState();
|
||||
m_tutorial->changeTutorialState(m_targetState);
|
||||
|
|
@ -125,7 +127,7 @@ void ChangeStateConstraint::tick(int iPad) {
|
|||
}
|
||||
}
|
||||
} else if (m_bHasChanged &&
|
||||
movementArea->contains(&ipad_player) != contains) {
|
||||
movementArea->contains(ipad_player) != contains) {
|
||||
m_bHasChanged = false;
|
||||
m_tutorial->changeTutorialState(m_changedFromState);
|
||||
|
||||
|
|
|
|||
|
|
@ -509,9 +509,9 @@ void Chunk::rebuild() {
|
|||
// 4J MGH - added this to take the bound from the value calc'd in the
|
||||
// tesselator
|
||||
if (bb) {
|
||||
bb->set(bounds.boundingBox[0], bounds.boundingBox[1],
|
||||
*bb = {bounds.boundingBox[0], bounds.boundingBox[1],
|
||||
bounds.boundingBox[2], bounds.boundingBox[3],
|
||||
bounds.boundingBox[4], bounds.boundingBox[5]);
|
||||
bounds.boundingBox[4], bounds.boundingBox[5]};
|
||||
}
|
||||
|
||||
delete tileRenderer;
|
||||
|
|
|
|||
|
|
@ -309,11 +309,12 @@ void GameRenderer::pick(float a) {
|
|||
to = to.add(from.x, from.y, from.z);
|
||||
hovered = nullptr;
|
||||
float overlap = 1;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = mc->level->getEntities(
|
||||
mc->cameraTargetPlayer,
|
||||
mc->cameraTargetPlayer->bb
|
||||
->expand(b.x * (range), b.y * (range), b.z * (range))
|
||||
->grow(overlap, overlap, overlap));
|
||||
AABB grown = mc->cameraTargetPlayer->bb
|
||||
->expand(b.x * (range), b.y * (range), b.z * (range))
|
||||
.grow(overlap, overlap, overlap);
|
||||
|
||||
std::vector<std::shared_ptr<Entity> >* objects =
|
||||
mc->level->getEntities(mc->cameraTargetPlayer, &grown);
|
||||
double nearest = dist;
|
||||
|
||||
AUTO_VAR(itEnd, objects->end());
|
||||
|
|
@ -322,9 +323,9 @@ void GameRenderer::pick(float a) {
|
|||
if (!e->isPickable()) continue;
|
||||
|
||||
float rr = e->getPickRadius();
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb->clip(&from, &to);
|
||||
if (bb->contains(&from)) {
|
||||
AABB bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb.clip(from, to);
|
||||
if (bb.contains(from)) {
|
||||
if (0 < nearest || nearest == 0) {
|
||||
hovered = e;
|
||||
nearest = 0;
|
||||
|
|
|
|||
|
|
@ -2479,10 +2479,13 @@ void LevelRenderer::renderHitOutline(std::shared_ptr<Player> player,
|
|||
double xo = player->xOld + (player->x - player->xOld) * a;
|
||||
double yo = player->yOld + (player->y - player->yOld) * a;
|
||||
double zo = player->zOld + (player->z - player->zOld) * a;
|
||||
render(Tile::tiles[tileId]
|
||||
|
||||
AABB bb = Tile::tiles[tileId]
|
||||
->getTileAABB(level[iPad], h->x, h->y, h->z)
|
||||
->grow(ss, ss, ss)
|
||||
->cloneMove(-xo, -yo, -zo));
|
||||
.move(-xo, -yo, -zo);
|
||||
|
||||
render(&bb);
|
||||
}
|
||||
glDepthMask(true);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
|
@ -3974,7 +3977,7 @@ void LevelRenderer::DestroyedTileManager::addAABBs(Level* level, AABB* box,
|
|||
// interested in, add them to the output list, making a temp
|
||||
// AABB copy so that we can destroy our own copy without
|
||||
// worrying about the lifespan of the copy we've passed out
|
||||
if (m_destroyedTiles[i]->boxes[j]->intersects(box)) {
|
||||
if (m_destroyedTiles[i]->boxes[j]->intersects(*box)) {
|
||||
boxes->push_back(
|
||||
AABB::newTemp(m_destroyedTiles[i]->boxes[j]->x0,
|
||||
m_destroyedTiles[i]->boxes[j]->y0,
|
||||
|
|
|
|||
|
|
@ -53,9 +53,10 @@ bool AvoidPlayerGoal::canUse() {
|
|||
mob->level->getNearestPlayer(mob->shared_from_this(), maxDist));
|
||||
if (toAvoid.lock() == NULL) return false;
|
||||
} else {
|
||||
AABB grown_bb = mob->bb->grow(maxDist, 3, maxDist);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
mob->level->getEntitiesOfClass(
|
||||
avoidType, mob->bb->grow(maxDist, 3, maxDist), entitySelector);
|
||||
avoidType, &grown_bb, entitySelector);
|
||||
if (entities->empty()) {
|
||||
delete entities;
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -48,8 +48,9 @@ void BreedGoal::tick() {
|
|||
|
||||
std::shared_ptr<Animal> BreedGoal::getFreePartner() {
|
||||
float r = 8;
|
||||
AABB grown_bb = animal->bb->grow(r, r, r);
|
||||
std::vector<std::shared_ptr<Entity> >* others =
|
||||
level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(r, r, r));
|
||||
level->getEntitiesOfClass(typeid(*animal), &grown_bb);
|
||||
double dist = std::numeric_limits<double>::max();
|
||||
std::shared_ptr<Animal> partner = nullptr;
|
||||
for (AUTO_VAR(it, others->begin()); it != others->end(); ++it) {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ FollowParentGoal::FollowParentGoal(Animal* animal, double speedModifier) {
|
|||
bool FollowParentGoal::canUse() {
|
||||
if (animal->getAge() >= 0) return false;
|
||||
|
||||
AABB grown_bb = animal->bb->grow(8, 4, 8);
|
||||
std::vector<std::shared_ptr<Entity> >* parents =
|
||||
animal->level->getEntitiesOfClass(typeid(*animal),
|
||||
animal->bb->grow(8, 4, 8));
|
||||
animal->level->getEntitiesOfClass(typeid(*animal), &grown_bb);
|
||||
|
||||
std::shared_ptr<Animal> closest = nullptr;
|
||||
double closestDistSqr = std::numeric_limits<double>::max();
|
||||
|
|
|
|||
|
|
@ -22,11 +22,10 @@ void HurtByTargetGoal::start() {
|
|||
|
||||
if (alertSameType) {
|
||||
double within = getFollowDistance();
|
||||
AABB mob_bb = AABB(mob->x, mob->y, mob->z, mob->x + 1, mob->y + 1, mob->z + 1).grow(within, 4, within);
|
||||
std::vector<std::shared_ptr<Entity> >* nearby =
|
||||
mob->level->getEntitiesOfClass(
|
||||
typeid(*mob), AABB::newTemp(mob->x, mob->y, mob->z, mob->x + 1,
|
||||
mob->y + 1, mob->z + 1)
|
||||
->grow(within, 4, within));
|
||||
typeid(*mob), &mob_bb);
|
||||
for (AUTO_VAR(it, nearby->begin()); it != nearby->end(); ++it) {
|
||||
std::shared_ptr<PathfinderMob> other =
|
||||
std::dynamic_pointer_cast<PathfinderMob>(*it);
|
||||
|
|
@ -40,4 +39,4 @@ void HurtByTargetGoal::start() {
|
|||
}
|
||||
|
||||
TargetGoal::start();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,9 @@ bool LookAtPlayerGoal::canUse() {
|
|||
lookAt =
|
||||
mob->level->getNearestPlayer(mob->shared_from_this(), lookDistance);
|
||||
} else {
|
||||
AABB mob_bb = mob->bb->grow(lookDistance, 3, lookDistance);
|
||||
lookAt = std::weak_ptr<Entity>(mob->level->getClosestEntityOfClass(
|
||||
lookAtType, mob->bb->grow(lookDistance, 3, lookDistance),
|
||||
lookAtType, &mob_bb,
|
||||
mob->shared_from_this()));
|
||||
}
|
||||
return lookAt.lock() != NULL;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@ bool MakeLoveGoal::canUse() {
|
|||
if (village.lock() == NULL) return false;
|
||||
if (!villageNeedsMoreVillagers()) return false;
|
||||
|
||||
AABB villager_bb = villager->bb->grow(8, 3, 8);
|
||||
std::shared_ptr<Entity> mate = level->getClosestEntityOfClass(
|
||||
typeid(Villager), villager->bb->grow(8, 3, 8),
|
||||
typeid(Villager), &villager_bb,
|
||||
villager->shared_from_this());
|
||||
if (mate == NULL) return false;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,9 +55,10 @@ bool NearestAttackableTargetGoal::canUse() {
|
|||
return false;
|
||||
double within = getFollowDistance();
|
||||
|
||||
AABB mob_bb = mob->bb->grow(within, 4, within);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
mob->level->getEntitiesOfClass(
|
||||
targetType, mob->bb->grow(within, 4, within), selector);
|
||||
targetType, &mob_bb, selector);
|
||||
|
||||
bool result = false;
|
||||
if (entities != NULL && !entities->empty()) {
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ OfferFlowerGoal::OfferFlowerGoal(VillagerGolem* golem) {
|
|||
bool OfferFlowerGoal::canUse() {
|
||||
if (!golem->level->isDay()) return false;
|
||||
if (golem->getRandom()->nextInt(8000) != 0) return false;
|
||||
AABB golem_bb = golem->bb->grow(6, 2, 6);
|
||||
villager = std::weak_ptr<Villager>(std::dynamic_pointer_cast<Villager>(
|
||||
golem->level->getClosestEntityOfClass(typeid(Villager),
|
||||
golem->bb->grow(6, 2, 6),
|
||||
&golem_bb,
|
||||
golem->shared_from_this())));
|
||||
return villager.lock() != NULL;
|
||||
}
|
||||
|
|
@ -39,4 +40,4 @@ void OfferFlowerGoal::stop() {
|
|||
void OfferFlowerGoal::tick() {
|
||||
golem->getLookControl()->setLookAt(villager.lock(), 30, 30);
|
||||
--_tick;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ bool PlayGoal::canUse() {
|
|||
if (mob->getAge() >= 0) return false;
|
||||
if (mob->getRandom()->nextInt(400) != 0) return false;
|
||||
|
||||
AABB mob_bb = mob->bb->grow(6, 3, 6);
|
||||
std::vector<std::shared_ptr<Entity> >* children =
|
||||
mob->level->getEntitiesOfClass(typeid(Villager),
|
||||
mob->bb->grow(6, 3, 6));
|
||||
&mob_bb);
|
||||
double closestDistSqr = std::numeric_limits<double>::max();
|
||||
// for (Entity c : children)
|
||||
for (AUTO_VAR(it, children->begin()); it != children->end(); ++it) {
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@ bool TakeFlowerGoal::canUse() {
|
|||
if (villager->getAge() >= 0) return false;
|
||||
if (!villager->level->isDay()) return false;
|
||||
|
||||
AABB villager_bb = villager->bb->grow(6, 2, 6);
|
||||
std::vector<std::shared_ptr<Entity> >* golems =
|
||||
villager->level->getEntitiesOfClass(typeid(VillagerGolem),
|
||||
villager->bb->grow(6, 2, 6));
|
||||
&villager_bb);
|
||||
if (golems->size() == 0) {
|
||||
delete golems;
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -2016,7 +2016,7 @@ AABB* Tile::getTileAABB(Level* level, int x, int y, int z) {
|
|||
void Tile::addAABBs(Level* level, int x, int y, int z, AABB* box,
|
||||
AABBList* boxes, std::shared_ptr<Entity> source) {
|
||||
AABB* aabb = getAABB(level, x, y, z);
|
||||
if (aabb != NULL && box->intersects(aabb)) boxes->push_back(aabb);
|
||||
if (aabb != NULL && box->intersects(*aabb)) boxes->push_back(aabb);
|
||||
}
|
||||
|
||||
AABB* Tile::getAABB(Level* level, int x, int y, int z) {
|
||||
|
|
|
|||
|
|
@ -70,11 +70,10 @@ void BeaconTileEntity::applyEffects() {
|
|||
baseAmp = 1;
|
||||
}
|
||||
|
||||
AABB* bb = AABB::newTemp(x, y, z, x + 1, y + 1, z + 1)
|
||||
->grow(range, range, range);
|
||||
bb->y1 = level->getMaxBuildHeight();
|
||||
AABB bb = AABB(x, y, z, x + 1, y + 1, z + 1).grow(range, range, range);
|
||||
bb.y1 = level->getMaxBuildHeight();
|
||||
std::vector<std::shared_ptr<Entity> >* players =
|
||||
level->getEntitiesOfClass(typeid(Player), bb);
|
||||
level->getEntitiesOfClass(typeid(Player), &bb);
|
||||
for (AUTO_VAR(it, players->begin()); it != players->end(); ++it) {
|
||||
std::shared_ptr<Player> player =
|
||||
std::dynamic_pointer_cast<Player>(*it);
|
||||
|
|
@ -299,4 +298,4 @@ bool BeaconTileEntity::canPlaceItem(int slot,
|
|||
std::shared_ptr<ItemInstance> item) {
|
||||
return (item->id == Item::emerald_Id || item->id == Item::diamond_Id ||
|
||||
item->id == Item::goldIngot_Id || item->id == Item::ironIngot_Id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -463,8 +463,8 @@ void Entity::setPos(double x, double y, double z) {
|
|||
this->z = z;
|
||||
float w = bbWidth / 2;
|
||||
float h = bbHeight;
|
||||
bb->set(x - w, y - heightOffset + ySlideOffset, z - w, x + w,
|
||||
y - heightOffset + ySlideOffset + h, z + w);
|
||||
*bb = {x - w, y - heightOffset + ySlideOffset, z - w, x + w,
|
||||
y - heightOffset + ySlideOffset + h, z + w};
|
||||
}
|
||||
|
||||
void Entity::turn(float xo, float yo) {
|
||||
|
|
@ -618,18 +618,18 @@ void Entity::clearFire() { onFire = 0; }
|
|||
void Entity::outOfWorld() { remove(); }
|
||||
|
||||
bool Entity::isFree(float xa, float ya, float za, float grow) {
|
||||
AABB* box = bb->grow(grow, grow, grow)->cloneMove(xa, ya, za);
|
||||
AABBList* aABBs = level->getCubes(shared_from_this(), box);
|
||||
AABB box = bb->grow(grow, grow, grow).move(xa, ya, za);
|
||||
AABBList* aABBs = level->getCubes(shared_from_this(), &box);
|
||||
if (!aABBs->empty()) return false;
|
||||
if (level->containsAnyLiquid(box)) return false;
|
||||
if (level->containsAnyLiquid(&box)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Entity::isFree(double xa, double ya, double za) {
|
||||
AABB* box = bb->cloneMove(xa, ya, za);
|
||||
AABBList* aABBs = level->getCubes(shared_from_this(), box);
|
||||
AABB box = bb->move(xa, ya, za);
|
||||
AABBList* aABBs = level->getCubes(shared_from_this(), &box);
|
||||
if (!aABBs->empty()) return false;
|
||||
if (level->containsAnyLiquid(box)) return false;
|
||||
if (level->containsAnyLiquid(&box)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -637,7 +637,7 @@ void Entity::move(double xa, double ya, double za,
|
|||
bool noEntityCubes) // 4J - added noEntityCubes parameter
|
||||
{
|
||||
if (noPhysics) {
|
||||
bb->move(xa, ya, za);
|
||||
*bb = bb->move(xa, ya, za);
|
||||
x = (bb->x0 + bb->x1) / 2.0f;
|
||||
y = bb->y0 + heightOffset - ySlideOffset;
|
||||
z = (bb->z0 + bb->z1) / 2.0f;
|
||||
|
|
@ -665,16 +665,17 @@ void Entity::move(double xa, double ya, double za,
|
|||
double yaOrg = ya;
|
||||
double zaOrg = za;
|
||||
|
||||
AABB* bbOrg = bb->copy();
|
||||
AABB bbOrg = *bb;
|
||||
|
||||
bool isPlayerSneaking =
|
||||
onGround && isSneaking() && instanceof(eTYPE_PLAYER);
|
||||
|
||||
if (isPlayerSneaking) {
|
||||
double d = 0.05;
|
||||
|
||||
AABB translated_bb = bb->move(xa, -1.0, 0.0);
|
||||
while (xa != 0 &&
|
||||
level->getCubes(shared_from_this(), bb->cloneMove(xa, -1.0, 0))
|
||||
->empty()) {
|
||||
level->getCubes(shared_from_this(), &translated_bb)->empty()) {
|
||||
if (xa < d && xa >= -d)
|
||||
xa = 0;
|
||||
else if (xa > 0)
|
||||
|
|
@ -683,9 +684,10 @@ void Entity::move(double xa, double ya, double za,
|
|||
xa += d;
|
||||
xaOrg = xa;
|
||||
}
|
||||
|
||||
translated_bb = bb->move(0, -1.0, za);
|
||||
while (za != 0 &&
|
||||
level->getCubes(shared_from_this(), bb->cloneMove(0, -1.0, za))
|
||||
->empty()) {
|
||||
level->getCubes(shared_from_this(), &translated_bb)->empty()) {
|
||||
if (za < d && za >= -d)
|
||||
za = 0;
|
||||
else if (za > 0)
|
||||
|
|
@ -694,9 +696,10 @@ void Entity::move(double xa, double ya, double za,
|
|||
za += d;
|
||||
zaOrg = za;
|
||||
}
|
||||
|
||||
translated_bb = bb->move(xa, -1.0, za);
|
||||
while (xa != 0 && za != 0 &&
|
||||
level->getCubes(shared_from_this(), bb->cloneMove(xa, -1.0, za))
|
||||
->empty()) {
|
||||
level->getCubes(shared_from_this(), &translated_bb)->empty()) {
|
||||
if (xa < d && xa >= -d)
|
||||
xa = 0;
|
||||
else if (xa > 0)
|
||||
|
|
@ -714,8 +717,9 @@ void Entity::move(double xa, double ya, double za,
|
|||
}
|
||||
}
|
||||
|
||||
AABBList* aABBs = level->getCubes(
|
||||
shared_from_this(), bb->expand(xa, ya, za), noEntityCubes, true);
|
||||
AABB expanded = bb->expand(xa, ya, za);
|
||||
AABBList* aABBs =
|
||||
level->getCubes(shared_from_this(), &expanded, noEntityCubes, true);
|
||||
|
||||
// LAND FIRST, then x and z
|
||||
AUTO_VAR(itEndAABB, aABBs->end());
|
||||
|
|
@ -729,8 +733,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
|
||||
// be incorrect as well
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
ya = (*it)->clipYCollide(bb, ya);
|
||||
bb->move(0, ya, 0);
|
||||
ya = (*it)->clipYCollide(*bb, ya);
|
||||
*bb = bb->move(0, ya, 0);
|
||||
}
|
||||
|
||||
if (!slide && yaOrg != ya) {
|
||||
|
|
@ -741,9 +745,9 @@ void Entity::move(double xa, double ya, double za,
|
|||
|
||||
itEndAABB = aABBs->end();
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
xa = (*it)->clipXCollide(bb, xa);
|
||||
xa = (*it)->clipXCollide(*bb, xa);
|
||||
|
||||
bb->move(xa, 0, 0);
|
||||
*bb = bb->move(xa, 0, 0);
|
||||
|
||||
if (!slide && xaOrg != xa) {
|
||||
xa = ya = za = 0;
|
||||
|
|
@ -751,8 +755,8 @@ void Entity::move(double xa, double ya, double za,
|
|||
|
||||
itEndAABB = aABBs->end();
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
za = (*it)->clipZCollide(bb, za);
|
||||
bb->move(0, 0, za);
|
||||
za = (*it)->clipZCollide(*bb, za);
|
||||
*bb = bb->move(0, 0, za);
|
||||
|
||||
if (!slide && zaOrg != za) {
|
||||
xa = ya = za = 0;
|
||||
|
|
@ -768,15 +772,14 @@ void Entity::move(double xa, double ya, double za,
|
|||
ya = footSize;
|
||||
za = zaOrg;
|
||||
|
||||
AABB* normal = bb->copy();
|
||||
bb->set(bbOrg);
|
||||
AABB normal = *bb;
|
||||
*bb = bbOrg;
|
||||
// 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
|
||||
// much as footSize downwards, so we'd better include cubes under our
|
||||
// feet in this list of things we might possibly collide with
|
||||
aABBs = level->getCubes(shared_from_this(),
|
||||
bb->expand(xa, ya, za)->expand(0, -ya, 0),
|
||||
false, true);
|
||||
AABB expanded = bb->expand(xa, ya, za).expand(0, -ya, 0);
|
||||
aABBs = level->getCubes(shared_from_this(), &expanded, false, true);
|
||||
|
||||
// LAND FIRST, then x and z
|
||||
itEndAABB = aABBs->end();
|
||||
|
|
@ -786,8 +789,8 @@ void Entity::move(double xa, double ya, double za,
|
|||
// all! But if we don't have the chunk data then all the collision
|
||||
// info will be incorrect as well
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
ya = (*it)->clipYCollide(bb, ya);
|
||||
bb->move(0, ya, 0);
|
||||
ya = (*it)->clipYCollide(*bb, ya);
|
||||
*bb = bb->move(0, ya, 0);
|
||||
}
|
||||
|
||||
if (!slide && yaOrg != ya) {
|
||||
|
|
@ -796,8 +799,8 @@ void Entity::move(double xa, double ya, double za,
|
|||
|
||||
itEndAABB = aABBs->end();
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
xa = (*it)->clipXCollide(bb, xa);
|
||||
bb->move(xa, 0, 0);
|
||||
xa = (*it)->clipXCollide(*bb, xa);
|
||||
*bb = bb->move(xa, 0, 0);
|
||||
|
||||
if (!slide && xaOrg != xa) {
|
||||
xa = ya = za = 0;
|
||||
|
|
@ -805,8 +808,8 @@ void Entity::move(double xa, double ya, double za,
|
|||
|
||||
itEndAABB = aABBs->end();
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
za = (*it)->clipZCollide(bb, za);
|
||||
bb->move(0, 0, za);
|
||||
za = (*it)->clipZCollide(*bb, za);
|
||||
*bb = bb->move(0, 0, za);
|
||||
|
||||
if (!slide && zaOrg != za) {
|
||||
xa = ya = za = 0;
|
||||
|
|
@ -819,15 +822,15 @@ void Entity::move(double xa, double ya, double za,
|
|||
// LAND FIRST, then x and z
|
||||
itEndAABB = aABBs->end();
|
||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
||||
ya = (*it)->clipYCollide(bb, ya);
|
||||
bb->move(0, ya, 0);
|
||||
ya = (*it)->clipYCollide(*bb, ya);
|
||||
*bb = bb->move(0, ya, 0);
|
||||
}
|
||||
|
||||
if (xaN * xaN + zaN * zaN >= xa * xa + za * za) {
|
||||
xa = xaN;
|
||||
ya = yaN;
|
||||
za = zaN;
|
||||
bb->set(normal);
|
||||
*bb = normal;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -888,7 +891,8 @@ void Entity::move(double xa, double ya, double za,
|
|||
checkInsideTiles();
|
||||
|
||||
bool water = isInWaterOrRain();
|
||||
if (level->containsFireTile(bb->shrink(0.001, 0.001, 0.001))) {
|
||||
const AABB& shrunk = bb->shrink(0.001, 0.001, 0.001);
|
||||
if (level->containsFireTile(bb)) {
|
||||
burn(1);
|
||||
if (!water) {
|
||||
onFire++;
|
||||
|
|
@ -996,9 +1000,9 @@ bool Entity::isInWaterOrRain() {
|
|||
bool Entity::isInWater() { return wasInWater; }
|
||||
|
||||
bool Entity::updateInWaterState() {
|
||||
if (level->checkAndHandleWater(
|
||||
bb->grow(0, -0.4f, 0)->shrink(0.001, 0.001, 0.001), Material::water,
|
||||
shared_from_this())) {
|
||||
AABB shrunk = bb->grow(0, -0.4, 0).shrink(0.001, 0.001, 0.001);
|
||||
if (level->checkAndHandleWater(&shrunk, Material::water,
|
||||
shared_from_this())) {
|
||||
if (!wasInWater && !firstTick && canCreateParticles()) {
|
||||
float speed =
|
||||
Mth::sqrt(xd * xd * 0.2f + yd * yd + zd * zd * 0.2f) * 0.2f;
|
||||
|
|
@ -1048,8 +1052,8 @@ bool Entity::isUnderLiquid(Material* material) {
|
|||
float Entity::getHeadHeight() { return 0; }
|
||||
|
||||
bool Entity::isInLava() {
|
||||
return level->containsMaterial(bb->grow(-0.1f, -0.4f, -0.1f),
|
||||
Material::lava);
|
||||
AABB mat_bounds = bb->grow(-0.1, -0.4, -0.1);
|
||||
return level->containsMaterial(&mat_bounds, Material::lava);
|
||||
}
|
||||
|
||||
void Entity::moveRelative(float xa, float za, float speed) {
|
||||
|
|
@ -1516,8 +1520,8 @@ 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
|
||||
// intersect the geometry they land in slightly.
|
||||
if (GetType() != eTYPE_ARROW) {
|
||||
AABBList* collisions = level->getCubes(
|
||||
shared_from_this(), bb->shrink(1 / 32.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);
|
||||
if (!collisions->empty()) {
|
||||
double yTop = 0;
|
||||
AUTO_VAR(itEnd, collisions->end());
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ void HangingEntity::setDir(int dir) {
|
|||
float y1 = y + h + ss;
|
||||
float z0 = z - d - ss;
|
||||
float z1 = z + d + ss;
|
||||
bb->set(std::min(x0, x1), std::min(y0, y1), std::min(z0, z1),
|
||||
std::max(x0, x1), std::max(y0, y1), std::max(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)};
|
||||
}
|
||||
|
||||
float HangingEntity::offs(int w) {
|
||||
|
|
@ -253,4 +253,4 @@ void HangingEntity::readAdditionalSaveData(CompoundTag* tag) {
|
|||
setDir(dir);
|
||||
}
|
||||
|
||||
bool HangingEntity::repositionEntityAfterLoad() { return false; }
|
||||
bool HangingEntity::repositionEntityAfterLoad() { return false; }
|
||||
|
|
|
|||
|
|
@ -119,8 +119,9 @@ void ItemEntity::tick() {
|
|||
}
|
||||
|
||||
void ItemEntity::mergeWithNeighbours() {
|
||||
AABB grown = bb->grow(0.5, 0, 0.5);
|
||||
std::vector<std::shared_ptr<Entity> >* neighbours =
|
||||
level->getEntitiesOfClass(typeid(*this), bb->grow(0.5, 0, 0.5));
|
||||
level->getEntitiesOfClass(typeid(*this), &grown);
|
||||
for (AUTO_VAR(it, neighbours->begin()); it != neighbours->end(); ++it) {
|
||||
std::shared_ptr<ItemEntity> entity =
|
||||
std::dynamic_pointer_cast<ItemEntity>(*it);
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@ void LargeFireball::readAdditionalSaveData(CompoundTag* tag) {
|
|||
Fireball::readAdditionalSaveData(tag);
|
||||
if (tag->contains(L"ExplosionPower"))
|
||||
explosionPower = tag->getInt(L"ExplosionPower");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1164,7 +1164,7 @@ void LivingEntity::teleportTo(double x, double y, double z) {
|
|||
}
|
||||
|
||||
void LivingEntity::findStandUpPosition(std::shared_ptr<Entity> vehicle) {
|
||||
AABB* boundingBox;
|
||||
AABB boundingBox;
|
||||
double fallbackX = vehicle->x;
|
||||
double fallbackY = vehicle->bb->y0 + vehicle->bbHeight;
|
||||
double fallbackZ = vehicle->z;
|
||||
|
|
@ -1177,9 +1177,9 @@ void LivingEntity::findStandUpPosition(std::shared_ptr<Entity> vehicle) {
|
|||
|
||||
int xToInt = (int)(x + xDiff);
|
||||
int zToInt = (int)(z + zDiff);
|
||||
boundingBox = bb->cloneMove(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)) {
|
||||
teleportTo(x + xDiff, y + 1, z + zDiff);
|
||||
return;
|
||||
|
|
@ -1511,9 +1511,9 @@ void LivingEntity::aiStep() {
|
|||
// 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
|
||||
// pop up the sides of walls, undersides of trees etc.
|
||||
AABB* shrinkbb = bb->shrink(0.1, 0, 0.1);
|
||||
shrinkbb->y1 = shrinkbb->y0 + 0.1;
|
||||
AABBList* collisions = level->getCubes(shared_from_this(), shrinkbb);
|
||||
AABB shrinkbb = bb->shrink(0.1, 0, 0.1);
|
||||
shrinkbb.y1 = shrinkbb.y0 + 0.1;
|
||||
AABBList* collisions = level->getCubes(shared_from_this(), &shrinkbb);
|
||||
if (collisions->size() > 0) {
|
||||
double yTop = 0;
|
||||
AUTO_VAR(itEnd, collisions->end());
|
||||
|
|
@ -1582,8 +1582,9 @@ void LivingEntity::aiStep() {
|
|||
void LivingEntity::newServerAiStep() {}
|
||||
|
||||
void LivingEntity::pushEntities() {
|
||||
AABB grown = bb->grow(0.2, 0, 0.2);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
level->getEntities(shared_from_this(), this->bb->grow(0.2f, 0, 0.2f));
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
if (entities != NULL && !entities->empty()) {
|
||||
AUTO_VAR(itEnd, entities->end());
|
||||
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
|
||||
|
|
|
|||
|
|
@ -85,8 +85,9 @@ void MinecartHopper::tick() {
|
|||
bool MinecartHopper::suckInItems() {
|
||||
if (HopperTileEntity::suckInItems(this)) return true;
|
||||
|
||||
AABB grown = bb->grow(0.25, 0, 0.25);
|
||||
std::vector<std::shared_ptr<Entity> >* items =
|
||||
level->getEntitiesOfClass(typeid(ItemEntity), bb->grow(0.25f, 0, 0.25f),
|
||||
level->getEntitiesOfClass(typeid(ItemEntity), &grown,
|
||||
EntitySelector::ENTITY_STILL_ALIVE);
|
||||
|
||||
if (items->size() > 0) {
|
||||
|
|
@ -116,4 +117,4 @@ void MinecartHopper::readAdditionalSaveData(CompoundTag* base) {
|
|||
|
||||
void MinecartHopper::setCooldown(int time) { cooldownTime = time; }
|
||||
|
||||
bool MinecartHopper::isOnCooldown() { return cooldownTime > 0; }
|
||||
bool MinecartHopper::isOnCooldown() { return cooldownTime > 0; }
|
||||
|
|
|
|||
|
|
@ -301,8 +301,9 @@ void Mob::aiStep() {
|
|||
|
||||
if (!level->isClientSide && canPickUpLoot() && !dead &&
|
||||
level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) {
|
||||
AABB grown = bb->grow(1, 0, 1);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
level->getEntitiesOfClass(typeid(ItemEntity), bb->grow(1, 0, 1));
|
||||
level->getEntitiesOfClass(typeid(ItemEntity), &grown);
|
||||
for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) {
|
||||
std::shared_ptr<ItemEntity> entity =
|
||||
std::dynamic_pointer_cast<ItemEntity>(*it);
|
||||
|
|
@ -847,9 +848,10 @@ void Mob::restoreLeashFromSave() {
|
|||
if (_isLeashed && leashInfoTag != NULL) {
|
||||
if (leashInfoTag->contains(L"UUID")) {
|
||||
std::wstring leashUuid = leashInfoTag->getString(L"UUID");
|
||||
AABB grown = bb->grow(10, 10, 10);
|
||||
std::vector<std::shared_ptr<Entity> >* livingEnts =
|
||||
level->getEntitiesOfClass(typeid(LivingEntity),
|
||||
bb->grow(10, 10, 10));
|
||||
&grown);
|
||||
for (AUTO_VAR(it, livingEnts->begin()); it != livingEnts->end();
|
||||
++it) {
|
||||
std::shared_ptr<LivingEntity> le =
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ void Animal::aiStep() {
|
|||
|
||||
void Animal::checkHurtTarget(std::shared_ptr<Entity> target, float d) {
|
||||
// 4J-JEV: Changed from dynamic cast to use eINSTANCEOF
|
||||
if (target->instanceof (eTYPE_PLAYER)) {
|
||||
if (target->instanceof(eTYPE_PLAYER)) {
|
||||
if (d < 3) {
|
||||
double xd = target->x - x;
|
||||
double zd = target->z - z;
|
||||
|
|
@ -77,7 +77,7 @@ void Animal::checkHurtTarget(std::shared_ptr<Entity> target, float d) {
|
|||
|
||||
}
|
||||
// 4J-JEV: Changed from dynamic cast to use eINSTANCEOF
|
||||
else if (target->instanceof (eTYPE_ANIMAL)) {
|
||||
else if (target->instanceof(eTYPE_ANIMAL)) {
|
||||
std::shared_ptr<Animal> a = std::dynamic_pointer_cast<Animal>(target);
|
||||
if (getAge() > 0 && a->getAge() < 0) {
|
||||
if (d < 2.5) {
|
||||
|
|
@ -162,22 +162,22 @@ bool Animal::hurt(DamageSource* dmgSource, float dmg) {
|
|||
std::shared_ptr<Entity> source = dmgSource->getDirectEntity();
|
||||
|
||||
// 4J-JEV: Changed from dynamic cast to use eINSTANCEOF
|
||||
if (source->instanceof
|
||||
(eTYPE_PLAYER) && !std::dynamic_pointer_cast<Player>(source)
|
||||
->isAllowedToAttackAnimals()) {
|
||||
if (source->instanceof(eTYPE_PLAYER) &&
|
||||
!std::dynamic_pointer_cast<Player>(source)
|
||||
->isAllowedToAttackAnimals()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((source != NULL) && source->instanceof (eTYPE_ARROW)) {
|
||||
if ((source != NULL) && source->instanceof(eTYPE_ARROW)) {
|
||||
std::shared_ptr<Arrow> arrow =
|
||||
std::dynamic_pointer_cast<Arrow>(source);
|
||||
|
||||
// 4J: Check that the arrow's owner can attack animals (dispenser
|
||||
// arrows are not owned)
|
||||
if (arrow->owner != NULL && arrow->owner->instanceof
|
||||
(eTYPE_PLAYER) &&
|
||||
!std::dynamic_pointer_cast<Player>(arrow->owner)
|
||||
->isAllowedToAttackAnimals()) {
|
||||
if (arrow->owner != NULL &&
|
||||
arrow->owner->instanceof(eTYPE_PLAYER) &&
|
||||
!std::dynamic_pointer_cast<Player>(arrow->owner)
|
||||
->isAllowedToAttackAnimals()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -216,8 +216,9 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
|
|||
|
||||
float r = 8;
|
||||
if (getInLoveValue() > 0) {
|
||||
AABB grown = bb->grow(r, r, r);
|
||||
std::vector<std::shared_ptr<Entity> >* others =
|
||||
level->getEntitiesOfClass(typeid(*this), bb->grow(r, r, r));
|
||||
level->getEntitiesOfClass(typeid(*this), &grown);
|
||||
// for (int i = 0; i < others->size(); i++)
|
||||
for (AUTO_VAR(it, others->begin()); it != others->end(); ++it) {
|
||||
std::shared_ptr<Animal> p = std::dynamic_pointer_cast<Animal>(*it);
|
||||
|
|
@ -229,8 +230,9 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
|
|||
delete others;
|
||||
} else {
|
||||
if (getAge() == 0) {
|
||||
AABB grown = bb->grow(r, r, r);
|
||||
std::vector<std::shared_ptr<Entity> >* players =
|
||||
level->getEntitiesOfClass(typeid(Player), bb->grow(r, r, r));
|
||||
level->getEntitiesOfClass(typeid(Player), &grown);
|
||||
// for (int i = 0; i < players.size(); i++)
|
||||
for (AUTO_VAR(it, players->begin()); it != players->end(); ++it) {
|
||||
setDespawnProtected();
|
||||
|
|
@ -245,8 +247,9 @@ std::shared_ptr<Entity> Animal::findAttackTarget() {
|
|||
}
|
||||
delete players;
|
||||
} else if (getAge() > 0) {
|
||||
AABB grown = bb->grow(r, r, r);
|
||||
std::vector<std::shared_ptr<Entity> >* others =
|
||||
level->getEntitiesOfClass(typeid(*this), bb->grow(r, r, r));
|
||||
level->getEntitiesOfClass(typeid(*this), &grown);
|
||||
// for (int i = 0; i < others.size(); i++)
|
||||
for (AUTO_VAR(it, others->begin()); it != others->end(); ++it) {
|
||||
std::shared_ptr<Animal> p =
|
||||
|
|
@ -332,7 +335,7 @@ bool Animal::mobInteract(std::shared_ptr<Player> player) {
|
|||
|
||||
return false;
|
||||
}
|
||||
} else if (instanceof (eTYPE_MONSTER)) {
|
||||
} else if (instanceof(eTYPE_MONSTER)) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ void Arrow::tick() {
|
|||
Tile::tiles[t]->updateShape(level, xTile, yTile, zTile);
|
||||
AABB* aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile);
|
||||
Vec3 pos{x, y, z};
|
||||
if (aabb != NULL && aabb->contains(&pos)) {
|
||||
if (aabb != NULL && aabb->contains(pos)) {
|
||||
inGround = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -230,8 +230,9 @@ void Arrow::tick() {
|
|||
}
|
||||
|
||||
std::shared_ptr<Entity> hitEntity = nullptr;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
|
||||
shared_from_this(), this->bb->expand(xd, yd, zd)->grow(1, 1, 1));
|
||||
AABB grown = bb->expand(xd, yd, zd).grow(1, 1, 1);
|
||||
std::vector<std::shared_ptr<Entity> >* objects =
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
double nearest = 0;
|
||||
AUTO_VAR(itEnd, objects->end());
|
||||
for (AUTO_VAR(it, objects->begin()); it != itEnd; it++) {
|
||||
|
|
@ -239,8 +240,8 @@ void Arrow::tick() {
|
|||
if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
|
||||
|
||||
float rr = 0.3f;
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb->clip(&from, &to);
|
||||
AABB bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb.clip(from, to);
|
||||
if (p != NULL) {
|
||||
double dd = from.distanceTo(p->pos);
|
||||
if (dd < nearest || nearest == 0) {
|
||||
|
|
|
|||
|
|
@ -345,8 +345,9 @@ void Boat::tick() {
|
|||
|
||||
if (level->isClientSide) return;
|
||||
|
||||
AABB grown = bb->grow(0.2, 0, 0.2);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
level->getEntities(shared_from_this(), bb->grow(0.2f, 0, 0.2f));
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
if (entities != NULL && !entities->empty()) {
|
||||
AUTO_VAR(itEnd, entities->end());
|
||||
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ DragonFireball::DragonFireball(Level* level, double x, double y, double z,
|
|||
|
||||
void DragonFireball::onHit(HitResult* res) {
|
||||
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 =
|
||||
level->getEntitiesOfClass(typeid(LivingEntity), aoe);
|
||||
level->getEntitiesOfClass(typeid(LivingEntity), &aoe);
|
||||
|
||||
if (entitiesOfClass != NULL && !entitiesOfClass->empty()) {
|
||||
// for (Entity e : entitiesOfClass)
|
||||
|
|
|
|||
|
|
@ -646,12 +646,17 @@ void EnderDragon::aiStep() {
|
|||
|
||||
if (!level->isClientSide) checkAttack();
|
||||
if (!level->isClientSide && hurtDuration == 0) {
|
||||
AABB wing_mov = wing1->bb->grow(4, 2, 4).move(0, -2, 0);
|
||||
knockBack(level->getEntities(shared_from_this(),
|
||||
wing1->bb->grow(4, 2, 4)->move(0, -2, 0)));
|
||||
&wing_mov));
|
||||
wing_mov = wing2->bb->grow(4, 2, 4).move(0, -2, 0);
|
||||
knockBack(level->getEntities(shared_from_this(),
|
||||
wing2->bb->grow(4, 2, 4)->move(0, -2, 0)));
|
||||
hurt(level->getEntities(shared_from_this(), neck->bb->grow(1, 1, 1)));
|
||||
hurt(level->getEntities(shared_from_this(), head->bb->grow(1, 1, 1)));
|
||||
&wing_mov));
|
||||
|
||||
AABB neck_bb = neck->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(), &head_bb));
|
||||
}
|
||||
|
||||
double p1components[3];
|
||||
|
|
@ -684,8 +689,8 @@ void EnderDragon::aiStep() {
|
|||
double acidX = x + ss * 9.5f * ccTilt;
|
||||
double acidY = y + yOffset + ssTilt * 10.5f;
|
||||
double acidZ = z - cc * 9.5f * ccTilt;
|
||||
m_acidArea->set(acidX - 5, acidY - 17, acidZ - 5, acidX + 5, acidY + 4,
|
||||
acidZ + 5);
|
||||
*m_acidArea = {acidX - 5, acidY - 17, acidZ - 5, acidX + 5, acidY + 4,
|
||||
acidZ + 5};
|
||||
|
||||
// app.DebugPrintf("\nDragon is %s, yRot = %f, yRotA = %f, ss = %f, cc =
|
||||
// %f, ccTilt = %f\n",level->isClientSide?"client":"server", yRot,
|
||||
|
|
@ -811,9 +816,11 @@ void EnderDragon::checkCrystals() {
|
|||
|
||||
if (random->nextInt(10) == 0) {
|
||||
float maxDist = 32;
|
||||
AABB grown =
|
||||
bb->grow(maxDist, maxDist, maxDist);
|
||||
std::vector<std::shared_ptr<Entity> >* crystals =
|
||||
level->getEntitiesOfClass(typeid(EnderCrystal),
|
||||
bb->grow(maxDist, maxDist, maxDist));
|
||||
&grown);
|
||||
|
||||
std::shared_ptr<EnderCrystal> crystal = nullptr;
|
||||
double nearest = std::numeric_limits<double>::max();
|
||||
|
|
@ -1422,8 +1429,9 @@ EnderDragon::EEnderdragonAction EnderDragon::getSynchedAction() {
|
|||
void EnderDragon::handleCrystalDestroyed(DamageSource* source) {
|
||||
AABB* tempBB = AABB::newTemp(PODIUM_X_POS, 84.0, PODIUM_Z_POS,
|
||||
PODIUM_X_POS + 1.0, 85.0, PODIUM_Z_POS + 1.0);
|
||||
AABB grown = tempBB->grow(48, 40, 48);
|
||||
std::vector<std::shared_ptr<Entity> >* crystals = level->getEntitiesOfClass(
|
||||
typeid(EnderCrystal), tempBB->grow(48, 40, 48));
|
||||
typeid(EnderCrystal), &grown);
|
||||
m_remainingCrystalsCount = (int)crystals->size() - 1;
|
||||
if (m_remainingCrystalsCount < 0) m_remainingCrystalsCount = 0;
|
||||
delete crystals;
|
||||
|
|
|
|||
|
|
@ -420,9 +420,9 @@ std::shared_ptr<EntityHorse> EntityHorse::getClosestMommy(
|
|||
double closestDistance = std::numeric_limits<double>::max();
|
||||
|
||||
std::shared_ptr<Entity> mommy = nullptr;
|
||||
std::vector<std::shared_ptr<Entity> >* list = level->getEntities(
|
||||
baby, baby->bb->expand(searchRadius, searchRadius, searchRadius),
|
||||
PARENT_HORSE_SELECTOR);
|
||||
AABB expanded = baby->bb->expand(searchRadius, searchRadius, searchRadius);
|
||||
std::vector<std::shared_ptr<Entity> >* list =
|
||||
level->getEntities(baby, &expanded, PARENT_HORSE_SELECTOR);
|
||||
|
||||
for (AUTO_VAR(it, list->begin()); it != list->end(); ++it) {
|
||||
std::shared_ptr<Entity> horse = *it;
|
||||
|
|
|
|||
|
|
@ -176,8 +176,9 @@ void Fireball::tick() {
|
|||
to = Vec3{res->pos.x, res->pos.y, res->pos.z};
|
||||
}
|
||||
std::shared_ptr<Entity> hitEntity = nullptr;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
|
||||
shared_from_this(), 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 =
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
double nearest = 0;
|
||||
AUTO_VAR(itEnd, objects->end());
|
||||
for (AUTO_VAR(it, objects->begin()); it != itEnd; it++) {
|
||||
|
|
@ -187,8 +188,8 @@ void Fireball::tick() {
|
|||
// && flightTime < 25)) continue;
|
||||
|
||||
float rr = 0.3f;
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb->clip(&from, &to);
|
||||
AABB bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb.clip(from, to);
|
||||
if (p != NULL) {
|
||||
double dd = from.distanceTo(p->pos);
|
||||
if (dd < nearest || nearest == 0) {
|
||||
|
|
|
|||
|
|
@ -213,8 +213,9 @@ void FishingHook::tick() {
|
|||
to = Vec3(res->pos.x, res->pos.y, res->pos.z);
|
||||
}
|
||||
std::shared_ptr<Entity> hitEntity = nullptr;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
|
||||
shared_from_this(), 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 =
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
double nearest = 0;
|
||||
AUTO_VAR(itEnd, objects->end());
|
||||
for (AUTO_VAR(it, objects->begin()); it != itEnd; it++) {
|
||||
|
|
@ -222,8 +223,8 @@ void FishingHook::tick() {
|
|||
if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
|
||||
|
||||
float rr = 0.3f;
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb->clip(&from, &to);
|
||||
AABB bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb.clip(from, to);
|
||||
if (p != NULL) {
|
||||
double dd = from.distanceTo(p->pos);
|
||||
if (dd < nearest || nearest == 0) {
|
||||
|
|
|
|||
|
|
@ -170,10 +170,10 @@ bool Ghast::canReach(double xt, double yt, double zt, double dist) {
|
|||
double yd = (yTarget - y) / dist;
|
||||
double zd = (zTarget - z) / dist;
|
||||
|
||||
AABB* bb = this->bb->copy();
|
||||
AABB bb = *this->bb;
|
||||
for (int d = 1; d < dist; d++) {
|
||||
bb->move(xd, yd, zd);
|
||||
if (!level->getCubes(shared_from_this(), bb)->empty()) return false;
|
||||
bb.move(xd, yd, zd);
|
||||
if (!level->getCubes(shared_from_this(), &bb)->empty()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -305,8 +305,9 @@ void Minecart::tick() {
|
|||
}
|
||||
setRot(yRot, xRot);
|
||||
|
||||
AABB grown = bb->grow(0.2, 0, 0.2);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
level->getEntities(shared_from_this(), bb->grow(0.2f, 0, 0.2f));
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
if (entities != NULL && !entities->empty()) {
|
||||
AUTO_VAR(itEnd, entities->end());
|
||||
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
|
||||
|
|
|
|||
|
|
@ -100,8 +100,9 @@ std::shared_ptr<Entity> PigZombie::findAttackTarget() {
|
|||
bool PigZombie::hurt(DamageSource* source, float dmg) {
|
||||
std::shared_ptr<Entity> sourceEntity = source->getEntity();
|
||||
if (sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER)) {
|
||||
AABB grown = bb->grow(32, 32, 32);
|
||||
std::vector<std::shared_ptr<Entity> >* nearby =
|
||||
level->getEntities(shared_from_this(), bb->grow(32, 32, 32));
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
AUTO_VAR(itEnd, nearby->end());
|
||||
for (AUTO_VAR(it, nearby->begin()); it != itEnd; it++) {
|
||||
std::shared_ptr<Entity> e = *it; // nearby->at(i);
|
||||
|
|
@ -158,4 +159,4 @@ MobGroupData* PigZombie::finalizeMobSpawn(
|
|||
Zombie::finalizeMobSpawn(groupData);
|
||||
setVillager(false);
|
||||
return groupData;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ void Squid::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) {
|
|||
}
|
||||
|
||||
bool Squid::isInWater() {
|
||||
return level->checkAndHandleWater(bb->grow(0, -0.6f, 0), Material::water,
|
||||
AABB grown = bb->grow(0, -0.6, 0);
|
||||
return level->checkAndHandleWater(&grown, Material::water,
|
||||
shared_from_this());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ void ThrownPotion::onHit(HitResult* res) {
|
|||
Item::potion->getMobEffects(potionItem);
|
||||
|
||||
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 =
|
||||
level->getEntitiesOfClass(typeid(LivingEntity), aoe);
|
||||
level->getEntitiesOfClass(typeid(LivingEntity), &aoe);
|
||||
|
||||
if (entitiesOfClass != NULL && !entitiesOfClass->empty()) {
|
||||
// for (Entity e : entitiesOfClass)
|
||||
|
|
|
|||
|
|
@ -252,9 +252,9 @@ void WitherBoss::newServerAiStep() {
|
|||
idleHeadUpdates[i - 1] = 0;
|
||||
}
|
||||
} else {
|
||||
AABB grown = bb->grow(20, 8, 20);
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
level->getEntitiesOfClass(typeid(LivingEntity),
|
||||
bb->grow(20, 8, 20),
|
||||
level->getEntitiesOfClass(typeid(LivingEntity), &grown,
|
||||
livingEntitySelector);
|
||||
// randomly try to find a target 10 times
|
||||
for (int attempt = 0; attempt < 10 && !entities->empty();
|
||||
|
|
|
|||
|
|
@ -147,8 +147,9 @@ void Throwable::tick() {
|
|||
|
||||
if (!level->isClientSide) {
|
||||
std::shared_ptr<Entity> hitEntity = nullptr;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
|
||||
shared_from_this(), 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 =
|
||||
level->getEntities(shared_from_this(), &grown);
|
||||
double nearest = 0;
|
||||
std::shared_ptr<LivingEntity> owner = getOwner();
|
||||
for (int i = 0; i < objects->size(); i++) {
|
||||
|
|
@ -156,8 +157,8 @@ void Throwable::tick() {
|
|||
if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
|
||||
|
||||
float rr = 0.3f;
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb->clip(&from, &to);
|
||||
AABB bb = e->bb->grow(rr, rr, rr);
|
||||
HitResult* p = bb.clip(from, to);
|
||||
if (p != NULL) {
|
||||
double dd = from.distanceTo(p->pos);
|
||||
delete p;
|
||||
|
|
|
|||
|
|
@ -105,4 +105,4 @@ void WitherSkull::setDangerous(bool value) {
|
|||
entityData->set(DATA_DANGEROUS, value ? (uint8_t)1 : (uint8_t)0);
|
||||
}
|
||||
|
||||
bool WitherSkull::shouldBurn() { return false; }
|
||||
bool WitherSkull::shouldBurn() { return false; }
|
||||
|
|
|
|||
|
|
@ -83,17 +83,18 @@ std::shared_ptr<ItemInstance> BoatItem::use(
|
|||
Vec3 b = player->getViewVector(a);
|
||||
bool hitEntity = false;
|
||||
float overlap = 1;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
|
||||
player, player->bb->expand(b.x * (range), b.y * (range), b.z * (range))
|
||||
->grow(overlap, overlap, overlap));
|
||||
AABB grown = player->bb->expand(b.x * (range), b.y * (range), b.z * (range))
|
||||
.grow(overlap, overlap, overlap);
|
||||
std::vector<std::shared_ptr<Entity> >* objects =
|
||||
level->getEntities(player, &grown);
|
||||
// for (int i = 0; i < objects.size(); i++) {
|
||||
for (AUTO_VAR(it, objects->begin()); it != objects->end(); ++it) {
|
||||
std::shared_ptr<Entity> e = *it; // objects.get(i);
|
||||
if (!e->isPickable()) continue;
|
||||
|
||||
float rr = e->getPickRadius();
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
if (bb->contains(&from)) {
|
||||
AABB bb = e->bb->grow(rr, rr, rr);
|
||||
if (bb.contains(from)) {
|
||||
hitEntity = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -115,8 +116,8 @@ std::shared_ptr<ItemInstance> BoatItem::use(
|
|||
boat->yRot =
|
||||
((Mth::floor(player->yRot * 4.0F / 360.0F + 0.5) & 0x3) - 1) *
|
||||
90;
|
||||
if (!level->getCubes(boat, boat->bb->grow(-.1, -.1, -.1))
|
||||
->empty()) {
|
||||
AABB grown = boat->bb->grow(-0.1, -0.1, -0.1);
|
||||
if (!level->getCubes(boat, &grown)->empty()) {
|
||||
return itemInstance;
|
||||
}
|
||||
if (!level->isClientSide) {
|
||||
|
|
|
|||
|
|
@ -83,14 +83,13 @@ void BaseMobSpawner::tick() {
|
|||
EntityIO::newEntity(getEntityId(), getLevel());
|
||||
if (entity == NULL) return;
|
||||
|
||||
int nearBy =
|
||||
getLevel()
|
||||
->getEntitiesOfClass(
|
||||
typeid(entity.get()),
|
||||
AABB::newTemp(getX(), getY(), getZ(), getX() + 1,
|
||||
getY() + 1, getZ() + 1)
|
||||
->grow(spawnRange * 2, 4, spawnRange * 2))
|
||||
->size();
|
||||
AABB grown =
|
||||
AABB(getX(), getY(), getZ(), getX() + 1, getY() + 1, getZ() + 1)
|
||||
.grow(spawnRange * 2, 4, spawnRange * 2);
|
||||
|
||||
int nearBy = getLevel()
|
||||
->getEntitiesOfClass(typeid(entity.get()), &grown)
|
||||
->size();
|
||||
if (nearBy >= maxNearbyEntities) {
|
||||
delay();
|
||||
return;
|
||||
|
|
@ -359,4 +358,4 @@ CompoundTag* BaseMobSpawner::SpawnData::save() {
|
|||
result->putInt(L"Weight", randomWeight);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1798,17 +1798,18 @@ AABBList* Level::getCubes(std::shared_ptr<Entity> source, AABB* box,
|
|||
if (noEntities) return &boxes;
|
||||
|
||||
double r = 0.25;
|
||||
AABB grown = box->grow(r, r, r);
|
||||
std::vector<std::shared_ptr<Entity> >* ee =
|
||||
getEntities(source, box->grow(r, r, r));
|
||||
getEntities(source, &grown);
|
||||
std::vector<std::shared_ptr<Entity> >::iterator itEnd = ee->end();
|
||||
for (AUTO_VAR(it, ee->begin()); it != itEnd; it++) {
|
||||
AABB* collideBox = (*it)->getCollideBox();
|
||||
if (collideBox != NULL && collideBox->intersects(box)) {
|
||||
if (collideBox != NULL && collideBox->intersects(*box)) {
|
||||
boxes.push_back(collideBox);
|
||||
}
|
||||
|
||||
collideBox = source->getCollideAgainstBox(*it);
|
||||
if (collideBox != NULL && collideBox->intersects(box)) {
|
||||
if (collideBox != NULL && collideBox->intersects(*box)) {
|
||||
boxes.push_back(collideBox);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1691,7 +1691,7 @@ void LevelChunk::getEntities(std::shared_ptr<Entity> except, AABB* bb,
|
|||
AUTO_VAR(itEnd, entities->end());
|
||||
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
|
||||
std::shared_ptr<Entity> e = *it; // entities->at(i);
|
||||
if (e != except && e->bb->intersects(bb) &&
|
||||
if (e != except && e->bb->intersects(*bb) &&
|
||||
(selector == NULL || selector->matches(e))) {
|
||||
es.push_back(e);
|
||||
std::vector<std::shared_ptr<Entity> >* subs =
|
||||
|
|
@ -1699,7 +1699,7 @@ void LevelChunk::getEntities(std::shared_ptr<Entity> except, AABB* bb,
|
|||
if (subs != NULL) {
|
||||
for (int j = 0; j < subs->size(); j++) {
|
||||
e = subs->at(j);
|
||||
if (e != except && e->bb->intersects(bb) &&
|
||||
if (e != except && e->bb->intersects(*bb) &&
|
||||
(selector == NULL || selector->matches(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();
|
||||
entity != NULL && ec == typeid(*entity))
|
||||
isAssignableFrom = true;
|
||||
if (isAssignableFrom && e->bb->intersects(bb)) {
|
||||
if (isAssignableFrom && e->bb->intersects(*bb)) {
|
||||
if (selector == NULL || selector->matches(e)) {
|
||||
es.push_back(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -961,17 +961,17 @@ void Player::aiStep() {
|
|||
tilt += (tTilt - tilt) * 0.8f;
|
||||
|
||||
if (getHealth() > 0) {
|
||||
AABB* pickupArea = NULL;
|
||||
AABB pickupArea;
|
||||
if (riding != NULL && !riding->removed) {
|
||||
// if the player is riding, also touch entities under the
|
||||
// pig/horse
|
||||
pickupArea = bb->minmax(riding->bb)->grow(1, 0, 1);
|
||||
pickupArea = bb->minmax(*riding->bb).grow(1, 0, 1);
|
||||
} else {
|
||||
pickupArea = bb->grow(1, .5, 1);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Entity> >* entities =
|
||||
level->getEntities(shared_from_this(), pickupArea);
|
||||
level->getEntities(shared_from_this(), &pickupArea);
|
||||
if (entities != NULL) {
|
||||
AUTO_VAR(itEnd, entities->end());
|
||||
for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@
|
|||
// import java->util.ArrayList;
|
||||
// import java->util.List;
|
||||
|
||||
// TODO: use brace initialization everywhere
|
||||
|
||||
#include "../Platform/stdafx.h"
|
||||
#include "AABB.h"
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#include "HitResult.h"
|
||||
#include "Util/Vec3.h"
|
||||
|
|
@ -50,7 +53,7 @@ AABB* AABB::newTemp(double x0, double y0, double z0, double x1, double y1,
|
|||
double z1) {
|
||||
ThreadStorage* tls = m_tlsPool;
|
||||
AABB* thisAABB = &tls->pool[tls->poolPointer];
|
||||
thisAABB->set(x0, y0, z0, x1, y1, z1);
|
||||
*thisAABB = {x0, y0, z0, x1, y1, z1};
|
||||
tls->poolPointer = (tls->poolPointer + 1) % ThreadStorage::POOL_SIZE;
|
||||
return thisAABB;
|
||||
}
|
||||
|
|
@ -64,18 +67,7 @@ AABB::AABB(double x0, double y0, double z0, double x1, double y1, double z1) {
|
|||
this->z1 = z1;
|
||||
}
|
||||
|
||||
AABB* AABB::set(double x0, double y0, double z0, double x1, double y1,
|
||||
double z1) {
|
||||
this->x0 = x0;
|
||||
this->y0 = y0;
|
||||
this->z0 = z0;
|
||||
this->x1 = x1;
|
||||
this->y1 = y1;
|
||||
this->z1 = z1;
|
||||
return this;
|
||||
}
|
||||
|
||||
AABB* AABB::expand(double xa, double ya, double za) {
|
||||
AABB AABB::expand(double xa, double ya, double za) const {
|
||||
double _x0 = x0;
|
||||
double _y0 = y0;
|
||||
double _z0 = z0;
|
||||
|
|
@ -92,10 +84,10 @@ AABB* AABB::expand(double xa, double ya, double za) {
|
|||
if (za < 0) _z0 += za;
|
||||
if (za > 0) _z1 += za;
|
||||
|
||||
return AABB::newTemp(_x0, _y0, _z0, _x1, _y1, _z1);
|
||||
return {_x0, _y0, _z0, _x1, _y1, _z1};
|
||||
}
|
||||
|
||||
AABB* AABB::grow(double xa, double ya, double za) {
|
||||
AABB AABB::grow(const double xa, const double ya, const double za) const {
|
||||
double _x0 = x0 - xa;
|
||||
double _y0 = y0 - ya;
|
||||
double _z0 = z0 - za;
|
||||
|
|
@ -103,127 +95,121 @@ AABB* AABB::grow(double xa, double ya, double za) {
|
|||
double _y1 = y1 + ya;
|
||||
double _z1 = z1 + za;
|
||||
|
||||
return AABB::newTemp(_x0, _y0, _z0, _x1, _y1, _z1);
|
||||
return {_x0, _y0, _z0, _x1, _y1, _z1};
|
||||
}
|
||||
|
||||
AABB* AABB::minmax(AABB* other) {
|
||||
double _x0 = std::min(x0, other->x0);
|
||||
double _y0 = std::min(y0, other->y0);
|
||||
double _z0 = std::min(z0, other->z0);
|
||||
double _x1 = std::max(x1, other->x1);
|
||||
double _y1 = std::max(y1, other->y1);
|
||||
double _z1 = std::max(z1, other->z1);
|
||||
AABB AABB::minmax(const AABB& other) const {
|
||||
double _x0 = std::min(x0, other.x0);
|
||||
double _y0 = std::min(y0, other.y0);
|
||||
double _z0 = std::min(z0, other.z0);
|
||||
double _x1 = std::max(x1, other.x1);
|
||||
double _y1 = std::max(y1, other.y1);
|
||||
double _z1 = std::max(z1, other.z1);
|
||||
|
||||
return newTemp(_x0, _y0, _z0, _x1, _y1, _z1);
|
||||
return {_x0, _y0, _z0, _x1, _y1, _z1};
|
||||
}
|
||||
|
||||
AABB* AABB::cloneMove(double xa, double ya, double za) {
|
||||
return AABB::newTemp(x0 + xa, y0 + ya, z0 + za, x1 + xa, y1 + ya, z1 + za);
|
||||
}
|
||||
double AABB::clipXCollide(const AABB& c, double xa) const {
|
||||
if (c.y1 <= y0 || c.y0 >= y1) return xa;
|
||||
if (c.z1 <= z0 || c.z0 >= z1) return xa;
|
||||
|
||||
double AABB::clipXCollide(AABB* c, double xa) {
|
||||
if (c->y1 <= y0 || c->y0 >= y1) return xa;
|
||||
if (c->z1 <= z0 || c->z0 >= z1) return xa;
|
||||
|
||||
if (xa > 0 && c->x1 <= x0) {
|
||||
double max = x0 - c->x1;
|
||||
if (xa > 0 && c.x1 <= x0) {
|
||||
double max = x0 - c.x1;
|
||||
if (max < xa) xa = max;
|
||||
}
|
||||
if (xa < 0 && c->x0 >= x1) {
|
||||
double max = x1 - c->x0;
|
||||
|
||||
if (xa < 0 && c.x0 >= x1) {
|
||||
double max = x1 - c.x0;
|
||||
if (max > xa) xa = max;
|
||||
}
|
||||
|
||||
return xa;
|
||||
}
|
||||
|
||||
double AABB::clipYCollide(AABB* c, double ya) {
|
||||
if (c->x1 <= x0 || c->x0 >= x1) return ya;
|
||||
if (c->z1 <= z0 || c->z0 >= z1) return ya;
|
||||
double AABB::clipYCollide(const AABB& c, double ya) const {
|
||||
if (c.x1 <= x0 || c.x0 >= x1) return ya;
|
||||
if (c.z1 <= z0 || c.z0 >= z1) return ya;
|
||||
|
||||
if (ya > 0 && c->y1 <= y0) {
|
||||
double max = y0 - c->y1;
|
||||
if (ya > 0 && c.y1 <= y0) {
|
||||
double max = y0 - c.y1;
|
||||
if (max < ya) ya = max;
|
||||
}
|
||||
if (ya < 0 && c->y0 >= y1) {
|
||||
double max = y1 - c->y0;
|
||||
|
||||
if (ya < 0 && c.y0 >= y1) {
|
||||
double max = y1 - c.y0;
|
||||
if (max > ya) ya = max;
|
||||
}
|
||||
|
||||
return ya;
|
||||
}
|
||||
|
||||
double AABB::clipZCollide(AABB* c, double za) {
|
||||
if (c->x1 <= x0 || c->x0 >= x1) return za;
|
||||
if (c->y1 <= y0 || c->y0 >= y1) return za;
|
||||
double AABB::clipZCollide(const AABB& c, double za) const {
|
||||
if (c.x1 <= x0 || c.x0 >= x1) return za;
|
||||
if (c.y1 <= y0 || c.y0 >= y1) return za;
|
||||
|
||||
if (za > 0 && c->z1 <= z0) {
|
||||
double max = z0 - c->z1;
|
||||
if (za > 0 && c.z1 <= z0) {
|
||||
double max = z0 - c.z1;
|
||||
if (max < za) za = max;
|
||||
}
|
||||
if (za < 0 && c->z0 >= z1) {
|
||||
double max = z1 - c->z0;
|
||||
|
||||
if (za < 0 && c.z0 >= z1) {
|
||||
double max = z1 - c.z0;
|
||||
if (max > za) za = max;
|
||||
}
|
||||
|
||||
return za;
|
||||
}
|
||||
|
||||
bool AABB::intersects(AABB* c) {
|
||||
if (c->x1 <= x0 || c->x0 >= x1) return false;
|
||||
if (c->y1 <= y0 || c->y0 >= y1) return false;
|
||||
if (c->z1 <= z0 || c->z0 >= z1) return false;
|
||||
bool AABB::intersects(const AABB& c) const {
|
||||
if (c.x1 <= x0 || c.x0 >= x1) return false;
|
||||
if (c.y1 <= y0 || c.y0 >= y1) return false;
|
||||
if (c.z1 <= z0 || c.z0 >= z1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AABB::intersectsInner(AABB* c) {
|
||||
if (c->x1 < x0 || c->x0 > x1) return false;
|
||||
if (c->y1 < y0 || c->y0 > y1) return false;
|
||||
if (c->z1 < z0 || c->z0 > z1) return false;
|
||||
return true;
|
||||
AABB AABB::move(const double xa, const double ya, const double za) const {
|
||||
return {
|
||||
x0 + xa, y0 + ya, z0 + za,
|
||||
|
||||
x1 + xa, y1 + ya, z1 + za,
|
||||
};
|
||||
}
|
||||
|
||||
AABB* AABB::move(double xa, double ya, double za) {
|
||||
x0 += xa;
|
||||
y0 += ya;
|
||||
z0 += za;
|
||||
x1 += xa;
|
||||
y1 += ya;
|
||||
z1 += za;
|
||||
return this;
|
||||
}
|
||||
|
||||
bool AABB::intersects(double x02, double y02, double z02, double x12,
|
||||
double y12, double z12) {
|
||||
bool AABB::intersects(const double x02, const double y02, const double z02,
|
||||
const double x12, const double y12,
|
||||
const double z12) const {
|
||||
if (x12 <= x0 || x02 >= x1) return false;
|
||||
if (y12 <= y0 || y02 >= y1) return false;
|
||||
if (z12 <= z0 || z02 >= z1) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AABB::contains(Vec3* p) {
|
||||
if (p->x <= x0 || p->x >= x1) return false;
|
||||
if (p->y <= y0 || p->y >= y1) return false;
|
||||
if (p->z <= z0 || p->z >= z1) return false;
|
||||
bool AABB::contains(const Vec3& p) const {
|
||||
if (p.x <= x0 || p.x >= x1) return false;
|
||||
if (p.y <= y0 || p.y >= y1) return false;
|
||||
if (p.z <= z0 || p.z >= z1) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 4J Added
|
||||
bool AABB::containsIncludingLowerBound(Vec3* p) {
|
||||
if (p->x < x0 || p->x >= x1) return false;
|
||||
if (p->y < y0 || p->y >= y1) return false;
|
||||
if (p->z < z0 || p->z >= z1) return false;
|
||||
bool AABB::containsIncludingLowerBound(const Vec3& p) const {
|
||||
if (p.x < x0 || p.x >= x1) return false;
|
||||
if (p.y < y0 || p.y >= y1) return false;
|
||||
if (p.z < z0 || p.z >= z1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
double AABB::getSize() {
|
||||
double xs = x1 - x0;
|
||||
double ys = y1 - y0;
|
||||
double zs = z1 - z0;
|
||||
double AABB::getSize() const {
|
||||
const double xs = x1 - x0;
|
||||
const double ys = y1 - y0;
|
||||
const double zs = z1 - z0;
|
||||
|
||||
return (xs + ys + zs) / 3.0f;
|
||||
}
|
||||
|
||||
AABB* AABB::shrink(double xa, double ya, double za) {
|
||||
AABB AABB::shrink(const double xa, const double ya, const double za) const {
|
||||
double _x0 = x0 + xa;
|
||||
double _y0 = y0 + ya;
|
||||
double _z0 = z0 + za;
|
||||
|
|
@ -231,58 +217,50 @@ AABB* AABB::shrink(double xa, double ya, double za) {
|
|||
double _y1 = y1 - ya;
|
||||
double _z1 = z1 - za;
|
||||
|
||||
return AABB::newTemp(_x0, _y0, _z0, _x1, _y1, _z1);
|
||||
return {_x0, _y0, _z0, _x1, _y1, _z1};
|
||||
}
|
||||
|
||||
AABB* AABB::copy() { return AABB::newTemp(x0, y0, z0, x1, y1, z1); }
|
||||
HitResult* AABB::clip(const Vec3& a, const Vec3& b) const {
|
||||
auto xh0 = a.clipX(b, x0);
|
||||
auto xh1 = a.clipX(b, x1);
|
||||
|
||||
HitResult* AABB::clip(Vec3* a, Vec3* b) {
|
||||
auto xh0 = a->clipX(*b, x0);
|
||||
auto xh1 = a->clipX(*b, x1);
|
||||
auto yh0 = a.clipY(b, y0);
|
||||
auto yh1 = a.clipY(b, y1);
|
||||
|
||||
auto yh0 = a->clipY(*b, y0);
|
||||
auto yh1 = a->clipY(*b, y1);
|
||||
auto zh0 = a.clipZ(b, z0);
|
||||
auto zh1 = a.clipZ(b, z1);
|
||||
|
||||
auto zh0 = a->clipZ(*b, z0);
|
||||
auto zh1 = a->clipZ(*b, z1);
|
||||
|
||||
if (!(xh0.has_value() and containsX(&*xh0))) xh0 = std::nullopt;
|
||||
if (!(xh1.has_value() and containsX(&*xh1))) xh1 = std::nullopt;
|
||||
if (!(yh0.has_value() and containsY(&*yh0))) yh0 = std::nullopt;
|
||||
if (!(yh1.has_value() and containsY(&*yh1))) yh1 = std::nullopt;
|
||||
if (!(zh0.has_value() and containsZ(&*zh0))) zh0 = std::nullopt;
|
||||
if (!(zh1.has_value() and containsZ(&*zh1))) zh1 = std::nullopt;
|
||||
if (!(xh0.has_value() and containsX(*xh0))) xh0 = std::nullopt;
|
||||
if (!(xh1.has_value() and containsX(*xh1))) xh1 = std::nullopt;
|
||||
if (!(yh0.has_value() and containsY(*yh0))) yh0 = std::nullopt;
|
||||
if (!(yh1.has_value() and containsY(*yh1))) yh1 = std::nullopt;
|
||||
if (!(zh0.has_value() and containsZ(*zh0))) zh0 = std::nullopt;
|
||||
if (!(zh1.has_value() and containsZ(*zh1))) zh1 = std::nullopt;
|
||||
|
||||
std::optional<Vec3> closest = std::nullopt;
|
||||
|
||||
if (xh0.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*xh0) < a->distanceToSqr(*closest)))
|
||||
if (xh0.has_value() and (!closest.has_value() or
|
||||
a.distanceToSqr(*xh0) < a.distanceToSqr(*closest)))
|
||||
closest = xh0;
|
||||
|
||||
if (xh1.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*xh1) < a->distanceToSqr(*closest)))
|
||||
if (xh1.has_value() and (!closest.has_value() or
|
||||
a.distanceToSqr(*xh1) < a.distanceToSqr(*closest)))
|
||||
closest = xh1;
|
||||
|
||||
if (yh0.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*yh0) < a->distanceToSqr(*closest)))
|
||||
if (yh0.has_value() and (!closest.has_value() or
|
||||
a.distanceToSqr(*yh0) < a.distanceToSqr(*closest)))
|
||||
closest = yh0;
|
||||
|
||||
if (yh1.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*yh1) < a->distanceToSqr(*closest)))
|
||||
if (yh1.has_value() and (!closest.has_value() or
|
||||
a.distanceToSqr(*yh1) < a.distanceToSqr(*closest)))
|
||||
closest = yh1;
|
||||
|
||||
if (zh0.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*zh0) < a->distanceToSqr(*closest)))
|
||||
if (zh0.has_value() and (!closest.has_value() or
|
||||
a.distanceToSqr(*zh0) < a.distanceToSqr(*closest)))
|
||||
closest = zh0;
|
||||
|
||||
if (zh1.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*zh1) < a->distanceToSqr(*closest)))
|
||||
if (zh1.has_value() and (!closest.has_value() or
|
||||
a.distanceToSqr(*zh1) < a.distanceToSqr(*closest)))
|
||||
closest = zh1;
|
||||
|
||||
if (!closest.has_value()) return nullptr;
|
||||
|
|
@ -299,32 +277,18 @@ HitResult* AABB::clip(Vec3* a, Vec3* b) {
|
|||
return new HitResult(0, 0, 0, face, *closest);
|
||||
}
|
||||
|
||||
bool AABB::containsX(Vec3* v) {
|
||||
if (v == NULL) return false;
|
||||
return v->y >= y0 && v->y <= y1 && v->z >= z0 && v->z <= z1;
|
||||
bool AABB::containsX(const Vec3& v) const {
|
||||
return v.y >= y0 && v.y <= y1 && v.z >= z0 && v.z <= z1;
|
||||
}
|
||||
|
||||
bool AABB::containsY(Vec3* v) {
|
||||
if (v == NULL) return false;
|
||||
return v->x >= x0 && v->x <= x1 && v->z >= z0 && v->z <= z1;
|
||||
bool AABB::containsY(const Vec3& v) const {
|
||||
return v.x >= x0 && v.x <= x1 && v.z >= z0 && v.z <= z1;
|
||||
}
|
||||
|
||||
bool AABB::containsZ(Vec3* v) {
|
||||
if (v == NULL) return false;
|
||||
return v->x >= x0 && v->x <= x1 && v->y >= y0 && v->y <= y1;
|
||||
bool AABB::containsZ(const Vec3& v) const {
|
||||
return v.x >= x0 && v.x <= x1 && v.y >= y0 && v.y <= y1;
|
||||
}
|
||||
|
||||
void AABB::set(AABB* b) {
|
||||
x0 = b->x0;
|
||||
y0 = b->y0;
|
||||
z0 = b->z0;
|
||||
x1 = b->x1;
|
||||
y1 = b->y1;
|
||||
z1 = b->z1;
|
||||
}
|
||||
|
||||
std::wstring AABB::toString() {
|
||||
return L"box[" + _toString<double>(x0) + L", " + _toString<double>(y0) +
|
||||
L", " + _toString<double>(z0) + L" -> " + _toString<double>(x1) +
|
||||
L", " + _toString<double>(y1) + L", " + _toString<double>(z1) + L"]";
|
||||
std::wstring AABB::toString() const {
|
||||
return std::format(L"box[{}, {}, {}, {}, {}, {}]", x0, y0, z0, x1, y1, z1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,33 +36,27 @@ public:
|
|||
double x0, y0, z0;
|
||||
double x1, y1, z1;
|
||||
|
||||
private:
|
||||
AABB(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||
AABB() {}
|
||||
AABB(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||
|
||||
public:
|
||||
AABB* set(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||
AABB* expand(double xa, double ya, double za);
|
||||
AABB* grow(double xa, double ya, double za);
|
||||
AABB* minmax(AABB* other);
|
||||
AABB* cloneMove(double xa, double ya, double za);
|
||||
double clipXCollide(AABB* c, double xa);
|
||||
double clipYCollide(AABB* c, double ya);
|
||||
double clipZCollide(AABB* c, double za);
|
||||
bool intersects(AABB* c);
|
||||
bool intersectsInner(AABB* c);
|
||||
AABB* move(double xa, double ya, double za);
|
||||
AABB expand(double xa, double ya, double za) const;
|
||||
AABB grow(double xa, double ya, double za) const;
|
||||
AABB minmax(const AABB& other) const;
|
||||
double clipXCollide(const AABB& c, double xa) const;
|
||||
double clipYCollide(const AABB& c, double ya) const;
|
||||
double clipZCollide(const AABB& c, double za) const;
|
||||
bool intersects(const AABB& c) const;
|
||||
AABB move(double xa, double ya, double za) const;
|
||||
bool intersects(double x02, double y02, double z02, double x12, double y12,
|
||||
double z12);
|
||||
bool contains(Vec3* p);
|
||||
bool containsIncludingLowerBound(Vec3* p); // 4J Added
|
||||
double getSize();
|
||||
AABB* shrink(double xa, double ya, double za);
|
||||
AABB* copy();
|
||||
HitResult* clip(Vec3* a, Vec3* b);
|
||||
bool containsX(Vec3* v);
|
||||
bool containsY(Vec3* v);
|
||||
bool containsZ(Vec3* v);
|
||||
void set(AABB* b);
|
||||
std::wstring toString();
|
||||
double z12) const;
|
||||
bool contains(const Vec3& p) const;
|
||||
bool containsIncludingLowerBound(const Vec3& p) const; // 4J Added
|
||||
double getSize() const;
|
||||
AABB shrink(double xa, double ya, double za) const;
|
||||
HitResult* clip(const Vec3& a, const Vec3& b) const;
|
||||
bool containsX(const Vec3& v) const;
|
||||
bool containsY(const Vec3& v) const;
|
||||
bool containsZ(const Vec3& v) const;
|
||||
std::wstring toString() const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -150,8 +150,9 @@ void Vec3::zRot(const float degs) {
|
|||
|
||||
// Returns 0 if this point is within the box
|
||||
// Otherwise returns the distance to the box
|
||||
// TODO: rewrite this function
|
||||
double Vec3::distanceTo(AABB* box) {
|
||||
if (box->contains(this)) return 0;
|
||||
if (box->contains(*this)) return 0;
|
||||
|
||||
double xd = 0, yd = 0, zd = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -138,4 +138,4 @@ bool StructureStart::isValid() { return true; }
|
|||
|
||||
int StructureStart::getChunkX() { return chunkX; }
|
||||
|
||||
int StructureStart::getChunkZ() { return chunkZ; }
|
||||
int StructureStart::getChunkZ() { return chunkZ; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue