|
@@ -0,0 +1,94 @@
|
|
|
+#include "Grass.h"
|
|
|
+
|
|
|
+#include "Game.h"
|
|
|
+
|
|
|
+GrassBlock::GrassBlock(
|
|
|
+ int typeId, const ItemType* zTool, Framework::Vec3<int> pos)
|
|
|
+ : Block(typeId, zTool, pos, 0)
|
|
|
+{
|
|
|
+ tickSource = 1;
|
|
|
+}
|
|
|
+
|
|
|
+bool GrassBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
|
|
|
+{
|
|
|
+ // TODO: spread to neighbor blocks if light level is hight enought
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+void GrassBlock::onPostTick() {}
|
|
|
+
|
|
|
+void GrassBlock::onDestroy()
|
|
|
+{
|
|
|
+ if (!deadAndRemoved)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < 6; i++)
|
|
|
+ {
|
|
|
+ if (neighbourTypes[i] == BlockTypeEnum::NO_BLOCK)
|
|
|
+ {
|
|
|
+ Framework::Vec3<int> pos
|
|
|
+ = getPos() + getDirection(getDirectionFromIndex(i));
|
|
|
+ Game::INSTANCE->zDimension(getDimensionId())
|
|
|
+ ->placeBlock(pos,
|
|
|
+ Game::INSTANCE->zGenerator()->generateSingleBlock(
|
|
|
+ pos, getDimensionId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // TODO: calculate chance for dropping wheat seeds
|
|
|
+ for (MultiblockStructure* structure : structures)
|
|
|
+ structure->onBlockRemoved(this);
|
|
|
+ Game::INSTANCE->zDimension(getDimensionId())
|
|
|
+ ->placeBlock(
|
|
|
+ getPos(), BlockTypeEnum::AIR); // this will be deleted here
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+GrassBlockType::GrassBlockType(
|
|
|
+ int typeId, int itemTypeId, ModelInfo model, const char* name)
|
|
|
+ : BlockType(typeId, 0, model, 1, 10, 0, name),
|
|
|
+ itemType(itemTypeId),
|
|
|
+ transparent(true),
|
|
|
+ passable(true),
|
|
|
+ hardness(0.1f),
|
|
|
+ zTool(0),
|
|
|
+ speedModifier(0.5f),
|
|
|
+ interactable(1)
|
|
|
+{}
|
|
|
+
|
|
|
+void GrassBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
|
|
|
+{
|
|
|
+ GrassBlock* block = dynamic_cast<GrassBlock*>(zBlock);
|
|
|
+ if (!block)
|
|
|
+ throw "GrassBlockType::createSuperBlock was called with a block "
|
|
|
+ "witch is not an instance of GrassBlock";
|
|
|
+ block->transparent = transparent;
|
|
|
+ block->passable = passable;
|
|
|
+ block->hp = (float)getInitialMaxHP();
|
|
|
+ block->maxHP = (float)getInitialMaxHP();
|
|
|
+ block->hardness = hardness;
|
|
|
+ block->zTool = zTool;
|
|
|
+ block->speedModifier = speedModifier;
|
|
|
+ block->interactable = interactable;
|
|
|
+ BlockType::createSuperBlock(zBlock, zItem);
|
|
|
+}
|
|
|
+
|
|
|
+void GrassBlockType::loadSuperBlock(
|
|
|
+ Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const
|
|
|
+{
|
|
|
+ BlockType::loadSuperBlock(zBlock, zReader, dimensionId);
|
|
|
+}
|
|
|
+
|
|
|
+void GrassBlockType::saveSuperBlock(
|
|
|
+ Block* zBlock, Framework::StreamWriter* zWriter) const
|
|
|
+{
|
|
|
+ BlockType::saveSuperBlock(zBlock, zWriter);
|
|
|
+}
|
|
|
+
|
|
|
+Item* GrassBlockType::createItem() const
|
|
|
+{
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+Block* GrassBlockType::createBlock(Framework::Vec3<int> position) const
|
|
|
+{
|
|
|
+ return new GrassBlock(getId(), zTool, position);
|
|
|
+}
|