#include "Grass.h" #include "AddEntityUpdate.h" #include "Game.h" #include "ItemEntity.h" GrassBlock::GrassBlock( int typeId, const ItemType* zTool, Framework::Vec3 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 pos = getPos() + getDirection(getDirectionFromIndex(i)); Game::INSTANCE->zDimension(getDimensionId()) ->placeBlock(pos, Game::INSTANCE->zGenerator()->generateSingleBlock( pos, getDimensionId())); } } if ((double)rand() / RAND_MAX < 0.1) { ItemStack* spawnedItems = StaticRegistry::INSTANCE .zElement(ItemTypeEnum::WHEAT_SEED) ->createItemStack(1); if (spawnedItems) { ItemEntity* itemEntity = (ItemEntity*)StaticRegistry::INSTANCE .zElement(EntityTypeEnum::ITEM) ->createEntity( location + Framework::Vec3(0.5f, 0.5f, 0.5f), getDimensionId(), Game::INSTANCE->getNextEntityId()); itemEntity->unsaveAddItem(spawnedItems, NO_DIRECTION); spawnedItems->release(); Game::INSTANCE->requestWorldUpdate( new AddEntityUpdate(itemEntity, getDimensionId())); } } 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, false), 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(zBlock); 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 position) const { return new GrassBlock(getId(), zTool, position); }