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 ||