#include "BasicBlocks.h" #include "ItemEntity.h" #include "Game.h" #include "AddEntityUpdate.h" #include "TreeSeblingBlock.h" BasicBlock::BasicBlock(const BlockType* zType, ItemType* zTool, Framework::Vec3 pos) : Block(zType, zTool, pos, false) {} bool BasicBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked) { return 0; } void BasicBlock::onPostTick() {} AdditionalItemSpawningBlock::AdditionalItemSpawningBlock(const BlockType* zType, ItemType* zTool, Framework::Vec3 pos) : BasicBlock(zType, 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*)ItemEntityType::INSTANCE->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) : BlockType(typeId, 0, model, 1, 100, 0), itemType(itemTypeId), transparent(0), passable(0), hardness(1.f), zTool(0), speedModifier(1.f), interactable(1) {} void BasicBlockType::createSuperBlock(Block* zBlock, Item* zItem) const { BasicBlock* block = dynamic_cast(zBlock); if (!block) throw "DirtBlockType::createSuperBlock was called with a block witch is not an instance of BasicBlock"; 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 new BasicBlock(this, 0, position); } Item* BasicBlockType::createItem() const { return StaticRegistry::INSTANCE.zElement(itemType)->createItem(); } // Dirt DirtBlockType::DirtBlockType() : BasicBlockType(ID, DirtBlockItemType::ID, ModelInfo("cube", { "blocks.ltdb/dirt.png", "blocks.ltdb/dirt.png", "blocks.ltdb/dirt.png", "blocks.ltdb/dirt.png", "blocks.ltdb/lawn.png", "blocks.ltdb/dirt.png" })) { defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } DirtBlockItemType::DirtBlockItemType() : BasicBlockItemType(ID, "Dirt", 0, 0, ModelInfo("itemCube", "blocks.ltdb/dirt.png", 6)) {} Item* DirtBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, DirtBlockType::INSTANCE, "Dirt"); initializeItem(item, 0, 0, 1, 0, 1); return item; } // Stone StoneBlockType::StoneBlockType() : BasicBlockType(ID, StoneBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/stone.png", 6)) { hardness = 2.f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } StoneBlockItemType::StoneBlockItemType() : BasicBlockItemType(ID, "Stone", 0, 0, ModelInfo("itemCube", "blocks.ltdb/stone.png", 6)) {} Item* StoneBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, StoneBlockType::INSTANCE, "Stone"); initializeItem(item, 0, 0, 2, 0, 1); return item; } // Sand SandBlockType::SandBlockType() : BasicBlockType(ID, SandBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/sand.png", 6)) { hardness = 0.5f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } SandBlockItemType::SandBlockItemType() : BasicBlockItemType(ID, "Sand", 0, 0, ModelInfo("itemCube", "blocks.ltdb/sand.png", 6)) {} Item* SandBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, SandBlockType::INSTANCE, "Sand"); initializeItem(item, 0, 0, 0.5f, 0, 1); return item; } // Oak Wood OakBlockType::OakBlockType() : BasicBlockType(ID, OakBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/oak.png", 6)) { hardness = 1.5f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } OakBlockItemType::OakBlockItemType() : BasicBlockItemType(ID, "Oak", 0, 0, ModelInfo("itemCube", "blocks.ltdb/oak.png", 6)) {} Item* OakBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, OakBlockType::INSTANCE, "Oak"); initializeItem(item, 0, 0, 1.5f, 0, 1); return item; } // Oak Leaves OakLeavesBlockType::OakLeavesBlockType() : BasicBlockType(ID, OakLeavesBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/leaves.png", 6)) { hardness = 0.1f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } Block* OakLeavesBlockType::createBlock(Framework::Vec3 position) const { AdditionalItemSpawningBlock* block = new AdditionalItemSpawningBlock(this, 0, position); block->addSpawn({ 1, 1, 0.015, OakSeblingBlockItemType::ID }); return block; } OakLeavesBlockItemType::OakLeavesBlockItemType() : BasicBlockItemType(ID, "Leaves", 0, 0, ModelInfo("itemCube", "blocks.ltdb/leaves.png", 6)) {} Item* OakLeavesBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, OakLeavesBlockType::INSTANCE, "Oak Leaves"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } // Oak Sebling OakSeblingBlockItemType::OakSeblingBlockItemType() : BasicBlockItemType(ID, "Oak Sebling", 0, 0, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1)) {} Item* OakSeblingBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, OakSeblingBlockType::INSTANCE, "Oak Sebling"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } // Gravel GravelBlockType::GravelBlockType() : BasicBlockType(ID, GravelBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/gravel.png", 6)) { hardness = 0.75f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } GravelBlockItemType::GravelBlockItemType() : BasicBlockItemType(ID, "Gravel", 0, 0, ModelInfo("itemCube", "blocks.ltdb/gravel.png", 6)) {} Item* GravelBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, GravelBlockType::INSTANCE, "Gravel"); initializeItem(item, 0, 0, 0.75f, 0, 1); return item; } // Granite GraniteBlockType::GraniteBlockType() : BasicBlockType(ID, GraniteBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/granite.png", 6)) { hardness = 3.f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } GraniteBlockItemType::GraniteBlockItemType() : BasicBlockItemType(ID, "Granite", 0, 0, ModelInfo("itemCube", "blocks.ltdb/granite.png", 6)) {} Item* GraniteBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, GraniteBlockType::INSTANCE, "Granite"); initializeItem(item, 0, 0, 3.f, 0, 1); return item; } // Cobble CobbleBlockType::CobbleBlockType() : BasicBlockType(ID, CobbleBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/cobble.png", 6)) { hardness = 1.f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } CobbleBlockItemType::CobbleBlockItemType() : BasicBlockItemType(ID, "Cobble", 0, 0, ModelInfo("itemCube", "blocks.ltdb/cobble.png", 6)) {} Item* CobbleBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, CobbleBlockType::INSTANCE, "Cobble"); initializeItem(item, 0, 0, 1.f, 0, 1); return item; } // Birch Wood BirchBlockType::BirchBlockType() : BasicBlockType(ID, BirchBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/birch.png", 6)) { hardness = 1.5f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } BirchBlockItemType::BirchBlockItemType() : BasicBlockItemType(ID, "Birch", 0, 0, ModelInfo("itemCube", "blocks.ltdb/birch.png", 6)) {} Item* BirchBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BirchBlockType::INSTANCE, "Birch"); initializeItem(item, 0, 0, 1.5f, 0, 1); return item; } // Birch Leaves BirchLeavesBlockType::BirchLeavesBlockType() : BasicBlockType(ID, BirchLeavesBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/leaves.png", 6)) { hardness = 0.1f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } Block* BirchLeavesBlockType::createBlock(Framework::Vec3 position) const { AdditionalItemSpawningBlock* block = new AdditionalItemSpawningBlock(this, 0, position); block->addSpawn({ 1, 1, 0.03, BirchSeblingBlockItemType::ID }); return block; } BirchLeavesBlockItemType::BirchLeavesBlockItemType() : BasicBlockItemType(ID, "Leaves", 0, 0, ModelInfo("itemCube", "blocks.ltdb/leaves.png", 6)) {} Item* BirchLeavesBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BirchLeavesBlockType::INSTANCE, "Birch Leaves"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } // Birch Sebling BirchSeblingBlockItemType::BirchSeblingBlockItemType() : BasicBlockItemType(ID, "Birch Sebling", 0, 0, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1)) {} Item* BirchSeblingBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BirchSeblingBlockType::INSTANCE, "Birch Sebling"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } // Beech Wood BeechBlockType::BeechBlockType() : BasicBlockType(ID, BeechBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/beech.png", 6)) { hardness = 1.5f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } BeechBlockItemType::BeechBlockItemType() : BasicBlockItemType(ID, "Beech", 0, 0, ModelInfo("itemCube", "blocks.ltdb/beech.png", 6)) {} Item* BeechBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BeechBlockType::INSTANCE, "Beech"); initializeItem(item, 0, 0, 1.5f, 0, 1); return item; } // Beech Leaves BeechLeavesBlockType::BeechLeavesBlockType() : BasicBlockType(ID, BeechLeavesBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/leaves.png", 6)) { hardness = 0.1f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } Block* BeechLeavesBlockType::createBlock(Framework::Vec3 position) const { AdditionalItemSpawningBlock* block = new AdditionalItemSpawningBlock(this, 0, position); block->addSpawn({ 1, 1, 0.02, BeechSeblingBlockItemType::ID }); return block; } BeechLeavesBlockItemType::BeechLeavesBlockItemType() : BasicBlockItemType(ID, "Leaves", 0, 0, ModelInfo("itemCube", "blocks.ltdb/leaves.png", 6)) {} Item* BeechLeavesBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BeechLeavesBlockType::INSTANCE, "Beech Leaves"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } // Beech Sebling BeechSeblingBlockItemType::BeechSeblingBlockItemType() : BasicBlockItemType(ID, "Beech Sebling", 0, 0, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1)) {} Item* BeechSeblingBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BeechSeblingBlockType::INSTANCE, "Beech Sebling"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } // Basalt BasaltBlockType::BasaltBlockType() : BasicBlockType(ID, BasaltBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/basalt.png", 6)) { hardness = 2.f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } BasaltBlockItemType::BasaltBlockItemType() : BasicBlockItemType(ID, "Basalt", 0, 0, ModelInfo("itemCube", "blocks.ltdb/basalt.png", 6)) {} Item* BasaltBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, BasaltBlockType::INSTANCE, "Basalt"); initializeItem(item, 0, 0, 2.f, 0, 1); return item; } // Pine Wood PineBlockType::PineBlockType() : BasicBlockType(ID, PineBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/pine.png", 6)) { hardness = 1.4f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } PineBlockItemType::PineBlockItemType() : BasicBlockItemType(ID, "Pine", 0, 0, ModelInfo("itemCube", "blocks.ltdb/pine.png", 6)) {} Item* PineBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, PineBlockType::INSTANCE, "Pine"); initializeItem(item, 0, 0, 1.4f, 0, 1); return item; } // Pine Leaves PineLeavesBlockType::PineLeavesBlockType() : BasicBlockType(ID, PineLeavesBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/leaves.png", 6)) { hardness = 0.1f; defaultBlock = createBlockAt({ 0, 0, 0 }, 0); } PineLeavesBlockItemType::PineLeavesBlockItemType() : BasicBlockItemType(ID, "Leaves", 0, 0, ModelInfo("itemCube", "blocks.ltdb/leaves.png", 6)) {} Item* PineLeavesBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, PineLeavesBlockType::INSTANCE, "Pine Leaves"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; } Block* PineLeavesBlockType::createBlock(Framework::Vec3 position) const { AdditionalItemSpawningBlock* block = new AdditionalItemSpawningBlock(this, 0, position); block->addSpawn({ 1, 1, 0.025, PineSeblingBlockItemType::ID }); return block; } // Pine Sebling PineSeblingBlockItemType::PineSeblingBlockItemType() : BasicBlockItemType(ID, "Pine Sebling", 0, 0, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1)) {} Item* PineSeblingBlockItemType::createItem() const { BasicBlockItem* item = new BasicBlockItem(this, PineSeblingBlockType::INSTANCE, "Pine Sebling"); initializeItem(item, 0, 0, 0.1f, 0, 1); return item; }