diff --git a/GameMods.hpp b/GameMods.hpp index f3488dd..328e0fc 100644 --- a/GameMods.hpp +++ b/GameMods.hpp @@ -9,6 +9,8 @@ #define DEMO #else +// TODO: Since this is the modded version, we don't need these anymore. Remove them + // Enhancements #define ENH_ENTITY_SHADING // Allows shading of entities #define ENH_SHADE_HELD_TILES // Allows shading of the item in hand diff --git a/source/Base/Utils.hpp b/source/Base/Utils.hpp index e0f0824..5b48dbb 100644 --- a/source/Base/Utils.hpp +++ b/source/Base/Utils.hpp @@ -117,22 +117,19 @@ enum eTileID TILE_WOOD, TILE_SAPLING, TILE_BEDROCK, - - TILE_WATER = 8, + TILE_WATER, TILE_WATER_CALM, TILE_LAVA, TILE_LAVA_CALM, - - TILE_SAND = 12, + TILE_SAND, TILE_GRAVEL, TILE_ORE_GOLD, TILE_ORE_IRON, TILE_ORE_COAL, - - TILE_TREE_TRUNK = 17, + TILE_TREE_TRUNK, TILE_LEAVES, - - TILE_GLASS = 20, + TILE_SPONGE, + TILE_GLASS, TILE_ORE_LAPIS, TILE_SANDSTONE = 24, diff --git a/source/Inventory.cpp b/source/Inventory.cpp index c529781..53a9343 100644 --- a/source/Inventory.cpp +++ b/source/Inventory.cpp @@ -155,7 +155,7 @@ Inventory::Inventory(Player* pPlayer) m_items[40] = Tile::cloth->m_ID; m_items[41] = Tile::clay->m_ID; m_items[42] = Tile::farmland->m_ID; - m_items[43] = Tile::lapisOre->m_ID; + m_items[43] = Tile::sponge->m_ID; m_items[44] = Tile::sapling->m_ID; #endif } diff --git a/source/World/Tile/LiquidTileDynamic.cpp b/source/World/Tile/LiquidTileDynamic.cpp index 66d6bbe..8023628 100644 --- a/source/World/Tile/LiquidTileDynamic.cpp +++ b/source/World/Tile/LiquidTileDynamic.cpp @@ -9,16 +9,45 @@ #include "Tile.hpp" #include "Level.hpp" +bool g_bDisableSponges = false; + LiquidTileDynamic::LiquidTileDynamic(int id, Material* pMtl) : LiquidTile(id, pMtl) { } +bool LiquidTileDynamic::checkSpongesNearby(Level* level, int x, int y, int z) +{ + // NOTE: I imagine this could get slow. So you can disable it + if (g_bDisableSponges) + return false; + + for (int ox = -2; ox <= 2; ox++) + { + for (int oy = -2; oy <= 2; oy++) + { + for (int oz = -2; oz <= 2; oz++) + { + if (level->getTile(x + ox, y + oy, z + oz) == Tile::sponge->m_ID) + return true; + } + } + } + + return false; +} + bool LiquidTileDynamic::isWaterBlocking(Level* level, int x, int y, int z) { TileID tile = level->getTile(x, y, z); if (tile == Tile::reeds->m_ID) return true; + if (!g_bDisableSponges) + { + if (checkSpongesNearby(level, x, y, z)) + return true; + } + if (!tile) return false; diff --git a/source/World/Tile/SpongeTile.cpp b/source/World/Tile/SpongeTile.cpp new file mode 100644 index 0000000..bc8add9 --- /dev/null +++ b/source/World/Tile/SpongeTile.cpp @@ -0,0 +1,44 @@ +#include "Tile.hpp" +#include "Level.hpp" + +SpongeTile::SpongeTile(int id, int texture) : Tile(id, texture, Material::sponge) +{ +} + +void SpongeTile::onPlace(Level* level, int x, int y, int z) +{ + // get rid of all water in a 5x5 cube around this + for (int ox = -2; ox <= 2; ox++) + { + for (int oy = -2; oy <= 2; oy++) + { + for (int oz = -2; oz <= 2; oz++) + { + if (level->getTile(x + ox, y + oy, z + oz) == Tile::water->m_ID || + level->getTile(x + ox, y + oy, z + oz) == Tile::calmWater->m_ID) + { + level->setTile(x + ox, y + oy, z + oz, TILE_AIR); + } + } + } + } +} + +void SpongeTile::destroy(Level* level, int x, int y, int z, int dir) +{ + // give an update to all water around us + for (int ox = -3; ox <= 3; ox++) + { + for (int oy = -3; oy <= 3; oy++) + { + for (int oz = -3; oz <= 3; oz++) + { + if (level->getTile(x + ox, y + oy, z + oz) == Tile::water->m_ID || + level->getTile(x + ox, y + oy, z + oz) == Tile::calmWater->m_ID) + { + level->neighborChanged(x + ox, y + oy, z + oz, TILE_AIR); + } + } + } + } +} diff --git a/source/World/Tile/Tile.cpp b/source/World/Tile/Tile.cpp index 3fb2bb4..09891cb 100644 --- a/source/World/Tile/Tile.cpp +++ b/source/World/Tile/Tile.cpp @@ -606,12 +606,20 @@ void Tile::initTiles() ->setSoundType(Tile::SOUND_CLOTH) ->setDescriptionId("cloth"); + // custom additions here + Tile::sapling = (new Sapling(TILE_SAPLING, TEXTURE_SAPLING)) ->init() ->setDestroyTime(0.0f) ->setSoundType(Tile::SOUND_GRASS) ->setDescriptionId("sapling"); + Tile::sponge = (new SpongeTile(TILE_SPONGE, TEXTURE_SPONGE)) + ->init() + ->setDestroyTime(0.5f) + ->setSoundType(Tile::SOUND_CLOTH) + ->setDescriptionId("sponge"); + for (int i = 0; i < C_MAX_TILES; i++) { if (Tile::tiles[i]) @@ -1219,4 +1227,5 @@ Tile *Tile::stairs_stone, *Tile::door_wood, *Tile::door_iron, - *Tile::sapling; + *Tile::sapling, + *Tile::sponge; diff --git a/source/World/Tile/Tile.hpp b/source/World/Tile/Tile.hpp index ba7313e..9194fe7 100644 --- a/source/World/Tile/Tile.hpp +++ b/source/World/Tile/Tile.hpp @@ -199,7 +199,9 @@ public: // static variables * stairs_stone, * door_wood, * door_iron, - * sapling; + // custom additions here + * sapling, + * sponge; public: int m_TextureFrame = 1; @@ -563,6 +565,7 @@ public: void onPlace(Level*, int x, int y, int z) override; void tick(Level*, int x, int y, int z, Random*) override; + bool checkSpongesNearby(Level*, int x, int y, int z); bool isWaterBlocking(Level*, int x, int y, int z); bool canSpreadTo(Level*, int x, int y, int z); int getSlopeDistance(Level*, int, int, int, int, int); @@ -761,3 +764,12 @@ public: return (data & 8) != 0; } }; + +class SpongeTile : public Tile +{ +public: + SpongeTile(int ID, int texture); + + void onPlace(Level*, int x, int y, int z) override; + void destroy(Level*, int x, int y, int z, int dir) override; +}; diff --git a/windows_vs/minecraftcpp.vcxproj b/windows_vs/minecraftcpp.vcxproj index 49af981..800f9b3 100644 --- a/windows_vs/minecraftcpp.vcxproj +++ b/windows_vs/minecraftcpp.vcxproj @@ -515,6 +515,7 @@ +