123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include "Grass.h"
- #include "AddEntityUpdate.h"
- #include "Game.h"
- #include "ItemEntity.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()));
- }
- }
- if ((double)rand() / RAND_MAX < 0.1)
- {
- ItemStack* spawnedItems = StaticRegistry<ItemType>::INSTANCE
- .zElement(ItemTypeEnum::WHEAT_SEED)
- ->createItemStack(1);
- if (spawnedItems)
- {
- ItemEntity* itemEntity
- = (ItemEntity*)StaticRegistry<EntityType>::INSTANCE
- .zElement(EntityTypeEnum::ITEM)
- ->createEntity(
- location
- + Framework::Vec3<float>(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<GrassBlock*>(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<int> position) const
- {
- return new GrassBlock(getId(), zTool, position);
- }
|