* Add sponges.

This commit is contained in:
iProgramInCpp
2023-08-03 23:02:15 +03:00
parent 352626224a
commit 139062625c
8 changed files with 105 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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);
}
}
}
}
}

View File

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

View File

@@ -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;
};

View File

@@ -515,6 +515,7 @@
<ClCompile Include="..\source\World\Tile\SandStoneTile.cpp" />
<ClCompile Include="..\source\World\Tile\SandTile.cpp" />
<ClCompile Include="..\source\World\Tile\Sapling.cpp" />
<ClCompile Include="..\source\World\Tile\SpongeTile.cpp" />
<ClCompile Include="..\source\World\Tile\StairTile.cpp" />
<ClCompile Include="..\source\World\Tile\StoneSlabTile.cpp" />
<ClCompile Include="..\source\World\Tile\StoneTile.cpp" />