123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- #include "BasicBlocks.h"
- #include "ItemEntity.h"
- #include "Game.h"
- #include "AddEntityUpdate.h"
- #include "TreeSeblingBlock.h"
- BasicBlock::BasicBlock(const BlockType* zType, ItemType* zTool, Framework::Vec3<int> 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<int> 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<ItemType>::INSTANCE.zElement(config.itemType)->createItemStack(amount);
- if (spawnedItems)
- {
- ItemEntity* itemEntity = (ItemEntity*)ItemEntityType::INSTANCE->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()));
- }
- }
- }
- }
- 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<BasicBlock*>(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<int> position) const
- {
- return new BasicBlock(this, 0, position);
- }
- Item* BasicBlockType::createItem() const
- {
- return StaticRegistry<ItemType>::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<int> 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<int> 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<int> 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<int> 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;
- }
|