#include "AddEntityUpdate.h" #include "BasicBlocks.h" #include "Game.h" #include "ItemEntity.h" #include "TreeSeblingBlock.h" BasicBlock::BasicBlock(int typeId, ItemType* zTool, Framework::Vec3 pos) : Block(typeId, zTool, pos, false) {} bool BasicBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked) { return 0; } void BasicBlock::onPostTick() {} AdditionalItemSpawningBlock::AdditionalItemSpawningBlock( int typeId, ItemType* zTool, Framework::Vec3 pos) : BasicBlock(typeId, zTool, pos) {} void AdditionalItemSpawningBlock::addSpawn(SpawnConfig config) { spawns.add(config); } void AdditionalItemSpawningBlock::onDestroy() { for (const SpawnConfig& config : spawns) { if ((double)rand() / RAND_MAX < config.chance) { int amount = config.min + (int)((config.max - config.min) * ((double)rand() / RAND_MAX)); if (amount > 0) { ItemStack* spawnedItems = StaticRegistry::INSTANCE .zElement(config.itemType) ->createItemStack(amount); 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())); } } } } BasicBlock::onDestroy(); } BasicBlockType::BasicBlockType( int typeId, int itemTypeId, ModelInfo model, const char* name) : BasicBlockType( typeId, itemTypeId, model, [typeId](Framework::Vec3 pos) { return new BasicBlock(typeId, 0, pos); }, name) {} BasicBlockType::BasicBlockType(int typeId, int itemTypeId, ModelInfo model, std::function)> creatBlockCustom, const char* name) : BlockType(typeId, 0, model, 1, 100, 0, name, false), itemType(itemTypeId), transparent(0), passable(0), hardness(1.f), zTool(0), speedModifier(1.f), interactable(1), creatBlockCustom(creatBlockCustom) {} void BasicBlockType::createSuperBlock(Block* zBlock, Item* zItem) const { BasicBlock* 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); } Block* BasicBlockType::createBlock(Framework::Vec3 position) const { return creatBlockCustom(position); } Item* BasicBlockType::createItem() const { return StaticRegistry::INSTANCE.zElement(itemType)->createItem(); } BasicBlockType* BasicBlockType::setHardness(float hardness) { this->hardness = hardness; return this; } BasicBlockType* BasicBlockType::setTransparent(bool transparent) { this->transparent = transparent; return this; }