From 79217ca8e380a931f352b03242b5d68f97d3ddbf Mon Sep 17 00:00:00 2001 From: orng Date: Fri, 27 Mar 2026 21:11:11 -0500 Subject: [PATCH 1/9] refactor: modernize `AABB` class --- Minecraft.Client/Network/PlayerConnection.cpp | 11 +- .../ApplySchematicRuleDefinition.cpp | 4 +- .../Common/GameRules/ConsoleSchematicFile.cpp | 4 +- .../Common/Tutorial/AreaConstraint.cpp | 6 +- .../Platform/Common/Tutorial/AreaHint.cpp | 2 +- .../Common/Tutorial/ChangeStateConstraint.cpp | 6 +- Minecraft.Client/Rendering/Chunk.cpp | 4 +- Minecraft.Client/Rendering/GameRenderer.cpp | 17 +- Minecraft.Client/Rendering/LevelRenderer.cpp | 9 +- Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp | 3 +- Minecraft.World/AI/Goals/BreedGoal.cpp | 3 +- Minecraft.World/AI/Goals/FollowParentGoal.cpp | 4 +- Minecraft.World/AI/Goals/HurtByTargetGoal.cpp | 7 +- Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp | 3 +- Minecraft.World/AI/Goals/MakeLoveGoal.cpp | 3 +- .../AI/Goals/NearestAttackableTargetGoal.cpp | 3 +- Minecraft.World/AI/Goals/OfferFlowerGoal.cpp | 5 +- Minecraft.World/AI/Goals/PlayGoal.cpp | 3 +- Minecraft.World/AI/Goals/TakeFlowerGoal.cpp | 3 +- Minecraft.World/Blocks/Tile.cpp | 2 +- .../Blocks/TileEntities/BeaconTileEntity.cpp | 9 +- Minecraft.World/Entities/Entity.cpp | 96 +++---- Minecraft.World/Entities/HangingEntity.cpp | 6 +- Minecraft.World/Entities/ItemEntity.cpp | 3 +- Minecraft.World/Entities/LargeFireball.cpp | 2 +- Minecraft.World/Entities/LivingEntity.cpp | 15 +- Minecraft.World/Entities/MinecartHopper.cpp | 5 +- Minecraft.World/Entities/Mob.cpp | 6 +- Minecraft.World/Entities/Mobs/Animal.cpp | 31 ++- Minecraft.World/Entities/Mobs/Arrow.cpp | 11 +- Minecraft.World/Entities/Mobs/Boat.cpp | 3 +- .../Entities/Mobs/DragonFireball.cpp | 4 +- Minecraft.World/Entities/Mobs/EnderDragon.cpp | 24 +- Minecraft.World/Entities/Mobs/EntityHorse.cpp | 6 +- Minecraft.World/Entities/Mobs/Fireball.cpp | 9 +- Minecraft.World/Entities/Mobs/FishingHook.cpp | 9 +- Minecraft.World/Entities/Mobs/Ghast.cpp | 6 +- Minecraft.World/Entities/Mobs/Minecart.cpp | 3 +- Minecraft.World/Entities/Mobs/PigZombie.cpp | 5 +- Minecraft.World/Entities/Mobs/Squid.cpp | 3 +- .../Entities/Mobs/ThrownPotion.cpp | 4 +- Minecraft.World/Entities/Mobs/WitherBoss.cpp | 4 +- Minecraft.World/Entities/Throwable.cpp | 9 +- Minecraft.World/Entities/WitherSkull.cpp | 2 +- Minecraft.World/Items/BoatItem.cpp | 15 +- Minecraft.World/Level/BaseMobSpawner.cpp | 17 +- Minecraft.World/Level/Level.cpp | 7 +- Minecraft.World/Level/LevelChunk.cpp | 6 +- Minecraft.World/Player/Player.cpp | 6 +- Minecraft.World/Util/AABB.cpp | 242 ++++++++---------- Minecraft.World/Util/AABB.h | 44 ++-- Minecraft.World/Util/Vec3.cpp | 3 +- .../WorldGen/Structures/StructureStart.cpp | 2 +- 53 files changed, 362 insertions(+), 357 deletions(-) diff --git a/Minecraft.Client/Network/PlayerConnection.cpp b/Minecraft.Client/Network/PlayerConnection.cpp index 9f5e861e8..5a4d5d3d7 100644 --- a/Minecraft.Client/Network/PlayerConnection.cpp +++ b/Minecraft.Client/Network/PlayerConnection.cpp @@ -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) { diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp index b2304fbdd..dd91c027c 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp @@ -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); diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index 217a7ffb8..2409b12c9 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -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 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; } diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp index 016cc71ff..271275948 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp @@ -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); diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp index 87dc976bf..1eb6c1017 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp @@ -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)) { diff --git a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp index e1f93eecb..9efbd42c9 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp @@ -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); diff --git a/Minecraft.Client/Rendering/Chunk.cpp b/Minecraft.Client/Rendering/Chunk.cpp index fa311aed4..03dc40b8f 100644 --- a/Minecraft.Client/Rendering/Chunk.cpp +++ b/Minecraft.Client/Rendering/Chunk.cpp @@ -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; diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index d228b1030..b2f589b88 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -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 >* 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 >* 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; diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 722fcfbef..d412a7ede 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -2479,10 +2479,13 @@ void LevelRenderer::renderHitOutline(std::shared_ptr 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, diff --git a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp index 59045d029..cf595ea05 100644 --- a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp @@ -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 >* entities = mob->level->getEntitiesOfClass( - avoidType, mob->bb->grow(maxDist, 3, maxDist), entitySelector); + avoidType, &grown_bb, entitySelector); if (entities->empty()) { delete entities; return false; diff --git a/Minecraft.World/AI/Goals/BreedGoal.cpp b/Minecraft.World/AI/Goals/BreedGoal.cpp index 25281c61d..1ec4f59fc 100644 --- a/Minecraft.World/AI/Goals/BreedGoal.cpp +++ b/Minecraft.World/AI/Goals/BreedGoal.cpp @@ -48,8 +48,9 @@ void BreedGoal::tick() { std::shared_ptr BreedGoal::getFreePartner() { float r = 8; + AABB grown_bb = animal->bb->grow(r, r, r); std::vector >* others = - level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(r, r, r)); + level->getEntitiesOfClass(typeid(*animal), &grown_bb); double dist = std::numeric_limits::max(); std::shared_ptr partner = nullptr; for (AUTO_VAR(it, others->begin()); it != others->end(); ++it) { diff --git a/Minecraft.World/AI/Goals/FollowParentGoal.cpp b/Minecraft.World/AI/Goals/FollowParentGoal.cpp index d60dd34a9..0a740a35c 100644 --- a/Minecraft.World/AI/Goals/FollowParentGoal.cpp +++ b/Minecraft.World/AI/Goals/FollowParentGoal.cpp @@ -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 >* parents = - animal->level->getEntitiesOfClass(typeid(*animal), - animal->bb->grow(8, 4, 8)); + animal->level->getEntitiesOfClass(typeid(*animal), &grown_bb); std::shared_ptr closest = nullptr; double closestDistSqr = std::numeric_limits::max(); diff --git a/Minecraft.World/AI/Goals/HurtByTargetGoal.cpp b/Minecraft.World/AI/Goals/HurtByTargetGoal.cpp index 7bee32298..00a3e838d 100644 --- a/Minecraft.World/AI/Goals/HurtByTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/HurtByTargetGoal.cpp @@ -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 >* 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 other = std::dynamic_pointer_cast(*it); @@ -40,4 +39,4 @@ void HurtByTargetGoal::start() { } TargetGoal::start(); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp b/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp index 32cd4d1d6..b073212c2 100644 --- a/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp @@ -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(mob->level->getClosestEntityOfClass( - lookAtType, mob->bb->grow(lookDistance, 3, lookDistance), + lookAtType, &mob_bb, mob->shared_from_this())); } return lookAt.lock() != NULL; diff --git a/Minecraft.World/AI/Goals/MakeLoveGoal.cpp b/Minecraft.World/AI/Goals/MakeLoveGoal.cpp index 733036801..0357f7113 100644 --- a/Minecraft.World/AI/Goals/MakeLoveGoal.cpp +++ b/Minecraft.World/AI/Goals/MakeLoveGoal.cpp @@ -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 mate = level->getClosestEntityOfClass( - typeid(Villager), villager->bb->grow(8, 3, 8), + typeid(Villager), &villager_bb, villager->shared_from_this()); if (mate == NULL) return false; diff --git a/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp b/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp index a67f91cf9..938102d3e 100644 --- a/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp @@ -55,9 +55,10 @@ bool NearestAttackableTargetGoal::canUse() { return false; double within = getFollowDistance(); + AABB mob_bb = mob->bb->grow(within, 4, within); std::vector >* entities = mob->level->getEntitiesOfClass( - targetType, mob->bb->grow(within, 4, within), selector); + targetType, &mob_bb, selector); bool result = false; if (entities != NULL && !entities->empty()) { diff --git a/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp b/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp index 01c1b3dbf..902b221ee 100644 --- a/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp +++ b/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp @@ -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(std::dynamic_pointer_cast( 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; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/PlayGoal.cpp b/Minecraft.World/AI/Goals/PlayGoal.cpp index 0259d5c93..550f3bb6e 100644 --- a/Minecraft.World/AI/Goals/PlayGoal.cpp +++ b/Minecraft.World/AI/Goals/PlayGoal.cpp @@ -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 >* children = mob->level->getEntitiesOfClass(typeid(Villager), - mob->bb->grow(6, 3, 6)); + &mob_bb); double closestDistSqr = std::numeric_limits::max(); // for (Entity c : children) for (AUTO_VAR(it, children->begin()); it != children->end(); ++it) { diff --git a/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp b/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp index e7c5410c4..e4e9ed042 100644 --- a/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp +++ b/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp @@ -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 >* golems = villager->level->getEntitiesOfClass(typeid(VillagerGolem), - villager->bb->grow(6, 2, 6)); + &villager_bb); if (golems->size() == 0) { delete golems; return false; diff --git a/Minecraft.World/Blocks/Tile.cpp b/Minecraft.World/Blocks/Tile.cpp index d110d7e8a..a895238ef 100644 --- a/Minecraft.World/Blocks/Tile.cpp +++ b/Minecraft.World/Blocks/Tile.cpp @@ -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 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) { diff --git a/Minecraft.World/Blocks/TileEntities/BeaconTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/BeaconTileEntity.cpp index 5b160f153..738303f3c 100644 --- a/Minecraft.World/Blocks/TileEntities/BeaconTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/BeaconTileEntity.cpp @@ -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 >* 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 = std::dynamic_pointer_cast(*it); @@ -299,4 +298,4 @@ bool BeaconTileEntity::canPlaceItem(int slot, std::shared_ptr item) { return (item->id == Item::emerald_Id || item->id == Item::diamond_Id || item->id == Item::goldIngot_Id || item->id == Item::ironIngot_Id); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Entity.cpp b/Minecraft.World/Entities/Entity.cpp index 51ed60e8f..191789eb8 100644 --- a/Minecraft.World/Entities/Entity.cpp +++ b/Minecraft.World/Entities/Entity.cpp @@ -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()); diff --git a/Minecraft.World/Entities/HangingEntity.cpp b/Minecraft.World/Entities/HangingEntity.cpp index d67329209..b94d8fdf1 100644 --- a/Minecraft.World/Entities/HangingEntity.cpp +++ b/Minecraft.World/Entities/HangingEntity.cpp @@ -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; } \ No newline at end of file +bool HangingEntity::repositionEntityAfterLoad() { return false; } diff --git a/Minecraft.World/Entities/ItemEntity.cpp b/Minecraft.World/Entities/ItemEntity.cpp index 8725cbe5f..880971f67 100644 --- a/Minecraft.World/Entities/ItemEntity.cpp +++ b/Minecraft.World/Entities/ItemEntity.cpp @@ -119,8 +119,9 @@ void ItemEntity::tick() { } void ItemEntity::mergeWithNeighbours() { + AABB grown = bb->grow(0.5, 0, 0.5); std::vector >* 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 entity = std::dynamic_pointer_cast(*it); diff --git a/Minecraft.World/Entities/LargeFireball.cpp b/Minecraft.World/Entities/LargeFireball.cpp index 81677498d..5c2eb50a6 100644 --- a/Minecraft.World/Entities/LargeFireball.cpp +++ b/Minecraft.World/Entities/LargeFireball.cpp @@ -44,4 +44,4 @@ void LargeFireball::readAdditionalSaveData(CompoundTag* tag) { Fireball::readAdditionalSaveData(tag); if (tag->contains(L"ExplosionPower")) explosionPower = tag->getInt(L"ExplosionPower"); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/LivingEntity.cpp b/Minecraft.World/Entities/LivingEntity.cpp index b4b870baf..8725643cf 100644 --- a/Minecraft.World/Entities/LivingEntity.cpp +++ b/Minecraft.World/Entities/LivingEntity.cpp @@ -1164,7 +1164,7 @@ void LivingEntity::teleportTo(double x, double y, double z) { } void LivingEntity::findStandUpPosition(std::shared_ptr 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 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 >* 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++) { diff --git a/Minecraft.World/Entities/MinecartHopper.cpp b/Minecraft.World/Entities/MinecartHopper.cpp index 55b7ed3aa..43707b810 100644 --- a/Minecraft.World/Entities/MinecartHopper.cpp +++ b/Minecraft.World/Entities/MinecartHopper.cpp @@ -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 >* 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; } \ No newline at end of file +bool MinecartHopper::isOnCooldown() { return cooldownTime > 0; } diff --git a/Minecraft.World/Entities/Mob.cpp b/Minecraft.World/Entities/Mob.cpp index 6b744faf8..b7fe61e1a 100644 --- a/Minecraft.World/Entities/Mob.cpp +++ b/Minecraft.World/Entities/Mob.cpp @@ -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 >* 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 entity = std::dynamic_pointer_cast(*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 >* livingEnts = level->getEntitiesOfClass(typeid(LivingEntity), - bb->grow(10, 10, 10)); + &grown); for (AUTO_VAR(it, livingEnts->begin()); it != livingEnts->end(); ++it) { std::shared_ptr le = diff --git a/Minecraft.World/Entities/Mobs/Animal.cpp b/Minecraft.World/Entities/Mobs/Animal.cpp index b404a0102..8df5245d2 100644 --- a/Minecraft.World/Entities/Mobs/Animal.cpp +++ b/Minecraft.World/Entities/Mobs/Animal.cpp @@ -61,7 +61,7 @@ void Animal::aiStep() { void Animal::checkHurtTarget(std::shared_ptr 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 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 a = std::dynamic_pointer_cast(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 source = dmgSource->getDirectEntity(); // 4J-JEV: Changed from dynamic cast to use eINSTANCEOF - if (source->instanceof - (eTYPE_PLAYER) && !std::dynamic_pointer_cast(source) - ->isAllowedToAttackAnimals()) { + if (source->instanceof(eTYPE_PLAYER) && + !std::dynamic_pointer_cast(source) + ->isAllowedToAttackAnimals()) { return false; } - if ((source != NULL) && source->instanceof (eTYPE_ARROW)) { + if ((source != NULL) && source->instanceof(eTYPE_ARROW)) { std::shared_ptr arrow = std::dynamic_pointer_cast(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(arrow->owner) - ->isAllowedToAttackAnimals()) { + if (arrow->owner != NULL && + arrow->owner->instanceof(eTYPE_PLAYER) && + !std::dynamic_pointer_cast(arrow->owner) + ->isAllowedToAttackAnimals()) { return false; } } @@ -216,8 +216,9 @@ std::shared_ptr Animal::findAttackTarget() { float r = 8; if (getInLoveValue() > 0) { + AABB grown = bb->grow(r, r, r); std::vector >* 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 p = std::dynamic_pointer_cast(*it); @@ -229,8 +230,9 @@ std::shared_ptr Animal::findAttackTarget() { delete others; } else { if (getAge() == 0) { + AABB grown = bb->grow(r, r, r); std::vector >* 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 Animal::findAttackTarget() { } delete players; } else if (getAge() > 0) { + AABB grown = bb->grow(r, r, r); std::vector >* 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 p = @@ -332,7 +335,7 @@ bool Animal::mobInteract(std::shared_ptr player) { return false; } - } else if (instanceof (eTYPE_MONSTER)) { + } else if (instanceof(eTYPE_MONSTER)) { } break; } diff --git a/Minecraft.World/Entities/Mobs/Arrow.cpp b/Minecraft.World/Entities/Mobs/Arrow.cpp index 5de30c9a4..6c02a0eea 100644 --- a/Minecraft.World/Entities/Mobs/Arrow.cpp +++ b/Minecraft.World/Entities/Mobs/Arrow.cpp @@ -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 hitEntity = nullptr; - std::vector >* 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 >* 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) { diff --git a/Minecraft.World/Entities/Mobs/Boat.cpp b/Minecraft.World/Entities/Mobs/Boat.cpp index 356dacf57..f379b068e 100644 --- a/Minecraft.World/Entities/Mobs/Boat.cpp +++ b/Minecraft.World/Entities/Mobs/Boat.cpp @@ -345,8 +345,9 @@ void Boat::tick() { if (level->isClientSide) return; + AABB grown = bb->grow(0.2, 0, 0.2); std::vector >* 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++) { diff --git a/Minecraft.World/Entities/Mobs/DragonFireball.cpp b/Minecraft.World/Entities/Mobs/DragonFireball.cpp index 62f4a067c..11607882a 100644 --- a/Minecraft.World/Entities/Mobs/DragonFireball.cpp +++ b/Minecraft.World/Entities/Mobs/DragonFireball.cpp @@ -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 >* entitiesOfClass = - level->getEntitiesOfClass(typeid(LivingEntity), aoe); + level->getEntitiesOfClass(typeid(LivingEntity), &aoe); if (entitiesOfClass != NULL && !entitiesOfClass->empty()) { // for (Entity e : entitiesOfClass) diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index 4625557e2..7f9697bc3 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -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 >* crystals = level->getEntitiesOfClass(typeid(EnderCrystal), - bb->grow(maxDist, maxDist, maxDist)); + &grown); std::shared_ptr crystal = nullptr; double nearest = std::numeric_limits::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 >* 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; diff --git a/Minecraft.World/Entities/Mobs/EntityHorse.cpp b/Minecraft.World/Entities/Mobs/EntityHorse.cpp index 65502c329..cd2563466 100644 --- a/Minecraft.World/Entities/Mobs/EntityHorse.cpp +++ b/Minecraft.World/Entities/Mobs/EntityHorse.cpp @@ -420,9 +420,9 @@ std::shared_ptr EntityHorse::getClosestMommy( double closestDistance = std::numeric_limits::max(); std::shared_ptr mommy = nullptr; - std::vector >* list = level->getEntities( - baby, baby->bb->expand(searchRadius, searchRadius, searchRadius), - PARENT_HORSE_SELECTOR); + AABB expanded = baby->bb->expand(searchRadius, searchRadius, searchRadius); + std::vector >* list = + level->getEntities(baby, &expanded, PARENT_HORSE_SELECTOR); for (AUTO_VAR(it, list->begin()); it != list->end(); ++it) { std::shared_ptr horse = *it; diff --git a/Minecraft.World/Entities/Mobs/Fireball.cpp b/Minecraft.World/Entities/Mobs/Fireball.cpp index 91bfe34f7..b6613549c 100644 --- a/Minecraft.World/Entities/Mobs/Fireball.cpp +++ b/Minecraft.World/Entities/Mobs/Fireball.cpp @@ -176,8 +176,9 @@ void Fireball::tick() { to = Vec3{res->pos.x, res->pos.y, res->pos.z}; } std::shared_ptr hitEntity = nullptr; - std::vector >* 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 >* 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) { diff --git a/Minecraft.World/Entities/Mobs/FishingHook.cpp b/Minecraft.World/Entities/Mobs/FishingHook.cpp index b8cc293bf..76a4d5b07 100644 --- a/Minecraft.World/Entities/Mobs/FishingHook.cpp +++ b/Minecraft.World/Entities/Mobs/FishingHook.cpp @@ -213,8 +213,9 @@ void FishingHook::tick() { to = Vec3(res->pos.x, res->pos.y, res->pos.z); } std::shared_ptr hitEntity = nullptr; - std::vector >* 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 >* 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) { diff --git a/Minecraft.World/Entities/Mobs/Ghast.cpp b/Minecraft.World/Entities/Mobs/Ghast.cpp index 6dedd39ef..40c65a43c 100644 --- a/Minecraft.World/Entities/Mobs/Ghast.cpp +++ b/Minecraft.World/Entities/Mobs/Ghast.cpp @@ -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; diff --git a/Minecraft.World/Entities/Mobs/Minecart.cpp b/Minecraft.World/Entities/Mobs/Minecart.cpp index 8f0350096..16dcbb183 100644 --- a/Minecraft.World/Entities/Mobs/Minecart.cpp +++ b/Minecraft.World/Entities/Mobs/Minecart.cpp @@ -305,8 +305,9 @@ void Minecart::tick() { } setRot(yRot, xRot); + AABB grown = bb->grow(0.2, 0, 0.2); std::vector >* 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++) { diff --git a/Minecraft.World/Entities/Mobs/PigZombie.cpp b/Minecraft.World/Entities/Mobs/PigZombie.cpp index e619286cb..0c016c83f 100644 --- a/Minecraft.World/Entities/Mobs/PigZombie.cpp +++ b/Minecraft.World/Entities/Mobs/PigZombie.cpp @@ -100,8 +100,9 @@ std::shared_ptr PigZombie::findAttackTarget() { bool PigZombie::hurt(DamageSource* source, float dmg) { std::shared_ptr sourceEntity = source->getEntity(); if (sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER)) { + AABB grown = bb->grow(32, 32, 32); std::vector >* 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 e = *it; // nearby->at(i); @@ -158,4 +159,4 @@ MobGroupData* PigZombie::finalizeMobSpawn( Zombie::finalizeMobSpawn(groupData); setVillager(false); return groupData; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Squid.cpp b/Minecraft.World/Entities/Mobs/Squid.cpp index 951d7b511..7cb96c08d 100644 --- a/Minecraft.World/Entities/Mobs/Squid.cpp +++ b/Minecraft.World/Entities/Mobs/Squid.cpp @@ -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()); } diff --git a/Minecraft.World/Entities/Mobs/ThrownPotion.cpp b/Minecraft.World/Entities/Mobs/ThrownPotion.cpp index 7bfc9cf6a..da329189c 100644 --- a/Minecraft.World/Entities/Mobs/ThrownPotion.cpp +++ b/Minecraft.World/Entities/Mobs/ThrownPotion.cpp @@ -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 >* entitiesOfClass = - level->getEntitiesOfClass(typeid(LivingEntity), aoe); + level->getEntitiesOfClass(typeid(LivingEntity), &aoe); if (entitiesOfClass != NULL && !entitiesOfClass->empty()) { // for (Entity e : entitiesOfClass) diff --git a/Minecraft.World/Entities/Mobs/WitherBoss.cpp b/Minecraft.World/Entities/Mobs/WitherBoss.cpp index 092e810ea..80316042e 100644 --- a/Minecraft.World/Entities/Mobs/WitherBoss.cpp +++ b/Minecraft.World/Entities/Mobs/WitherBoss.cpp @@ -252,9 +252,9 @@ void WitherBoss::newServerAiStep() { idleHeadUpdates[i - 1] = 0; } } else { + AABB grown = bb->grow(20, 8, 20); std::vector >* 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(); diff --git a/Minecraft.World/Entities/Throwable.cpp b/Minecraft.World/Entities/Throwable.cpp index 93e9a9701..056129287 100644 --- a/Minecraft.World/Entities/Throwable.cpp +++ b/Minecraft.World/Entities/Throwable.cpp @@ -147,8 +147,9 @@ void Throwable::tick() { if (!level->isClientSide) { std::shared_ptr hitEntity = nullptr; - std::vector >* 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 >* objects = + level->getEntities(shared_from_this(), &grown); double nearest = 0; std::shared_ptr 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; diff --git a/Minecraft.World/Entities/WitherSkull.cpp b/Minecraft.World/Entities/WitherSkull.cpp index 81a6a4cca..049309c04 100644 --- a/Minecraft.World/Entities/WitherSkull.cpp +++ b/Minecraft.World/Entities/WitherSkull.cpp @@ -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; } \ No newline at end of file +bool WitherSkull::shouldBurn() { return false; } diff --git a/Minecraft.World/Items/BoatItem.cpp b/Minecraft.World/Items/BoatItem.cpp index d84290919..0c4d6a1b9 100644 --- a/Minecraft.World/Items/BoatItem.cpp +++ b/Minecraft.World/Items/BoatItem.cpp @@ -83,17 +83,18 @@ std::shared_ptr BoatItem::use( Vec3 b = player->getViewVector(a); bool hitEntity = false; float overlap = 1; - std::vector >* 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 >* 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 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 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) { diff --git a/Minecraft.World/Level/BaseMobSpawner.cpp b/Minecraft.World/Level/BaseMobSpawner.cpp index 522290eec..bf6fcb51c 100644 --- a/Minecraft.World/Level/BaseMobSpawner.cpp +++ b/Minecraft.World/Level/BaseMobSpawner.cpp @@ -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; -} \ No newline at end of file +} diff --git a/Minecraft.World/Level/Level.cpp b/Minecraft.World/Level/Level.cpp index f61f88c8b..cd572cbf7 100644 --- a/Minecraft.World/Level/Level.cpp +++ b/Minecraft.World/Level/Level.cpp @@ -1798,17 +1798,18 @@ AABBList* Level::getCubes(std::shared_ptr source, AABB* box, if (noEntities) return &boxes; double r = 0.25; + AABB grown = box->grow(r, r, r); std::vector >* ee = - getEntities(source, box->grow(r, r, r)); + getEntities(source, &grown); std::vector >::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); } } diff --git a/Minecraft.World/Level/LevelChunk.cpp b/Minecraft.World/Level/LevelChunk.cpp index 71c285e5c..c5c0632ef 100644 --- a/Minecraft.World/Level/LevelChunk.cpp +++ b/Minecraft.World/Level/LevelChunk.cpp @@ -1691,7 +1691,7 @@ void LevelChunk::getEntities(std::shared_ptr except, AABB* bb, AUTO_VAR(itEnd, entities->end()); for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) { std::shared_ptr 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 >* subs = @@ -1699,7 +1699,7 @@ void LevelChunk::getEntities(std::shared_ptr 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); } diff --git a/Minecraft.World/Player/Player.cpp b/Minecraft.World/Player/Player.cpp index a345d2087..fff23c15e 100644 --- a/Minecraft.World/Player/Player.cpp +++ b/Minecraft.World/Player/Player.cpp @@ -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 >* 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++) { diff --git a/Minecraft.World/Util/AABB.cpp b/Minecraft.World/Util/AABB.cpp index 2cb797e38..53b4412f3 100644 --- a/Minecraft.World/Util/AABB.cpp +++ b/Minecraft.World/Util/AABB.cpp @@ -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 #include #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 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(x0) + L", " + _toString(y0) + - L", " + _toString(z0) + L" -> " + _toString(x1) + - L", " + _toString(y1) + L", " + _toString(z1) + L"]"; +std::wstring AABB::toString() const { + return std::format(L"box[{}, {}, {}, {}, {}, {}]", x0, y0, z0, x1, y1, z1); } diff --git a/Minecraft.World/Util/AABB.h b/Minecraft.World/Util/AABB.h index 205d5ac98..975f6ebcd 100644 --- a/Minecraft.World/Util/AABB.h +++ b/Minecraft.World/Util/AABB.h @@ -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; }; diff --git a/Minecraft.World/Util/Vec3.cpp b/Minecraft.World/Util/Vec3.cpp index 810456f27..00718fabe 100644 --- a/Minecraft.World/Util/Vec3.cpp +++ b/Minecraft.World/Util/Vec3.cpp @@ -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; diff --git a/Minecraft.World/WorldGen/Structures/StructureStart.cpp b/Minecraft.World/WorldGen/Structures/StructureStart.cpp index 9bcb12777..d378e9c33 100644 --- a/Minecraft.World/WorldGen/Structures/StructureStart.cpp +++ b/Minecraft.World/WorldGen/Structures/StructureStart.cpp @@ -138,4 +138,4 @@ bool StructureStart::isValid() { return true; } int StructureStart::getChunkX() { return chunkX; } -int StructureStart::getChunkZ() { return chunkZ; } \ No newline at end of file +int StructureStart::getChunkZ() { return chunkZ; } From 534879e2e74af790907190b0b05717bcb16c5111 Mon Sep 17 00:00:00 2001 From: orng Date: Fri, 27 Mar 2026 21:17:55 -0500 Subject: [PATCH 2/9] refactor: replace `AABB::newPermanent` with `new AABB` --- .../Common/GameRules/ApplySchematicRuleDefinition.cpp | 2 +- .../Platform/Common/GameRules/NamedAreaRuleDefinition.cpp | 2 +- Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp | 4 ++-- Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp | 2 +- .../Platform/Common/Tutorial/ChangeStateConstraint.cpp | 2 +- Minecraft.Client/Rendering/Chunk.cpp | 2 +- Minecraft.Client/Rendering/LevelRenderer.cpp | 2 +- Minecraft.World/Entities/Entity.cpp | 2 +- Minecraft.World/Entities/Mobs/EnderDragon.cpp | 2 +- Minecraft.World/Util/AABB.cpp | 5 ----- Minecraft.World/Util/AABB.h | 2 -- 11 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp index dd91c027c..f2c5b4360 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp @@ -130,7 +130,7 @@ void ApplySchematicRuleDefinition::updateLocationBox() { if (m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); - m_locationBox = AABB::newPermanent(0, 0, 0, 0, 0, 0); + m_locationBox = new AABB(0, 0, 0, 0, 0, 0); m_locationBox->x0 = m_location.x; m_locationBox->y0 = m_location.y; diff --git a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp index b09982ae9..aefc12453 100644 --- a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp @@ -5,7 +5,7 @@ NamedAreaRuleDefinition::NamedAreaRuleDefinition() { m_name = L""; - m_area = AABB::newPermanent(0, 0, 0, 0, 0, 0); + m_area = new AABB(0, 0, 0, 0, 0, 0); } NamedAreaRuleDefinition::~NamedAreaRuleDefinition() { delete m_area; } diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp index 271275948..36c53aa47 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp @@ -11,8 +11,8 @@ AreaConstraint::AreaConstraint(int descriptionId, double x0, double y0, bool restrictsMovement /*=true*/) : TutorialConstraint(descriptionId) { messageArea = - AABB::newPermanent(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2); - movementArea = AABB::newPermanent(x0, y0, z0, x1, y1, z1); + new AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2); + movementArea = new AABB(x0, y0, z0, x1, y1, z1); this->contains = contains; m_restrictsMovement = restrictsMovement; diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp index 1eb6c1017..b6bae48d3 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp @@ -12,7 +12,7 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial, double x1, double y1, double z1, bool allowFade /*= false*/, bool contains /*= true*/) : TutorialHint(id, tutorial, descriptionId, e_Hint_Area, allowFade) { - area = AABB::newPermanent(x0, y0, z0, x1, y1, z1); + area = new AABB(x0, y0, z0, x1, y1, z1); this->contains = contains; diff --git a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp index 9efbd42c9..5934505e8 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp @@ -16,7 +16,7 @@ ChangeStateConstraint::ChangeStateConstraint( bool contains /*= true*/, bool changeGameMode /*= false*/, GameType* targetGameMode /*= 0*/) : TutorialConstraint(-1) { - movementArea = AABB::newPermanent(x0, y0, z0, x1, y1, z1); + movementArea = new AABB(x0, y0, z0, x1, y1, z1); this->contains = contains; diff --git a/Minecraft.Client/Rendering/Chunk.cpp b/Minecraft.Client/Rendering/Chunk.cpp index 03dc40b8f..95e060ed9 100644 --- a/Minecraft.Client/Rendering/Chunk.cpp +++ b/Minecraft.Client/Rendering/Chunk.cpp @@ -95,7 +95,7 @@ void Chunk::setPos(int x, int y, int z) { // 4J - changed to just set the value rather than make a new one, if we've // already created storage if (bb == NULL) { - bb = AABB::newPermanent(-g, -g, -g, XZSIZE + g, SIZE + g, XZSIZE + g); + bb = new AABB(-g, -g, -g, XZSIZE + g, SIZE + g, XZSIZE + g); } else { // 4J MGH - bounds are relative to the position now, so the AABB will be // setup already, either above, or from the tesselator bounds. diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index d412a7ede..84f11665f 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -3901,7 +3901,7 @@ void LevelRenderer::DestroyedTileManager::destroyingTileAt(Level* level, int x, // Make these temporary AABBs into permanently allocated AABBs for (unsigned int i = 0; i < recentTile->boxes.size(); i++) { - recentTile->boxes[i] = AABB::newPermanent( + recentTile->boxes[i] = new AABB( recentTile->boxes[i]->x0, recentTile->boxes[i]->y0, recentTile->boxes[i]->z0, recentTile->boxes[i]->x1, recentTile->boxes[i]->y1, recentTile->boxes[i]->z1); diff --git a/Minecraft.World/Entities/Entity.cpp b/Minecraft.World/Entities/Entity.cpp index 191789eb8..80a56fd74 100644 --- a/Minecraft.World/Entities/Entity.cpp +++ b/Minecraft.World/Entities/Entity.cpp @@ -268,7 +268,7 @@ void Entity::_init(bool useSmallId, Level* level) { xd = yd = zd = 0.0; yRot = xRot = 0.0f; yRotO = xRotO = 0.0f; - bb = AABB::newPermanent(0, 0, 0, 0, 0, 0); // 4J Was final + bb = new AABB(0, 0, 0, 0, 0, 0); // 4J Was final onGround = false; horizontalCollision = verticalCollision = false; collision = false; diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index 7f9697bc3..2cb92716b 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -73,7 +73,7 @@ void EnderDragon::_init() { m_actionTicks = 0; m_sittingDamageReceived = 0; m_headYRot = 0.0; - m_acidArea = AABB::newPermanent(-4, -10, -3, 6, 3, 3); + m_acidArea = new AABB(-4, -10, -3, 6, 3, 3); m_flameAttacks = 0; for (int i = 0; i < positionsLength; i++) { diff --git a/Minecraft.World/Util/AABB.cpp b/Minecraft.World/Util/AABB.cpp index 53b4412f3..2cf5236e5 100644 --- a/Minecraft.World/Util/AABB.cpp +++ b/Minecraft.World/Util/AABB.cpp @@ -40,11 +40,6 @@ void AABB::ReleaseThreadStorage() { } } -AABB* AABB::newPermanent(double x0, double y0, double z0, double x1, double y1, - double z1) { - return new AABB(x0, y0, z0, x1, y1, z1); -} - void AABB::clearPool() {} void AABB::resetPool() {} diff --git a/Minecraft.World/Util/AABB.h b/Minecraft.World/Util/AABB.h index 975f6ebcd..61d8446cd 100644 --- a/Minecraft.World/Util/AABB.h +++ b/Minecraft.World/Util/AABB.h @@ -26,8 +26,6 @@ public: static void UseDefaultThreadStorage(); static void ReleaseThreadStorage(); - static AABB* newPermanent(double x0, double y0, double z0, double x1, - double y1, double z1); static void clearPool(); static void resetPool(); static AABB* newTemp(double x0, double y0, double z0, double x1, double y1, From d7d99db4c5cf518fc46701faf95ec161e64b156d Mon Sep 17 00:00:00 2001 From: orng Date: Fri, 27 Mar 2026 21:56:57 -0500 Subject: [PATCH 3/9] refactor: remove `AABB::newTemp` when not returned --- .../Common/GameRules/ConsoleSchematicFile.cpp | 4 +-- .../GameRules/LevelGenerationOptions.cpp | 14 ++++---- .../PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp | 4 +-- Minecraft.Client/Rendering/LevelRenderer.cpp | 34 +++++++++---------- .../Blocks/BasePressurePlateTile.cpp | 2 +- Minecraft.World/Blocks/ButtonTile.cpp | 9 +++-- Minecraft.World/Blocks/CakeTile.cpp | 2 +- Minecraft.World/Blocks/ChestTile.cpp | 5 +-- Minecraft.World/Blocks/DetectorRailTile.cpp | 12 +++---- Minecraft.World/Blocks/FenceGateTile.cpp | 2 +- Minecraft.World/Blocks/SoulSandTile.cpp | 2 +- .../Blocks/TileEntities/ChestTileEntity.cpp | 9 +++-- .../Blocks/TileEntities/HopperTileEntity.cpp | 13 +++---- Minecraft.World/Blocks/TripWireTile.cpp | 7 ++-- .../Entities/LeashFenceKnotEntity.cpp | 21 ++++++------ Minecraft.World/Entities/Mobs/Boat.cpp | 4 +-- Minecraft.World/Entities/Mobs/EnderDragon.cpp | 26 ++++++-------- Minecraft.World/Entities/Mobs/FishingHook.cpp | 4 +-- .../Entities/Mobs/LightningBolt.cpp | 5 ++- Minecraft.World/Items/ArmorItem.cpp | 6 ++-- Minecraft.World/Items/LeashItem.cpp | 15 ++++---- Minecraft.World/Level/Explosion.cpp | 5 ++- Minecraft.World/Player/Player.cpp | 7 ++-- .../WorldGen/Structures/Village.cpp | 11 +++--- 24 files changed, 112 insertions(+), 111 deletions(-) diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index 2409b12c9..3ba460f65 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -733,9 +733,9 @@ void ConsoleSchematicFile::generateSchematicFile( } tag.put(L"TileEntities", tileEntitiesTag); - AABB* bb = AABB::newTemp(xStart, yStart, zStart, xEnd, yEnd, zEnd); + AABB bb(xStart, yStart, zStart, xEnd, yEnd, zEnd); std::vector >* entities = - level->getEntities(nullptr, bb); + level->getEntities(nullptr, &bb); ListTag* entitiesTag = new ListTag(L"entities"); for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp index 8e2260a11..5e65c983f 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp @@ -253,13 +253,12 @@ void LevelGenerationOptions::addAttribute(const std::wstring& attributeName, void LevelGenerationOptions::processSchematics(LevelChunk* chunk) { PIXBeginNamedEvent(0, "Processing schematics for chunk (%d,%d)", chunk->x, chunk->z); - AABB* chunkBox = - AABB::newTemp(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16, - Level::maxBuildHeight, chunk->z * 16 + 16); + AABB chunkBox(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16, + Level::maxBuildHeight, chunk->z * 16 + 16); for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); ++it) { ApplySchematicRuleDefinition* rule = *it; - rule->processSchematic(chunkBox, chunk); + rule->processSchematic(&chunkBox, chunk); } int cx = (chunk->x << 4); @@ -282,13 +281,12 @@ void LevelGenerationOptions::processSchematics(LevelChunk* chunk) { void LevelGenerationOptions::processSchematicsLighting(LevelChunk* chunk) { PIXBeginNamedEvent(0, "Processing schematics (lighting) for chunk (%d,%d)", chunk->x, chunk->z); - AABB* chunkBox = - AABB::newTemp(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16, - Level::maxBuildHeight, chunk->z * 16 + 16); + AABB chunkBox(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16, + Level::maxBuildHeight, chunk->z * 16 + 16); for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); ++it) { ApplySchematicRuleDefinition* rule = *it; - rule->processSchematicLighting(chunkBox, chunk); + rule->processSchematicLighting(&chunkBox, chunk); } PIXEndNamedEvent(); } diff --git a/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp b/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp index c12e1def6..8e7a0af90 100644 --- a/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp +++ b/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp @@ -329,8 +329,8 @@ bool Tile_SPU::isSolidRender(bool isServerLevel) { return true; } // { // int newCount = // ExperienceOrb::getExperienceValue(amount); amount -= -// newCount; level->addEntity(std::shared_ptr( new -// ExperienceOrb(level, x + .5, y + .5, z + .5, newCount))); +// newCount; level->addEntity(std::shared_ptr( +// new ExperienceOrb(level, x + .5, y + .5, z + .5, newCount))); // } // } // } diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 84f11665f..76138cf23 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -2481,9 +2481,9 @@ void LevelRenderer::renderHitOutline(std::shared_ptr player, double zo = player->zOld + (player->z - player->zOld) * a; AABB bb = Tile::tiles[tileId] - ->getTileAABB(level[iPad], h->x, h->y, h->z) - ->grow(ss, ss, ss) - .move(-xo, -yo, -zo); + ->getTileAABB(level[iPad], h->x, h->y, h->z) + ->grow(ss, ss, ss) + .move(-xo, -yo, -zo); render(&bb); } @@ -3891,20 +3891,20 @@ void LevelRenderer::DestroyedTileManager::destroyingTileAt(Level* level, int x, // ones, so make a temporary list and then copy over RecentTile* recentTile = new RecentTile(x, y, z, level); - AABB* box = AABB::newTemp((float)x, (float)y, (float)z, (float)(x + 1), - (float)(y + 1), (float)(z + 1)); + AABB box((float)x, (float)y, (float)z, (float)(x + 1), (float)(y + 1), + (float)(z + 1)); Tile* tile = Tile::tiles[level->getTile(x, y, z)]; if (tile != NULL) { - tile->addAABBs(level, x, y, z, box, &recentTile->boxes, nullptr); + tile->addAABBs(level, x, y, z, &box, &recentTile->boxes, nullptr); } // Make these temporary AABBs into permanently allocated AABBs for (unsigned int i = 0; i < recentTile->boxes.size(); i++) { - recentTile->boxes[i] = new AABB( - recentTile->boxes[i]->x0, recentTile->boxes[i]->y0, - recentTile->boxes[i]->z0, recentTile->boxes[i]->x1, - recentTile->boxes[i]->y1, recentTile->boxes[i]->z1); + recentTile->boxes[i] = + new AABB(recentTile->boxes[i]->x0, recentTile->boxes[i]->y0, + recentTile->boxes[i]->z0, recentTile->boxes[i]->x1, + recentTile->boxes[i]->y1, recentTile->boxes[i]->z1); } m_destroyedTiles.push_back(recentTile); @@ -3978,13 +3978,13 @@ void LevelRenderer::DestroyedTileManager::addAABBs(Level* level, AABB* box, // 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)) { - boxes->push_back( - AABB::newTemp(m_destroyedTiles[i]->boxes[j]->x0, - m_destroyedTiles[i]->boxes[j]->y0, - m_destroyedTiles[i]->boxes[j]->z0, - m_destroyedTiles[i]->boxes[j]->x1, - m_destroyedTiles[i]->boxes[j]->y1, - m_destroyedTiles[i]->boxes[j]->z1)); + AABB bb(m_destroyedTiles[i]->boxes[j]->x0, + m_destroyedTiles[i]->boxes[j]->y0, + m_destroyedTiles[i]->boxes[j]->z0, + m_destroyedTiles[i]->boxes[j]->x1, + m_destroyedTiles[i]->boxes[j]->y1, + m_destroyedTiles[i]->boxes[j]->z1); + boxes->push_back(&bb); } } } diff --git a/Minecraft.World/Blocks/BasePressurePlateTile.cpp b/Minecraft.World/Blocks/BasePressurePlateTile.cpp index 740e0a871..d6fb7e697 100644 --- a/Minecraft.World/Blocks/BasePressurePlateTile.cpp +++ b/Minecraft.World/Blocks/BasePressurePlateTile.cpp @@ -160,4 +160,4 @@ int BasePressurePlateTile::getPistonPushReaction() { void BasePressurePlateTile::registerIcons(IconRegister* iconRegister) { icon = iconRegister->registerIcon(texture); -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/ButtonTile.cpp b/Minecraft.World/Blocks/ButtonTile.cpp index 73ac3122a..550805d9d 100644 --- a/Minecraft.World/Blocks/ButtonTile.cpp +++ b/Minecraft.World/Blocks/ButtonTile.cpp @@ -261,9 +261,12 @@ void ButtonTile::checkPressed(Level* level, int x, int y, int z) { updateShape(data); Tile::ThreadStorage* tls = m_tlsShape; - std::vector >* entities = level->getEntitiesOfClass( - typeid(Arrow), AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, - x + tls->xx1, y + tls->yy1, z + tls->zz1)); + AABB arrow_aabb{ + x + tls->xx0, y + tls->yy0, z + tls->zz0, + x + tls->xx1, y + tls->yy1, z + tls->zz1, + }; + std::vector >* entities = + level->getEntitiesOfClass(typeid(Arrow), &arrow_aabb); shouldBePressed = !entities->empty(); delete entities; diff --git a/Minecraft.World/Blocks/CakeTile.cpp b/Minecraft.World/Blocks/CakeTile.cpp index b0d8d8ee9..437438c48 100644 --- a/Minecraft.World/Blocks/CakeTile.cpp +++ b/Minecraft.World/Blocks/CakeTile.cpp @@ -124,4 +124,4 @@ int CakeTile::getResource(int data, Random* random, int playerBonusLevel) { int CakeTile::cloneTileId(Level* level, int x, int y, int z) { return Item::cake_Id; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/ChestTile.cpp b/Minecraft.World/Blocks/ChestTile.cpp index 9ac3c5364..4a866151c 100644 --- a/Minecraft.World/Blocks/ChestTile.cpp +++ b/Minecraft.World/Blocks/ChestTile.cpp @@ -345,8 +345,9 @@ int ChestTile::getDirectSignal(LevelSource* level, int x, int y, int z, } bool ChestTile::isCatSittingOnChest(Level* level, int x, int y, int z) { - std::vector >* entities = level->getEntitiesOfClass( - typeid(Ocelot), AABB::newTemp(x, y + 1, z, x + 1, y + 2, z + 1)); + AABB ocelot_aabb(x, y + 1, z, x + 1, y + 2, z + 1); + std::vector >* entities = + level->getEntitiesOfClass(typeid(Ocelot), &ocelot_aabb); for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { std::shared_ptr ocelot = std::dynamic_pointer_cast(*it); if (ocelot->isSitting()) { diff --git a/Minecraft.World/Blocks/DetectorRailTile.cpp b/Minecraft.World/Blocks/DetectorRailTile.cpp index dacc5f51b..b7bd2d4e5 100644 --- a/Minecraft.World/Blocks/DetectorRailTile.cpp +++ b/Minecraft.World/Blocks/DetectorRailTile.cpp @@ -64,9 +64,9 @@ void DetectorRailTile::checkPressed(Level* level, int x, int y, int z, bool shouldBePressed = false; float b = 2 / 16.0f; - std::vector >* entities = level->getEntitiesOfClass( - typeid(Minecart), - AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b)); + AABB minecart_aabb(x + b, y, z + b, x + b - b, y + b - b, z + 1 - b); + std::vector >* entities = + level->getEntitiesOfClass(typeid(Minecart), &minecart_aabb); if (!entities->empty()) { shouldBePressed = true; } @@ -105,10 +105,10 @@ int DetectorRailTile::getAnalogOutputSignal(Level* level, int x, int y, int z, int dir) { if ((level->getData(x, y, z) & RAIL_DATA_BIT) > 0) { float b = 2 / 16.0f; + AABB minecart_bb(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b); std::vector >* entities = level->getEntitiesOfClass( - typeid(Minecart), - AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b), + typeid(Minecart), &minecart_bb, EntitySelector::CONTAINER_ENTITY_SELECTOR); if (entities->size() > 0) { @@ -133,4 +133,4 @@ Icon* DetectorRailTile::getTexture(int face, int data) { return icons[1]; } return icons[0]; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/FenceGateTile.cpp b/Minecraft.World/Blocks/FenceGateTile.cpp index 4a9a11268..44ee44135 100644 --- a/Minecraft.World/Blocks/FenceGateTile.cpp +++ b/Minecraft.World/Blocks/FenceGateTile.cpp @@ -123,4 +123,4 @@ void FenceGateTile::registerIcons(IconRegister* iconRegister) { bool FenceGateTile::shouldRenderFace(LevelSource* level, int x, int y, int z, int face) { return true; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/SoulSandTile.cpp b/Minecraft.World/Blocks/SoulSandTile.cpp index fe240022f..22b4f8509 100644 --- a/Minecraft.World/Blocks/SoulSandTile.cpp +++ b/Minecraft.World/Blocks/SoulSandTile.cpp @@ -14,4 +14,4 @@ void SoulSandTile::entityInside(Level* level, int x, int y, int z, std::shared_ptr entity) { entity->xd *= 0.4; entity->zd *= 0.4; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp index d1cbd500b..d66c15c24 100644 --- a/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp @@ -242,11 +242,10 @@ void ChestTileEntity::tick() { openCount = 0; float range = 5; + AABB player_aabb(x - range, y - range, z - range, x + 1 + range, + y + 1 + range, z + 1 + range); std::vector >* players = - level->getEntitiesOfClass( - typeid(Player), - AABB::newTemp(x - range, y - range, z - range, x + 1 + range, - y + 1 + range, z + 1 + range)); + level->getEntitiesOfClass(typeid(Player), &player_aabb); for (AUTO_VAR(it, players->begin()); it != players->end(); ++it) { std::shared_ptr player = std::dynamic_pointer_cast(*it); @@ -383,4 +382,4 @@ std::shared_ptr ChestTileEntity::clone() { } } return result; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/TileEntities/HopperTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/HopperTileEntity.cpp index 36da69010..26ed8f516 100644 --- a/Minecraft.World/Blocks/TileEntities/HopperTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/HopperTileEntity.cpp @@ -345,9 +345,10 @@ std::shared_ptr HopperTileEntity::getSourceContainer( std::shared_ptr HopperTileEntity::getItemAt(Level* level, double xt, double yt, double zt) { - std::vector >* entities = level->getEntitiesOfClass( - typeid(ItemEntity), AABB::newTemp(xt, yt, zt, xt + 1, yt + 1, zt + 1), - EntitySelector::ENTITY_STILL_ALIVE); + AABB item_entity_aabb{xt, yt, zt, xt + 1, yt + 1, zt + 1}; + std::vector >* entities = + level->getEntitiesOfClass(typeid(ItemEntity), &item_entity_aabb, + EntitySelector::ENTITY_STILL_ALIVE); if (entities->size() > 0) { std::shared_ptr out = @@ -384,9 +385,9 @@ std::shared_ptr HopperTileEntity::getContainerAt(Level* level, } if (result == NULL) { + AABB block_above{x, y, z, x + 1, y + 1, z + 1}; std::vector >* entities = level->getEntities( - nullptr, AABB::newTemp(x, y, z, x + 1, y + 1, z + 1), - EntitySelector::CONTAINER_ENTITY_SELECTOR); + nullptr, &block_above, EntitySelector::CONTAINER_ENTITY_SELECTOR); if ((entities != NULL) && (entities->size() > 0)) { result = std::dynamic_pointer_cast( @@ -432,4 +433,4 @@ std::shared_ptr HopperTileEntity::clone() { } } return result; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/TripWireTile.cpp b/Minecraft.World/Blocks/TripWireTile.cpp index 0118aa0a1..0e5755e47 100644 --- a/Minecraft.World/Blocks/TripWireTile.cpp +++ b/Minecraft.World/Blocks/TripWireTile.cpp @@ -132,9 +132,10 @@ void TripWireTile::checkPressed(Level* level, int x, int y, int z) { bool shouldBePressed = false; ThreadStorage* tls = m_tlsShape; - std::vector >* entities = level->getEntities( - nullptr, AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, - x + tls->xx1, y + tls->yy1, z + tls->zz1)); + AABB offs_aabb(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, + y + tls->yy1, z + tls->zz1); + std::vector >* entities = + level->getEntities(nullptr, &offs_aabb); if (!entities->empty()) { for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { std::shared_ptr e = *it; diff --git a/Minecraft.World/Entities/LeashFenceKnotEntity.cpp b/Minecraft.World/Entities/LeashFenceKnotEntity.cpp index 5a4ccd45f..d86972cad 100644 --- a/Minecraft.World/Entities/LeashFenceKnotEntity.cpp +++ b/Minecraft.World/Entities/LeashFenceKnotEntity.cpp @@ -54,11 +54,10 @@ bool LeashFenceKnotEntity::interact(std::shared_ptr player) { if (!level->isClientSide) { // look for entities that can be attached to the fence double range = 7; + AABB mob_aabb{x - range, y - range, z - range, + x + range, y + range, z + range}; std::vector >* mobs = - level->getEntitiesOfClass( - typeid(Mob), - AABB::newTemp(x - range, y - range, z - range, x + range, - y + range, z + range)); + level->getEntitiesOfClass(typeid(Mob), &mob_aabb); if (mobs != NULL) { for (AUTO_VAR(it, mobs->begin()); it != mobs->end(); ++it) { std::shared_ptr mob = @@ -79,11 +78,10 @@ bool LeashFenceKnotEntity::interact(std::shared_ptr player) { // if the player is in creative mode, attempt to remove all leashed // mobs without dropping additional items double range = 7; + AABB mob_aabb{x - range, y - range, z - range, + x + range, y + range, z + range}; std::vector >* mobs = - level->getEntitiesOfClass( - typeid(Mob), - AABB::newTemp(x - range, y - range, z - range, x + range, - y + range, z + range)); + level->getEntitiesOfClass(typeid(Mob), &mob_aabb); if (mobs != NULL) { for (AUTO_VAR(it, mobs->begin()); it != mobs->end(); ++it) { std::shared_ptr mob = @@ -122,9 +120,10 @@ std::shared_ptr LeashFenceKnotEntity::createAndAddKnot( std::shared_ptr LeashFenceKnotEntity::findKnotAt( Level* level, int x, int y, int z) { + AABB leash_fence_knot_entity_aabb{x - 1.0, y - 1.0, z - 1.0, + x + 1.0, y + 1.0, z + 1.0}; std::vector >* knots = level->getEntitiesOfClass( - typeid(LeashFenceKnotEntity), - AABB::newTemp(x - 1.0, y - 1.0, z - 1.0, x + 1.0, y + 1.0, z + 1.0)); + typeid(LeashFenceKnotEntity), &leash_fence_knot_entity_aabb); if (knots != NULL) { for (AUTO_VAR(it, knots->begin()); it != knots->end(); ++it) { std::shared_ptr knot = @@ -137,4 +136,4 @@ std::shared_ptr LeashFenceKnotEntity::findKnotAt( delete knots; } return nullptr; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Boat.cpp b/Minecraft.World/Entities/Mobs/Boat.cpp index f379b068e..d04c7f33e 100644 --- a/Minecraft.World/Entities/Mobs/Boat.cpp +++ b/Minecraft.World/Entities/Mobs/Boat.cpp @@ -167,8 +167,8 @@ void Boat::tick() { for (int i = 0; i < steps; i++) { 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; - AABB* bb2 = AABB::newTemp(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); - if (level->containsLiquid(bb2, Material::water)) { + AABB bb2(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); + if (level->containsLiquid(&bb2, Material::water)) { waterPercentage += 1.0 / steps; } } diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index 2cb92716b..abcab5c46 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -647,11 +647,9 @@ 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(), - &wing_mov)); + knockBack(level->getEntities(shared_from_this(), &wing_mov)); 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 head_bb = head->bb->grow(1, 1, 1); @@ -689,8 +687,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 = {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, @@ -816,11 +814,9 @@ void EnderDragon::checkCrystals() { if (random->nextInt(10) == 0) { float maxDist = 32; - AABB grown = -bb->grow(maxDist, maxDist, maxDist); + AABB grown = bb->grow(maxDist, maxDist, maxDist); std::vector >* crystals = - level->getEntitiesOfClass(typeid(EnderCrystal), - &grown); + level->getEntitiesOfClass(typeid(EnderCrystal), &grown); std::shared_ptr crystal = nullptr; double nearest = std::numeric_limits::max(); @@ -1427,11 +1423,11 @@ 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 >* crystals = level->getEntitiesOfClass( - typeid(EnderCrystal), &grown); + AABB tempBB(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 >* crystals = + level->getEntitiesOfClass(typeid(EnderCrystal), &grown); m_remainingCrystalsCount = (int)crystals->size() - 1; if (m_remainingCrystalsCount < 0) m_remainingCrystalsCount = 0; delete crystals; diff --git a/Minecraft.World/Entities/Mobs/FishingHook.cpp b/Minecraft.World/Entities/Mobs/FishingHook.cpp index 76a4d5b07..fe8ff9b8b 100644 --- a/Minecraft.World/Entities/Mobs/FishingHook.cpp +++ b/Minecraft.World/Entities/Mobs/FishingHook.cpp @@ -288,8 +288,8 @@ void FishingHook::tick() { 2 / 16.0f; double y1 = bb->y0 + (bb->y1 - bb->y0) * (i + 1) / steps - 2 / 16.0f + 2 / 16.0f; - AABB* bb2 = AABB::newTemp(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); - if (level->containsLiquid(bb2, Material::water)) { + AABB bb2(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); + if (level->containsLiquid(&bb2, Material::water)) { waterPercentage += 1.0 / steps; } } diff --git a/Minecraft.World/Entities/Mobs/LightningBolt.cpp b/Minecraft.World/Entities/Mobs/LightningBolt.cpp index fe864cb07..24bd495dd 100644 --- a/Minecraft.World/Entities/Mobs/LightningBolt.cpp +++ b/Minecraft.World/Entities/Mobs/LightningBolt.cpp @@ -105,10 +105,9 @@ void LightningBolt::tick() { level->skyFlashTime = 2; } else { double r = 3; + AABB aoe_bb = AABB(x, y, z, x, y + 6, z).grow(r, r, r); std::vector >* entities = - level->getEntities(shared_from_this(), - AABB::newTemp(x - r, y - r, z - r, x + r, - y + 6 + r, z + r)); + level->getEntities(shared_from_this(), &aoe_bb); AUTO_VAR(itEnd, entities->end()); for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) { std::shared_ptr e = (*it); // entities->at(i); diff --git a/Minecraft.World/Items/ArmorItem.cpp b/Minecraft.World/Items/ArmorItem.cpp index 3feb87e07..2f4173530 100644 --- a/Minecraft.World/Items/ArmorItem.cpp +++ b/Minecraft.World/Items/ArmorItem.cpp @@ -26,10 +26,10 @@ std::shared_ptr ArmorItem::ArmorDispenseItemBehavior::execute( int x = source->getBlockX() + facing->getStepX(); int y = source->getBlockY() + facing->getStepY(); int z = source->getBlockZ() + facing->getStepZ(); - AABB* bb = AABB::newTemp(x, y, z, x + 1, y + 1, z + 1); + AABB bb = AABB(x, y, z, x + 1, y + 1, z + 1); EntitySelector* selector = new MobCanWearArmourEntitySelector(dispensed); std::vector >* entities = - source->getWorld()->getEntitiesOfClass(typeid(LivingEntity), bb, + source->getWorld()->getEntitiesOfClass(typeid(LivingEntity), &bb, selector); delete selector; @@ -237,4 +237,4 @@ Icon* ArmorItem::getEmptyIcon(int slot) { } return NULL; -} \ No newline at end of file +} diff --git a/Minecraft.World/Items/LeashItem.cpp b/Minecraft.World/Items/LeashItem.cpp index a00d296a1..1139a5d86 100644 --- a/Minecraft.World/Items/LeashItem.cpp +++ b/Minecraft.World/Items/LeashItem.cpp @@ -3,6 +3,7 @@ #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.entity.h" #include "../Headers/net.minecraft.world.phys.h" +#include "Util/AABB.h" #include "LeashItem.h" LeashItem::LeashItem(int id) : Item(id) {} @@ -35,9 +36,9 @@ bool LeashItem::bindPlayerMobs(std::shared_ptr player, Level* level, // look for entities that can be attached to the fence bool foundMobs = false; double range = 7; - std::vector >* mobs = level->getEntitiesOfClass( - typeid(Mob), AABB::newTemp(x - range, y - range, z - range, x + range, - y + range, z + range)); + AABB mob_bb = AABB(x, y, z, x, y, z).grow(range, range, range); + std::vector >* mobs = + level->getEntitiesOfClass(typeid(Mob), &mob_bb); if (mobs != NULL) { for (AUTO_VAR(it, mobs->begin()); it != mobs->end(); ++it) { std::shared_ptr mob = std::dynamic_pointer_cast(*it); @@ -59,9 +60,9 @@ bool LeashItem::bindPlayerMobsTest(std::shared_ptr player, Level* level, int x, int y, int z) { // look for entities that can be attached to the fence double range = 7; - std::vector >* mobs = level->getEntitiesOfClass( - typeid(Mob), AABB::newTemp(x - range, y - range, z - range, x + range, - y + range, z + range)); + AABB mob_bb = AABB(x, y, z, x, y, z).grow(range, range, range); + std::vector >* mobs = + level->getEntitiesOfClass(typeid(Mob), &mob_bb); if (mobs != NULL) { for (AUTO_VAR(it, mobs->begin()); it != mobs->end(); ++it) { @@ -71,4 +72,4 @@ bool LeashItem::bindPlayerMobsTest(std::shared_ptr player, Level* level, } } return false; -} \ No newline at end of file +} diff --git a/Minecraft.World/Level/Explosion.cpp b/Minecraft.World/Level/Explosion.cpp index a82786ebe..bdc17689d 100644 --- a/Minecraft.World/Level/Explosion.cpp +++ b/Minecraft.World/Level/Explosion.cpp @@ -9,6 +9,7 @@ #include "TilePos.h" #include "Explosion.h" #include "../Util/SoundTypes.h" +#include "Util/AABB.h" Explosion::Explosion(Level* level, std::shared_ptr source, double x, double y, double z, float r) { @@ -99,8 +100,10 @@ void Explosion::explode() { // time. If we explode something next to an EnderCrystal then it creates a // new explosion that overwrites the shared vector in the level So copy it // here instead of directly using the shared one + + AABB source_bb(x0, y0, z0, x1, y1, z1); std::vector >* levelEntities = - level->getEntities(source, AABB::newTemp(x0, y0, z0, x1, y1, z1)); + level->getEntities(source, &source_bb); std::vector > entities(levelEntities->begin(), levelEntities->end()); Vec3 center(x, y, z); diff --git a/Minecraft.World/Player/Player.cpp b/Minecraft.World/Player/Player.cpp index fff23c15e..f36caeefa 100644 --- a/Minecraft.World/Player/Player.cpp +++ b/Minecraft.World/Player/Player.cpp @@ -1596,11 +1596,10 @@ Player::BedSleepingResult Player::startSleepInBed(int x, int y, int z, double hRange = 8; double vRange = 5; + AABB monster_bb = + AABB(x, y, z, x, y, z).grow(hRange, vRange, hRange); std::vector >* monsters = - level->getEntitiesOfClass( - typeid(Monster), - AABB::newTemp(x - hRange, y - vRange, z - hRange, - x + hRange, y + vRange, z + hRange)); + level->getEntitiesOfClass(typeid(Monster), &monster_bb); if (!monsters->empty()) { delete monsters; return NOT_SAFE; diff --git a/Minecraft.World/WorldGen/Structures/Village.cpp b/Minecraft.World/WorldGen/Structures/Village.cpp index 16a6a2283..03a079387 100644 --- a/Minecraft.World/WorldGen/Structures/Village.cpp +++ b/Minecraft.World/WorldGen/Structures/Village.cpp @@ -117,21 +117,22 @@ bool Village::canSpawnAt(int x, int y, int z, int sx, int sy, int sz) { void Village::countGolem() { // Fix - let bots report themselves? + AABB village_golem_bb = + AABB(center->x, center->y, center->z, center->x, center->y, center->z) + .grow(radius, 4, radius); std::vector >* golems = level->getEntitiesOfClass( typeid(VillagerGolem), - AABB::newTemp(center->x - radius, center->y - 4, center->z - radius, - center->x + radius, center->y + 4, center->z + radius)); + &village_golem_bb); golemCount = golems->size(); delete golems; } void Village::countPopulation() { + AABB villager_bb = AABB(center->x, center->y, center->z, center->x, center->y, center->z).grow(radius, 4, radius); std::vector >* villagers = level->getEntitiesOfClass( typeid(Villager), - AABB::newTemp(center->x - radius, center->y - 4, center->z - radius, - center->x + radius, center->y + 4, - center->z + radius)); + &villager_bb); populationSize = villagers->size(); delete villagers; From 78b5255224afe66b567426e24067749c720d4fd6 Mon Sep 17 00:00:00 2001 From: orng Date: Fri, 27 Mar 2026 22:37:22 -0500 Subject: [PATCH 4/9] refactor: make `AABBList` own its values --- Minecraft.Client/Rendering/LevelRenderer.cpp | 29 +++++--------------- Minecraft.Client/Rendering/LevelRenderer.h | 2 +- Minecraft.World/Blocks/Tile.cpp | 2 +- Minecraft.World/Entities/Entity.cpp | 19 ++++++------- Minecraft.World/Entities/LivingEntity.cpp | 3 +- Minecraft.World/Level/Level.cpp | 4 +-- Minecraft.World/Util/Definitions.h | 4 +-- 7 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 76138cf23..927a8b71f 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -3862,12 +3862,6 @@ LevelRenderer::DestroyedTileManager::RecentTile::RecentTile(int x, int y, int z, rebuilt = false; } -LevelRenderer::DestroyedTileManager::RecentTile::~RecentTile() { - for (AUTO_VAR(it, boxes.begin()); it != boxes.end(); it++) { - delete *it; - } -} - LevelRenderer::DestroyedTileManager::DestroyedTileManager() { InitializeCriticalSection(&m_csDestroyedTiles); } @@ -3899,14 +3893,6 @@ void LevelRenderer::DestroyedTileManager::destroyingTileAt(Level* level, int x, tile->addAABBs(level, x, y, z, &box, &recentTile->boxes, nullptr); } - // Make these temporary AABBs into permanently allocated AABBs - for (unsigned int i = 0; i < recentTile->boxes.size(); i++) { - recentTile->boxes[i] = - new AABB(recentTile->boxes[i]->x0, recentTile->boxes[i]->y0, - recentTile->boxes[i]->z0, recentTile->boxes[i]->x1, - recentTile->boxes[i]->y1, recentTile->boxes[i]->z1); - } - m_destroyedTiles.push_back(recentTile); LeaveCriticalSection(&m_csDestroyedTiles); @@ -3977,14 +3963,13 @@ 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)) { - AABB bb(m_destroyedTiles[i]->boxes[j]->x0, - m_destroyedTiles[i]->boxes[j]->y0, - m_destroyedTiles[i]->boxes[j]->z0, - m_destroyedTiles[i]->boxes[j]->x1, - m_destroyedTiles[i]->boxes[j]->y1, - m_destroyedTiles[i]->boxes[j]->z1); - boxes->push_back(&bb); + if (m_destroyedTiles[i]->boxes[j].intersects(*box)) { + boxes->push_back({m_destroyedTiles[i]->boxes[j].x0, + m_destroyedTiles[i]->boxes[j].y0, + m_destroyedTiles[i]->boxes[j].z0, + m_destroyedTiles[i]->boxes[j].x1, + m_destroyedTiles[i]->boxes[j].y1, + m_destroyedTiles[i]->boxes[j].z1}); } } } diff --git a/Minecraft.Client/Rendering/LevelRenderer.h b/Minecraft.Client/Rendering/LevelRenderer.h index 1275ee4e8..58f194a3b 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.h +++ b/Minecraft.Client/Rendering/LevelRenderer.h @@ -234,7 +234,7 @@ public: int timeout_ticks; bool rebuilt; RecentTile(int x, int y, int z, Level* level); - ~RecentTile(); + ~RecentTile() = default; }; CRITICAL_SECTION m_csDestroyedTiles; std::vector m_destroyedTiles; diff --git a/Minecraft.World/Blocks/Tile.cpp b/Minecraft.World/Blocks/Tile.cpp index a895238ef..a2033379b 100644 --- a/Minecraft.World/Blocks/Tile.cpp +++ b/Minecraft.World/Blocks/Tile.cpp @@ -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 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) { diff --git a/Minecraft.World/Entities/Entity.cpp b/Minecraft.World/Entities/Entity.cpp index 80a56fd74..d07f16799 100644 --- a/Minecraft.World/Entities/Entity.cpp +++ b/Minecraft.World/Entities/Entity.cpp @@ -733,7 +733,7 @@ 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); + ya = it->clipYCollide(*bb, ya); *bb = bb->move(0, ya, 0); } @@ -745,7 +745,7 @@ 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 = bb->move(xa, 0, 0); @@ -755,7 +755,7 @@ 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); + za = it->clipZCollide(*bb, za); *bb = bb->move(0, 0, za); if (!slide && zaOrg != za) { @@ -789,7 +789,7 @@ 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); + ya = it->clipYCollide(*bb, ya); *bb = bb->move(0, ya, 0); } @@ -799,7 +799,7 @@ 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 = bb->move(xa, 0, 0); if (!slide && xaOrg != xa) { @@ -808,7 +808,7 @@ 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); + za = it->clipZCollide(*bb, za); *bb = bb->move(0, 0, za); if (!slide && zaOrg != za) { @@ -822,7 +822,7 @@ 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); + ya = it->clipYCollide(*bb, ya); *bb = bb->move(0, ya, 0); } @@ -1526,8 +1526,7 @@ void Entity::lerpTo(double x, double y, double z, float yRot, float xRot, double yTop = 0; AUTO_VAR(itEnd, collisions->end()); for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) { - AABB* ab = *it; // collisions->at(i); - if (ab->y1 > yTop) yTop = ab->y1; + if (it->y1 > yTop) yTop = it->y1; } y += yTop - bb->y0; @@ -1668,7 +1667,7 @@ bool Entity::checkInTile(double x, double y, double z) { double yd = y - (yTile); double zd = z - (zTile); - std::vector* cubes = level->getTileCubes(bb); + auto* cubes = level->getTileCubes(bb); if ((cubes && !cubes->empty()) || level->isFullAABBTile(xTile, yTile, zTile)) { bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile); diff --git a/Minecraft.World/Entities/LivingEntity.cpp b/Minecraft.World/Entities/LivingEntity.cpp index 8725643cf..c30033456 100644 --- a/Minecraft.World/Entities/LivingEntity.cpp +++ b/Minecraft.World/Entities/LivingEntity.cpp @@ -1518,8 +1518,7 @@ void LivingEntity::aiStep() { double yTop = 0; AUTO_VAR(itEnd, collisions->end()); for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) { - AABB* ab = *it; // collisions->at(i); - if (ab->y1 > yTop) yTop = ab->y1; + if (it->y1 > yTop) yTop = it->y1; } yt += yTop - bb->y0; diff --git a/Minecraft.World/Level/Level.cpp b/Minecraft.World/Level/Level.cpp index cd572cbf7..bfaab0c3d 100644 --- a/Minecraft.World/Level/Level.cpp +++ b/Minecraft.World/Level/Level.cpp @@ -1805,12 +1805,12 @@ AABBList* Level::getCubes(std::shared_ptr source, AABB* box, for (AUTO_VAR(it, ee->begin()); it != itEnd; it++) { AABB* collideBox = (*it)->getCollideBox(); if (collideBox != NULL && collideBox->intersects(*box)) { - boxes.push_back(collideBox); + boxes.push_back(*collideBox); } collideBox = source->getCollideAgainstBox(*it); if (collideBox != NULL && collideBox->intersects(*box)) { - boxes.push_back(collideBox); + boxes.push_back(*collideBox); } } diff --git a/Minecraft.World/Util/Definitions.h b/Minecraft.World/Util/Definitions.h index b0dec3cfe..3ad0caa91 100644 --- a/Minecraft.World/Util/Definitions.h +++ b/Minecraft.World/Util/Definitions.h @@ -4,7 +4,7 @@ class AABB; class Recipy; class Object; -typedef std::vector AABBList; +typedef std::vector AABBList; typedef std::vector RecipyList; typedef std::vector ObjectList; @@ -34,4 +34,4 @@ enum EDefaultSkins { eDefaultSkins_Skin7, eDefaultSkins_Count, -}; \ No newline at end of file +}; From 7158fd398fff993b89ae593a49136ae4ee776876 Mon Sep 17 00:00:00 2001 From: orng Date: Sat, 28 Mar 2026 00:11:19 -0500 Subject: [PATCH 5/9] refactor: make `Tile::getAABB` return `optional` --- .../Blocks/BasePressurePlateTile.cpp | 6 ++-- .../Blocks/BasePressurePlateTile.h | 4 +-- Minecraft.World/Blocks/BaseRailTile.cpp | 5 ++-- Minecraft.World/Blocks/BaseRailTile.h | 2 +- Minecraft.World/Blocks/ButtonTile.cpp | 3 +- Minecraft.World/Blocks/ButtonTile.h | 4 +-- Minecraft.World/Blocks/CactusTile.cpp | 4 +-- Minecraft.World/Blocks/CactusTile.h | 4 +-- Minecraft.World/Blocks/CakeTile.cpp | 4 +-- Minecraft.World/Blocks/CakeTile.h | 4 +-- Minecraft.World/Blocks/CocoaTile.cpp | 5 ++-- Minecraft.World/Blocks/CocoaTile.h | 2 +- Minecraft.World/Blocks/DoorTile.cpp | 7 ++--- Minecraft.World/Blocks/DoorTile.h | 2 +- Minecraft.World/Blocks/FarmTile.cpp | 4 +-- Minecraft.World/Blocks/FarmTile.h | 2 +- Minecraft.World/Blocks/FenceGateTile.cpp | 29 +++++++++++++------ Minecraft.World/Blocks/FenceGateTile.h | 2 +- Minecraft.World/Blocks/FireTile.cpp | 3 +- Minecraft.World/Blocks/FireTile.h | 4 +-- Minecraft.World/Blocks/LadderTile.cpp | 5 ++-- Minecraft.World/Blocks/LadderTile.h | 4 +-- Minecraft.World/Blocks/LeverTile.cpp | 3 +- Minecraft.World/Blocks/LeverTile.h | 2 +- Minecraft.World/Blocks/LiquidTile.cpp | 6 +++- Minecraft.World/Blocks/LiquidTile.h | 3 +- Minecraft.World/Blocks/PistonBaseTile.cpp | 5 +++- Minecraft.World/Blocks/PistonBaseTile.h | 5 ++-- .../Blocks/PistonMovingTileEntity.cpp | 22 +++++++++----- .../Blocks/PistonMovingTileEntity.h | 6 ++-- Minecraft.World/Blocks/PlantTile.cpp | 3 +- Minecraft.World/Blocks/PlantTile.h | 2 +- Minecraft.World/Blocks/PortalTile.cpp | 5 +++- Minecraft.World/Blocks/PortalTile.h | 3 +- Minecraft.World/Blocks/RedStoneDustTile.cpp | 8 +++-- Minecraft.World/Blocks/RedStoneDustTile.h | 3 +- Minecraft.World/Blocks/ReedTile.cpp | 3 +- Minecraft.World/Blocks/ReedTile.h | 3 +- Minecraft.World/Blocks/SignTile.cpp | 7 +++-- Minecraft.World/Blocks/SignTile.h | 5 ++-- Minecraft.World/Blocks/SkullTile.cpp | 4 +-- Minecraft.World/Blocks/SkullTile.h | 2 +- Minecraft.World/Blocks/SoulSandTile.cpp | 4 +-- Minecraft.World/Blocks/SoulSandTile.h | 4 +-- Minecraft.World/Blocks/Tile.cpp | 10 +++---- Minecraft.World/Blocks/Tile.h | 3 +- .../TileEntities/PistonPieceTileEntity.cpp | 7 +++-- Minecraft.World/Blocks/TopSnowTile.cpp | 4 +-- Minecraft.World/Blocks/TopSnowTile.h | 2 +- Minecraft.World/Blocks/TorchTile.cpp | 4 ++- Minecraft.World/Blocks/TorchTile.h | 2 +- Minecraft.World/Blocks/TrapDoorTile.cpp | 5 ++-- Minecraft.World/Blocks/TrapDoorTile.h | 4 +-- Minecraft.World/Blocks/TripWireSourceTile.cpp | 6 ++-- Minecraft.World/Blocks/TripWireSourceTile.h | 2 +- Minecraft.World/Blocks/TripWireTile.cpp | 3 +- Minecraft.World/Blocks/TripWireTile.h | 2 +- Minecraft.World/Blocks/VineTile.cpp | 3 +- Minecraft.World/Blocks/VineTile.h | 4 +-- Minecraft.World/Blocks/WallTile.cpp | 4 +-- Minecraft.World/Blocks/WallTile.h | 4 +-- Minecraft.World/Blocks/WaterLilyTile.cpp | 4 +-- Minecraft.World/Blocks/WaterLilyTile.h | 2 +- Minecraft.World/Blocks/WebTile.cpp | 5 ++-- Minecraft.World/Blocks/WebTile.h | 4 +-- Minecraft.World/Blocks/WoolCarpetTile.cpp | 4 +-- Minecraft.World/Blocks/WoolCarpetTile.h | 5 ++-- Minecraft.World/Entities/Mobs/Arrow.cpp | 4 +-- Minecraft.World/Items/SnowItem.cpp | 6 ++-- .../Items/TileItems/StoneSlabTileItem.cpp | 9 ++++-- Minecraft.World/Level/Level.cpp | 15 +++++----- 71 files changed, 205 insertions(+), 139 deletions(-) diff --git a/Minecraft.World/Blocks/BasePressurePlateTile.cpp b/Minecraft.World/Blocks/BasePressurePlateTile.cpp index d6fb7e697..434ce8e56 100644 --- a/Minecraft.World/Blocks/BasePressurePlateTile.cpp +++ b/Minecraft.World/Blocks/BasePressurePlateTile.cpp @@ -6,6 +6,8 @@ #include "../Headers/net.minecraft.h" #include "../Headers/net.minecraft.world.h" #include "BasePressurePlateTile.h" +#include +#include "Util/AABB.h" BasePressurePlateTile::BasePressurePlateTile(int id, const std::wstring& tex, Material* material) @@ -38,8 +40,8 @@ int BasePressurePlateTile::getTickDelay(Level* level) { return SharedConstants::TICKS_PER_SECOND; } -AABB* BasePressurePlateTile::getAABB(Level* level, int x, int y, int z) { - return NULL; +std::optional BasePressurePlateTile::getAABB(Level* level, int x, int y, int z) { + return std::nullopt; } bool BasePressurePlateTile::isSolidRender(bool isServerLevel) { return false; } diff --git a/Minecraft.World/Blocks/BasePressurePlateTile.h b/Minecraft.World/Blocks/BasePressurePlateTile.h index 62d8de583..e42ff69eb 100644 --- a/Minecraft.World/Blocks/BasePressurePlateTile.h +++ b/Minecraft.World/Blocks/BasePressurePlateTile.h @@ -20,7 +20,7 @@ protected: public: virtual int getTickDelay(Level* level); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool isSolidRender(bool isServerLevel = false); virtual bool blocksLight(); virtual bool isCubeShaped(); @@ -56,4 +56,4 @@ protected: public: virtual void registerIcons(IconRegister* iconRegister); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/BaseRailTile.cpp b/Minecraft.World/Blocks/BaseRailTile.cpp index 6478c61bb..31332510e 100644 --- a/Minecraft.World/Blocks/BaseRailTile.cpp +++ b/Minecraft.World/Blocks/BaseRailTile.cpp @@ -3,6 +3,7 @@ #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.h" #include "BaseRailTile.h" +#include BaseRailTile::Rail::Rail(Level* level, int x, int y, int z) { this->level = level; @@ -311,7 +312,7 @@ BaseRailTile::BaseRailTile(int id, bool usesDataBit) bool BaseRailTile::isUsesDataBit() { return usesDataBit; } -AABB* BaseRailTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional BaseRailTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } bool BaseRailTile::blocksLight() { return false; } @@ -415,4 +416,4 @@ void BaseRailTile::onRemove(Level* level, int x, int y, int z, int id, level->updateNeighborsAt(x, y, z, id); level->updateNeighborsAt(x, y - 1, z, id); } -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/BaseRailTile.h b/Minecraft.World/Blocks/BaseRailTile.h index e352bd3ca..23a7b45af 100644 --- a/Minecraft.World/Blocks/BaseRailTile.h +++ b/Minecraft.World/Blocks/BaseRailTile.h @@ -70,7 +70,7 @@ public: using Tile::getResourceCount; bool isUsesDataBit(); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool blocksLight(); virtual bool isSolidRender(bool isServerLevel = false); virtual HitResult* clip(Level* level, int xt, int yt, int zt, Vec3* a, diff --git a/Minecraft.World/Blocks/ButtonTile.cpp b/Minecraft.World/Blocks/ButtonTile.cpp index 550805d9d..bf0cb742e 100644 --- a/Minecraft.World/Blocks/ButtonTile.cpp +++ b/Minecraft.World/Blocks/ButtonTile.cpp @@ -5,6 +5,7 @@ #include "../Headers/net.minecraft.world.phys.h" #include "../Headers/net.minecraft.h" #include "ButtonTile.h" +#include #include "../Util/SoundTypes.h" ButtonTile::ButtonTile(int id, bool sensitive) @@ -20,7 +21,7 @@ Icon* ButtonTile::getTexture(int face, int data) { return Tile::stone->getTexture(Facing::UP); } -AABB* ButtonTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional ButtonTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } int ButtonTile::getTickDelay(Level* level) { return sensitive ? 30 : 20; } diff --git a/Minecraft.World/Blocks/ButtonTile.h b/Minecraft.World/Blocks/ButtonTile.h index da0f6f757..570dc1be0 100644 --- a/Minecraft.World/Blocks/ButtonTile.h +++ b/Minecraft.World/Blocks/ButtonTile.h @@ -17,7 +17,7 @@ protected: public: Icon* getTexture(int face, int data); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual int getTickDelay(Level* level); virtual bool blocksLight(); virtual bool isSolidRender(bool isServerLevel = false); @@ -74,4 +74,4 @@ public: // 4J Added so we can check before we try to add a tile to the tick list if // it's actually going to do seomthing virtual bool shouldTileTick(Level* level, int x, int y, int z); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/CactusTile.cpp b/Minecraft.World/Blocks/CactusTile.cpp index 34469f773..43aaa0062 100644 --- a/Minecraft.World/Blocks/CactusTile.cpp +++ b/Minecraft.World/Blocks/CactusTile.cpp @@ -33,9 +33,9 @@ void CactusTile::tick(Level* level, int x, int y, int z, Random* random) { } } -AABB* CactusTile::getAABB(Level* level, int x, int y, int z) { +std::optional CactusTile::getAABB(Level* level, int x, int y, int z) { float r = 1 / 16.0f; - return AABB::newTemp(x + r, y, z + r, x + 1 - r, y + 1 - r, z + 1 - r); + return AABB{x + r, static_cast(y), z + r, x + 1 - r, y + 1 - r, z + 1 - r}; } AABB* CactusTile::getTileAABB(Level* level, int x, int y, int z) { diff --git a/Minecraft.World/Blocks/CactusTile.h b/Minecraft.World/Blocks/CactusTile.h index a34b596d0..ef0cf69f9 100644 --- a/Minecraft.World/Blocks/CactusTile.h +++ b/Minecraft.World/Blocks/CactusTile.h @@ -20,7 +20,7 @@ protected: public: virtual void tick(Level* level, int x, int y, int z, Random* random); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual AABB* getTileAABB(Level* level, int x, int y, int z); virtual Icon* getTexture(int face, int data); virtual bool isCubeShaped(); @@ -37,4 +37,4 @@ public: // 4J Added so we can check before we try to add a tile to the tick list if // it's actually going to do seomthing virtual bool shouldTileTick(Level* level, int x, int y, int z); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/CakeTile.cpp b/Minecraft.World/Blocks/CakeTile.cpp index 437438c48..f35919594 100644 --- a/Minecraft.World/Blocks/CakeTile.cpp +++ b/Minecraft.World/Blocks/CakeTile.cpp @@ -34,12 +34,12 @@ void CakeTile::updateDefaultShape() { this->setShape(r, 0, r, 1 - r, h, 1 - r); } -AABB* CakeTile::getAABB(Level* level, int x, int y, int z) { +std::optional CakeTile::getAABB(Level* level, int x, int y, int z) { int d = level->getData(x, y, z); float r = 1 / 16.0f; float r2 = (1 + d * 2) / 16.0f; float h = 8 / 16.0f; - return AABB::newTemp(x + r2, y, z + r, x + 1 - r, y + h - r, z + 1 - r); + return AABB{x + r2, static_cast(y), z + r, x + 1 - r, y + h - r, z + 1 - r}; } AABB* CakeTile::getTileAABB(Level* level, int x, int y, int z) { diff --git a/Minecraft.World/Blocks/CakeTile.h b/Minecraft.World/Blocks/CakeTile.h index 4f201e0a0..ebd33baf2 100644 --- a/Minecraft.World/Blocks/CakeTile.h +++ b/Minecraft.World/Blocks/CakeTile.h @@ -24,7 +24,7 @@ protected: std::shared_ptr forceEntity = std::shared_ptr< TileEntity>()); // 4J added forceData, forceEntity param virtual void updateDefaultShape(); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual AABB* getTileAABB(Level* level, int x, int y, int z); virtual Icon* getTexture(int face, int data); //@Override @@ -49,4 +49,4 @@ public: virtual int getResourceCount(Random* random); virtual int getResource(int data, Random* random, int playerBonusLevel); int cloneTileId(Level* level, int x, int y, int z); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/CocoaTile.cpp b/Minecraft.World/Blocks/CocoaTile.cpp index c0a066699..6250508a8 100644 --- a/Minecraft.World/Blocks/CocoaTile.cpp +++ b/Minecraft.World/Blocks/CocoaTile.cpp @@ -5,6 +5,7 @@ #include "../Headers/net.minecraft.world.h" #include "../Headers/net.minecraft.h" #include "CocoaTile.h" +#include "Util/AABB.h" const std::wstring CocoaTile::TEXTURE_AGES[] = {L"cocoa_0", L"cocoa_1", L"cocoa_2"}; @@ -56,7 +57,7 @@ bool CocoaTile::isCubeShaped() { return false; } bool CocoaTile::isSolidRender(bool isServerLevel) { return false; } -AABB* CocoaTile::getAABB(Level* level, int x, int y, int z) { +std::optional CocoaTile::getAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return DirectionalTile::getAABB(level, x, y, z); } @@ -157,4 +158,4 @@ void CocoaTile::registerIcons(IconRegister* iconRegister) { for (int i = 0; i < COCOA_TEXTURES_LENGTH; i++) { icons[i] = iconRegister->registerIcon(TEXTURE_AGES[i]); } -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/CocoaTile.h b/Minecraft.World/Blocks/CocoaTile.h index 9726e232b..7ff5c81ee 100644 --- a/Minecraft.World/Blocks/CocoaTile.h +++ b/Minecraft.World/Blocks/CocoaTile.h @@ -22,7 +22,7 @@ public: virtual int getRenderShape(); virtual bool isCubeShaped(); virtual bool isSolidRender(bool isServerLevel = false); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual AABB* getTileAABB(Level* level, int x, int y, int z); virtual void updateShape(LevelSource* level, int x, int y, int z, int forceData = -1, diff --git a/Minecraft.World/Blocks/DoorTile.cpp b/Minecraft.World/Blocks/DoorTile.cpp index 11378ce8a..df461bb6b 100644 --- a/Minecraft.World/Blocks/DoorTile.cpp +++ b/Minecraft.World/Blocks/DoorTile.cpp @@ -91,10 +91,9 @@ AABB* DoorTile::getTileAABB(Level* level, int x, int y, int z) { return retval; } -AABB* DoorTile::getAABB(Level* level, int x, int y, int z) { +std::optional DoorTile::getAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); - AABB* retval = Tile::getAABB(level, x, y, z); - return retval; + return Tile::getAABB(level, x, y, z); } void DoorTile::updateShape( @@ -307,4 +306,4 @@ void DoorTile::playerWillDestroy(Level* level, int x, int y, int z, int data, } } } -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/DoorTile.h b/Minecraft.World/Blocks/DoorTile.h index 1c9abde7b..339775515 100644 --- a/Minecraft.World/Blocks/DoorTile.h +++ b/Minecraft.World/Blocks/DoorTile.h @@ -41,7 +41,7 @@ public: virtual bool isCubeShaped(); virtual int getRenderShape(); virtual AABB* getTileAABB(Level* level, int x, int y, int z); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< diff --git a/Minecraft.World/Blocks/FarmTile.cpp b/Minecraft.World/Blocks/FarmTile.cpp index dce769962..191f0963c 100644 --- a/Minecraft.World/Blocks/FarmTile.cpp +++ b/Minecraft.World/Blocks/FarmTile.cpp @@ -17,8 +17,8 @@ FarmTile::FarmTile(int id) : Tile(id, Material::dirt, false) { // 4J Added override void FarmTile::updateDefaultShape() { setShape(0, 0, 0, 1, 15 / 16.0f, 1); } -AABB* FarmTile::getAABB(Level* level, int x, int y, int z) { - return AABB::newTemp(x + 0, y + 0, z + 0, x + 1, y + 1, z + 1); +std::optional FarmTile::getAABB(Level* level, int x, int y, int z) { + return AABB(x + 0, y + 0, z + 0, x + 1, y + 1, z + 1); } bool FarmTile::isSolidRender(bool isServerLevel) { return false; } diff --git a/Minecraft.World/Blocks/FarmTile.h b/Minecraft.World/Blocks/FarmTile.h index 15be34ebd..ee7a7e3df 100644 --- a/Minecraft.World/Blocks/FarmTile.h +++ b/Minecraft.World/Blocks/FarmTile.h @@ -18,7 +18,7 @@ protected: public: virtual void updateDefaultShape(); // 4J Added override - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool isSolidRender(bool isServerLevel = false); virtual bool isCubeShaped(); virtual Icon* getTexture(int face, int data); diff --git a/Minecraft.World/Blocks/FenceGateTile.cpp b/Minecraft.World/Blocks/FenceGateTile.cpp index 44ee44135..2b947b0e8 100644 --- a/Minecraft.World/Blocks/FenceGateTile.cpp +++ b/Minecraft.World/Blocks/FenceGateTile.cpp @@ -4,6 +4,7 @@ #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.h" #include "../Level/Events/LevelEvent.h" +#include "Util/Direction.h" FenceGateTile::FenceGateTile(int id) : DirectionalTile(id, Material::wood, false) {} @@ -17,19 +18,29 @@ bool FenceGateTile::mayPlace(Level* level, int x, int y, int z) { return Tile::mayPlace(level, x, y, z); } -AABB* FenceGateTile::getAABB(Level* level, int x, int y, int z) { +std::optional FenceGateTile::getAABB(Level* level, int x, int y, int z) { int data = level->getData(x, y, z); if (isOpen(data)) { - return NULL; + return std::nullopt; } - // 4J Brought forward change from 1.2.3 to fix hit box rotation - if (data == Direction::NORTH || data == Direction::SOUTH) { - return AABB::newTemp(x, y, z + 6.0f / 16.0f, x + 1, y + 1.5f, - z + 10.0f / 16.0f); + + switch (data) { + case Direction::NORTH: + case Direction::SOUTH: + return AABB{static_cast(x), + static_cast(y), + z + 6.0 / 16.0, + x + 1.0, + y + 1.5, + z + 10.0 / 16.0}; + default: + return AABB{x + 6.0 / 16.0, + static_cast(y), + static_cast(z), + x + 10.0 / 16.0, + y + 1.5, + z + 1.0}; } - return AABB::newTemp(x + 6.0f / 16.0f, y, z, x + 10.0f / 16.0f, y + 1.5f, - z + 1); - // return AABB::newTemp(x, y, z, x + 1, y + 1.5f, z + 1); } // 4J - Brought forward from 1.2.3 to fix hit box rotation diff --git a/Minecraft.World/Blocks/FenceGateTile.h b/Minecraft.World/Blocks/FenceGateTile.h index 85767bf37..c43b41416 100644 --- a/Minecraft.World/Blocks/FenceGateTile.h +++ b/Minecraft.World/Blocks/FenceGateTile.h @@ -9,7 +9,7 @@ public: FenceGateTile(int id); Icon* getTexture(int face, int data); virtual bool mayPlace(Level* level, int x, int y, int z); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< diff --git a/Minecraft.World/Blocks/FireTile.cpp b/Minecraft.World/Blocks/FireTile.cpp index 8b5d45b51..e70202920 100644 --- a/Minecraft.World/Blocks/FireTile.cpp +++ b/Minecraft.World/Blocks/FireTile.cpp @@ -7,6 +7,7 @@ #include "../Util/SoundTypes.h" #include "../../Minecraft.Client/MinecraftServer.h" #include "../../Minecraft.Client/Network/PlayerList.h" +#include "Util/AABB.h" // AP - added for Vita to set Alpha Cut out #include "../IO/Streams/IntBuffer.h" @@ -57,7 +58,7 @@ void FireTile::setFlammable(int id, int flame, int burn) { burnOdds[id] = burn; } -AABB* FireTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional FireTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } bool FireTile::blocksLight() { return false; } diff --git a/Minecraft.World/Blocks/FireTile.h b/Minecraft.World/Blocks/FireTile.h index 260e98d97..c93e7e94f 100644 --- a/Minecraft.World/Blocks/FireTile.h +++ b/Minecraft.World/Blocks/FireTile.h @@ -39,7 +39,7 @@ private: void setFlammable(int id, int flame, int burn); public: - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool blocksLight(); virtual bool isSolidRender(bool isServerLevel = false); virtual bool isCubeShaped(); @@ -69,4 +69,4 @@ public: void registerIcons(IconRegister* iconRegister); Icon* getTextureLayer(int layer); Icon* getTexture(int face, int data); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/LadderTile.cpp b/Minecraft.World/Blocks/LadderTile.cpp index ac0595ea5..f95650843 100644 --- a/Minecraft.World/Blocks/LadderTile.cpp +++ b/Minecraft.World/Blocks/LadderTile.cpp @@ -1,11 +1,12 @@ #include "../Platform/stdafx.h" #include "../Headers/net.minecraft.world.level.h" #include "LadderTile.h" +#include "Util/AABB.h" LadderTile::LadderTile(int id) : Tile(id, Material::decoration, false) {} -AABB* LadderTile::getAABB(Level* level, int x, int y, int z) { +std::optional LadderTile::getAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return Tile::getAABB(level, x, y, z); } @@ -87,4 +88,4 @@ void LadderTile::neighborChanged(Level* level, int x, int y, int z, int type) { Tile::neighborChanged(level, x, y, z, type); } -int LadderTile::getResourceCount(Random* random) { return 1; } \ No newline at end of file +int LadderTile::getResourceCount(Random* random) { return 1; } diff --git a/Minecraft.World/Blocks/LadderTile.h b/Minecraft.World/Blocks/LadderTile.h index d91eeda1f..133c01230 100644 --- a/Minecraft.World/Blocks/LadderTile.h +++ b/Minecraft.World/Blocks/LadderTile.h @@ -11,7 +11,7 @@ protected: LadderTile(int id); public: - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual AABB* getTileAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, @@ -29,4 +29,4 @@ public: float clickZ, int itemValue); virtual void neighborChanged(Level* level, int x, int y, int z, int type); virtual int getResourceCount(Random* random); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/LeverTile.cpp b/Minecraft.World/Blocks/LeverTile.cpp index e44a69ac3..ffb8deead 100644 --- a/Minecraft.World/Blocks/LeverTile.cpp +++ b/Minecraft.World/Blocks/LeverTile.cpp @@ -3,11 +3,12 @@ #include "../Headers/net.minecraft.world.level.redstone.h" #include "../Headers/net.minecraft.h" #include "LeverTile.h" +#include "Util/AABB.h" LeverTile::LeverTile(int id) : Tile(id, Material::decoration, false) {} -AABB* LeverTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional LeverTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } bool LeverTile::blocksLight() { return false; } diff --git a/Minecraft.World/Blocks/LeverTile.h b/Minecraft.World/Blocks/LeverTile.h index 47a6b21cf..7f27ba4a4 100644 --- a/Minecraft.World/Blocks/LeverTile.h +++ b/Minecraft.World/Blocks/LeverTile.h @@ -8,7 +8,7 @@ protected: LeverTile(int id); public: - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool blocksLight(); virtual bool isSolidRender(bool isServerLevel = false); virtual bool isCubeShaped(); diff --git a/Minecraft.World/Blocks/LiquidTile.cpp b/Minecraft.World/Blocks/LiquidTile.cpp index af1ee85b4..1c94595f9 100644 --- a/Minecraft.World/Blocks/LiquidTile.cpp +++ b/Minecraft.World/Blocks/LiquidTile.cpp @@ -5,9 +5,11 @@ #include "../Headers/net.minecraft.world.level.biome.h" #include "../Headers/net.minecraft.world.h" #include "LiquidTile.h" +#include #include "../Util/Facing.h" #include "../Util/SoundTypes.h" #include "Blocks/Material.h" +#include "Util/AABB.h" const std::wstring LiquidTile::TEXTURE_LAVA_STILL = L"lava"; const std::wstring LiquidTile::TEXTURE_WATER_STILL = L"water"; @@ -107,7 +109,9 @@ bool LiquidTile::shouldRenderFace(LevelSource* level, int x, int y, int z, return Tile::shouldRenderFace(level, x, y, z, face); } -AABB* LiquidTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional LiquidTile::getAABB(Level* level, int x, int y, int z) { + return std::nullopt; +} int LiquidTile::getRenderShape() { return Tile::SHAPE_WATER; } diff --git a/Minecraft.World/Blocks/LiquidTile.h b/Minecraft.World/Blocks/LiquidTile.h index 1d59d274a..7ffed063a 100644 --- a/Minecraft.World/Blocks/LiquidTile.h +++ b/Minecraft.World/Blocks/LiquidTile.h @@ -1,4 +1,5 @@ #pragma once +#include #include "Tile.h" #include "../Util/Definitions.h" @@ -40,7 +41,7 @@ public: virtual bool isSolidFace(LevelSource* level, int x, int y, int z, int face); virtual bool shouldRenderFace(LevelSource* level, int x, int y, int z, int face); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual int getRenderShape(); virtual int getResource(int data, Random* random, int playerBonusLevel); virtual int getResourceCount(Random* random); diff --git a/Minecraft.World/Blocks/PistonBaseTile.cpp b/Minecraft.World/Blocks/PistonBaseTile.cpp index de8c30b23..8a85152cc 100644 --- a/Minecraft.World/Blocks/PistonBaseTile.cpp +++ b/Minecraft.World/Blocks/PistonBaseTile.cpp @@ -1,5 +1,6 @@ #include "../Platform/stdafx.h" #include +#include #include "PistonBaseTile.h" #include "PistonMovingTileEntity.h" #include "TileEntities/PistonPieceTileEntity.h" @@ -12,6 +13,8 @@ #include "../Level/LevelChunk.h" #include "../Level/Dimensions/Dimension.h" +#include "Util/AABB.h" + const std::wstring PistonBaseTile::EDGE_TEX = L"piston_side"; const std::wstring PistonBaseTile::PLATFORM_TEX = L"piston_top"; const std::wstring PistonBaseTile::PLATFORM_STICKY_TEX = L"piston_top_sticky"; @@ -398,7 +401,7 @@ void PistonBaseTile::addAABBs(Level* level, int x, int y, int z, AABB* box, Tile::addAABBs(level, x, y, z, box, boxes, source); } -AABB* PistonBaseTile::getAABB(Level* level, int x, int y, int z) { +std::optional PistonBaseTile::getAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return Tile::getAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/PistonBaseTile.h b/Minecraft.World/Blocks/PistonBaseTile.h index 272b44e81..36097aacf 100644 --- a/Minecraft.World/Blocks/PistonBaseTile.h +++ b/Minecraft.World/Blocks/PistonBaseTile.h @@ -1,6 +1,7 @@ #pragma once #include "Tile.h" #include +#include class PistonBaseTile : public Tile { public: @@ -68,7 +69,7 @@ public: virtual void updateDefaultShape(); virtual void addAABBs(Level* level, int x, int y, int z, AABB* box, AABBList* boxes, std::shared_ptr source); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool isCubeShaped(); static int getFacing(int data); @@ -84,4 +85,4 @@ private: int z); // 4J added bool createPush(Level* level, int sx, int sy, int sz, int facing); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/PistonMovingTileEntity.cpp b/Minecraft.World/Blocks/PistonMovingTileEntity.cpp index b12d0dd7d..f4109695d 100644 --- a/Minecraft.World/Blocks/PistonMovingTileEntity.cpp +++ b/Minecraft.World/Blocks/PistonMovingTileEntity.cpp @@ -1,5 +1,6 @@ #include "../Platform/stdafx.h" #include "PistonMovingTileEntity.h" +#include #include "TileEntities/PistonPieceTileEntity.h" #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.h" @@ -91,10 +92,11 @@ std::shared_ptr PistonMovingPiece::newMovingPieceEntity( new PistonPieceEntity(block, data, facing, extending, isSourcePiston)); } -AABB* PistonMovingPiece::getAABB(Level* level, int x, int y, int z) { +std::optional PistonMovingPiece::getAABB(Level* level, int x, int y, + int z) { std::shared_ptr entity = getEntity(level, x, y, z); if (entity == NULL) { - return NULL; + return std::nullopt; } // move the aabb depending on the animation @@ -136,15 +138,16 @@ void PistonMovingPiece::updateShape( } } -AABB* PistonMovingPiece::getAABB(Level* level, int x, int y, int z, int tile, - float progress, int facing) { +std::optional PistonMovingPiece::getAABB(Level* level, int x, int y, + int z, int tile, float progress, + int facing) { if (tile == 0 || tile == id) { - return NULL; + return std::nullopt; } - AABB* aabb = Tile::tiles[tile]->getAABB(level, x, y, z); + auto aabb = Tile::tiles[tile]->getAABB(level, x, y, z); - if (aabb == NULL) { - return NULL; + if (!aabb.has_value()) { + return std::nullopt; } // move the aabb depending on the animation @@ -153,16 +156,19 @@ AABB* PistonMovingPiece::getAABB(Level* level, int x, int y, int z, int tile, } else { aabb->x1 -= Facing::STEP_X[facing] * progress; } + if (Facing::STEP_Y[facing] < 0) { aabb->y0 -= Facing::STEP_Y[facing] * progress; } else { aabb->y1 -= Facing::STEP_Y[facing] * progress; } + if (Facing::STEP_Z[facing] < 0) { aabb->z0 -= Facing::STEP_Z[facing] * progress; } else { aabb->z1 -= Facing::STEP_Z[facing] * progress; } + return aabb; } diff --git a/Minecraft.World/Blocks/PistonMovingTileEntity.h b/Minecraft.World/Blocks/PistonMovingTileEntity.h index 530c6e87d..ec3a5aa7f 100644 --- a/Minecraft.World/Blocks/PistonMovingTileEntity.h +++ b/Minecraft.World/Blocks/PistonMovingTileEntity.h @@ -28,13 +28,13 @@ public: virtual void neighborChanged(Level* level, int x, int y, int z, int type); static std::shared_ptr newMovingPieceEntity( int block, int data, int facing, bool extending, bool isSourcePiston); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< TileEntity>()); // 4J added forceData, forceEntity param - AABB* getAABB(Level* level, int x, int y, int z, int tile, float progress, + std::optional getAABB(Level* level, int x, int y, int z, int tile, float progress, int facing); private: @@ -44,4 +44,4 @@ private: public: virtual int cloneTileId(Level* level, int x, int y, int z); void registerIcons(IconRegister* iconRegister); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/PlantTile.cpp b/Minecraft.World/Blocks/PlantTile.cpp index ee3f09669..543008466 100644 --- a/Minecraft.World/Blocks/PlantTile.cpp +++ b/Minecraft.World/Blocks/PlantTile.cpp @@ -2,6 +2,7 @@ #include "../Headers/net.minecraft.world.level.h" #include "GrassTile.h" #include "PlantTile.h" +#include "Util/AABB.h" void Bush::_init() { setTicking(true); @@ -52,7 +53,7 @@ bool Bush::canSurvive(Level* level, int x, int y, int z) { mayPlaceOn(level->getTile(x, y - 1, z)); } -AABB* Bush::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional Bush::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } bool Bush::blocksLight() { return false; } diff --git a/Minecraft.World/Blocks/PlantTile.h b/Minecraft.World/Blocks/PlantTile.h index 53ebbcb46..72c134196 100644 --- a/Minecraft.World/Blocks/PlantTile.h +++ b/Minecraft.World/Blocks/PlantTile.h @@ -32,7 +32,7 @@ protected: public: virtual bool canSurvive(Level* level, int x, int y, int z); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool blocksLight(); virtual bool isSolidRender(bool isServerLevel = false); diff --git a/Minecraft.World/Blocks/PortalTile.cpp b/Minecraft.World/Blocks/PortalTile.cpp index 994e79a24..bd4f199b3 100644 --- a/Minecraft.World/Blocks/PortalTile.cpp +++ b/Minecraft.World/Blocks/PortalTile.cpp @@ -4,6 +4,9 @@ #include "../Headers/net.minecraft.world.level.dimension.h" #include "../Headers/net.minecraft.world.item.h" #include "PortalTile.h" +#include + +#include "Util/AABB.h" #include "FireTile.h" PortalTile::PortalTile(int id) @@ -34,7 +37,7 @@ void PortalTile::tick(Level* level, int x, int y, int z, Random* random) { } } -AABB* PortalTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional PortalTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } void PortalTile::updateShape( LevelSource* level, int x, int y, int z, int forceData, diff --git a/Minecraft.World/Blocks/PortalTile.h b/Minecraft.World/Blocks/PortalTile.h index b498fb1ac..c62fb1033 100644 --- a/Minecraft.World/Blocks/PortalTile.h +++ b/Minecraft.World/Blocks/PortalTile.h @@ -1,4 +1,5 @@ #pragma once +#include #include "HalfTransparentTile.h" #include "../Util/Definitions.h" @@ -8,7 +9,7 @@ class PortalTile : public HalfTransparentTile { public: PortalTile(int id); virtual void tick(Level* level, int x, int y, int z, Random* random); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< diff --git a/Minecraft.World/Blocks/RedStoneDustTile.cpp b/Minecraft.World/Blocks/RedStoneDustTile.cpp index f4e3ce074..581469f50 100644 --- a/Minecraft.World/Blocks/RedStoneDustTile.cpp +++ b/Minecraft.World/Blocks/RedStoneDustTile.cpp @@ -1,6 +1,8 @@ #include "../Platform/stdafx.h" #include "../../Minecraft.Client/Minecraft.h" #include "RedStoneDustTile.h" +#include +#include #include "../Headers/net.minecraft.world.item.h" #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.level.redstone.h" @@ -9,6 +11,7 @@ #include "../Headers/net.minecraft.h" #include "../Util/Direction.h" #include "DiodeTile.h" +#include "Util/AABB.h" // AP - added for Vita to set Alpha Cut out #include "../IO/Streams/IntBuffer.h" @@ -36,8 +39,9 @@ void RedStoneDustTile::updateDefaultShape() { setShape(0, 0, 0, 1, 1 / 16.0f, 1); } -AABB* RedStoneDustTile::getAABB(Level* level, int x, int y, int z) { - return NULL; +std::optional RedStoneDustTile::getAABB(Level* level, int x, int y, + int z) { + return std::nullopt; } bool RedStoneDustTile::isSolidRender(bool isServerLevel) { return false; } diff --git a/Minecraft.World/Blocks/RedStoneDustTile.h b/Minecraft.World/Blocks/RedStoneDustTile.h index 872f9ea58..e9656d395 100644 --- a/Minecraft.World/Blocks/RedStoneDustTile.h +++ b/Minecraft.World/Blocks/RedStoneDustTile.h @@ -1,4 +1,5 @@ #pragma once +#include #include "Tile.h" #include "../Util/Definitions.h" @@ -26,7 +27,7 @@ private: public: RedStoneDustTile(int id); virtual void updateDefaultShape(); // 4J Added override - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool isSolidRender(bool isServerLevel = false); virtual bool isCubeShaped(); virtual int getRenderShape(); diff --git a/Minecraft.World/Blocks/ReedTile.cpp b/Minecraft.World/Blocks/ReedTile.cpp index c9297caf4..7961dbaeb 100644 --- a/Minecraft.World/Blocks/ReedTile.cpp +++ b/Minecraft.World/Blocks/ReedTile.cpp @@ -5,6 +5,7 @@ #include "../Headers/net.minecraft.world.level.material.h" #include "../Headers/net.minecraft.world.phys.h" #include "ReedTile.h" +#include ReedTile::ReedTile(int id) : Tile(id, Material::plant, false) { this->updateDefaultShape(); @@ -64,7 +65,7 @@ bool ReedTile::canSurvive(Level* level, int x, int y, int z) { return mayPlace(level, x, y, z); } -AABB* ReedTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional ReedTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } int ReedTile::getResource(int data, Random* random, int playerBonusLevel) { return Item::reeds->id; diff --git a/Minecraft.World/Blocks/ReedTile.h b/Minecraft.World/Blocks/ReedTile.h index dd3a3bab4..4fbe21aa3 100644 --- a/Minecraft.World/Blocks/ReedTile.h +++ b/Minecraft.World/Blocks/ReedTile.h @@ -1,5 +1,6 @@ #pragma once +#include #include "Tile.h" #include "../Util/Definitions.h" @@ -28,7 +29,7 @@ public: bool canSurvive(Level* level, int x, int y, int z); public: - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); public: int getResource(int data, Random* random, int playerBonusLevel); diff --git a/Minecraft.World/Blocks/SignTile.cpp b/Minecraft.World/Blocks/SignTile.cpp index 0ffd3e7b9..2004f9e4a 100644 --- a/Minecraft.World/Blocks/SignTile.cpp +++ b/Minecraft.World/Blocks/SignTile.cpp @@ -4,6 +4,9 @@ #include "Material.h" #include "TileEntities/SignTileEntity.h" #include "SignTile.h" +#include "Util/AABB.h" + +#include SignTile::SignTile(int id, eINSTANCEOF clas, bool onGround) : BaseEntityTile(id, Material::wood, false) { @@ -22,7 +25,7 @@ void SignTile::updateDefaultShape() { this->setShape(0.5f - r, 0, 0.5f - r, 0.5f + r, h, 0.5f + r); } -AABB* SignTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional SignTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } AABB* SignTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); @@ -109,4 +112,4 @@ int SignTile::cloneTileId(Level* level, int x, int y, int z) { void SignTile::registerIcons(IconRegister* iconRegister) { // None -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/SignTile.h b/Minecraft.World/Blocks/SignTile.h index b3e5ec372..9e4c009d2 100644 --- a/Minecraft.World/Blocks/SignTile.h +++ b/Minecraft.World/Blocks/SignTile.h @@ -1,5 +1,6 @@ #pragma once +#include #include "BaseEntityTile.h" #include "TileEntities/TileEntity.h" @@ -19,7 +20,7 @@ protected: public: Icon* getTexture(int face, int data); virtual void updateDefaultShape(); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); AABB* getTileAABB(Level* level, int x, int y, int z); void updateShape(LevelSource* level, int x, int y, int z, int forceData = -1, @@ -39,4 +40,4 @@ public: void neighborChanged(Level* level, int x, int y, int z, int type); int cloneTileId(Level* level, int x, int y, int z); void registerIcons(IconRegister* iconRegister); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/SkullTile.cpp b/Minecraft.World/Blocks/SkullTile.cpp index 251cb7833..1a0340b7d 100644 --- a/Minecraft.World/Blocks/SkullTile.cpp +++ b/Minecraft.World/Blocks/SkullTile.cpp @@ -49,7 +49,7 @@ void SkullTile::updateShape(LevelSource* level, int x, int y, int z, } } -AABB* SkullTile::getAABB(Level* level, int x, int y, int z) { +std::optional SkullTile::getAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return BaseEntityTile::getAABB(level, x, y, z); } @@ -316,4 +316,4 @@ Icon* SkullTile::getTexture(int face, int data) { std::wstring SkullTile::getTileItemIconName() { return getIconName() + L"_" + SkullItem::ICON_NAMES[0]; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/SkullTile.h b/Minecraft.World/Blocks/SkullTile.h index 5c2642b01..f8fea1299 100644 --- a/Minecraft.World/Blocks/SkullTile.h +++ b/Minecraft.World/Blocks/SkullTile.h @@ -26,7 +26,7 @@ public: int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr()); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); void setPlacedBy(Level* level, int x, int y, int z, std::shared_ptr by); std::shared_ptr newTileEntity(Level* level); diff --git a/Minecraft.World/Blocks/SoulSandTile.cpp b/Minecraft.World/Blocks/SoulSandTile.cpp index 22b4f8509..b9f7b48df 100644 --- a/Minecraft.World/Blocks/SoulSandTile.cpp +++ b/Minecraft.World/Blocks/SoulSandTile.cpp @@ -5,9 +5,9 @@ SoulSandTile::SoulSandTile(int id) : Tile(id, Material::sand) {} -AABB* SoulSandTile::getAABB(Level* level, int x, int y, int z) { +std::optional SoulSandTile::getAABB(Level* level, int x, int y, int z) { float r = 2 / 16.0f; - return AABB::newTemp(x, y, z, x + 1, y + 1 - r, z + 1); + return AABB(x, y, z, x + 1, y + 1 - r, z + 1); } void SoulSandTile::entityInside(Level* level, int x, int y, int z, diff --git a/Minecraft.World/Blocks/SoulSandTile.h b/Minecraft.World/Blocks/SoulSandTile.h index 62d6b1e45..b45c8dc53 100644 --- a/Minecraft.World/Blocks/SoulSandTile.h +++ b/Minecraft.World/Blocks/SoulSandTile.h @@ -5,7 +5,7 @@ class SoulSandTile : public Tile { public: SoulSandTile(int id); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual void entityInside(Level* level, int x, int y, int z, std::shared_ptr entity); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/Tile.cpp b/Minecraft.World/Blocks/Tile.cpp index a2033379b..66d58c632 100644 --- a/Minecraft.World/Blocks/Tile.cpp +++ b/Minecraft.World/Blocks/Tile.cpp @@ -2015,16 +2015,16 @@ 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 source) { - AABB* aabb = getAABB(level, x, y, z); - if (aabb != NULL && box->intersects(*aabb)) boxes->push_back(*aabb); + auto aabb = getAABB(level, x, y, z); + if (aabb.has_value() && box->intersects(*aabb)) boxes->push_back(*aabb); } -AABB* Tile::getAABB(Level* level, int x, int y, int z) { +std::optional Tile::getAABB(Level* level, int x, int y, int z) { ThreadStorage* tls = m_tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if (tls->tileId != this->id) updateDefaultShape(); - return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, - y + tls->yy1, z + tls->zz1); + return AABB{x + tls->xx0, y + tls->yy0, z + tls->zz0, + x + tls->xx1, y + tls->yy1, z + tls->zz1}; } bool Tile::isSolidRender(bool isServerLevel) { return true; } diff --git a/Minecraft.World/Blocks/Tile.h b/Minecraft.World/Blocks/Tile.h index b46748ff5..4346f6d26 100644 --- a/Minecraft.World/Blocks/Tile.h +++ b/Minecraft.World/Blocks/Tile.h @@ -4,6 +4,7 @@ #include "../Util/Definitions.h" #include "../Util/SoundTypes.h" #include +#include class GrassTile; class LeafTile; @@ -633,7 +634,7 @@ public: virtual AABB* getTileAABB(Level* level, int x, int y, int z); virtual void addAABBs(Level* level, int x, int y, int z, AABB* box, AABBList* boxes, std::shared_ptr source); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool isSolidRender( bool isServerLevel = false); // 4J - Added isServerLevel param virtual bool mayPick(int data, bool liquid); diff --git a/Minecraft.World/Blocks/TileEntities/PistonPieceTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/PistonPieceTileEntity.cpp index fb49032ca..84d73b9c7 100644 --- a/Minecraft.World/Blocks/TileEntities/PistonPieceTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/PistonPieceTileEntity.cpp @@ -5,6 +5,7 @@ #include "../../Headers/net.minecraft.world.level.h" #include "../../Util/Facing.h" #include "../Tile.h" +#include "../../Util/AABB.h" PistonPieceEntity::PistonPieceEntity() { // for the tile entity loader @@ -81,11 +82,11 @@ void PistonPieceEntity::moveCollidedEntities(float progress, float amount) { progress = progress - 1.0f; } - AABB* aabb = + auto aabb = Tile::pistonMovingPiece->getAABB(level, x, y, z, id, progress, facing); - if (aabb != NULL) { + if (aabb.has_value()) { std::vector >* entities = - level->getEntities(nullptr, aabb); + level->getEntities(nullptr, &*aabb); if (!entities->empty()) { std::vector > collisionHolder; for (AUTO_VAR(it, entities->begin()); it != entities->end(); it++) { diff --git a/Minecraft.World/Blocks/TopSnowTile.cpp b/Minecraft.World/Blocks/TopSnowTile.cpp index 8ba44c61b..cd5182116 100644 --- a/Minecraft.World/Blocks/TopSnowTile.cpp +++ b/Minecraft.World/Blocks/TopSnowTile.cpp @@ -21,11 +21,11 @@ void TopSnowTile::registerIcons(IconRegister* iconRegister) { icon = iconRegister->registerIcon(L"snow"); } -AABB* TopSnowTile::getAABB(Level* level, int x, int y, int z) { +std::optional TopSnowTile::getAABB(Level* level, int x, int y, int z) { int height = level->getData(x, y, z) & HEIGHT_MASK; float offset = 2.0f / SharedConstants::WORLD_RESOLUTION; ThreadStorage* tls = m_tlsShape; - return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, + return AABB(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + (height * offset), z + tls->zz1); } diff --git a/Minecraft.World/Blocks/TopSnowTile.h b/Minecraft.World/Blocks/TopSnowTile.h index 710aab8b8..bfa529d76 100644 --- a/Minecraft.World/Blocks/TopSnowTile.h +++ b/Minecraft.World/Blocks/TopSnowTile.h @@ -16,7 +16,7 @@ protected: public: void registerIcons(IconRegister* iconRegister); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); public: static float getHeight(Level* level, int x, int y, int z); diff --git a/Minecraft.World/Blocks/TorchTile.cpp b/Minecraft.World/Blocks/TorchTile.cpp index bca94562f..556370789 100644 --- a/Minecraft.World/Blocks/TorchTile.cpp +++ b/Minecraft.World/Blocks/TorchTile.cpp @@ -3,12 +3,14 @@ #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.level.tile.h" #include "TorchTile.h" +#include +#include "Util/AABB.h" TorchTile::TorchTile(int id) : Tile(id, Material::decoration, false) { this->setTicking(true); } -AABB* TorchTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional TorchTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } AABB* TorchTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); diff --git a/Minecraft.World/Blocks/TorchTile.h b/Minecraft.World/Blocks/TorchTile.h index 0369a3584..3f7d0a4d1 100644 --- a/Minecraft.World/Blocks/TorchTile.h +++ b/Minecraft.World/Blocks/TorchTile.h @@ -12,7 +12,7 @@ protected: TorchTile(int id); public: - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual AABB* getTileAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, diff --git a/Minecraft.World/Blocks/TrapDoorTile.cpp b/Minecraft.World/Blocks/TrapDoorTile.cpp index eb685504d..bca1ce813 100644 --- a/Minecraft.World/Blocks/TrapDoorTile.cpp +++ b/Minecraft.World/Blocks/TrapDoorTile.cpp @@ -4,6 +4,7 @@ #include "../Headers/net.minecraft.world.level.tile.h" #include "../Headers/net.minecraft.h" #include "TrapDoorTile.h" +#include "Util/AABB.h" TrapDoorTile::TrapDoorTile(int id, Material* material) : Tile(id, material, false) { @@ -29,7 +30,7 @@ AABB* TrapDoorTile::getTileAABB(Level* level, int x, int y, int z) { return Tile::getTileAABB(level, x, y, z); } -AABB* TrapDoorTile::getAABB(Level* level, int x, int y, int z) { +std::optional TrapDoorTile::getAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return Tile::getAABB(level, x, y, z); } @@ -175,4 +176,4 @@ bool TrapDoorTile::attachesTo(int id) { tile == Tile::glowstone || (dynamic_cast(tile) != NULL) || (dynamic_cast(tile) != NULL); -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/TrapDoorTile.h b/Minecraft.World/Blocks/TrapDoorTile.h index f2e978759..9765b61c6 100644 --- a/Minecraft.World/Blocks/TrapDoorTile.h +++ b/Minecraft.World/Blocks/TrapDoorTile.h @@ -40,7 +40,7 @@ public: AABB* getTileAABB(Level* level, int x, int y, int z); public: - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); public: void updateShape(LevelSource* level, int x, int y, int z, @@ -91,4 +91,4 @@ public: private: static bool attachesTo(int id); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/TripWireSourceTile.cpp b/Minecraft.World/Blocks/TripWireSourceTile.cpp index 14fc620b9..c9115901e 100644 --- a/Minecraft.World/Blocks/TripWireSourceTile.cpp +++ b/Minecraft.World/Blocks/TripWireSourceTile.cpp @@ -4,14 +4,16 @@ #include "../Headers/net.minecraft.world.level.tile.h" #include "../Headers/net.minecraft.world.level.redstone.h" #include "TripWireSourceTile.h" +#include "optional" +#include "Util/AABB.h" TripWireSourceTile::TripWireSourceTile(int id) : Tile(id, Material::decoration, false) { this->setTicking(true); } -AABB* TripWireSourceTile::getAABB(Level* level, int x, int y, int z) { - return NULL; +std::optional TripWireSourceTile::getAABB(Level* level, int x, int y, int z) { + return std::nullopt; } bool TripWireSourceTile::blocksLight() { return false; } diff --git a/Minecraft.World/Blocks/TripWireSourceTile.h b/Minecraft.World/Blocks/TripWireSourceTile.h index 9cce09eb6..e23c61feb 100644 --- a/Minecraft.World/Blocks/TripWireSourceTile.h +++ b/Minecraft.World/Blocks/TripWireSourceTile.h @@ -14,7 +14,7 @@ public: TripWireSourceTile(int id); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); bool blocksLight(); bool isSolidRender(bool isServerLevel = false); bool isCubeShaped(); diff --git a/Minecraft.World/Blocks/TripWireTile.cpp b/Minecraft.World/Blocks/TripWireTile.cpp index 0e5755e47..e72ea5cdd 100644 --- a/Minecraft.World/Blocks/TripWireTile.cpp +++ b/Minecraft.World/Blocks/TripWireTile.cpp @@ -4,6 +4,7 @@ #include "../Headers/net.minecraft.world.level.tile.h" #include "../Headers/net.minecraft.world.phys.h" #include "TripWireTile.h" +#include TripWireTile::TripWireTile(int id) : Tile(id, Material::decoration, false) { setShape(0, 0, 0, 1, 2.5f / 16.0f, 1); @@ -16,7 +17,7 @@ int TripWireTile::getTickDelay(Level* level) { return 20; // 10; } -AABB* TripWireTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional TripWireTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } bool TripWireTile::blocksLight() { return false; } diff --git a/Minecraft.World/Blocks/TripWireTile.h b/Minecraft.World/Blocks/TripWireTile.h index f6c7becef..6963d0305 100644 --- a/Minecraft.World/Blocks/TripWireTile.h +++ b/Minecraft.World/Blocks/TripWireTile.h @@ -14,7 +14,7 @@ public: TripWireTile(int id); int getTickDelay(Level* level); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); bool blocksLight(); bool isSolidRender(bool isServerLevel = false); bool isCubeShaped(); diff --git a/Minecraft.World/Blocks/VineTile.cpp b/Minecraft.World/Blocks/VineTile.cpp index d2febbaa9..787fb4588 100644 --- a/Minecraft.World/Blocks/VineTile.cpp +++ b/Minecraft.World/Blocks/VineTile.cpp @@ -7,6 +7,7 @@ #include "../Headers/net.minecraft.world.item.h" #include "../Headers/net.minecraft.stats.h" #include "../Headers/net.minecraft.world.level.biome.h" +#include "Util/AABB.h" VineTile::VineTile(int id) : Tile(id, Material::replaceable_plant, false) { @@ -85,7 +86,7 @@ void VineTile::updateShape( setShape(minX, minY, minZ, maxX, maxY, maxZ); } -AABB* VineTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional VineTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } bool VineTile::mayPlace(Level* level, int x, int y, int z, int face) { switch (face) { diff --git a/Minecraft.World/Blocks/VineTile.h b/Minecraft.World/Blocks/VineTile.h index 965eba70f..dc123a38c 100644 --- a/Minecraft.World/Blocks/VineTile.h +++ b/Minecraft.World/Blocks/VineTile.h @@ -21,7 +21,7 @@ public: LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< TileEntity>()); // 4J added forceData, forceEntity param - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual bool mayPlace(Level* level, int x, int y, int z, int face); private: @@ -43,4 +43,4 @@ public: virtual int getResourceCount(Random* random); virtual void playerDestroy(Level* level, std::shared_ptr player, int x, int y, int z, int data); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/WallTile.cpp b/Minecraft.World/Blocks/WallTile.cpp index 67d3c0bae..a072b82c8 100644 --- a/Minecraft.World/Blocks/WallTile.cpp +++ b/Minecraft.World/Blocks/WallTile.cpp @@ -80,7 +80,7 @@ void WallTile::updateShape(LevelSource* level, int x, int y, int z, setShape(west, 0, north, east, up, south); } -AABB* WallTile::getAABB(Level* level, int x, int y, int z) { +std::optional WallTile::getAABB(Level* level, int x, int y, int z) { // 4J-JEV: Changed to avoid race conditions associated with calling update // shape. @@ -125,7 +125,7 @@ AABB* WallTile::getAABB(Level* level, int x, int y, int z) { // south = .5f + WALL_WIDTH; } - return AABB::newTemp(x + west, y, z + north, x + east, y + 1.5f, z + south); + return AABB(x + west, y, z + north, x + east, y + 1.5f, z + south); } bool WallTile::connectsTo(LevelSource* level, int x, int y, int z) { diff --git a/Minecraft.World/Blocks/WallTile.h b/Minecraft.World/Blocks/WallTile.h index 634253966..7f5a963c6 100644 --- a/Minecraft.World/Blocks/WallTile.h +++ b/Minecraft.World/Blocks/WallTile.h @@ -25,9 +25,9 @@ public: int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr()); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); bool connectsTo(LevelSource* level, int x, int y, int z); int getSpawnResourcesAuxValue(int data); bool shouldRenderFace(LevelSource* level, int x, int y, int z, int face); void registerIcons(IconRegister* iconRegister); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/WaterLilyTile.cpp b/Minecraft.World/Blocks/WaterLilyTile.cpp index 3ea6660a4..ce0a7d2be 100644 --- a/Minecraft.World/Blocks/WaterLilyTile.cpp +++ b/Minecraft.World/Blocks/WaterLilyTile.cpp @@ -23,11 +23,11 @@ void WaterlilyTile::addAABBs(Level* level, int x, int y, int z, AABB* box, } } -AABB* WaterlilyTile::getAABB(Level* level, int x, int y, int z) { +std::optional WaterlilyTile::getAABB(Level* level, int x, int y, int z) { ThreadStorage* tls = m_tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if (tls->tileId != this->id) updateDefaultShape(); - return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, + return AABB(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1); } diff --git a/Minecraft.World/Blocks/WaterLilyTile.h b/Minecraft.World/Blocks/WaterLilyTile.h index 81143ddfd..23b39fdc0 100644 --- a/Minecraft.World/Blocks/WaterLilyTile.h +++ b/Minecraft.World/Blocks/WaterLilyTile.h @@ -12,7 +12,7 @@ public: virtual int getRenderShape(); virtual void addAABBs(Level* level, int x, int y, int z, AABB* box, AABBList* boxes, std::shared_ptr source); - virtual AABB* getAABB(Level* level, int x, int y, int z); + virtual std::optional getAABB(Level* level, int x, int y, int z); virtual int getColor() const; virtual int getColor(int auxData); virtual int getColor(LevelSource* level, int x, int y, int z); diff --git a/Minecraft.World/Blocks/WebTile.cpp b/Minecraft.World/Blocks/WebTile.cpp index ffc4137d5..26e8e909a 100644 --- a/Minecraft.World/Blocks/WebTile.cpp +++ b/Minecraft.World/Blocks/WebTile.cpp @@ -2,6 +2,7 @@ #include "../Headers/net.minecraft.world.entity.h" #include "../Headers/net.minecraft.world.item.h" #include "WebTile.h" +#include "Util/AABB.h" WebTile::WebTile(int id) : Tile(id, Material::web) {} @@ -12,7 +13,7 @@ void WebTile::entityInside(Level* level, int x, int y, int z, bool WebTile::isSolidRender(bool isServerLevel) { return false; } -AABB* WebTile::getAABB(Level* level, int x, int y, int z) { return NULL; } +std::optional WebTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } int WebTile::getRenderShape() { return Tile::SHAPE_CROSS_TEXTURE; } @@ -25,4 +26,4 @@ int WebTile::getResource(int data, Random* random, int playerBonusLevel) { return Item::string->id; } -bool WebTile::isSilkTouchable() { return true; } \ No newline at end of file +bool WebTile::isSilkTouchable() { return true; } diff --git a/Minecraft.World/Blocks/WebTile.h b/Minecraft.World/Blocks/WebTile.h index 1512cd92d..5b8049d6b 100644 --- a/Minecraft.World/Blocks/WebTile.h +++ b/Minecraft.World/Blocks/WebTile.h @@ -14,7 +14,7 @@ public: bool isSolidRender(bool isServerLevel = false); public: - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); public: int getRenderShape(); @@ -25,4 +25,4 @@ public: protected: bool isSilkTouchable(); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/WoolCarpetTile.cpp b/Minecraft.World/Blocks/WoolCarpetTile.cpp index 2800a94c0..030285d7f 100644 --- a/Minecraft.World/Blocks/WoolCarpetTile.cpp +++ b/Minecraft.World/Blocks/WoolCarpetTile.cpp @@ -15,13 +15,13 @@ Icon* WoolCarpetTile::getTexture(int face, int data) { return Tile::wool->getTexture(face, data); } -AABB* WoolCarpetTile::getAABB(Level* level, int x, int y, int z) { +std::optional WoolCarpetTile::getAABB(Level* level, int x, int y, int z) { int height = 0; float offset = 1.0f / SharedConstants::WORLD_RESOLUTION; ThreadStorage* tls = m_tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if (tls->tileId != this->id) updateDefaultShape(); - return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, + return AABB(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + (height * offset), z + tls->zz1); } diff --git a/Minecraft.World/Blocks/WoolCarpetTile.h b/Minecraft.World/Blocks/WoolCarpetTile.h index 7ad28797c..cb473c2f1 100644 --- a/Minecraft.World/Blocks/WoolCarpetTile.h +++ b/Minecraft.World/Blocks/WoolCarpetTile.h @@ -1,5 +1,6 @@ #pragma once +#include #include "Tile.h" class WoolCarpetTile : public Tile { @@ -10,7 +11,7 @@ protected: public: Icon* getTexture(int face, int data); - AABB* getAABB(Level* level, int x, int y, int z); + std::optional getAABB(Level* level, int x, int y, int z); bool blocksLight(); bool isSolidRender(bool isServerLevel = false); bool isCubeShaped(); @@ -37,4 +38,4 @@ public: static int getTileDataForItemAuxValue(int auxValue); static int getItemAuxValueForTileData(int data); void registerIcons(IconRegister* iconRegister); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Entities/Mobs/Arrow.cpp b/Minecraft.World/Entities/Mobs/Arrow.cpp index 6c02a0eea..471ee3a2e 100644 --- a/Minecraft.World/Entities/Mobs/Arrow.cpp +++ b/Minecraft.World/Entities/Mobs/Arrow.cpp @@ -183,9 +183,9 @@ void Arrow::tick() { int t = level->getTile(xTile, yTile, zTile); if (t > 0) { Tile::tiles[t]->updateShape(level, xTile, yTile, zTile); - AABB* aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile); + auto aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile); Vec3 pos{x, y, z}; - if (aabb != NULL && aabb->contains(pos)) { + if (aabb.has_value() && aabb->contains(pos)) { inGround = true; } } diff --git a/Minecraft.World/Items/SnowItem.cpp b/Minecraft.World/Items/SnowItem.cpp index b6196253e..66524f9b4 100644 --- a/Minecraft.World/Items/SnowItem.cpp +++ b/Minecraft.World/Items/SnowItem.cpp @@ -3,6 +3,7 @@ #include "../Headers/net.minecraft.world.level.tile.h" #include "../Headers/net.minecraft.world.level.h" #include "SnowItem.h" +#include "Util/AABB.h" SnowItem::SnowItem(int id, Tile* parentTile) : AuxDataTileItem(id, parentTile) {} @@ -22,8 +23,9 @@ bool SnowItem::useOn(std::shared_ptr instance, int currentData = level->getData(x, y, z); int currentHeight = currentData & TopSnowTile::HEIGHT_MASK; + auto snow_bb = snowTile->getAABB(level, x, y, z); if (currentHeight <= TopSnowTile::MAX_HEIGHT && - level->isUnobstructed(snowTile->getAABB(level, x, y, z))) { + level->isUnobstructed(snow_bb.has_value() ? &*snow_bb : nullptr)) { if (!bTestUseOnOnly) { // Increase snow tile height if (level->setData( @@ -46,4 +48,4 @@ bool SnowItem::useOn(std::shared_ptr instance, return AuxDataTileItem::useOn(instance, player, level, x, y, z, face, clickX, clickY, clickZ, bTestUseOnOnly); -} \ No newline at end of file +} diff --git a/Minecraft.World/Items/TileItems/StoneSlabTileItem.cpp b/Minecraft.World/Items/TileItems/StoneSlabTileItem.cpp index 86940cbff..e7e83fa93 100644 --- a/Minecraft.World/Items/TileItems/StoneSlabTileItem.cpp +++ b/Minecraft.World/Items/TileItems/StoneSlabTileItem.cpp @@ -6,6 +6,7 @@ #include "../../Headers/net.minecraft.world.level.tile.h" #include "../../Headers/net.minecraft.h" #include "StoneSlabTileItem.h" +#include "../../Util/AABB.h" StoneSlabTileItem::StoneSlabTileItem(int id, HalfSlabTile* halfTile, HalfSlabTile* fullTile, bool full) @@ -55,7 +56,8 @@ bool StoneSlabTileItem::useOn(std::shared_ptr instance, return true; } - if (level->isUnobstructed(fullTile->getAABB(level, x, y, z)) && + auto tile_bb = fullTile->getAABB(level, x, y, z); + if (level->isUnobstructed(tile_bb.has_value() ? &*tile_bb : nullptr) && level->setTileAndData(x, y, z, fullTile->id, slabType, Tile::UPDATE_ALL)) { level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, @@ -127,7 +129,8 @@ bool StoneSlabTileItem::tryConvertTargetTile( if (bTestUseOnOnly) { return true; } - if (level->isUnobstructed(fullTile->getAABB(level, x, y, z)) && + auto tile_bb = fullTile->getAABB(level, x, y, z); + if (level->isUnobstructed(tile_bb.has_value() ? &*tile_bb : nullptr) && level->setTileAndData(x, y, z, fullTile->id, slabType, Tile::UPDATE_ALL)) { level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, @@ -140,4 +143,4 @@ bool StoneSlabTileItem::tryConvertTargetTile( } return false; -} \ No newline at end of file +} diff --git a/Minecraft.World/Level/Level.cpp b/Minecraft.World/Level/Level.cpp index bfaab0c3d..ab251a833 100644 --- a/Minecraft.World/Level/Level.cpp +++ b/Minecraft.World/Level/Level.cpp @@ -41,6 +41,7 @@ #include #include #include +#include // 4J : WESTY : Added for time played stats. #include "../Headers/net.minecraft.stats.h" @@ -1391,7 +1392,7 @@ HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid, bool solidOnly) { int data = getData(xTile0, yTile0, zTile0); Tile* tile = Tile::tiles[t]; if (solidOnly && tile != NULL && - tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) { + !tile->getAABB(this, xTile0, yTile0, zTile0).has_value()) { // No collision } else if (t > 0 && tile->mayPick(data, liquid)) { @@ -1499,7 +1500,7 @@ HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid, bool solidOnly) { int data = getData(xTile0, yTile0, zTile0); Tile* tile = Tile::tiles[t]; if (solidOnly && tile != NULL && - tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) { + !tile->getAABB(this, xTile0, yTile0, zTile0).has_value()) { // No collision } else if (t > 0 && tile->mayPick(data, liquid)) { @@ -2796,8 +2797,8 @@ bool Level::isFullAABBTile(int x, int y, int z) { if (tile == 0 || Tile::tiles[tile] == NULL) { return false; } - AABB* aabb = Tile::tiles[tile]->getAABB(this, x, y, z); - return aabb != NULL && aabb->getSize() >= 1; + auto aabb = Tile::tiles[tile]->getAABB(this, x, y, z); + return aabb.has_value() && aabb->getSize() >= 1; } bool Level::isTopSolidBlocking(int x, int y, int z) { @@ -3664,9 +3665,9 @@ bool Level::mayPlace(int tileId, int x, int y, int z, bool ignoreEntities, Tile* tile = Tile::tiles[tileId]; - AABB* aabb = tile->getAABB(this, x, y, z); - if (ignoreEntities) aabb = NULL; - if (aabb != NULL && !isUnobstructed(aabb, ignoreEntity)) return false; + auto aabb = tile->getAABB(this, x, y, z); + if (ignoreEntities) aabb = std::nullopt; + if (aabb.has_value() && !isUnobstructed(&*aabb, ignoreEntity)) return false; if (targetTile != NULL && (targetTile == Tile::water || targetTile == Tile::calmWater || targetTile == Tile::lava || targetTile == Tile::calmLava || From ddfe9b3d48486155dfe94eafa4480e3291aa7c16 Mon Sep 17 00:00:00 2001 From: orng Date: Sat, 28 Mar 2026 00:30:07 -0500 Subject: [PATCH 6/9] refactor: make `Tile::getTileAABB` return `AABB` --- Minecraft.Client/Rendering/LevelRenderer.cpp | 2 +- Minecraft.World/Blocks/CactusTile.cpp | 4 ++-- Minecraft.World/Blocks/CactusTile.h | 2 +- Minecraft.World/Blocks/CakeTile.cpp | 4 ++-- Minecraft.World/Blocks/CakeTile.h | 2 +- Minecraft.World/Blocks/CocoaTile.cpp | 2 +- Minecraft.World/Blocks/CocoaTile.h | 2 +- Minecraft.World/Blocks/DoorTile.cpp | 5 ++--- Minecraft.World/Blocks/DoorTile.h | 2 +- Minecraft.World/Blocks/LadderTile.cpp | 2 +- Minecraft.World/Blocks/LadderTile.h | 2 +- Minecraft.World/Blocks/SignTile.cpp | 2 +- Minecraft.World/Blocks/SignTile.h | 2 +- Minecraft.World/Blocks/StairTile.cpp | 2 +- Minecraft.World/Blocks/StairTile.h | 2 +- Minecraft.World/Blocks/Tile.cpp | 4 ++-- Minecraft.World/Blocks/Tile.h | 2 +- Minecraft.World/Blocks/TorchTile.cpp | 2 +- Minecraft.World/Blocks/TorchTile.h | 2 +- Minecraft.World/Blocks/TrapDoorTile.cpp | 2 +- Minecraft.World/Blocks/TrapDoorTile.h | 2 +- 21 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 927a8b71f..d970c3f3b 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -2482,7 +2482,7 @@ void LevelRenderer::renderHitOutline(std::shared_ptr player, AABB bb = Tile::tiles[tileId] ->getTileAABB(level[iPad], h->x, h->y, h->z) - ->grow(ss, ss, ss) + .grow(ss, ss, ss) .move(-xo, -yo, -zo); render(&bb); diff --git a/Minecraft.World/Blocks/CactusTile.cpp b/Minecraft.World/Blocks/CactusTile.cpp index 43aaa0062..229c52e6a 100644 --- a/Minecraft.World/Blocks/CactusTile.cpp +++ b/Minecraft.World/Blocks/CactusTile.cpp @@ -38,9 +38,9 @@ std::optional CactusTile::getAABB(Level* level, int x, int y, int z) { return AABB{x + r, static_cast(y), z + r, x + 1 - r, y + 1 - r, z + 1 - r}; } -AABB* CactusTile::getTileAABB(Level* level, int x, int y, int z) { +AABB CactusTile::getTileAABB(Level* level, int x, int y, int z) { float r = 1 / 16.0f; - return AABB::newTemp(x + r, y, z + r, x + 1 - r, y + 1, z + 1 - r); + return AABB(x + r, y, z + r, x + 1 - r, y + 1, z + 1 - r); } Icon* CactusTile::getTexture(int face, int data) { diff --git a/Minecraft.World/Blocks/CactusTile.h b/Minecraft.World/Blocks/CactusTile.h index ef0cf69f9..c35dc18a2 100644 --- a/Minecraft.World/Blocks/CactusTile.h +++ b/Minecraft.World/Blocks/CactusTile.h @@ -21,7 +21,7 @@ protected: public: virtual void tick(Level* level, int x, int y, int z, Random* random); virtual std::optional getAABB(Level* level, int x, int y, int z); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual Icon* getTexture(int face, int data); virtual bool isCubeShaped(); virtual bool isSolidRender(bool isServerLevel = false); diff --git a/Minecraft.World/Blocks/CakeTile.cpp b/Minecraft.World/Blocks/CakeTile.cpp index f35919594..53e2e41e3 100644 --- a/Minecraft.World/Blocks/CakeTile.cpp +++ b/Minecraft.World/Blocks/CakeTile.cpp @@ -42,12 +42,12 @@ std::optional CakeTile::getAABB(Level* level, int x, int y, int z) { return AABB{x + r2, static_cast(y), z + r, x + 1 - r, y + h - r, z + 1 - r}; } -AABB* CakeTile::getTileAABB(Level* level, int x, int y, int z) { +AABB CakeTile::getTileAABB(Level* level, int x, int y, int z) { int d = level->getData(x, y, z); float r = 1 / 16.0f; float r2 = (1 + d * 2) / 16.0f; float h = 8 / 16.0f; - return AABB::newTemp(x + r2, y, z + r, x + 1 - r, y + h, z + 1 - r); + return AABB(x + r2, y, z + r, x + 1 - r, y + h, z + 1 - r); } Icon* CakeTile::getTexture(int face, int data) { diff --git a/Minecraft.World/Blocks/CakeTile.h b/Minecraft.World/Blocks/CakeTile.h index ebd33baf2..b2f2a3655 100644 --- a/Minecraft.World/Blocks/CakeTile.h +++ b/Minecraft.World/Blocks/CakeTile.h @@ -25,7 +25,7 @@ protected: TileEntity>()); // 4J added forceData, forceEntity param virtual void updateDefaultShape(); virtual std::optional getAABB(Level* level, int x, int y, int z); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual Icon* getTexture(int face, int data); //@Override void registerIcons(IconRegister* iconRegister); diff --git a/Minecraft.World/Blocks/CocoaTile.cpp b/Minecraft.World/Blocks/CocoaTile.cpp index 6250508a8..73449170d 100644 --- a/Minecraft.World/Blocks/CocoaTile.cpp +++ b/Minecraft.World/Blocks/CocoaTile.cpp @@ -62,7 +62,7 @@ std::optional CocoaTile::getAABB(Level* level, int x, int y, int z) { return DirectionalTile::getAABB(level, x, y, z); } -AABB* CocoaTile::getTileAABB(Level* level, int x, int y, int z) { +AABB CocoaTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return DirectionalTile::getTileAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/CocoaTile.h b/Minecraft.World/Blocks/CocoaTile.h index 7ff5c81ee..ff8c02c6f 100644 --- a/Minecraft.World/Blocks/CocoaTile.h +++ b/Minecraft.World/Blocks/CocoaTile.h @@ -23,7 +23,7 @@ public: virtual bool isCubeShaped(); virtual bool isSolidRender(bool isServerLevel = false); virtual std::optional getAABB(Level* level, int x, int y, int z); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual void updateShape(LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = diff --git a/Minecraft.World/Blocks/DoorTile.cpp b/Minecraft.World/Blocks/DoorTile.cpp index df461bb6b..1c2692370 100644 --- a/Minecraft.World/Blocks/DoorTile.cpp +++ b/Minecraft.World/Blocks/DoorTile.cpp @@ -85,10 +85,9 @@ bool DoorTile::isCubeShaped() { return false; } int DoorTile::getRenderShape() { return Tile::SHAPE_DOOR; } -AABB* DoorTile::getTileAABB(Level* level, int x, int y, int z) { +AABB DoorTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); - AABB* retval = Tile::getTileAABB(level, x, y, z); - return retval; + return Tile::getTileAABB(level, x, y, z); } std::optional DoorTile::getAABB(Level* level, int x, int y, int z) { diff --git a/Minecraft.World/Blocks/DoorTile.h b/Minecraft.World/Blocks/DoorTile.h index 339775515..3f844a27d 100644 --- a/Minecraft.World/Blocks/DoorTile.h +++ b/Minecraft.World/Blocks/DoorTile.h @@ -40,7 +40,7 @@ public: virtual bool isSolidRender(bool isServerLevel = false); virtual bool isCubeShaped(); virtual int getRenderShape(); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual std::optional getAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, diff --git a/Minecraft.World/Blocks/LadderTile.cpp b/Minecraft.World/Blocks/LadderTile.cpp index f95650843..06b016284 100644 --- a/Minecraft.World/Blocks/LadderTile.cpp +++ b/Minecraft.World/Blocks/LadderTile.cpp @@ -11,7 +11,7 @@ std::optional LadderTile::getAABB(Level* level, int x, int y, int z) { return Tile::getAABB(level, x, y, z); } -AABB* LadderTile::getTileAABB(Level* level, int x, int y, int z) { +AABB LadderTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return Tile::getTileAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/LadderTile.h b/Minecraft.World/Blocks/LadderTile.h index 133c01230..9bde7712d 100644 --- a/Minecraft.World/Blocks/LadderTile.h +++ b/Minecraft.World/Blocks/LadderTile.h @@ -12,7 +12,7 @@ protected: public: virtual std::optional getAABB(Level* level, int x, int y, int z); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< diff --git a/Minecraft.World/Blocks/SignTile.cpp b/Minecraft.World/Blocks/SignTile.cpp index 2004f9e4a..7a62f9248 100644 --- a/Minecraft.World/Blocks/SignTile.cpp +++ b/Minecraft.World/Blocks/SignTile.cpp @@ -27,7 +27,7 @@ void SignTile::updateDefaultShape() { std::optional SignTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } -AABB* SignTile::getTileAABB(Level* level, int x, int y, int z) { +AABB SignTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return BaseEntityTile::getTileAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/SignTile.h b/Minecraft.World/Blocks/SignTile.h index 9e4c009d2..952b5e1cc 100644 --- a/Minecraft.World/Blocks/SignTile.h +++ b/Minecraft.World/Blocks/SignTile.h @@ -21,7 +21,7 @@ public: Icon* getTexture(int face, int data); virtual void updateDefaultShape(); std::optional getAABB(Level* level, int x, int y, int z); - AABB* getTileAABB(Level* level, int x, int y, int z); + AABB getTileAABB(Level* level, int x, int y, int z); void updateShape(LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = diff --git a/Minecraft.World/Blocks/StairTile.cpp b/Minecraft.World/Blocks/StairTile.cpp index 2990ada14..244c58895 100644 --- a/Minecraft.World/Blocks/StairTile.cpp +++ b/Minecraft.World/Blocks/StairTile.cpp @@ -326,7 +326,7 @@ Icon* StairTile::getTexture(int face, int data) { int StairTile::getTickDelay(Level* level) { return base->getTickDelay(level); } -AABB* StairTile::getTileAABB(Level* level, int x, int y, int z) { +AABB StairTile::getTileAABB(Level* level, int x, int y, int z) { return base->getTileAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/StairTile.h b/Minecraft.World/Blocks/StairTile.h index 23d906835..690b52bd2 100644 --- a/Minecraft.World/Blocks/StairTile.h +++ b/Minecraft.World/Blocks/StairTile.h @@ -65,7 +65,7 @@ public: virtual int getRenderLayer(); virtual Icon* getTexture(int face, int data); virtual int getTickDelay(Level* level); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual void handleEntityInside(Level* level, int x, int y, int z, std::shared_ptr e, Vec3* current); virtual bool mayPick(); diff --git a/Minecraft.World/Blocks/Tile.cpp b/Minecraft.World/Blocks/Tile.cpp index 66d58c632..d12283e69 100644 --- a/Minecraft.World/Blocks/Tile.cpp +++ b/Minecraft.World/Blocks/Tile.cpp @@ -2005,11 +2005,11 @@ Icon* Tile::getTexture(int face, int data) { return icon; } Icon* Tile::getTexture(int face) { return getTexture(face, 0); } -AABB* Tile::getTileAABB(Level* level, int x, int y, int z) { +AABB Tile::getTileAABB(Level* level, int x, int y, int z) { ThreadStorage* tls = m_tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if (tls->tileId != this->id) updateDefaultShape(); - return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, + return AABB(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1); } diff --git a/Minecraft.World/Blocks/Tile.h b/Minecraft.World/Blocks/Tile.h index 4346f6d26..2b94b9ffe 100644 --- a/Minecraft.World/Blocks/Tile.h +++ b/Minecraft.World/Blocks/Tile.h @@ -631,7 +631,7 @@ public: virtual Icon* getTexture(LevelSource* level, int x, int y, int z, int face); virtual Icon* getTexture(int face, int data); virtual Icon* getTexture(int face); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual void addAABBs(Level* level, int x, int y, int z, AABB* box, AABBList* boxes, std::shared_ptr source); virtual std::optional getAABB(Level* level, int x, int y, int z); diff --git a/Minecraft.World/Blocks/TorchTile.cpp b/Minecraft.World/Blocks/TorchTile.cpp index 556370789..4932ff4fc 100644 --- a/Minecraft.World/Blocks/TorchTile.cpp +++ b/Minecraft.World/Blocks/TorchTile.cpp @@ -12,7 +12,7 @@ TorchTile::TorchTile(int id) : Tile(id, Material::decoration, false) { std::optional TorchTile::getAABB(Level* level, int x, int y, int z) { return std::nullopt; } -AABB* TorchTile::getTileAABB(Level* level, int x, int y, int z) { +AABB TorchTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return Tile::getTileAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/TorchTile.h b/Minecraft.World/Blocks/TorchTile.h index 3f7d0a4d1..525f851cc 100644 --- a/Minecraft.World/Blocks/TorchTile.h +++ b/Minecraft.World/Blocks/TorchTile.h @@ -13,7 +13,7 @@ protected: public: virtual std::optional getAABB(Level* level, int x, int y, int z); - virtual AABB* getTileAABB(Level* level, int x, int y, int z); + virtual AABB getTileAABB(Level* level, int x, int y, int z); virtual void updateShape( LevelSource* level, int x, int y, int z, int forceData = -1, std::shared_ptr forceEntity = std::shared_ptr< diff --git a/Minecraft.World/Blocks/TrapDoorTile.cpp b/Minecraft.World/Blocks/TrapDoorTile.cpp index bca1ce813..7a6e46e5a 100644 --- a/Minecraft.World/Blocks/TrapDoorTile.cpp +++ b/Minecraft.World/Blocks/TrapDoorTile.cpp @@ -25,7 +25,7 @@ bool TrapDoorTile::isPathfindable(LevelSource* level, int x, int y, int z) { int TrapDoorTile::getRenderShape() { return Tile::SHAPE_BLOCK; } -AABB* TrapDoorTile::getTileAABB(Level* level, int x, int y, int z) { +AABB TrapDoorTile::getTileAABB(Level* level, int x, int y, int z) { updateShape(level, x, y, z); return Tile::getTileAABB(level, x, y, z); } diff --git a/Minecraft.World/Blocks/TrapDoorTile.h b/Minecraft.World/Blocks/TrapDoorTile.h index 9765b61c6..8ef150568 100644 --- a/Minecraft.World/Blocks/TrapDoorTile.h +++ b/Minecraft.World/Blocks/TrapDoorTile.h @@ -37,7 +37,7 @@ public: int getRenderShape(); public: - AABB* getTileAABB(Level* level, int x, int y, int z); + AABB getTileAABB(Level* level, int x, int y, int z); public: std::optional getAABB(Level* level, int x, int y, int z); From e48a05bb8fa6fb918ef1abe738a3e02dbdbf3ea4 Mon Sep 17 00:00:00 2001 From: orng Date: Sat, 28 Mar 2026 00:50:56 -0500 Subject: [PATCH 7/9] refactor: remove the last `AABB::newTemp` --- Minecraft.World/Blocks/BasePressurePlateTile.cpp | 7 ++++--- Minecraft.World/Blocks/BasePressurePlateTile.h | 2 +- Minecraft.World/Blocks/PressurePlateTile.cpp | 13 ++++++------- .../Blocks/WeightedPressurePlateTile.cpp | 6 ++++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Minecraft.World/Blocks/BasePressurePlateTile.cpp b/Minecraft.World/Blocks/BasePressurePlateTile.cpp index 434ce8e56..212fbb914 100644 --- a/Minecraft.World/Blocks/BasePressurePlateTile.cpp +++ b/Minecraft.World/Blocks/BasePressurePlateTile.cpp @@ -40,7 +40,8 @@ int BasePressurePlateTile::getTickDelay(Level* level) { return SharedConstants::TICKS_PER_SECOND; } -std::optional BasePressurePlateTile::getAABB(Level* level, int x, int y, int z) { +std::optional BasePressurePlateTile::getAABB(Level* level, int x, int y, + int z) { return std::nullopt; } @@ -113,9 +114,9 @@ void BasePressurePlateTile::checkPressed(Level* level, int x, int y, int z, } } -AABB* BasePressurePlateTile::getSensitiveAABB(int x, int y, int z) { +AABB BasePressurePlateTile::getSensitiveAABB(int x, int y, int z) { float b = 2 / 16.0f; - return AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 0.25, z + 1 - b); + return AABB(x + b, y, z + b, x + 1 - b, y + 0.25, z + 1 - b); } void BasePressurePlateTile::onRemove(Level* level, int x, int y, int z, int id, diff --git a/Minecraft.World/Blocks/BasePressurePlateTile.h b/Minecraft.World/Blocks/BasePressurePlateTile.h index e42ff69eb..254f72e1d 100644 --- a/Minecraft.World/Blocks/BasePressurePlateTile.h +++ b/Minecraft.World/Blocks/BasePressurePlateTile.h @@ -33,7 +33,7 @@ public: protected: virtual void checkPressed(Level* level, int x, int y, int z, int oldSignal); - virtual AABB* getSensitiveAABB(int x, int y, int z); + virtual AABB getSensitiveAABB(int x, int y, int z); public: virtual void onRemove(Level* level, int x, int y, int z, int id, int data); diff --git a/Minecraft.World/Blocks/PressurePlateTile.cpp b/Minecraft.World/Blocks/PressurePlateTile.cpp index ef1223bb3..48a273f0d 100644 --- a/Minecraft.World/Blocks/PressurePlateTile.cpp +++ b/Minecraft.World/Blocks/PressurePlateTile.cpp @@ -2,6 +2,7 @@ #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.level.redstone.h" #include "PressurePlateTile.h" +#include "Util/AABB.h" PressurePlateTile::PressurePlateTile(int id, const std::wstring& tex, Material* material, @@ -23,15 +24,13 @@ int PressurePlateTile::getSignalForData(int data) { int PressurePlateTile::getSignalStrength(Level* level, int x, int y, int z) { std::vector >* entities = NULL; - + AABB at_bb = getSensitiveAABB(x, y, z); if (sensitivity == everything) - entities = level->getEntities(nullptr, getSensitiveAABB(x, y, z)); + entities = level->getEntities(nullptr, &at_bb); else if (sensitivity == mobs) - entities = level->getEntitiesOfClass(typeid(LivingEntity), - getSensitiveAABB(x, y, z)); + entities = level->getEntitiesOfClass(typeid(LivingEntity), &at_bb); else if (sensitivity == players) - entities = level->getEntitiesOfClass(typeid(Player), - getSensitiveAABB(x, y, z)); + entities = level->getEntitiesOfClass(typeid(Player), &at_bb); else __debugbreak(); // 4J-JEV: We're going to delete something at a random // location. @@ -48,4 +47,4 @@ int PressurePlateTile::getSignalStrength(Level* level, int x, int y, int z) { if (sensitivity != everything) delete entities; return Redstone::SIGNAL_NONE; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/WeightedPressurePlateTile.cpp b/Minecraft.World/Blocks/WeightedPressurePlateTile.cpp index 55e1b5a15..e31a7c451 100644 --- a/Minecraft.World/Blocks/WeightedPressurePlateTile.cpp +++ b/Minecraft.World/Blocks/WeightedPressurePlateTile.cpp @@ -5,6 +5,7 @@ #include "../Headers/net.minecraft.world.item.h" #include "../Entities/Entity.h" #include "WeightedPressurePlateTile.h" +#include "Util/AABB.h" WeightedPressurePlateTile::WeightedPressurePlateTile(int id, const std::wstring& tex, @@ -19,8 +20,9 @@ WeightedPressurePlateTile::WeightedPressurePlateTile(int id, int WeightedPressurePlateTile::getSignalStrength(Level* level, int x, int y, int z) { + AABB at_bb = getSensitiveAABB(x, y, z); int weightOfEntities = - level->getEntitiesOfClass(typeid(Entity), getSensitiveAABB(x, y, z)) + level->getEntitiesOfClass(typeid(Entity), &at_bb) ->size(); int count = std::min(weightOfEntities, maxWeight); @@ -38,4 +40,4 @@ int WeightedPressurePlateTile::getDataForSignal(int signal) { return signal; } int WeightedPressurePlateTile::getTickDelay(Level* level) { return SharedConstants::TICKS_PER_SECOND / 2; -} \ No newline at end of file +} From 7101d03c6ab11fa91cc5d84b2f350ee4ce6d1850 Mon Sep 17 00:00:00 2001 From: orng Date: Sat, 28 Mar 2026 02:58:56 -0500 Subject: [PATCH 8/9] refactor: remove heap-allocated `AABB`s --- Minecraft.Client/Network/ClientConnection.cpp | 2 +- Minecraft.Client/Network/PlayerConnection.cpp | 6 +- Minecraft.Client/Network/PlayerList.cpp | 6 +- .../ApplySchematicRuleDefinition.cpp | 19 +-- .../GameRules/ApplySchematicRuleDefinition.h | 4 +- .../GameRules/NamedAreaRuleDefinition.cpp | 44 ++++--- .../GameRules/NamedAreaRuleDefinition.h | 6 +- .../Common/Tutorial/AreaConstraint.cpp | 18 +-- .../Platform/Common/Tutorial/AreaConstraint.h | 7 +- .../Platform/Common/Tutorial/AreaHint.cpp | 6 +- .../Platform/Common/Tutorial/AreaHint.h | 5 +- .../Common/Tutorial/ChangeStateConstraint.cpp | 7 +- .../Common/Tutorial/ChangeStateConstraint.h | 2 +- Minecraft.Client/Player/LocalPlayer.cpp | 8 +- .../Player/MultiPlayerLocalPlayer.cpp | 8 +- Minecraft.Client/Rendering/Chunk.cpp | 36 ++---- Minecraft.Client/Rendering/Chunk.h | 3 +- .../EntityRenderers/EntityRenderer.cpp | 4 +- .../EntityRenderers/FireballRenderer.cpp | 4 +- Minecraft.Client/Rendering/GameRenderer.cpp | 4 +- Minecraft.Client/Rendering/LevelRenderer.cpp | 4 +- .../Rendering/Particles/CritParticle.cpp | 8 +- .../Particles/PlayerCloudParticle.cpp | 6 +- Minecraft.World/AI/Control/LookControl.cpp | 4 +- Minecraft.World/AI/Control/MoveControl.cpp | 4 +- Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp | 2 +- Minecraft.World/AI/Goals/BreedGoal.cpp | 2 +- Minecraft.World/AI/Goals/FleeSunGoal.cpp | 4 +- Minecraft.World/AI/Goals/FollowOwnerGoal.cpp | 2 +- Minecraft.World/AI/Goals/FollowParentGoal.cpp | 2 +- Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp | 5 +- Minecraft.World/AI/Goals/MakeLoveGoal.cpp | 5 +- Minecraft.World/AI/Goals/MeleeAttackGoal.cpp | 4 +- .../AI/Goals/NearestAttackableTargetGoal.cpp | 5 +- Minecraft.World/AI/Goals/OcelotAttackGoal.cpp | 2 +- Minecraft.World/AI/Goals/OfferFlowerGoal.cpp | 5 +- Minecraft.World/AI/Goals/PlayGoal.cpp | 5 +- Minecraft.World/AI/Goals/RangedAttackGoal.cpp | 4 +- Minecraft.World/AI/Goals/TakeFlowerGoal.cpp | 4 +- Minecraft.World/AI/Navigation/PathFinder.cpp | 10 +- .../AI/Navigation/PathNavigation.cpp | 8 +- Minecraft.World/Blocks/FallingTile.cpp | 4 +- Minecraft.World/Entities/Entity.cpp | 114 +++++++++--------- Minecraft.World/Entities/Entity.h | 3 +- Minecraft.World/Entities/FlyingMob.cpp | 6 +- Minecraft.World/Entities/HangingEntity.cpp | 8 +- Minecraft.World/Entities/ItemEntity.cpp | 8 +- Minecraft.World/Entities/LivingEntity.cpp | 44 +++---- Minecraft.World/Entities/MinecartHopper.cpp | 2 +- Minecraft.World/Entities/Mob.cpp | 18 +-- Minecraft.World/Entities/Mobs/Animal.cpp | 8 +- Minecraft.World/Entities/Mobs/Arrow.cpp | 4 +- Minecraft.World/Entities/Mobs/Bat.cpp | 4 +- Minecraft.World/Entities/Mobs/Blaze.cpp | 8 +- Minecraft.World/Entities/Mobs/Boat.cpp | 12 +- .../Entities/Mobs/DragonFireball.cpp | 2 +- Minecraft.World/Entities/Mobs/EnderDragon.cpp | 48 ++++---- Minecraft.World/Entities/Mobs/EnderDragon.h | 2 +- Minecraft.World/Entities/Mobs/EnderMan.cpp | 8 +- Minecraft.World/Entities/Mobs/EntityHorse.cpp | 2 +- .../Entities/Mobs/ExperienceOrb.cpp | 6 +- .../Entities/Mobs/EyeOfEnderSignal.cpp | 4 +- Minecraft.World/Entities/Mobs/Fireball.cpp | 6 +- Minecraft.World/Entities/Mobs/FishingHook.cpp | 16 +-- Minecraft.World/Entities/Mobs/Ghast.cpp | 3 +- Minecraft.World/Entities/Mobs/LavaSlime.cpp | 8 +- Minecraft.World/Entities/Mobs/Minecart.cpp | 4 +- Minecraft.World/Entities/Mobs/MushroomCow.cpp | 2 +- Minecraft.World/Entities/Mobs/Ocelot.cpp | 8 +- Minecraft.World/Entities/Mobs/PigZombie.cpp | 8 +- Minecraft.World/Entities/Mobs/Silverfish.cpp | 6 +- Minecraft.World/Entities/Mobs/Slime.cpp | 2 +- Minecraft.World/Entities/Mobs/Squid.cpp | 2 +- .../Entities/Mobs/ThrownPotion.cpp | 2 +- .../Entities/Mobs/VillagerGolem.cpp | 4 +- Minecraft.World/Entities/Mobs/Witch.cpp | 2 +- Minecraft.World/Entities/Mobs/WitherBoss.cpp | 2 +- Minecraft.World/Entities/Mobs/Wolf.cpp | 4 +- Minecraft.World/Entities/Mobs/Zombie.cpp | 8 +- Minecraft.World/Entities/Monster.cpp | 8 +- Minecraft.World/Entities/PathfinderMob.cpp | 4 +- Minecraft.World/Entities/Throwable.cpp | 6 +- Minecraft.World/Entities/WaterAnimal.cpp | 4 +- Minecraft.World/Items/BoatItem.cpp | 6 +- Minecraft.World/Level/Explosion.cpp | 4 +- Minecraft.World/Level/LevelChunk.cpp | 6 +- Minecraft.World/Player/Player.cpp | 4 +- Minecraft.World/Util/CombatTracker.cpp | 2 +- 88 files changed, 353 insertions(+), 387 deletions(-) diff --git a/Minecraft.Client/Network/ClientConnection.cpp b/Minecraft.Client/Network/ClientConnection.cpp index 8494759de..e41f43d77 100644 --- a/Minecraft.Client/Network/ClientConnection.cpp +++ b/Minecraft.Client/Network/ClientConnection.cpp @@ -1010,7 +1010,7 @@ void ClientConnection::handleMovePlayer( player->xd = player->yd = player->zd = 0; player->absMoveTo(x, y, z, yRot, xRot); packet->x = player->x; - packet->y = player->bb->y0; + packet->y = player->bb.y0; packet->z = player->z; packet->yView = player->y; connection->send(packet); diff --git a/Minecraft.Client/Network/PlayerConnection.cpp b/Minecraft.Client/Network/PlayerConnection.cpp index 5a4d5d3d7..cb70ca016 100644 --- a/Minecraft.Client/Network/PlayerConnection.cpp +++ b/Minecraft.Client/Network/PlayerConnection.cpp @@ -272,7 +272,7 @@ void PlayerConnection::handleMovePlayer( */ float r = 1 / 16.0f; - AABB shrunk = player->bb->shrink(r, r, r); + AABB shrunk = player->bb.shrink(r, r, r); bool oldOk = level->getCubes(player, &shrunk) ->empty(); @@ -326,7 +326,7 @@ void PlayerConnection::handleMovePlayer( player->absMoveTo(xt, yt, zt, yRotT, xRotT); // TODO: check if this can be elided - shrunk = player->bb->shrink(r, r, r); + shrunk = player->bb.shrink(r, r, r); bool newOk = level->getCubes(player, &shrunk) ->empty(); @@ -334,7 +334,7 @@ void PlayerConnection::handleMovePlayer( teleport(xLastOk, yLastOk, zLastOk, yRotT, xRotT); 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 if (!server->isFlightAllowed() && !player->gameMode->isCreative() && !level->containsAnyBlocks(&testBox) && !player->isAllowedToFly()) { diff --git a/Minecraft.Client/Network/PlayerList.cpp b/Minecraft.Client/Network/PlayerList.cpp index c3286234c..2eadfa824 100644 --- a/Minecraft.Client/Network/PlayerList.cpp +++ b/Minecraft.Client/Network/PlayerList.cpp @@ -416,7 +416,7 @@ void PlayerList::validatePlayerSpawnPosition( player->y, player->z, 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); } app.DebugPrintf("Final pos is %f, %f, %f in dimension %d\n", player->x, @@ -456,7 +456,7 @@ void PlayerList::validatePlayerSpawnPosition( } 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); } @@ -749,7 +749,7 @@ std::shared_ptr PlayerList::respawn( // Ensure the area the player is spawning in is loaded! 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); } diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp index f2c5b4360..2101756d7 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp @@ -8,12 +8,13 @@ #include "ApplySchematicRuleDefinition.h" #include "LevelGenerationOptions.h" #include "ConsoleSchematicFile.h" +#include "../../Minecraft.World/Util/AABB.h" ApplySchematicRuleDefinition::ApplySchematicRuleDefinition( LevelGenerationOptions* levelGenOptions) { m_levelGenOptions = levelGenOptions; m_location = Vec3(0, 0, 0); - m_locationBox = NULL; + m_locationBox = std::nullopt; m_totalBlocksChanged = 0; m_totalBlocksChangedLighting = 0; m_rotation = ConsoleSchematicFile::eSchematicRot_0; @@ -130,7 +131,7 @@ void ApplySchematicRuleDefinition::updateLocationBox() { if (m_schematic == NULL) 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->y0 = m_location.y; @@ -162,7 +163,7 @@ void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox, if (m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); - if (m_locationBox == NULL) updateLocationBox(); + if (!m_locationBox.has_value()) updateLocationBox(); if (chunkBox->intersects(*m_locationBox)) { m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1); @@ -173,12 +174,12 @@ void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox, #endif PIXBeginNamedEvent(0, "Applying blocks and data"); m_totalBlocksChanged += m_schematic->applyBlocksAndData( - chunk, chunkBox, m_locationBox, m_rotation); + chunk, chunkBox, &*m_locationBox, m_rotation); PIXEndNamedEvent(); // Add the tileEntities PIXBeginNamedEvent(0, "Applying tile entities"); - m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox, + m_schematic->applyTileEntities(chunk, chunkBox, &*m_locationBox, m_rotation); PIXEndNamedEvent(); @@ -206,7 +207,7 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox, if (m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); - if (m_locationBox == NULL) updateLocationBox(); + if (!m_locationBox.has_value()) updateLocationBox(); if (chunkBox->intersects(*m_locationBox)) { m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1); @@ -217,7 +218,7 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox, #endif PIXBeginNamedEvent(0, "Patching lighting"); m_totalBlocksChangedLighting += m_schematic->applyLighting( - chunk, chunkBox, m_locationBox, m_rotation); + chunk, chunkBox, &*m_locationBox, m_rotation); PIXEndNamedEvent(); // 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, 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); } int ApplySchematicRuleDefinition::getMinY() { - if (m_locationBox == NULL) updateLocationBox(); + if (!m_locationBox.has_value()) updateLocationBox(); return m_locationBox->y0; } diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h index 283c19586..1f5a5cbc1 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h @@ -1,6 +1,8 @@ #pragma once +#include #include "GameRuleDefinition.h" #include "ConsoleSchematicFile.h" +#include "../../Minecraft.World/Util/AABB.h" class AABB; class Vec3; @@ -14,7 +16,7 @@ private: std::wstring m_schematicName; ConsoleSchematicFile* m_schematic; Vec3 m_location; - AABB* m_locationBox; + std::optional m_locationBox; ConsoleSchematicFile::ESchematicRotation m_rotation; int m_dimension; diff --git a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp index aefc12453..da0524ff7 100644 --- a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp @@ -5,11 +5,9 @@ NamedAreaRuleDefinition::NamedAreaRuleDefinition() { 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, unsigned int numAttributes) { GameRuleDefinition::writeAttributes(dos, numAttributes + 7); @@ -18,18 +16,18 @@ void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos, dos->writeUTF(m_name); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); - dos->writeUTF(_toString(m_area->x0)); + dos->writeUTF(_toString(m_area.x0)); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0); - dos->writeUTF(_toString(m_area->y0)); + dos->writeUTF(_toString(m_area.y0)); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0); - dos->writeUTF(_toString(m_area->z0)); + dos->writeUTF(_toString(m_area.z0)); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1); - dos->writeUTF(_toString(m_area->x1)); + dos->writeUTF(_toString(m_area.x1)); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1); - dos->writeUTF(_toString(m_area->y1)); + dos->writeUTF(_toString(m_area.y1)); 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, @@ -41,31 +39,31 @@ void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName, m_name.c_str()); #endif } else if (attributeName.compare(L"x0") == 0) { - m_area->x0 = _fromString(attributeValue); + m_area.x0 = _fromString(attributeValue); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n", - m_area->x0); + m_area.x0); } else if (attributeName.compare(L"y0") == 0) { - m_area->y0 = _fromString(attributeValue); - if (m_area->y0 < 0) m_area->y0 = 0; + m_area.y0 = _fromString(attributeValue); + if (m_area.y0 < 0) m_area.y0 = 0; app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n", - m_area->y0); + m_area.y0); } else if (attributeName.compare(L"z0") == 0) { - m_area->z0 = _fromString(attributeValue); + m_area.z0 = _fromString(attributeValue); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n", - m_area->z0); + m_area.z0); } else if (attributeName.compare(L"x1") == 0) { - m_area->x1 = _fromString(attributeValue); + m_area.x1 = _fromString(attributeValue); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n", - m_area->x1); + m_area.x1); } else if (attributeName.compare(L"y1") == 0) { - m_area->y1 = _fromString(attributeValue); - if (m_area->y1 < 0) m_area->y1 = 0; + m_area.y1 = _fromString(attributeValue); + if (m_area.y1 < 0) m_area.y1 = 0; app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n", - m_area->y1); + m_area.y1); } else if (attributeName.compare(L"z1") == 0) { - m_area->z1 = _fromString(attributeValue); + m_area.z1 = _fromString(attributeValue); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n", - m_area->z1); + m_area.z1); } else { GameRuleDefinition::addAttribute(attributeName, attributeValue); } diff --git a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h index 93f8a0c47..81be6c4bc 100644 --- a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h @@ -1,15 +1,15 @@ #pragma once #include "GameRuleDefinition.h" +#include "../../Minecraft.World/Util/AABB.h" class NamedAreaRuleDefinition : public GameRuleDefinition { private: std::wstring m_name; - AABB* m_area; + AABB m_area; public: NamedAreaRuleDefinition(); - ~NamedAreaRuleDefinition(); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttributes); @@ -21,6 +21,6 @@ public: virtual void addAttribute(const std::wstring& attributeName, const std::wstring& attributeValue); - AABB* getArea() { return m_area; } + AABB* getArea() { return &m_area; } std::wstring getName() { return m_name; } }; diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp index 36c53aa47..2cf4ab5ee 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp @@ -10,25 +10,19 @@ AreaConstraint::AreaConstraint(int descriptionId, double x0, double y0, bool contains /*= true*/, bool restrictsMovement /*=true*/) : TutorialConstraint(descriptionId) { - messageArea = - new AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2); - movementArea = new AABB(x0, y0, z0, x1, y1, z1); + messageArea = AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2); + movementArea = AABB(x0, y0, z0, x1, y1, z1); this->contains = contains; m_restrictsMovement = restrictsMovement; } -AreaConstraint::~AreaConstraint() { - delete messageArea; - delete movementArea; -} - 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) { @@ -42,12 +36,12 @@ 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); - double currDist = origPos.distanceTo(movementArea); - double targetDist = targetPos.distanceTo(movementArea); + double currDist = origPos.distanceTo(&movementArea); + double targetDist = targetPos.distanceTo(&movementArea); return targetDist < currDist; } diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.h b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.h index 721ab6eb1..05265b73f 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.h +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.h @@ -6,8 +6,8 @@ class AABB; class AreaConstraint : public TutorialConstraint { private: - AABB* movementArea; - AABB* messageArea; + AABB movementArea; + AABB messageArea; bool contains; // If true we must stay in this area, if false must stay out // of this area bool m_restrictsMovement; @@ -18,10 +18,9 @@ public: AreaConstraint(int descriptionId, double x0, double y0, double z0, double x1, double y1, double z1, bool contains = true, bool restrictsMovement = true); - ~AreaConstraint(); virtual bool isConstraintSatisfied(int iPad); virtual bool isConstraintRestrictive(int iPad); virtual bool canMoveToPosition(double xo, double yo, double zo, double xt, double yt, double zt); -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp index b6bae48d3..b3ebdf65a 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp @@ -12,7 +12,7 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial, double x1, double y1, double z1, bool allowFade /*= false*/, bool contains /*= true*/) : 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; @@ -20,15 +20,13 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial, m_completeState = completeState; } -AreaHint::~AreaHint() { delete area; } - int AreaHint::tick() { Minecraft* minecraft = Minecraft::GetInstance(); Vec3 player_pos = minecraft->player->getPos(1); if ((m_displayState == e_Tutorial_State_Any || m_tutorial->getCurrentState() == m_displayState) && - m_hintNeeded && area->contains(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)) { diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.h b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.h index 71d8219f2..68ec72ba5 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.h +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.h @@ -6,7 +6,7 @@ class AABB; class AreaHint : public TutorialHint { private: - AABB* area; + AABB area; bool contains; // If true we must stay in this area, if false must stay out // of this area @@ -21,7 +21,6 @@ public: eTutorial_State displayState, eTutorial_State completeState, int descriptionId, double x0, double y0, double z0, double x1, double y1, double z1, bool allowFade = true, bool contains = true); - ~AreaHint(); virtual int tick(); -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp index 5934505e8..4296a04bd 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp @@ -16,7 +16,7 @@ ChangeStateConstraint::ChangeStateConstraint( bool contains /*= true*/, bool changeGameMode /*= false*/, GameType* targetGameMode /*= 0*/) : TutorialConstraint(-1) { - movementArea = new AABB(x0, y0, z0, x1, y1, z1); + movementArea = AABB(x0, y0, z0, x1, y1, z1); this->contains = contains; @@ -40,7 +40,6 @@ ChangeStateConstraint::ChangeStateConstraint( } ChangeStateConstraint::~ChangeStateConstraint() { - delete movementArea; if (m_sourceStatesCount > 0) delete[] m_sourceStates; } @@ -89,7 +88,7 @@ void ChangeStateConstraint::tick(int iPad) { // 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); @@ -127,7 +126,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); diff --git a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.h b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.h index 5ec51d437..44c9b410b 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.h +++ b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.h @@ -11,7 +11,7 @@ class GameType; class ChangeStateConstraint : public TutorialConstraint { private: - AABB* movementArea; + AABB movementArea; bool contains; // If true we must stay in this area, if false must stay out // of this area bool m_changeGameMode; diff --git a/Minecraft.Client/Player/LocalPlayer.cpp b/Minecraft.Client/Player/LocalPlayer.cpp index 4a8e126e5..a02033d66 100644 --- a/Minecraft.Client/Player/LocalPlayer.cpp +++ b/Minecraft.Client/Player/LocalPlayer.cpp @@ -245,10 +245,10 @@ void LocalPlayer::aiStep() { 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 = getFoodData()->getFoodLevel() > diff --git a/Minecraft.Client/Player/MultiPlayerLocalPlayer.cpp b/Minecraft.Client/Player/MultiPlayerLocalPlayer.cpp index 4d287b9cc..e6dd6f9a9 100644 --- a/Minecraft.Client/Player/MultiPlayerLocalPlayer.cpp +++ b/Minecraft.Client/Player/MultiPlayerLocalPlayer.cpp @@ -140,7 +140,7 @@ void MultiplayerLocalPlayer::sendPosition() { } double xdd = x - xLast; - double ydd1 = bb->y0 - yLast1; + double ydd1 = bb.y0 - yLast1; double zdd = z - zLast; double rydd = yRot - yRotLast; @@ -158,11 +158,11 @@ void MultiplayerLocalPlayer::sendPosition() { if (move && rot) { connection->send( std::shared_ptr(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) { connection->send( std::shared_ptr(new MovePlayerPacket::Pos( - x, bb->y0, y, z, onGround, abilities.flying))); + x, bb.y0, y, z, onGround, abilities.flying))); } else if (rot) { connection->send( std::shared_ptr(new MovePlayerPacket::Rot( @@ -178,7 +178,7 @@ void MultiplayerLocalPlayer::sendPosition() { if (move) { xLast = x; - yLast1 = bb->y0; + yLast1 = bb.y0; yLast2 = y; zLast = z; positionReminder = 0; diff --git a/Minecraft.Client/Rendering/Chunk.cpp b/Minecraft.Client/Rendering/Chunk.cpp index 95e060ed9..a52ac7459 100644 --- a/Minecraft.Client/Rendering/Chunk.cpp +++ b/Minecraft.Client/Rendering/Chunk.cpp @@ -43,7 +43,8 @@ Chunk::Chunk(Level* level, LevelRenderer::rteMap& globalRenderableTileEntities, : globalRenderableTileEntities(&globalRenderableTileEntities), globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs) { clipChunk->visible = false; - bb = NULL; + const double g = 6; + bb = AABB(-g, -g, -g, XZSIZE + g, SIZE + g, XZSIZE + g); id = 0; this->level = level; @@ -92,21 +93,13 @@ void Chunk::setPos(int x, int y, int z) { #endif float g = 6.0f; - // 4J - changed to just set the value rather than make a new one, if we've - // already created storage - if (bb == NULL) { - bb = new AABB(-g, -g, -g, XZSIZE + g, SIZE + g, XZSIZE + g); - } else { - // 4J MGH - bounds are relative to the position now, so the AABB will be - // setup already, either above, or from the tesselator bounds. - // 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; + + 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; @@ -508,11 +501,8 @@ void Chunk::rebuild() { // 4J MGH - added this to take the bound from the value calc'd in the // tesselator - if (bb) { - *bb = {bounds.boundingBox[0], bounds.boundingBox[1], - bounds.boundingBox[2], bounds.boundingBox[3], - bounds.boundingBox[4], bounds.boundingBox[5]}; - } + bb = {bounds.boundingBox[0], bounds.boundingBox[1], bounds.boundingBox[2], + bounds.boundingBox[3], bounds.boundingBox[4], bounds.boundingBox[5]}; delete tileRenderer; delete region; @@ -1033,7 +1023,7 @@ int Chunk::getList(int layer) { 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() { // glCallList(lists + 2); // 4J - removed - TODO put back in @@ -1064,8 +1054,6 @@ void Chunk::clearDirty() { #endif } -Chunk::~Chunk() { delete bb; } - bool Chunk::emptyFlagSet(int layer) { return levelRenderer->getGlobalChunkFlag( x, y, z, level, LevelRenderer::CHUNK_FLAG_EMPTY0, layer); diff --git a/Minecraft.Client/Rendering/Chunk.h b/Minecraft.Client/Rendering/Chunk.h index 379b258ba..e6d214ab2 100644 --- a/Minecraft.Client/Rendering/Chunk.h +++ b/Minecraft.Client/Rendering/Chunk.h @@ -46,7 +46,7 @@ public: int xRenderOffs, yRenderOffs, zRenderOffs; int xm, ym, zm; - AABB* bb; + AABB bb; ClipChunk* clipChunk; int id; @@ -88,5 +88,4 @@ public: void setDirty(); void clearDirty(); // 4J added bool emptyFlagSet(int layer); - ~Chunk(); }; diff --git a/Minecraft.Client/Rendering/EntityRenderers/EntityRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/EntityRenderer.cpp index 9b4d7bda3..86c76a334 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/EntityRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/EntityRenderer.cpp @@ -91,7 +91,7 @@ void EntityRenderer::renderFlame(std::shared_ptr e, double x, double y, float xo = 0.0f; 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); @@ -394,4 +394,4 @@ void EntityRenderer::registerTerrainTextures(IconRegister* iconRegister) {} ResourceLocation* EntityRenderer::getTextureLocation( std::shared_ptr mob) { return NULL; -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/EntityRenderers/FireballRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/FireballRenderer.cpp index 87251b8c9..fd1dce90c 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/FireballRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/FireballRenderer.cpp @@ -78,7 +78,7 @@ void FireballRenderer::renderFlame(std::shared_ptr e, double x, // float yo = 0.0f; 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); @@ -118,4 +118,4 @@ void FireballRenderer::renderFlame(std::shared_ptr e, double x, ResourceLocation* FireballRenderer::getTextureLocation( std::shared_ptr mob) { return &TextureAtlas::LOCATION_ITEMS; -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index b2f589b88..e405931b0 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -310,7 +310,7 @@ void GameRenderer::pick(float a) { hovered = nullptr; float overlap = 1; 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); std::vector >* objects = @@ -323,7 +323,7 @@ void GameRenderer::pick(float a) { if (!e->isPickable()) continue; 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); if (bb.contains(from)) { if (0 < nearest || nearest == 0) { diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index d970c3f3b..556d83ec7 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -585,14 +585,14 @@ void LevelRenderer::renderEntities(Vec3* cam, Culler* culler, float a) { bool shouldRender = (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 if (!shouldRender && entity->instanceof(eTYPE_MOB)) { std::shared_ptr mob = std::dynamic_pointer_cast(entity); if (mob->isLeashed() && (mob->getLeashHolder() != NULL)) { std::shared_ptr leashHolder = mob->getLeashHolder(); - shouldRender = culler->isVisible(leashHolder->bb); + shouldRender = culler->isVisible(&leashHolder->bb); } } diff --git a/Minecraft.Client/Rendering/Particles/CritParticle.cpp b/Minecraft.Client/Rendering/Particles/CritParticle.cpp index 11457da37..fba87aca0 100644 --- a/Minecraft.Client/Rendering/Particles/CritParticle.cpp +++ b/Minecraft.Client/Rendering/Particles/CritParticle.cpp @@ -16,14 +16,14 @@ void CritParticle::_init(Level* level, std::shared_ptr entity, } CritParticle::CritParticle(Level* level, std::shared_ptr 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) { _init(level, entity, eParticleType_crit); } CritParticle::CritParticle(Level* level, std::shared_ptr entity, 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) { _init(level, entity, type); } @@ -43,7 +43,7 @@ void CritParticle::tick() { if (xa * xa + ya * ya + za * za > 1) continue; double x = entity->x + xa * entity->bbWidth / 4; 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; level->addParticle(particleName, x, y, z, xa, ya + 0.2, za); } @@ -55,4 +55,4 @@ void CritParticle::tick() { int CritParticle::getParticleTexture() { return ParticleEngine::ENTITY_PARTICLE_TEXTURE; -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/Particles/PlayerCloudParticle.cpp b/Minecraft.Client/Rendering/Particles/PlayerCloudParticle.cpp index 145630db1..a38775947 100644 --- a/Minecraft.Client/Rendering/Particles/PlayerCloudParticle.cpp +++ b/Minecraft.Client/Rendering/Particles/PlayerCloudParticle.cpp @@ -52,8 +52,8 @@ void PlayerCloudParticle::tick() { zd *= 0.96f; std::shared_ptr p = level->getNearestPlayer(shared_from_this(), 2); if (p != NULL) { - if (y > p->bb->y0) { - y += (p->bb->y0 - y) * 0.2; + if (y > p->bb.y0) { + y += (p->bb.y0 - y) * 0.2; yd += (p->yd - yd) * 0.2; setPos(x, y, z); } @@ -63,4 +63,4 @@ void PlayerCloudParticle::tick() { xd *= 0.7f; zd *= 0.7f; } -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Control/LookControl.cpp b/Minecraft.World/AI/Control/LookControl.cpp index f5b7519b1..c956da61d 100644 --- a/Minecraft.World/AI/Control/LookControl.cpp +++ b/Minecraft.World/AI/Control/LookControl.cpp @@ -20,7 +20,7 @@ void LookControl::setLookAt(std::shared_ptr target, float yMax, target->y + std::dynamic_pointer_cast(target)->getHeadHeight(); else - wantedY = (target->bb->y0 + target->bb->y1) / 2; + wantedY = (target->bb.y0 + target->bb.y1) / 2; wantedZ = target->z; this->yMax = yMax; this->xMax = xMax; @@ -88,4 +88,4 @@ double LookControl::getWantedX() { return wantedX; } double LookControl::getWantedY() { return wantedY; } -double LookControl::getWantedZ() { return wantedZ; } \ No newline at end of file +double LookControl::getWantedZ() { return wantedZ; } diff --git a/Minecraft.World/AI/Control/MoveControl.cpp b/Minecraft.World/AI/Control/MoveControl.cpp index 3834ed6a4..684ccd498 100644 --- a/Minecraft.World/AI/Control/MoveControl.cpp +++ b/Minecraft.World/AI/Control/MoveControl.cpp @@ -38,7 +38,7 @@ void MoveControl::tick() { if (!_hasWanted) return; _hasWanted = false; - int yFloor = floor(mob->bb->y0 + .5f); + int yFloor = floor(mob->bb.y0 + .5f); double xd = wantedX - mob->x; double zd = wantedZ - mob->z; @@ -66,4 +66,4 @@ float MoveControl::rotlerp(float a, float b, float max) { diff = -max; } return a + diff; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp index cf595ea05..af58f48ec 100644 --- a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp @@ -53,7 +53,7 @@ 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); + AABB grown_bb = mob->bb.grow(maxDist, 3, maxDist); std::vector >* entities = mob->level->getEntitiesOfClass( avoidType, &grown_bb, entitySelector); diff --git a/Minecraft.World/AI/Goals/BreedGoal.cpp b/Minecraft.World/AI/Goals/BreedGoal.cpp index 1ec4f59fc..7c9fc4ce7 100644 --- a/Minecraft.World/AI/Goals/BreedGoal.cpp +++ b/Minecraft.World/AI/Goals/BreedGoal.cpp @@ -48,7 +48,7 @@ void BreedGoal::tick() { std::shared_ptr BreedGoal::getFreePartner() { float r = 8; - AABB grown_bb = animal->bb->grow(r, r, r); + AABB grown_bb = animal->bb.grow(r, r, r); std::vector >* others = level->getEntitiesOfClass(typeid(*animal), &grown_bb); double dist = std::numeric_limits::max(); diff --git a/Minecraft.World/AI/Goals/FleeSunGoal.cpp b/Minecraft.World/AI/Goals/FleeSunGoal.cpp index fdddfd6e0..4f35fb567 100644 --- a/Minecraft.World/AI/Goals/FleeSunGoal.cpp +++ b/Minecraft.World/AI/Goals/FleeSunGoal.cpp @@ -17,7 +17,7 @@ FleeSunGoal::FleeSunGoal(PathfinderMob* mob, double speedModifier) { bool FleeSunGoal::canUse() { if (!level->isDay()) 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))) return false; @@ -39,7 +39,7 @@ std::optional FleeSunGoal::getHidePos() { Random* random = mob->getRandom(); for (int i = 0; i < 10; i++) { 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); if (!level->canSeeSky(xt, yt, zt) && mob->getWalkTargetValue(xt, yt, zt) < 0) diff --git a/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp b/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp index a0ddb3ccb..62c0431ab 100644 --- a/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp +++ b/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp @@ -69,7 +69,7 @@ void FollowOwnerGoal::tick() { // find a good spawn position nearby the owner int sx = Mth::floor(owner.lock()->x) - 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 z = 0; z <= 4; z++) { if (x >= 1 && z >= 1 && x <= 3 && z <= 3) { diff --git a/Minecraft.World/AI/Goals/FollowParentGoal.cpp b/Minecraft.World/AI/Goals/FollowParentGoal.cpp index 0a740a35c..bcdc860ae 100644 --- a/Minecraft.World/AI/Goals/FollowParentGoal.cpp +++ b/Minecraft.World/AI/Goals/FollowParentGoal.cpp @@ -16,7 +16,7 @@ FollowParentGoal::FollowParentGoal(Animal* animal, double speedModifier) { bool FollowParentGoal::canUse() { 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 >* parents = animal->level->getEntitiesOfClass(typeid(*animal), &grown_bb); diff --git a/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp b/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp index b073212c2..8ab999411 100644 --- a/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp @@ -37,10 +37,9 @@ bool LookAtPlayerGoal::canUse() { lookAt = mob->level->getNearestPlayer(mob->shared_from_this(), lookDistance); } else { - AABB mob_bb = mob->bb->grow(lookDistance, 3, lookDistance); + AABB mob_bb = mob->bb.grow(lookDistance, 3, lookDistance); lookAt = std::weak_ptr(mob->level->getClosestEntityOfClass( - lookAtType, &mob_bb, - mob->shared_from_this())); + lookAtType, &mob_bb, mob->shared_from_this())); } return lookAt.lock() != NULL; } diff --git a/Minecraft.World/AI/Goals/MakeLoveGoal.cpp b/Minecraft.World/AI/Goals/MakeLoveGoal.cpp index 0357f7113..af3dd10e3 100644 --- a/Minecraft.World/AI/Goals/MakeLoveGoal.cpp +++ b/Minecraft.World/AI/Goals/MakeLoveGoal.cpp @@ -29,10 +29,9 @@ bool MakeLoveGoal::canUse() { if (village.lock() == NULL) 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 mate = level->getClosestEntityOfClass( - typeid(Villager), &villager_bb, - villager->shared_from_this()); + typeid(Villager), &villager_bb, villager->shared_from_this()); if (mate == NULL) return false; partner = diff --git a/Minecraft.World/AI/Goals/MeleeAttackGoal.cpp b/Minecraft.World/AI/Goals/MeleeAttackGoal.cpp index b3f059d8e..3c9b28244 100644 --- a/Minecraft.World/AI/Goals/MeleeAttackGoal.cpp +++ b/Minecraft.World/AI/Goals/MeleeAttackGoal.cpp @@ -41,7 +41,7 @@ bool MeleeAttackGoal::canUse() { std::shared_ptr target = mob->getTarget(); if (target == NULL) return false; if (!target->isAlive()) return false; - if (attackType != eTYPE_NOTSET && !target->instanceof (attackType)) + if (attackType != eTYPE_NOTSET && !target->instanceof(attackType)) return false; path.reset(mob->getNavigation()->createPath(target)); return path != nullptr; @@ -79,7 +79,7 @@ void MeleeAttackGoal::tick() { double meleeRadiusSqr = (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) return; if (attackTime > 0) return; diff --git a/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp b/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp index 938102d3e..a1126b45e 100644 --- a/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp @@ -55,10 +55,9 @@ bool NearestAttackableTargetGoal::canUse() { return false; double within = getFollowDistance(); - AABB mob_bb = mob->bb->grow(within, 4, within); + AABB mob_bb = mob->bb.grow(within, 4, within); std::vector >* entities = - mob->level->getEntitiesOfClass( - targetType, &mob_bb, selector); + mob->level->getEntitiesOfClass(targetType, &mob_bb, selector); bool result = false; if (entities != NULL && !entities->empty()) { diff --git a/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp b/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp index d14d3bc9d..6753e64e3 100644 --- a/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp +++ b/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp @@ -40,7 +40,7 @@ void OcelotAttackGoal::tick() { mob->getLookControl()->setLookAt(target.lock(), 30, 30); 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); double speedModifier = Ocelot::WALK_SPEED_MOD; diff --git a/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp b/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp index 902b221ee..f78623fec 100644 --- a/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp +++ b/Minecraft.World/AI/Goals/OfferFlowerGoal.cpp @@ -15,10 +15,9 @@ 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); + AABB golem_bb = golem->bb.grow(6, 2, 6); villager = std::weak_ptr(std::dynamic_pointer_cast( - golem->level->getClosestEntityOfClass(typeid(Villager), - &golem_bb, + golem->level->getClosestEntityOfClass(typeid(Villager), &golem_bb, golem->shared_from_this()))); return villager.lock() != NULL; } diff --git a/Minecraft.World/AI/Goals/PlayGoal.cpp b/Minecraft.World/AI/Goals/PlayGoal.cpp index 550f3bb6e..b748d7519 100644 --- a/Minecraft.World/AI/Goals/PlayGoal.cpp +++ b/Minecraft.World/AI/Goals/PlayGoal.cpp @@ -23,10 +23,9 @@ 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); + AABB mob_bb = mob->bb.grow(6, 3, 6); std::vector >* children = - mob->level->getEntitiesOfClass(typeid(Villager), - &mob_bb); + mob->level->getEntitiesOfClass(typeid(Villager), &mob_bb); double closestDistSqr = std::numeric_limits::max(); // for (Entity c : children) for (AUTO_VAR(it, children->begin()); it != children->end(); ++it) { diff --git a/Minecraft.World/AI/Goals/RangedAttackGoal.cpp b/Minecraft.World/AI/Goals/RangedAttackGoal.cpp index e58c59d1c..2c7f22d9e 100644 --- a/Minecraft.World/AI/Goals/RangedAttackGoal.cpp +++ b/Minecraft.World/AI/Goals/RangedAttackGoal.cpp @@ -67,7 +67,7 @@ void RangedAttackGoal::tick() { if (target.lock() == NULL) return; 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()); if (canSee) { @@ -100,4 +100,4 @@ void RangedAttackGoal::tick() { attackTime = Mth::floor(dist * (attackIntervalMax - attackIntervalMin) + attackIntervalMin); } -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp b/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp index e4e9ed042..7c3a49f44 100644 --- a/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp +++ b/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp @@ -22,10 +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); + AABB villager_bb = villager->bb.grow(6, 2, 6); std::vector >* golems = villager->level->getEntitiesOfClass(typeid(VillagerGolem), - &villager_bb); + &villager_bb); if (golems->size() == 0) { delete golems; return false; diff --git a/Minecraft.World/AI/Navigation/PathFinder.cpp b/Minecraft.World/AI/Navigation/PathFinder.cpp index 20a730c4a..429b99302 100644 --- a/Minecraft.World/AI/Navigation/PathFinder.cpp +++ b/Minecraft.World/AI/Navigation/PathFinder.cpp @@ -33,7 +33,7 @@ PathFinder::~PathFinder() { } 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) { @@ -46,9 +46,9 @@ Path* PathFinder::findPath(Entity* e, double xt, double yt, double zt, nodes.clear(); 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()) { - startY = (int)(e->bb->y0); + startY = (int)(e->bb.y0); int tileId = level->getTile((int)Mth::floor(e->x), startY, (int)Mth::floor(e->z)); 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; avoidWater = false; } 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), (int)floor(zt - e->bbWidth / 2)); diff --git a/Minecraft.World/AI/Navigation/PathNavigation.cpp b/Minecraft.World/AI/Navigation/PathNavigation.cpp index 62547c4f0..fc03d1948 100644 --- a/Minecraft.World/AI/Navigation/PathNavigation.cpp +++ b/Minecraft.World/AI/Navigation/PathNavigation.cpp @@ -188,9 +188,9 @@ Vec3 PathNavigation::getTempMobPos() { } 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 = level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z)); int steps = 0; @@ -198,7 +198,7 @@ int PathNavigation::getSurfaceY() { ++surface; tileId = 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; } @@ -212,7 +212,7 @@ bool PathNavigation::isInLiquid() { } 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))) return; diff --git a/Minecraft.World/Blocks/FallingTile.cpp b/Minecraft.World/Blocks/FallingTile.cpp index a57aa58d2..eb7adda42 100644 --- a/Minecraft.World/Blocks/FallingTile.cpp +++ b/Minecraft.World/Blocks/FallingTile.cpp @@ -168,7 +168,7 @@ void FallingTile::causeFallDamage(float distance) { // entities (invalidating our iterator) std::vector >* entities = new std::vector >( - *level->getEntities(shared_from_this(), bb)); + *level->getEntities(shared_from_this(), &bb)); DamageSource* source = tile == Tile::anvil_Id ? DamageSource::anvil : DamageSource::fallingBlock; @@ -242,4 +242,4 @@ Level* FallingTile::getLevel() { return level; } void FallingTile::setHurtsEntities(bool value) { this->hurtEntities = value; } -bool FallingTile::displayFireAnimation() { return false; } \ No newline at end of file +bool FallingTile::displayFireAnimation() { return false; } diff --git a/Minecraft.World/Entities/Entity.cpp b/Minecraft.World/Entities/Entity.cpp index d07f16799..216e49beb 100644 --- a/Minecraft.World/Entities/Entity.cpp +++ b/Minecraft.World/Entities/Entity.cpp @@ -268,7 +268,7 @@ void Entity::_init(bool useSmallId, Level* level) { xd = yd = zd = 0.0; yRot = xRot = 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; horizontalCollision = verticalCollision = false; collision = false; @@ -376,7 +376,6 @@ Entity::Entity(Level* level, Entity::~Entity() { freeSmallId(entityId); delete random; - delete bb; } std::shared_ptr Entity::getEntityData() { @@ -402,7 +401,7 @@ void Entity::resetPos() { std::shared_ptr sharedThis = shared_from_this(); while (true && y > 0) { setPos(x, y, z); - if (level->getCubes(sharedThis, bb)->empty()) break; + if (level->getCubes(sharedThis, &bb)->empty()) break; y += 1; } @@ -419,9 +418,9 @@ void Entity::setSize(float w, float h) { bbWidth = w; bbHeight = h; - bb->x1 = bb->x0 + bbWidth; - bb->z1 = bb->z0 + bbWidth; - bb->y1 = bb->y0 + bbHeight; + bb.x1 = bb.x0 + bbWidth; + bb.z1 = bb.z0 + bbWidth; + bb.y1 = bb.y0 + bbHeight; if (bbWidth > oldW && !firstTick && !level->isClientSide) { move(oldW - bbWidth, 0, oldW - bbWidth); @@ -463,7 +462,7 @@ void Entity::setPos(double x, double y, double z) { this->z = z; float w = bbWidth / 2; 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}; } @@ -551,7 +550,7 @@ void Entity::baseTick() { if (t > 0) { level->addParticle(PARTICLE_TILECRACK(t, d), x + (random->nextFloat() - 0.5) * bbWidth, - bb->y0 + 0.1, + bb.y0 + 0.1, z + (random->nextFloat() - 0.5) * bbWidth, -xd * 4, 1.5, -zd * 4); } @@ -618,7 +617,7 @@ 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).move(xa, ya, za); + 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; @@ -626,7 +625,7 @@ bool Entity::isFree(float xa, float ya, float za, float grow) { } 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); if (!aABBs->empty()) 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 { if (noPhysics) { - *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; + 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; return; } @@ -665,15 +664,13 @@ void Entity::move(double xa, double ya, double za, double yaOrg = ya; double zaOrg = za; - 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); + AABB translated_bb = bb.move(xa, -1.0, 0.0); while (xa != 0 && level->getCubes(shared_from_this(), &translated_bb)->empty()) { if (xa < d && xa >= -d) @@ -685,7 +682,7 @@ void Entity::move(double xa, double ya, double za, xaOrg = xa; } - translated_bb = bb->move(0, -1.0, za); + translated_bb = bb.move(0, -1.0, za); while (za != 0 && level->getCubes(shared_from_this(), &translated_bb)->empty()) { if (za < d && za >= -d) @@ -697,7 +694,7 @@ void Entity::move(double xa, double ya, double za, zaOrg = za; } - translated_bb = bb->move(xa, -1.0, za); + translated_bb = bb.move(xa, -1.0, za); while (xa != 0 && za != 0 && level->getCubes(shared_from_this(), &translated_bb)->empty()) { 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 = 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 // be incorrect as well for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) - ya = it->clipYCollide(*bb, ya); - *bb = bb->move(0, ya, 0); + ya = it->clipYCollide(bb, ya); + bb = bb.move(0, ya, 0); } if (!slide && yaOrg != ya) { @@ -745,9 +742,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 = bb->move(xa, 0, 0); + bb = bb.move(xa, 0, 0); if (!slide && xaOrg != xa) { xa = ya = za = 0; @@ -755,8 +752,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 = bb->move(0, 0, za); + za = it->clipZCollide(bb, za); + bb = bb.move(0, 0, za); if (!slide && zaOrg != za) { xa = ya = za = 0; @@ -772,13 +769,11 @@ void Entity::move(double xa, double ya, double za, ya = footSize; za = zaOrg; - 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 - 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); // 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 // info will be incorrect as well for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++) - ya = it->clipYCollide(*bb, ya); - *bb = bb->move(0, ya, 0); + ya = it->clipYCollide(bb, ya); + bb = bb.move(0, ya, 0); } if (!slide && yaOrg != ya) { @@ -799,8 +794,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 = bb->move(xa, 0, 0); + xa = it->clipXCollide(bb, xa); + bb = bb.move(xa, 0, 0); if (!slide && xaOrg != xa) { xa = ya = za = 0; @@ -808,8 +803,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 = bb->move(0, 0, za); + za = it->clipZCollide(bb, za); + bb = bb.move(0, 0, za); if (!slide && zaOrg != za) { xa = ya = za = 0; @@ -822,21 +817,20 @@ 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 = 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 = normal; } } - x = (bb->x0 + bb->x1) / 2.0f; - y = bb->y0 + heightOffset - ySlideOffset; - z = (bb->z0 + bb->z1) / 2.0f; + x = (bb.x0 + bb.x1) / 2.0f; + y = bb.y0 + heightOffset - ySlideOffset; + z = (bb.z0 + bb.z1) / 2.0f; horizontalCollision = (xaOrg != xa) || (zaOrg != za); verticalCollision = !m_ignoreVerticalCollisions && (yaOrg != ya); @@ -891,8 +885,8 @@ void Entity::move(double xa, double ya, double za, checkInsideTiles(); bool water = isInWaterOrRain(); - const AABB& shrunk = bb->shrink(0.001, 0.001, 0.001); - if (level->containsFireTile(bb)) { + const AABB& shrunk = bb.shrink(0.001, 0.001, 0.001); + if (level->containsFireTile(&bb)) { burn(1); if (!water) { onFire++; @@ -912,12 +906,12 @@ void Entity::move(double xa, double ya, double za, } void Entity::checkInsideTiles() { - int x0 = Mth::floor(bb->x0 + 0.001); - int y0 = Mth::floor(bb->y0 + 0.001); - int z0 = Mth::floor(bb->z0 + 0.001); - int x1 = Mth::floor(bb->x1 - 0.001); - int y1 = Mth::floor(bb->y1 - 0.001); - int z1 = Mth::floor(bb->z1 - 0.001); + int x0 = Mth::floor(bb.x0 + 0.001); + int y0 = Mth::floor(bb.y0 + 0.001); + int z0 = Mth::floor(bb.z0 + 0.001); + int x1 = Mth::floor(bb.x1 - 0.001); + int y1 = Mth::floor(bb.y1 - 0.001); + int z1 = Mth::floor(bb.z1 - 0.001); if (level->hasChunksAt(x0, y0, z0, x1, y1, z1)) { for (int x = x0; x <= x1; x++) @@ -1000,7 +994,7 @@ bool Entity::isInWaterOrRain() { bool Entity::isInWater() { return wasInWater; } 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, shared_from_this())) { if (!wasInWater && !firstTick && canCreateParticles()) { @@ -1011,7 +1005,7 @@ bool Entity::updateInWaterState() { playSound(eSoundType_RANDOM_SPLASH, speed, 1 + (random->nextFloat() - random->nextFloat()) * 0.4f); 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++) { float xo = (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; } 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); } @@ -1079,7 +1073,7 @@ int Entity::getLightColor(float a) { int zTile = Mth::floor(z); 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); return level->getLightColor(xTile, yTile, zTile, 0); } @@ -1091,7 +1085,7 @@ float Entity::getBrightness(float a) { int xTile = Mth::floor(x); int zTile = Mth::floor(z); 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); 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, 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; } @@ -1220,7 +1214,7 @@ bool Entity::shouldRender(Vec3* c) { } bool Entity::shouldRenderAtSqrDistance(double distance) { - double size = bb->getSize(); + double size = bb.getSize(); size *= 64.0f * viewScale; return distance < size * size; } @@ -1497,7 +1491,7 @@ void Entity::ride(std::shared_ptr e) { // 4J Stu - Position should already be updated before the // SetEntityLinkPacket comes in 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); riding->rider = std::weak_ptr(); } @@ -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 // intersect the geometry they land in slightly. 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); if (!collisions->empty()) { 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; } - y += yTop - bb->y0; + y += yTop - bb.y0; setPos(x, y, z); } } @@ -1667,7 +1661,7 @@ bool Entity::checkInTile(double x, double y, double z) { double yd = y - (yTile); double zd = z - (zTile); - auto* cubes = level->getTileCubes(bb); + auto* cubes = level->getTileCubes(&bb); if ((cubes && !cubes->empty()) || level->isFullAABBTile(xTile, yTile, zTile)) { bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile); diff --git a/Minecraft.World/Entities/Entity.h b/Minecraft.World/Entities/Entity.h index df348f5cd..485a2ae57 100644 --- a/Minecraft.World/Entities/Entity.h +++ b/Minecraft.World/Entities/Entity.h @@ -5,6 +5,7 @@ #include "../IO/NBT/FloatTag.h" #include "../Util/Vec3.h" #include "../Util/Definitions.h" +#include "../Util/AABB.h" #include #include @@ -72,7 +73,7 @@ public: double xd, yd, zd; float yRot, xRot; float yRotO, xRotO; - /*const*/ AABB* bb; // 4J Was final + /*const*/ AABB bb; // 4J Was final bool onGround; bool horizontalCollision, verticalCollision; bool collision; diff --git a/Minecraft.World/Entities/FlyingMob.cpp b/Minecraft.World/Entities/FlyingMob.cpp index 752c68047..6a38c457d 100644 --- a/Minecraft.World/Entities/FlyingMob.cpp +++ b/Minecraft.World/Entities/FlyingMob.cpp @@ -34,7 +34,7 @@ void FlyingMob::travel(float xa, float ya) { float friction = 0.91f; if (onGround) { 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)); if (t > 0) { friction = Tile::tiles[t]->friction * 0.91f; @@ -48,7 +48,7 @@ void FlyingMob::travel(float xa, float ya) { friction = 0.91f; if (onGround) { 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)); if (t > 0) { friction = Tile::tiles[t]->friction * 0.91f; @@ -70,4 +70,4 @@ void FlyingMob::travel(float xa, float ya) { walkAnimPos += walkAnimSpeed; } -bool FlyingMob::onLadder() { return false; } \ No newline at end of file +bool FlyingMob::onLadder() { return false; } diff --git a/Minecraft.World/Entities/HangingEntity.cpp b/Minecraft.World/Entities/HangingEntity.cpp index b94d8fdf1..aa693de88 100644 --- a/Minecraft.World/Entities/HangingEntity.cpp +++ b/Minecraft.World/Entities/HangingEntity.cpp @@ -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 = {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) { @@ -98,7 +98,7 @@ void HangingEntity::tick() { } 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; } else { @@ -128,7 +128,7 @@ bool HangingEntity::survives() { } std::vector >* entities = - level->getEntities(shared_from_this(), bb); + level->getEntities(shared_from_this(), &bb); if (entities != NULL && entities->size() > 0) { AUTO_VAR(itEnd, entities->end()); diff --git a/Minecraft.World/Entities/ItemEntity.cpp b/Minecraft.World/Entities/ItemEntity.cpp index 880971f67..8d4706e39 100644 --- a/Minecraft.World/Entities/ItemEntity.cpp +++ b/Minecraft.World/Entities/ItemEntity.cpp @@ -68,7 +68,7 @@ void ItemEntity::tick() { zo = z; 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 // other entities @@ -96,7 +96,7 @@ void ItemEntity::tick() { float friction = 0.98f; if (onGround) { 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)); if (t > 0) { friction = Tile::tiles[t]->friction * 0.98f; @@ -119,7 +119,7 @@ void ItemEntity::tick() { } void ItemEntity::mergeWithNeighbours() { - AABB grown = bb->grow(0.5, 0, 0.5); + AABB grown = bb.grow(0.5, 0, 0.5); std::vector >* neighbours = level->getEntitiesOfClass(typeid(*this), &grown); for (AUTO_VAR(it, neighbours->begin()); it != neighbours->end(); ++it) { @@ -164,7 +164,7 @@ void ItemEntity::setShortLifeTime() { } 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); } diff --git a/Minecraft.World/Entities/LivingEntity.cpp b/Minecraft.World/Entities/LivingEntity.cpp index c30033456..e0646a26a 100644 --- a/Minecraft.World/Entities/LivingEntity.cpp +++ b/Minecraft.World/Entities/LivingEntity.cpp @@ -897,7 +897,7 @@ void LivingEntity::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) { bool LivingEntity::onLadder() { int xt = Mth::floor(x); - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); int zt = Mth::floor(z); // 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 vehicle) { AABB boundingBox; double fallbackX = vehicle->x; - double fallbackY = vehicle->bb->y0 + vehicle->bbHeight; + double fallbackY = vehicle->bb.y0 + vehicle->bbHeight; double fallbackZ = vehicle->z; for (double xDiff = -1.5; xDiff < 2; xDiff += 1.5) { @@ -1177,7 +1177,7 @@ void LivingEntity::findStandUpPosition(std::shared_ptr vehicle) { int xToInt = (int)(x + xDiff); 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->isTopSolidBlocking(xToInt, (int)y, zToInt)) { @@ -1259,7 +1259,7 @@ void LivingEntity::travel(float xa, float ya) { float friction = 0.91f; if (onGround) { 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)); if (t > 0) { friction = Tile::tiles[t]->friction * 0.91f; @@ -1281,7 +1281,7 @@ void LivingEntity::travel(float xa, float ya) { friction = 0.91f; if (onGround) { 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)); if (t > 0) { 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. int LivingEntity::getLightColor(float a) { float accum[2] = {0, 0}; - float totVol = (bb->x1 - bb->x0) * (bb->y1 - bb->y0) * (bb->z1 - bb->z0); - int xmin = Mth::floor(bb->x0); - int xmax = Mth::floor(bb->x1); - int ymin = Mth::floor(bb->y0); - int ymax = Mth::floor(bb->y1); - int zmin = Mth::floor(bb->z0); - int zmax = Mth::floor(bb->z1); + float totVol = (bb.x1 - bb.x0) * (bb.y1 - bb.y0) * (bb.z1 - bb.z0); + int xmin = Mth::floor(bb.x0); + int xmax = Mth::floor(bb.x1); + int ymin = Mth::floor(bb.y0); + int ymax = Mth::floor(bb.y1); + int zmin = Mth::floor(bb.z0); + int zmax = Mth::floor(bb.z1); for (int xt = xmin; xt <= xmax; xt++) for (int yt = ymin; yt <= ymax; yt++) for (int zt = zmin; zt <= zmax; zt++) { @@ -1353,12 +1353,12 @@ int LivingEntity::getLightColor(float a) { float tileymax = (float)(yt + 1); float tilezmin = (float)zt; float tilezmax = (float)(zt + 1); - if (tilexmin < bb->x0) tilexmin = bb->x0; - if (tilexmax > bb->x1) tilexmax = bb->x1; - if (tileymin < bb->y0) tileymin = bb->y0; - if (tileymax > bb->y1) tileymax = bb->y1; - if (tilezmin < bb->z0) tilezmin = bb->z0; - if (tilezmax > bb->z1) tilezmax = bb->z1; + if (tilexmin < bb.x0) tilexmin = bb.x0; + if (tilexmax > bb.x1) tilexmax = bb.x1; + if (tileymin < bb.y0) tileymin = bb.y0; + if (tileymax > bb.y1) tileymax = bb.y1; + if (tilezmin < bb.z0) tilezmin = bb.z0; + if (tilezmax > bb.z1) tilezmax = bb.z1; float tileVol = (tilexmax - tilexmin) * (tileymax - tileymin) * (tilezmax - tilezmin); float frac = tileVol / totVol; @@ -1508,10 +1508,10 @@ void LivingEntity::aiStep() { // 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 // 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 // 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; AABBList* collisions = level->getCubes(shared_from_this(), &shrinkbb); if (collisions->size() > 0) { @@ -1521,7 +1521,7 @@ void LivingEntity::aiStep() { if (it->y1 > yTop) yTop = it->y1; } - yt += yTop - bb->y0; + yt += yTop - bb.y0; setPos(xt, yt, zt); } } else if (!isEffectiveAi()) { @@ -1581,7 +1581,7 @@ void LivingEntity::aiStep() { void LivingEntity::newServerAiStep() {} void LivingEntity::pushEntities() { - AABB grown = bb->grow(0.2, 0, 0.2); + AABB grown = bb.grow(0.2, 0, 0.2); std::vector >* entities = level->getEntities(shared_from_this(), &grown); if (entities != NULL && !entities->empty()) { diff --git a/Minecraft.World/Entities/MinecartHopper.cpp b/Minecraft.World/Entities/MinecartHopper.cpp index 43707b810..ef70622c7 100644 --- a/Minecraft.World/Entities/MinecartHopper.cpp +++ b/Minecraft.World/Entities/MinecartHopper.cpp @@ -85,7 +85,7 @@ void MinecartHopper::tick() { bool MinecartHopper::suckInItems() { 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 >* items = level->getEntitiesOfClass(typeid(ItemEntity), &grown, EntitySelector::ENTITY_STILL_ALIVE); diff --git a/Minecraft.World/Entities/Mob.cpp b/Minecraft.World/Entities/Mob.cpp index b7fe61e1a..4ebcf21ac 100644 --- a/Minecraft.World/Entities/Mob.cpp +++ b/Minecraft.World/Entities/Mob.cpp @@ -301,7 +301,7 @@ void Mob::aiStep() { if (!level->isClientSide && canPickUpLoot() && !dead && level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) { - AABB grown = bb->grow(1, 0, 1); + AABB grown = bb.grow(1, 0, 1); std::vector >* entities = level->getEntitiesOfClass(typeid(ItemEntity), &grown); for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { @@ -499,7 +499,7 @@ void Mob::lookAt(std::shared_ptr e, float yMax, float xMax) { std::dynamic_pointer_cast(e); yd = (mob->y + mob->getHeadHeight()) - (y + getHeadHeight()); } 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); @@ -527,9 +527,9 @@ float Mob::rotlerp(float a, float b, float max) { bool Mob::canSpawn() { // 4J - altered to use special containsAnyLiquid variant - return level->isUnobstructed(bb) && - level->getCubes(shared_from_this(), bb)->empty() && - !level->containsAnyLiquid_NoLoad(bb); + return level->isUnobstructed(&bb) && + level->getCubes(shared_from_this(), &bb)->empty() && + !level->containsAnyLiquid_NoLoad(&bb); } float Mob::getSizeScale() { return 1.0f; } @@ -848,7 +848,7 @@ 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); + AABB grown = bb.grow(10, 10, 10); std::vector >* livingEnts = level->getEntitiesOfClass(typeid(LivingEntity), &grown); @@ -889,9 +889,9 @@ void Mob::restoreLeashFromSave() { // resolve bug 10327 :Gameplay: NPCs can spawn over chunks that have not yet // been streamed and display jitter. bool Mob::shouldRender(Vec3* c) { - if (!level->reallyHasChunksAt(Mth::floor(bb->x0), Mth::floor(bb->y0), - Mth::floor(bb->z0), Mth::floor(bb->x1), - Mth::floor(bb->y1), Mth::floor(bb->z1))) { + if (!level->reallyHasChunksAt(Mth::floor(bb.x0), Mth::floor(bb.y0), + Mth::floor(bb.z0), Mth::floor(bb.x1), + Mth::floor(bb.y1), Mth::floor(bb.z1))) { return false; } return Entity::shouldRender(c); diff --git a/Minecraft.World/Entities/Mobs/Animal.cpp b/Minecraft.World/Entities/Mobs/Animal.cpp index 8df5245d2..a2ce25b5b 100644 --- a/Minecraft.World/Entities/Mobs/Animal.cpp +++ b/Minecraft.World/Entities/Mobs/Animal.cpp @@ -216,7 +216,7 @@ std::shared_ptr Animal::findAttackTarget() { float r = 8; if (getInLoveValue() > 0) { - AABB grown = bb->grow(r, r, r); + AABB grown = bb.grow(r, r, r); std::vector >* others = level->getEntitiesOfClass(typeid(*this), &grown); // for (int i = 0; i < others->size(); i++) @@ -230,7 +230,7 @@ std::shared_ptr Animal::findAttackTarget() { delete others; } else { if (getAge() == 0) { - AABB grown = bb->grow(r, r, r); + AABB grown = bb.grow(r, r, r); std::vector >* players = level->getEntitiesOfClass(typeid(Player), &grown); // for (int i = 0; i < players.size(); i++) @@ -247,7 +247,7 @@ std::shared_ptr Animal::findAttackTarget() { } delete players; } else if (getAge() > 0) { - AABB grown = bb->grow(r, r, r); + AABB grown = bb.grow(r, r, r); std::vector >* others = level->getEntitiesOfClass(typeid(*this), &grown); // for (int i = 0; i < others.size(); i++) @@ -267,7 +267,7 @@ std::shared_ptr Animal::findAttackTarget() { bool Animal::canSpawn() { int xt = Mth::floor(x); - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); int zt = Mth::floor(z); return level->getTile(xt, yt - 1, zt) == Tile::grass_Id && level->getDaytimeRawBrightness(xt, yt, zt) > 8 && diff --git a/Minecraft.World/Entities/Mobs/Arrow.cpp b/Minecraft.World/Entities/Mobs/Arrow.cpp index 471ee3a2e..4c8977b66 100644 --- a/Minecraft.World/Entities/Mobs/Arrow.cpp +++ b/Minecraft.World/Entities/Mobs/Arrow.cpp @@ -230,7 +230,7 @@ void Arrow::tick() { } std::shared_ptr 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 >* objects = level->getEntities(shared_from_this(), &grown); double nearest = 0; @@ -240,7 +240,7 @@ void Arrow::tick() { if (!e->isPickable() || (e == owner && flightTime < 5)) continue; 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); if (p != NULL) { double dd = from.distanceTo(p->pos); diff --git a/Minecraft.World/Entities/Mobs/Bat.cpp b/Minecraft.World/Entities/Mobs/Bat.cpp index 43c180678..5835875af 100644 --- a/Minecraft.World/Entities/Mobs/Bat.cpp +++ b/Minecraft.World/Entities/Mobs/Bat.cpp @@ -185,7 +185,7 @@ void Bat::addAdditonalSaveData(CompoundTag* entityTag) { } bool Bat::canSpawn() { - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); if (yt >= level->seaLevel) return false; int xt = Mth::floor(x); @@ -205,4 +205,4 @@ bool Bat::canSpawn() { if (br > random->nextInt(maxLight)) return false; return AmbientCreature::canSpawn(); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Blaze.cpp b/Minecraft.World/Entities/Mobs/Blaze.cpp index 2ac264dbd..ce7fec922 100644 --- a/Minecraft.World/Entities/Mobs/Blaze.cpp +++ b/Minecraft.World/Entities/Mobs/Blaze.cpp @@ -93,14 +93,14 @@ void Blaze::aiStep() { } void Blaze::checkHurtTarget(std::shared_ptr target, float d) { - if (attackTime <= 0 && d < 2.0f && target->bb->y1 > bb->y0 && - target->bb->y0 < bb->y1) { + if (attackTime <= 0 && d < 2.0f && target->bb.y1 > bb.y0 && + target->bb.y0 < bb.y1) { attackTime = 20; doHurtTarget(target); } else if (d < 30) { double xd = target->x - x; 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; if (attackTime == 0) { @@ -181,4 +181,4 @@ void Blaze::setCharged(bool value) { entityData->set(DATA_FLAGS_ID, flags); } -bool Blaze::isDarkEnoughToSpawn() { return true; } \ No newline at end of file +bool Blaze::isDarkEnoughToSpawn() { return true; } diff --git a/Minecraft.World/Entities/Mobs/Boat.cpp b/Minecraft.World/Entities/Mobs/Boat.cpp index d04c7f33e..4b21065e9 100644 --- a/Minecraft.World/Entities/Mobs/Boat.cpp +++ b/Minecraft.World/Entities/Mobs/Boat.cpp @@ -44,10 +44,10 @@ void Boat::defineSynchedData() { } AABB* Boat::getCollideAgainstBox(std::shared_ptr entity) { - return entity->bb; + return &entity->bb; } -AABB* Boat::getCollideBox() { return bb; } +AABB* Boat::getCollideBox() { return &bb; } bool Boat::isPushable() { return true; } @@ -165,9 +165,9 @@ void Boat::tick() { int steps = 5; double waterPercentage = 0; for (int i = 0; i < steps; i++) { - 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; - AABB bb2(bb->x0, y0, bb->z0, bb->x1, y1, bb->z1); + 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; + AABB bb2(bb.x0, y0, bb.z0, bb.x1, y1, bb.z1); if (level->containsLiquid(&bb2, Material::water)) { waterPercentage += 1.0 / steps; } @@ -345,7 +345,7 @@ void Boat::tick() { if (level->isClientSide) return; - AABB grown = bb->grow(0.2, 0, 0.2); + AABB grown = bb.grow(0.2, 0, 0.2); std::vector >* entities = level->getEntities(shared_from_this(), &grown); if (entities != NULL && !entities->empty()) { diff --git a/Minecraft.World/Entities/Mobs/DragonFireball.cpp b/Minecraft.World/Entities/Mobs/DragonFireball.cpp index 11607882a..19486ffbe 100644 --- a/Minecraft.World/Entities/Mobs/DragonFireball.cpp +++ b/Minecraft.World/Entities/Mobs/DragonFireball.cpp @@ -29,7 +29,7 @@ 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 >* entitiesOfClass = level->getEntitiesOfClass(typeid(LivingEntity), &aoe); diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index abcab5c46..7aa192c13 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -73,7 +73,7 @@ void EnderDragon::_init() { m_actionTicks = 0; m_sittingDamageReceived = 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; for (int i = 0; i < positionsLength; i++) { @@ -324,7 +324,7 @@ void EnderDragon::aiStep() { { xP = head->x; // - vN->x * d; yP = - head->bb->y0 + + head->bb.y0 + head->bbHeight / 2; // - vN->y * d; //head->y + // head->bbHeight / 2 + 0.5f - v->y * d; @@ -346,7 +346,7 @@ void EnderDragon::aiStep() { for (unsigned int j = 0; j < 6; ++j) { xP = head->x; // - vN->x * d; yP = - head->bb->y0 + + head->bb.y0 + head->bbHeight / 2; // - vN->y * d; //head->y + // head->bbHeight / 2 + 0.5f - v->y * d; @@ -462,7 +462,7 @@ void EnderDragon::aiStep() { getSynchedAction() == e_EnderdragonAction_Landing) { if (m_actionTicks < (FLAME_TICKS - 10)) { std::vector >* targets = - level->getEntities(shared_from_this(), m_acidArea); + level->getEntities(shared_from_this(), &m_acidArea); for (AUTO_VAR(it, targets->begin()); it != targets->end(); ++it) { @@ -491,7 +491,7 @@ void EnderDragon::aiStep() { if (angleDegs < 0 || angleDegs > 10) { double xdd = attackTarget->x - head->x; - // double ydd = (attackTarget->bb->y0 + + // double ydd = (attackTarget->bb.y0 + // attackTarget->bbHeight / 2) - (head->y + head->bbHeight / // 2); double zdd = attackTarget->z - head->z; @@ -541,7 +541,7 @@ void EnderDragon::aiStep() { double sd = sqrt(xd * xd + zd * zd); double ho = 0.4f + sd / 80.0f - 1; if (ho > 10) ho = 10; - yTarget = attackTarget->bb->y0 + ho; + yTarget = attackTarget->bb.y0 + ho; } else { // xTarget += random->nextGaussian() * 2; // zTarget += random->nextGaussian() * 2; @@ -646,13 +646,13 @@ 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); + AABB wing_mov = wing1->bb.grow(4, 2, 4).move(0, -2, 0); 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)); - AABB neck_bb = neck->bb->grow(1, 1, 1); - AABB head_bb = head->bb->grow(1, 1, 1); + 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)); } @@ -687,19 +687,19 @@ 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 = {acidX - 5, acidY - 17, 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, // yRotA, ss, cc, ccTilt); app.DebugPrintf("Body (%f,%f,%f) to - // (%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 - // (%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); - // 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->z1); app.DebugPrintf("Acid (%f,%f,%f) to (%f,%f,%f)\n\n", + // (%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 + // (%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); + // 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.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->y1, m_acidArea->z1); } @@ -757,7 +757,7 @@ void EnderDragon::aiStep() { double xdd = attackTarget->x - startingX; double ydd = - (attackTarget->bb->y0 + attackTarget->bbHeight / 2) - + (attackTarget->bb.y0 + attackTarget->bbHeight / 2) - (startingY + head->bbHeight / 2); double zdd = attackTarget->z - startingZ; @@ -795,7 +795,7 @@ void EnderDragon::aiStep() { if (!level->isClientSide) { 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) { float maxDist = 32; - AABB grown = bb->grow(maxDist, maxDist, maxDist); + AABB grown = bb.grow(maxDist, maxDist, maxDist); std::vector >* crystals = level->getEntitiesOfClass(typeid(EnderCrystal), &grown); @@ -851,9 +851,9 @@ void EnderDragon::checkAttack() { } void EnderDragon::knockBack(std::vector >* 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 zm = (body->bb->z0 + body->bb->z1) / 2; + double zm = (body->bb.z0 + body->bb.z1) / 2; // for (Entity e : entities) 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 ho = 0.4f + sd / 80.0f - 1; if (ho > 10) ho = 10; - int finalYTarget = attackTarget->bb->y0 + ho; + int finalYTarget = attackTarget->bb.y0 + ho; Node finalNode(finalXTarget, finalYTarget, finalZTarget); diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.h b/Minecraft.World/Entities/Mobs/EnderDragon.h index e8270dcae..1e8479407 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.h +++ b/Minecraft.World/Entities/Mobs/EnderDragon.h @@ -59,7 +59,7 @@ private: int m_iGrowlTimer; double m_headYRot; - AABB* m_acidArea; + AABB m_acidArea; NodeArray* m_nodes; int m_nodeAdjacency[24]; diff --git a/Minecraft.World/Entities/Mobs/EnderMan.cpp b/Minecraft.World/Entities/Mobs/EnderMan.cpp index 9762254f9..c83c478f5 100644 --- a/Minecraft.World/Entities/Mobs/EnderMan.cpp +++ b/Minecraft.World/Entities/Mobs/EnderMan.cpp @@ -117,7 +117,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr player) { Vec3 look = player->getViewVector(1).normalize(); Vec3 dir{x - player->x, - (bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), + (bb.y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), z - player->z}; double dist = dir.length(); @@ -250,7 +250,7 @@ bool EnderMan::teleport() { } bool EnderMan::teleportTowards(std::shared_ptr 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}; dir = dir.normalize(); double d = 16; @@ -286,8 +286,8 @@ bool EnderMan::teleport(double xx, double yy, double zz) { } if (landed) { setPos(x, y, z); - if (level->getCubes(shared_from_this(), bb)->empty() && - !level->containsAnyLiquid(bb)) { + if (level->getCubes(shared_from_this(), &bb)->empty() && + !level->containsAnyLiquid(&bb)) { ok = true; } } diff --git a/Minecraft.World/Entities/Mobs/EntityHorse.cpp b/Minecraft.World/Entities/Mobs/EntityHorse.cpp index cd2563466..2692045da 100644 --- a/Minecraft.World/Entities/Mobs/EntityHorse.cpp +++ b/Minecraft.World/Entities/Mobs/EntityHorse.cpp @@ -420,7 +420,7 @@ std::shared_ptr EntityHorse::getClosestMommy( double closestDistance = std::numeric_limits::max(); std::shared_ptr mommy = nullptr; - AABB expanded = baby->bb->expand(searchRadius, searchRadius, searchRadius); + AABB expanded = baby->bb.expand(searchRadius, searchRadius, searchRadius); std::vector >* list = level->getEntities(baby, &expanded, PARENT_HORSE_SELECTOR); diff --git a/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp b/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp index 26418c28e..fb7755f52 100644 --- a/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp +++ b/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp @@ -84,7 +84,7 @@ void ExperienceOrb::tick() { playSound(eSoundType_RANDOM_FIZZ, 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; // 4J - PC Comment @@ -121,7 +121,7 @@ void ExperienceOrb::tick() { float friction = 0.98f; if (onGround) { 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)); if (t > 0) { friction = Tile::tiles[t]->friction * 0.98f; @@ -145,7 +145,7 @@ void ExperienceOrb::tick() { } 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); } diff --git a/Minecraft.World/Entities/Mobs/EyeOfEnderSignal.cpp b/Minecraft.World/Entities/Mobs/EyeOfEnderSignal.cpp index 71981b9b9..ed3311a2c 100644 --- a/Minecraft.World/Entities/Mobs/EyeOfEnderSignal.cpp +++ b/Minecraft.World/Entities/Mobs/EyeOfEnderSignal.cpp @@ -28,7 +28,7 @@ EyeOfEnderSignal::EyeOfEnderSignal(Level* level) : Entity(level) { void EyeOfEnderSignal::defineSynchedData() {} bool EyeOfEnderSignal::shouldRenderAtSqrDistance(double distance) { - double size = bb->getSize() * 4; + double size = bb.getSize() * 4; size *= 64.0f; return distance < size * size; } @@ -159,4 +159,4 @@ float EyeOfEnderSignal::getBrightness(float a) { return 1.0f; } int EyeOfEnderSignal::getLightColor(float a) { return 15 << 20 | 15 << 4; } -bool EyeOfEnderSignal::isAttackable() { return false; } \ No newline at end of file +bool EyeOfEnderSignal::isAttackable() { return false; } diff --git a/Minecraft.World/Entities/Mobs/Fireball.cpp b/Minecraft.World/Entities/Mobs/Fireball.cpp index b6613549c..86ebfd150 100644 --- a/Minecraft.World/Entities/Mobs/Fireball.cpp +++ b/Minecraft.World/Entities/Mobs/Fireball.cpp @@ -39,7 +39,7 @@ Fireball::Fireball(Level* level) : Entity(level) { void Fireball::defineSynchedData() {} bool Fireball::shouldRenderAtSqrDistance(double distance) { - double size = bb->getSize() * 4; + double size = bb.getSize() * 4; size *= 64.0f; return distance < size * size; } @@ -176,7 +176,7 @@ void Fireball::tick() { to = Vec3{res->pos.x, res->pos.y, res->pos.z}; } std::shared_ptr 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 >* objects = level->getEntities(shared_from_this(), &grown); double nearest = 0; @@ -188,7 +188,7 @@ void Fireball::tick() { // && flightTime < 25)) continue; 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); if (p != NULL) { double dd = from.distanceTo(p->pos); diff --git a/Minecraft.World/Entities/Mobs/FishingHook.cpp b/Minecraft.World/Entities/Mobs/FishingHook.cpp index fe8ff9b8b..617f363e8 100644 --- a/Minecraft.World/Entities/Mobs/FishingHook.cpp +++ b/Minecraft.World/Entities/Mobs/FishingHook.cpp @@ -88,7 +88,7 @@ FishingHook::FishingHook(Level* level, std::shared_ptr mob) void FishingHook::defineSynchedData() {} bool FishingHook::shouldRenderAtSqrDistance(double distance) { - double size = bb->getSize() * 4; + double size = bb.getSize() * 4; size *= 64.0f; return distance < size * size; } @@ -175,7 +175,7 @@ void FishingHook::tick() { hookedIn = nullptr; else { x = hookedIn->x; - y = hookedIn->bb->y0 + hookedIn->bbHeight * 0.8; + y = hookedIn->bb.y0 + hookedIn->bbHeight * 0.8; z = hookedIn->z; return; } @@ -213,7 +213,7 @@ void FishingHook::tick() { to = Vec3(res->pos.x, res->pos.y, res->pos.z); } std::shared_ptr 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 >* objects = level->getEntities(shared_from_this(), &grown); double nearest = 0; @@ -223,7 +223,7 @@ void FishingHook::tick() { if (!e->isPickable() || (e == owner && flightTime < 5)) continue; 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); if (p != NULL) { double dd = from.distanceTo(p->pos); @@ -284,11 +284,11 @@ void FishingHook::tick() { int steps = 5; double waterPercentage = 0; 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; - 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; - 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)) { waterPercentage += 1.0 / steps; } @@ -309,7 +309,7 @@ void FishingHook::tick() { playSound( eSoundType_RANDOM_SPLASH, 0.25f, 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++) { float xo = (random->nextFloat() * 2 - 1) * bbWidth; float zo = (random->nextFloat() * 2 - 1) * bbWidth; diff --git a/Minecraft.World/Entities/Mobs/Ghast.cpp b/Minecraft.World/Entities/Mobs/Ghast.cpp index 40c65a43c..e6a36730c 100644 --- a/Minecraft.World/Entities/Mobs/Ghast.cpp +++ b/Minecraft.World/Entities/Mobs/Ghast.cpp @@ -119,7 +119,7 @@ void Ghast::serverAiStep() { target->distanceToSqr(shared_from_this()) < maxDist * maxDist) { double xdd = target->x - x; 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; 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 zd = (zTarget - z) / dist; - 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; diff --git a/Minecraft.World/Entities/Mobs/LavaSlime.cpp b/Minecraft.World/Entities/Mobs/LavaSlime.cpp index a84116c43..bcf420571 100644 --- a/Minecraft.World/Entities/Mobs/LavaSlime.cpp +++ b/Minecraft.World/Entities/Mobs/LavaSlime.cpp @@ -27,9 +27,9 @@ void LavaSlime::registerAttributes() { bool LavaSlime::canSpawn() { return level->difficulty > Difficulty::PEACEFUL && - level->isUnobstructed(bb) && - level->getCubes(shared_from_this(), bb)->empty() && - !level->containsAnyLiquid(bb); + level->isUnobstructed(&bb) && + level->getCubes(shared_from_this(), &bb)->empty() && + !level->containsAnyLiquid(&bb); } int LavaSlime::getArmorValue() { return getSize() * 3; } @@ -102,4 +102,4 @@ bool LavaSlime::isInLava() { return false; } -bool LavaSlime::doPlayLandSound() { return true; } \ No newline at end of file +bool LavaSlime::doPlayLandSound() { return true; } diff --git a/Minecraft.World/Entities/Mobs/Minecart.cpp b/Minecraft.World/Entities/Mobs/Minecart.cpp index 16dcbb183..7c6b1e24c 100644 --- a/Minecraft.World/Entities/Mobs/Minecart.cpp +++ b/Minecraft.World/Entities/Mobs/Minecart.cpp @@ -98,7 +98,7 @@ void Minecart::defineSynchedData() { AABB* Minecart::getCollideAgainstBox(std::shared_ptr entity) { if (entity->isPushable()) { - return entity->bb; + return &entity->bb; } return NULL; } @@ -305,7 +305,7 @@ void Minecart::tick() { } setRot(yRot, xRot); - AABB grown = bb->grow(0.2, 0, 0.2); + AABB grown = bb.grow(0.2, 0, 0.2); std::vector >* entities = level->getEntities(shared_from_this(), &grown); if (entities != NULL && !entities->empty()) { diff --git a/Minecraft.World/Entities/Mobs/MushroomCow.cpp b/Minecraft.World/Entities/Mobs/MushroomCow.cpp index fe8bed57b..5ab441782 100644 --- a/Minecraft.World/Entities/Mobs/MushroomCow.cpp +++ b/Minecraft.World/Entities/Mobs/MushroomCow.cpp @@ -67,7 +67,7 @@ bool MushroomCow::mobInteract(std::shared_ptr player) { // already really bool MushroomCow::canSpawn() { int xt = Mth::floor(x); - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); int zt = Mth::floor(z); return (level->getTile(xt, yt - 1, zt) == Tile::grass_Id || level->getTile(xt, yt - 1, zt) == Tile::mycel_Id) && diff --git a/Minecraft.World/Entities/Mobs/Ocelot.cpp b/Minecraft.World/Entities/Mobs/Ocelot.cpp index b31798af2..ea104f5e5 100644 --- a/Minecraft.World/Entities/Mobs/Ocelot.cpp +++ b/Minecraft.World/Entities/Mobs/Ocelot.cpp @@ -240,11 +240,11 @@ bool Ocelot::canSpawn() { if (level->random->nextInt(3) == 0) { return false; } - if (level->isUnobstructed(bb) && - level->getCubes(shared_from_this(), bb)->empty() && - !level->containsAnyLiquid(bb)) { + if (level->isUnobstructed(&bb) && + level->getCubes(shared_from_this(), &bb)->empty() && + !level->containsAnyLiquid(&bb)) { int xt = Mth::floor(x); - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); int zt = Mth::floor(z); if (yt < level->seaLevel) { return false; diff --git a/Minecraft.World/Entities/Mobs/PigZombie.cpp b/Minecraft.World/Entities/Mobs/PigZombie.cpp index 0c016c83f..f88d30044 100644 --- a/Minecraft.World/Entities/Mobs/PigZombie.cpp +++ b/Minecraft.World/Entities/Mobs/PigZombie.cpp @@ -69,9 +69,9 @@ void PigZombie::tick() { bool PigZombie::canSpawn() { return level->difficulty > Difficulty::PEACEFUL && - level->isUnobstructed(bb) && - level->getCubes(shared_from_this(), bb)->empty() && - !level->containsAnyLiquid(bb); + level->isUnobstructed(&bb) && + level->getCubes(shared_from_this(), &bb)->empty() && + !level->containsAnyLiquid(&bb); } void PigZombie::addAdditonalSaveData(CompoundTag* tag) { @@ -100,7 +100,7 @@ std::shared_ptr PigZombie::findAttackTarget() { bool PigZombie::hurt(DamageSource* source, float dmg) { std::shared_ptr sourceEntity = source->getEntity(); if (sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER)) { - AABB grown = bb->grow(32, 32, 32); + AABB grown = bb.grow(32, 32, 32); std::vector >* nearby = level->getEntities(shared_from_this(), &grown); AUTO_VAR(itEnd, nearby->end()); diff --git a/Minecraft.World/Entities/Mobs/Silverfish.cpp b/Minecraft.World/Entities/Mobs/Silverfish.cpp index 2ced041aa..ec0e014da 100644 --- a/Minecraft.World/Entities/Mobs/Silverfish.cpp +++ b/Minecraft.World/Entities/Mobs/Silverfish.cpp @@ -69,8 +69,8 @@ bool Silverfish::hurt(DamageSource* source, float dmg) { void Silverfish::checkHurtTarget(std::shared_ptr target, float d) { // super.checkHurtTarget(target, d); - if (attackTime <= 0 && d < 1.2f && target->bb->y1 > bb->y0 && - target->bb->y0 < bb->y1) { + if (attackTime <= 0 && d < 1.2f && target->bb.y1 > bb.y0 && + target->bb.y0 < bb.y1) { attackTime = 20; doHurtTarget(target); } @@ -192,4 +192,4 @@ bool Silverfish::canSpawn() { return false; } -MobType Silverfish::getMobType() { return ARTHROPOD; } \ No newline at end of file +MobType Silverfish::getMobType() { return ARTHROPOD; } diff --git a/Minecraft.World/Entities/Mobs/Slime.cpp b/Minecraft.World/Entities/Mobs/Slime.cpp index 6db5e5c4b..de4816ea7 100644 --- a/Minecraft.World/Entities/Mobs/Slime.cpp +++ b/Minecraft.World/Entities/Mobs/Slime.cpp @@ -91,7 +91,7 @@ void Slime::tick() { float d = random->nextFloat() * 0.5f + 0.5f; float xd = Mth::sin(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); } diff --git a/Minecraft.World/Entities/Mobs/Squid.cpp b/Minecraft.World/Entities/Mobs/Squid.cpp index 7cb96c08d..c04bba6eb 100644 --- a/Minecraft.World/Entities/Mobs/Squid.cpp +++ b/Minecraft.World/Entities/Mobs/Squid.cpp @@ -65,7 +65,7 @@ void Squid::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) { } 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, shared_from_this()); } diff --git a/Minecraft.World/Entities/Mobs/ThrownPotion.cpp b/Minecraft.World/Entities/Mobs/ThrownPotion.cpp index da329189c..71020e479 100644 --- a/Minecraft.World/Entities/Mobs/ThrownPotion.cpp +++ b/Minecraft.World/Entities/Mobs/ThrownPotion.cpp @@ -82,7 +82,7 @@ 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 >* entitiesOfClass = level->getEntitiesOfClass(typeid(LivingEntity), &aoe); diff --git a/Minecraft.World/Entities/Mobs/VillagerGolem.cpp b/Minecraft.World/Entities/Mobs/VillagerGolem.cpp index 6f1880259..a9811005d 100644 --- a/Minecraft.World/Entities/Mobs/VillagerGolem.cpp +++ b/Minecraft.World/Entities/Mobs/VillagerGolem.cpp @@ -113,7 +113,7 @@ void VillagerGolem::aiStep() { if (t > 0) { level->addParticle(PARTICLE_TILECRACK(t, d), x + (random->nextFloat() - 0.5) * bbWidth, - bb->y0 + 0.1, + bb.y0 + 0.1, z + (random->nextFloat() - 0.5) * bbWidth, 4 * (random->nextFloat() - 0.5), .5, (random->nextFloat() - 0.5) * 4); @@ -226,4 +226,4 @@ bool VillagerGolem::hurt(DamageSource* source, float dmg) { } return Golem::hurt(source, dmg); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Witch.cpp b/Minecraft.World/Entities/Mobs/Witch.cpp index 50950d57f..f8e970389 100644 --- a/Minecraft.World/Entities/Mobs/Witch.cpp +++ b/Minecraft.World/Entities/Mobs/Witch.cpp @@ -153,7 +153,7 @@ void Witch::handleEntityEvent(uint8_t id) { for (int i = 0; i < random->nextInt(35) + 10; i++) { level->addParticle(eParticleType_witchMagic, 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); } } else { diff --git a/Minecraft.World/Entities/Mobs/WitherBoss.cpp b/Minecraft.World/Entities/Mobs/WitherBoss.cpp index 80316042e..1263662d9 100644 --- a/Minecraft.World/Entities/Mobs/WitherBoss.cpp +++ b/Minecraft.World/Entities/Mobs/WitherBoss.cpp @@ -252,7 +252,7 @@ void WitherBoss::newServerAiStep() { idleHeadUpdates[i - 1] = 0; } } else { - AABB grown = bb->grow(20, 8, 20); + AABB grown = bb.grow(20, 8, 20); std::vector >* entities = level->getEntitiesOfClass(typeid(LivingEntity), &grown, livingEntitySelector); diff --git a/Minecraft.World/Entities/Mobs/Wolf.cpp b/Minecraft.World/Entities/Mobs/Wolf.cpp index e5ce60cd5..bccbe462e 100644 --- a/Minecraft.World/Entities/Mobs/Wolf.cpp +++ b/Minecraft.World/Entities/Mobs/Wolf.cpp @@ -182,7 +182,7 @@ void Wolf::tick() { } if (shakeAnim > 0.4f) { - float yt = (float)bb->y0; + float yt = (float)bb.y0; int shakeCount = (int)(Mth::sin((shakeAnim - 0.4f) * PI) * 7.0f); for (int i = 0; i < shakeCount; i++) { @@ -503,4 +503,4 @@ bool Wolf::wantsToAttack(std::shared_ptr target, return false; } return true; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Zombie.cpp b/Minecraft.World/Entities/Mobs/Zombie.cpp index d6d15644d..c67e1ccfd 100644 --- a/Minecraft.World/Entities/Mobs/Zombie.cpp +++ b/Minecraft.World/Entities/Mobs/Zombie.cpp @@ -176,10 +176,10 @@ bool Zombie::hurt(DamageSource* source, float dmg) { level->getRawBrightness(xt, yt, zt) < 10) { reinforcement->setPos(xt, yt, zt); - if (level->isUnobstructed(reinforcement->bb) && - level->getCubes(reinforcement, reinforcement->bb) + if (level->isUnobstructed(&reinforcement->bb) && + level->getCubes(reinforcement, &reinforcement->bb) ->empty() && - !level->containsAnyLiquid(reinforcement->bb)) { + !level->containsAnyLiquid(&reinforcement->bb)) { level->addEntity(reinforcement); reinforcement->setTarget(target); reinforcement->finalizeMobSpawn(NULL); @@ -492,4 +492,4 @@ int Zombie::getConversionProgress() { Zombie::ZombieGroupData::ZombieGroupData(bool baby, bool villager) { isBaby = baby; isVillager = villager; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Monster.cpp b/Minecraft.World/Entities/Monster.cpp index 2b89198e5..a0e98c5d5 100644 --- a/Minecraft.World/Entities/Monster.cpp +++ b/Minecraft.World/Entities/Monster.cpp @@ -113,8 +113,8 @@ bool Monster::doHurtTarget(std::shared_ptr target) { } void Monster::checkHurtTarget(std::shared_ptr target, float distance) { - if (attackTime <= 0 && distance < 2.0f && target->bb->y1 > bb->y0 && - target->bb->y0 < bb->y1) { + if (attackTime <= 0 && distance < 2.0f && target->bb.y1 > bb.y0 && + target->bb.y0 < bb.y1) { attackTime = 20; doHurtTarget(target); } @@ -126,7 +126,7 @@ float Monster::getWalkTargetValue(int x, int y, int z) { bool Monster::isDarkEnoughToSpawn() { int xt = Mth::floor(x); - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); int zt = Mth::floor(z); if (level->getBrightness(LightLayer::Sky, xt, yt, zt) > random->nextInt(32)) return false; @@ -152,4 +152,4 @@ void Monster::registerAttributes() { PathfinderMob::registerAttributes(); getAttributes()->registerAttribute(SharedMonsterAttributes::ATTACK_DAMAGE); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/PathfinderMob.cpp b/Minecraft.World/Entities/PathfinderMob.cpp index aec748483..b2dbbdca6 100644 --- a/Minecraft.World/Entities/PathfinderMob.cpp +++ b/Minecraft.World/Entities/PathfinderMob.cpp @@ -109,7 +109,7 @@ void PathfinderMob::serverAiStep() { // protected. considerForExtraWandering(isDespawnProtected()); - int yFloor = Mth::floor(bb->y0 + 0.5f); + int yFloor = Mth::floor(bb.y0 + 0.5f); bool inWater = isInWater(); bool inLava = isInLava(); @@ -226,7 +226,7 @@ std::shared_ptr PathfinderMob::findAttackTarget() { bool PathfinderMob::canSpawn() { int xt = Mth::floor(x); - int yt = Mth::floor(bb->y0); + int yt = Mth::floor(bb.y0); int zt = Mth::floor(z); return this->Mob::canSpawn() && getWalkTargetValue(xt, yt, zt) >= 0; } diff --git a/Minecraft.World/Entities/Throwable.cpp b/Minecraft.World/Entities/Throwable.cpp index 056129287..973c7d8d7 100644 --- a/Minecraft.World/Entities/Throwable.cpp +++ b/Minecraft.World/Entities/Throwable.cpp @@ -27,7 +27,7 @@ Throwable::Throwable(Level* level) : Entity(level) { void Throwable::defineSynchedData() {} bool Throwable::shouldRenderAtSqrDistance(double distance) { - double size = bb->getSize() * 4; + double size = bb.getSize() * 4; size *= 64.0f; return distance < size * size; } @@ -147,7 +147,7 @@ void Throwable::tick() { if (!level->isClientSide) { std::shared_ptr 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 >* objects = level->getEntities(shared_from_this(), &grown); double nearest = 0; @@ -157,7 +157,7 @@ void Throwable::tick() { if (!e->isPickable() || (e == owner && flightTime < 5)) continue; 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); if (p != NULL) { double dd = from.distanceTo(p->pos); diff --git a/Minecraft.World/Entities/WaterAnimal.cpp b/Minecraft.World/Entities/WaterAnimal.cpp index 7cdd2ed31..71470f35b 100644 --- a/Minecraft.World/Entities/WaterAnimal.cpp +++ b/Minecraft.World/Entities/WaterAnimal.cpp @@ -18,7 +18,7 @@ bool WaterAnimal::isWaterMob() { return true; // prevent drowning } -bool WaterAnimal::canSpawn() { return level->isUnobstructed(bb); } +bool WaterAnimal::canSpawn() { return level->isUnobstructed(&bb); } int WaterAnimal::getAmbientSoundInterval() { return 20 * 6; } @@ -42,4 +42,4 @@ void WaterAnimal::baseTick() { } else { setAirSupply(TOTAL_AIR_SUPPLY); } -} \ No newline at end of file +} diff --git a/Minecraft.World/Items/BoatItem.cpp b/Minecraft.World/Items/BoatItem.cpp index 0c4d6a1b9..313b658e1 100644 --- a/Minecraft.World/Items/BoatItem.cpp +++ b/Minecraft.World/Items/BoatItem.cpp @@ -83,7 +83,7 @@ std::shared_ptr BoatItem::use( Vec3 b = player->getViewVector(a); bool hitEntity = false; 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); std::vector >* objects = level->getEntities(player, &grown); @@ -93,7 +93,7 @@ std::shared_ptr BoatItem::use( if (!e->isPickable()) continue; float rr = e->getPickRadius(); - AABB bb = e->bb->grow(rr, rr, rr); + AABB bb = e->bb.grow(rr, rr, rr); if (bb.contains(from)) { hitEntity = true; } @@ -116,7 +116,7 @@ std::shared_ptr BoatItem::use( boat->yRot = ((Mth::floor(player->yRot * 4.0F / 360.0F + 0.5) & 0x3) - 1) * 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()) { return itemInstance; } diff --git a/Minecraft.World/Level/Explosion.cpp b/Minecraft.World/Level/Explosion.cpp index bdc17689d..9be40d49b 100644 --- a/Minecraft.World/Level/Explosion.cpp +++ b/Minecraft.World/Level/Explosion.cpp @@ -118,7 +118,7 @@ void Explosion::explode() { // walls bool canDamage = false; 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)) { canDamage = true; break; @@ -144,7 +144,7 @@ void Explosion::explode() { za /= da; } - double sp = level->getSeenPercent(¢er, e->bb); + double sp = level->getSeenPercent(¢er, &e->bb); double pow = (1 - dist) * sp; if (canDamage) e->hurt(DamageSource::explosion(this), diff --git a/Minecraft.World/Level/LevelChunk.cpp b/Minecraft.World/Level/LevelChunk.cpp index c5c0632ef..5f95fd9d2 100644 --- a/Minecraft.World/Level/LevelChunk.cpp +++ b/Minecraft.World/Level/LevelChunk.cpp @@ -1691,7 +1691,7 @@ void LevelChunk::getEntities(std::shared_ptr except, AABB* bb, AUTO_VAR(itEnd, entities->end()); for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) { std::shared_ptr 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 >* subs = @@ -1699,7 +1699,7 @@ void LevelChunk::getEntities(std::shared_ptr 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); } diff --git a/Minecraft.World/Player/Player.cpp b/Minecraft.World/Player/Player.cpp index f36caeefa..13c1354e3 100644 --- a/Minecraft.World/Player/Player.cpp +++ b/Minecraft.World/Player/Player.cpp @@ -965,9 +965,9 @@ void Player::aiStep() { 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); + pickupArea = bb.grow(1, .5, 1); } std::vector >* entities = diff --git a/Minecraft.World/Util/CombatTracker.cpp b/Minecraft.World/Util/CombatTracker.cpp index 0dbc0a2d3..80b0a3072 100644 --- a/Minecraft.World/Util/CombatTracker.cpp +++ b/Minecraft.World/Util/CombatTracker.cpp @@ -19,7 +19,7 @@ void CombatTracker::prepareForDamage() { if (mob->onLadder()) { 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) { nextLocation = eLocation_LADDER; From a0be2e2fb5793a16323f0c1bae4d56d02bd2e9bb Mon Sep 17 00:00:00 2001 From: orng Date: Sat, 28 Mar 2026 03:05:06 -0500 Subject: [PATCH 9/9] refactor: remove aabb tls --- Minecraft.Client/Minecraft.cpp | 4 -- Minecraft.Client/MinecraftServer.cpp | 4 -- .../Platform/Common/Consoles_App.cpp | 2 - .../Common/Network/GameNetworkManager.cpp | 5 --- .../Platform/Common/UI/IUIScene_PauseMenu.cpp | 2 - .../Platform/Common/XUI/XUI_Death.cpp | 1 - .../Platform/Common/XUI/XUI_PauseMenu.cpp | 2 - .../Platform/Durango/Durango_Minecraft.cpp | 1 - .../Platform/Linux/Linux_Minecraft.cpp | 1 - .../Platform/Orbis/Orbis_Minecraft.cpp | 2 - .../Platform/PS3/PS3_Minecraft.cpp | 1 - .../Platform/PS3/Xbox_Minecraft.cpp | 1 - .../Platform/PSVita/PSVita_Minecraft.cpp | 1 - .../Windows64/Windows64_Minecraft.cpp | 1 - .../Platform/Xbox/Xbox_Minecraft.cpp | 1 - Minecraft.Client/Rendering/GameRenderer.cpp | 2 - Minecraft.Client/Rendering/LevelRenderer.cpp | 1 - Minecraft.World/Util/AABB.cpp | 41 ------------------- Minecraft.World/Util/AABB.h | 25 ----------- 19 files changed, 98 deletions(-) diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 722d2eafb..65d5e87dd 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -726,7 +726,6 @@ void Minecraft::run() { // try { // 4J - removed try/catch // if (minecraftApplet != null && !minecraftApplet.isActive()) break; // 4J - removed - AABB::resetPool(); // if (parent == NULL && Display.isCloseRequested()) { // 4J - removed // stop(); @@ -1282,7 +1281,6 @@ void Minecraft::run_middle() { // try { // 4J - removed try/catch // if (minecraftApplet != null && // !minecraftApplet.isActive()) break; // 4J - removed - AABB::resetPool(); // if (parent == NULL && Display.isCloseRequested()) { // // 4J - removed @@ -2226,7 +2224,6 @@ void Minecraft::run_end() { destroy(); } void Minecraft::emergencySave() { // 4J - lots of try/catches removed here, and garbage collector things levelRenderer->clear(); - AABB::clearPool(); setLevel(NULL); } @@ -2402,7 +2399,6 @@ void Minecraft::levelTickUpdateFunc(void* pParam) { } void Minecraft::levelTickThreadInitFunc() { - AABB::CreateNewThreadStorage(); Compression::UseDefaultThreadStorage(); } diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 23cd23251..7009e71ef 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -316,7 +316,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) { MinecraftServer* server = (MinecraftServer*)lpParam; Entity::useSmallIds(); // This thread can end up spawning entities as // resources - AABB::CreateNewThreadStorage(); Compression::UseDefaultThreadStorage(); Level::enableLightingCache(); Tile::CreateNewThreadStorage(); @@ -365,7 +364,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) { LeaveCriticalSection(&server->m_postProcessCS); // #endif //__PS3__ Tile::ReleaseThreadStorage(); - AABB::ReleaseThreadStorage(); Level::destroyLightingCache(); ShutdownManager::HasFinished(ShutdownManager::ePostProcessThread); @@ -1650,8 +1648,6 @@ void MinecraftServer::tick() { ironTimers.erase(toRemove[i]); } - AABB::resetPool(); - tickCount++; // 4J We need to update client difficulty levels based on the servers diff --git a/Minecraft.Client/Platform/Common/Consoles_App.cpp b/Minecraft.Client/Platform/Common/Consoles_App.cpp index a1cdfa0d3..24b4c72a5 100644 --- a/Minecraft.Client/Platform/Common/Consoles_App.cpp +++ b/Minecraft.Client/Platform/Common/Consoles_App.cpp @@ -4707,7 +4707,6 @@ int CMinecraftApp::EthernetDisconnectReturned( int CMinecraftApp::SignoutExitWorldThreadProc(void* lpParameter) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); // app.SetGameStarted(false); @@ -7698,7 +7697,6 @@ void CMinecraftApp::LeaveSaveNotificationSection() { int CMinecraftApp::RemoteSaveThreadProc(void* lpParameter) { // The game should be stopped while we are doing this, but the connections // ticks may try to create some AABB's or Vec3's - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); // 4J-PB - Xbox 360 - 163153 - [CRASH] TU17: Code: Multiplayer: During the diff --git a/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp index 180049628..06bf5ffec 100644 --- a/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp @@ -950,7 +950,6 @@ bool CGameNetworkManager::IsNetworkThreadRunning() { int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); Tile::CreateNewThreadStorage(); @@ -1009,7 +1008,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) { } SetThreadName(-1, "Minecraft Server thread"); - AABB::CreateNewThreadStorage(); Compression::UseDefaultThreadStorage(); OldChunkStorage::UseDefaultThreadStorage(); Entity::useSmallIds(); @@ -1022,7 +1020,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) { lpParameter); // saveData, app.GetGameHostOption(eGameHostOption_All)); Tile::ReleaseThreadStorage(); - AABB::ReleaseThreadStorage(); Level::destroyLightingCache(); if (lpParameter != NULL) delete (NetworkGameInitData*)lpParameter; @@ -1033,7 +1030,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) { int CGameNetworkManager::ExitAndJoinFromInviteThreadProc(void* lpParam) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); // app.SetGameStarted(false); @@ -1185,7 +1181,6 @@ void CGameNetworkManager::_LeaveGame() { int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); Minecraft* pMinecraft = Minecraft::GetInstance(); diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp index f748a6343..e815d7a5c 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp @@ -383,7 +383,6 @@ int IUIScene_PauseMenu::SaveWorldThreadProc(void* lpParameter) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); Minecraft* pMinecraft = Minecraft::GetInstance(); @@ -420,7 +419,6 @@ int IUIScene_PauseMenu::SaveWorldThreadProc(void* lpParameter) { int IUIScene_PauseMenu::ExitWorldThreadProc(void* lpParameter) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); // app.SetGameStarted(false); diff --git a/Minecraft.Client/Platform/Common/XUI/XUI_Death.cpp b/Minecraft.Client/Platform/Common/XUI/XUI_Death.cpp index df7adb806..738499468 100644 --- a/Minecraft.Client/Platform/Common/XUI/XUI_Death.cpp +++ b/Minecraft.Client/Platform/Common/XUI/XUI_Death.cpp @@ -222,7 +222,6 @@ HRESULT CScene_Death::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) { } int CScene_Death::RespawnThreadProc(void* lpParameter) { - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); size_t iPad = (size_t)lpParameter; diff --git a/Minecraft.Client/Platform/Common/XUI/XUI_PauseMenu.cpp b/Minecraft.Client/Platform/Common/XUI/XUI_PauseMenu.cpp index 01b8b4405..a0c633adb 100644 --- a/Minecraft.Client/Platform/Common/XUI/XUI_PauseMenu.cpp +++ b/Minecraft.Client/Platform/Common/XUI/XUI_PauseMenu.cpp @@ -1075,7 +1075,6 @@ int UIScene_PauseMenu::SaveWorldThreadProc(LPVOID lpParameter) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); Minecraft* pMinecraft = Minecraft::GetInstance(); @@ -1107,7 +1106,6 @@ int UIScene_PauseMenu::SaveWorldThreadProc(LPVOID lpParameter) { int UIScene_PauseMenu::ExitWorldThreadProc(void* lpParameter) { // Share AABB & Vec3 pools with default (main thread) - should be ok as long // as we don't tick the main thread whilst this thread is running - AABB::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage(); // app.SetGameStarted(false); diff --git a/Minecraft.Client/Platform/Durango/Durango_Minecraft.cpp b/Minecraft.Client/Platform/Durango/Durango_Minecraft.cpp index e7f5179c4..30b9c8eb7 100644 --- a/Minecraft.Client/Platform/Durango/Durango_Minecraft.cpp +++ b/Minecraft.Client/Platform/Durango/Durango_Minecraft.cpp @@ -794,7 +794,6 @@ void oldWinMainInit() { // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); Tile::CreateNewThreadStorage(); diff --git a/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp b/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp index 290b4626e..f7cb7d184 100644 --- a/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp +++ b/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp @@ -856,7 +856,6 @@ return -1; // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); Compression::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); diff --git a/Minecraft.Client/Platform/Orbis/Orbis_Minecraft.cpp b/Minecraft.Client/Platform/Orbis/Orbis_Minecraft.cpp index 84e6fbf12..5744dc9d9 100644 --- a/Minecraft.Client/Platform/Orbis/Orbis_Minecraft.cpp +++ b/Minecraft.Client/Platform/Orbis/Orbis_Minecraft.cpp @@ -1040,7 +1040,6 @@ void RegisterAwardsWithProfileManager() { } int StartMinecraftThreadProc(void* lpParameter) { - AABB::UseDefaultThreadStorage(); Tesselator::CreateNewThreadStorage(1024 * 1024); RenderManager.InitialiseContext(); Minecraft::start(std::wstring(), std::wstring()); @@ -1376,7 +1375,6 @@ int main(int argc, const char* argv[]) { // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); Compression::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); diff --git a/Minecraft.Client/Platform/PS3/PS3_Minecraft.cpp b/Minecraft.Client/Platform/PS3/PS3_Minecraft.cpp index e2200c8a8..6aaced5fd 100644 --- a/Minecraft.Client/Platform/PS3/PS3_Minecraft.cpp +++ b/Minecraft.Client/Platform/PS3/PS3_Minecraft.cpp @@ -1210,7 +1210,6 @@ int main() { // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); Tile::CreateNewThreadStorage(); diff --git a/Minecraft.Client/Platform/PS3/Xbox_Minecraft.cpp b/Minecraft.Client/Platform/PS3/Xbox_Minecraft.cpp index 90c153b8d..968ab073a 100644 --- a/Minecraft.Client/Platform/PS3/Xbox_Minecraft.cpp +++ b/Minecraft.Client/Platform/PS3/Xbox_Minecraft.cpp @@ -660,7 +660,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); Level::enableLightingCache(); Minecraft::main(); diff --git a/Minecraft.Client/Platform/PSVita/PSVita_Minecraft.cpp b/Minecraft.Client/Platform/PSVita/PSVita_Minecraft.cpp index 9065eccb7..4849f15a1 100644 --- a/Minecraft.Client/Platform/PSVita/PSVita_Minecraft.cpp +++ b/Minecraft.Client/Platform/PSVita/PSVita_Minecraft.cpp @@ -895,7 +895,6 @@ int main() { // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); Compression::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); diff --git a/Minecraft.Client/Platform/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Platform/Windows64/Windows64_Minecraft.cpp index 0e009e4ce..4fc3b34db 100644 --- a/Minecraft.Client/Platform/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Platform/Windows64/Windows64_Minecraft.cpp @@ -940,7 +940,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); Compression::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); diff --git a/Minecraft.Client/Platform/Xbox/Xbox_Minecraft.cpp b/Minecraft.Client/Platform/Xbox/Xbox_Minecraft.cpp index 1b2cdd997..9a1530c85 100644 --- a/Minecraft.Client/Platform/Xbox/Xbox_Minecraft.cpp +++ b/Minecraft.Client/Platform/Xbox/Xbox_Minecraft.cpp @@ -699,7 +699,6 @@ int __cdecl main() { // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024 * 1024); // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); Compression::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage(); Level::enableLightingCache(); diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index e405931b0..7b1ac303b 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -1121,7 +1121,6 @@ void GameRenderer::FinishedReassigning() { int GameRenderer::runUpdate(void* lpParam) { Minecraft* minecraft = Minecraft::GetInstance(); - AABB::CreateNewThreadStorage(); Tesselator::CreateNewThreadStorage(1024 * 1024); Compression::UseDefaultThreadStorage(); RenderManager.InitialiseContext(); @@ -1200,7 +1199,6 @@ int GameRenderer::runUpdate(void* lpParam) { // PIXEndNamedEvent(); - AABB::resetPool(); m_updateEvents->Set(eUpdateEventIsFinished); } diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 556d83ec7..0d5e9afa7 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -4030,7 +4030,6 @@ void LevelRenderer::staticCtor() { } int LevelRenderer::rebuildChunkThreadProc(void* lpParam) { - AABB::CreateNewThreadStorage(); Tesselator::CreateNewThreadStorage(1024 * 1024); RenderManager.InitialiseContext(); Chunk::CreateNewThreadStorage(); diff --git a/Minecraft.World/Util/AABB.cpp b/Minecraft.World/Util/AABB.cpp index 2cf5236e5..a31d27728 100644 --- a/Minecraft.World/Util/AABB.cpp +++ b/Minecraft.World/Util/AABB.cpp @@ -12,47 +12,6 @@ #include "HitResult.h" #include "Util/Vec3.h" -thread_local AABB::ThreadStorage* AABB::m_tlsPool = nullptr; -AABB::ThreadStorage* AABB::m_tlsPoolDefault = nullptr; - -AABB::ThreadStorage::ThreadStorage() { - pool = new AABB[POOL_SIZE]; // 4jcraft, needs to be deleted with delete[] - poolPointer = 0; -} - -AABB::ThreadStorage::~ThreadStorage() { - delete[] pool; // 4jcraft, changed to [] -} - -void AABB::CreateNewThreadStorage() { - ThreadStorage* tls = new ThreadStorage(); - if (m_tlsPoolDefault == nullptr) { - m_tlsPoolDefault = tls; - } - m_tlsPool = tls; -} - -void AABB::UseDefaultThreadStorage() { m_tlsPool = m_tlsPoolDefault; } - -void AABB::ReleaseThreadStorage() { - if (m_tlsPool != m_tlsPoolDefault) { - delete m_tlsPool; - } -} - -void AABB::clearPool() {} - -void AABB::resetPool() {} - -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 = {x0, y0, z0, x1, y1, z1}; - tls->poolPointer = (tls->poolPointer + 1) % ThreadStorage::POOL_SIZE; - return thisAABB; -} - AABB::AABB(double x0, double y0, double z0, double x1, double y1, double z1) { this->x0 = x0; this->y0 = y0; diff --git a/Minecraft.World/Util/AABB.h b/Minecraft.World/Util/AABB.h index 61d8446cd..fb62056d8 100644 --- a/Minecraft.World/Util/AABB.h +++ b/Minecraft.World/Util/AABB.h @@ -6,38 +6,13 @@ class HitResult; class AABB { - // 4J added so we can have separate pools for different threads - class ThreadStorage { - public: - static const int POOL_SIZE = 1024; - AABB* pool; - unsigned int poolPointer; - ThreadStorage(); - ~ThreadStorage(); - }; - static thread_local ThreadStorage* m_tlsPool; - static ThreadStorage* m_tlsPoolDefault; - public: - // Each new thread that needs to use Vec3 pools will need to call one of the - // following 2 functions, to either create its own local storage, or share - // the default storage already allocated by the main thread - static void CreateNewThreadStorage(); - static void UseDefaultThreadStorage(); - static void ReleaseThreadStorage(); - - static void clearPool(); - static void resetPool(); - static AABB* newTemp(double x0, double y0, double z0, double x1, double y1, - double z1); - double x0, y0, z0; double x1, y1, z1; AABB() {} AABB(double x0, double y0, double z0, double x1, double y1, double z1); -public: AABB expand(double xa, double ya, double za) const; AABB grow(double xa, double ya, double za) const; AABB minmax(const AABB& other) const;