Skip to content

Commit

Permalink
* Make Rocket Launcher activate with redstone
Browse files Browse the repository at this point in the history
* StartMenuScreen: Prevent non cube shaped SHAPE_SOLID blocks from showing up on the title screen logo.
  • Loading branch information
iProgramMC committed Apr 8, 2024
1 parent 855def5 commit fb050e7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/client/gui/screens/StartMenuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ Tile* TitleTile::getRandomTile(Tile* except1, Tile* except2)

// If found a tile, check if it can be rendered
Tile* pTile = Tile::tiles[id];
if (!TileRenderer::canRender(pTile->getRenderShape()))
if (!pTile->isCubeShaped())
continue;

if (pTile == except1 || pTile == except2)
Expand Down
51 changes: 44 additions & 7 deletions source/world/tile/RocketLauncherTile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include "world/level/Level.hpp"
#include "world/entity/Rocket.hpp"

#define STATE_RECHARGING (0x1)
#define STATE_POWERED (0x2)

RocketLauncherTile::RocketLauncherTile(int id) : Tile(id, 16*14+2, Material::wood)
{
setTicking(true);
}

int RocketLauncherTile::getTexture(int dir, int data)
{
return data == 1 ? 16*14+3 : 16*14+2;
return (data & STATE_RECHARGING) ? 16*14+3 : 16*14+2;
}

AABB* RocketLauncherTile::getAABB(Level*, int x, int y, int z)
Expand All @@ -39,26 +41,61 @@ bool RocketLauncherTile::isSolidRender()
return false;
}

bool RocketLauncherTile::isSignalSource()
{
// Not really a signal _source_ per se, but it receives signals
return true;
}

int RocketLauncherTile::use(Level* level, int x, int y, int z, Player* player)
{
if (level->getData(x, y, z) == 1)
int data = level->getData(x, y, z);
if (data & STATE_RECHARGING)
return 1;

level->setData(x, y, z, 1);
level->setData(x, y, z, data | STATE_RECHARGING);

// spawn a rocket
level->addEntity(new Rocket(level, float(x) + 0.5f, float(y) + 0.5f, float(z) + 0.5f));

// add a tick so that the rocket launcher will reset
level->addToTickNextTick(x, y, z, m_ID, 10);
level->addToTickNextTick(x, y, z, m_ID, getTickDelay());

return 1;
}

void RocketLauncherTile::neighborChanged(Level* level, int x, int y, int z, int newTile)
{
if (newTile <= 0 || !Tile::tiles[newTile]->isSignalSource())
return;

int data = level->getData(x, y, z);

if (level->hasNeighborSignal(x, y, z))
{
if (data & (STATE_POWERED | STATE_RECHARGING))
return;

level->setDataNoUpdate(x, y, z, data | STATE_POWERED);
use(level, x, y, z, nullptr);
}
else
{
if (data & STATE_POWERED)
level->setDataNoUpdate(x, y, z, data & ~STATE_POWERED);
}
}

void RocketLauncherTile::tick(Level* level, int x, int y, int z, Random* random)
{
if (level->getData(x, y, z) != 1)
int data = level->getData(x, y, z);
if (~data & STATE_RECHARGING)
return;

level->setData(x, y, z, 0);
level->setData(x, y, z, data & ~STATE_RECHARGING);
}

int RocketLauncherTile::getTickDelay()
{
return 10;
}
3 changes: 3 additions & 0 deletions source/world/tile/RocketLauncherTile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class RocketLauncherTile : public Tile
int getRenderShape() override;
bool isCubeShaped() override;
bool isSolidRender() override;
bool isSignalSource() override;
int use(Level* pLevel, int x, int y, int z, Player* player) override;
void neighborChanged(Level*, int x, int y, int z, int newTile) override;
void tick(Level*, int, int, int, Random*) override;
int getTickDelay() override;
};

0 comments on commit fb050e7

Please sign in to comment.