|
@@ -1,4 +1,7 @@
|
|
|
#include "BasicBlocks.h"
|
|
|
+#include "ItemEntity.h"
|
|
|
+#include "Game.h"
|
|
|
+#include "AddEntityUpdate.h"
|
|
|
|
|
|
|
|
|
BasicBlock::BasicBlock(const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos)
|
|
@@ -14,6 +17,39 @@ 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),
|
|
@@ -130,22 +166,55 @@ Item* OakBlockItemType::createItem() const
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
-// Leaves Wood
|
|
|
-LeavesBlockType::LeavesBlockType()
|
|
|
- : BasicBlockType(ID, LeavesBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/leaves.png", 6))
|
|
|
+// 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;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
-LeavesBlockItemType::LeavesBlockItemType()
|
|
|
+OakLeavesBlockItemType::OakLeavesBlockItemType()
|
|
|
: BasicBlockItemType(ID, "Leaves", 0, 0, ModelInfo("itemCube", "blocks.ltdb/leaves.png", 6))
|
|
|
{}
|
|
|
|
|
|
-Item* LeavesBlockItemType::createItem() const
|
|
|
+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
|
|
|
+OakSeblingBlockType::OakSeblingBlockType()
|
|
|
+ : BasicBlockType(ID, OakSeblingBlockItemType::ID, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1))
|
|
|
+{
|
|
|
+ hardness = 0.1f;
|
|
|
+ defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
|
|
|
+}
|
|
|
+
|
|
|
+Block* OakSeblingBlockType::createBlock(Framework::Vec3<int> position) const
|
|
|
+{
|
|
|
+ // TODO: add sebling block
|
|
|
+ return BasicBlockType::createBlock(position);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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, LeavesBlockType::INSTANCE, "Leaves");
|
|
|
+ BasicBlockItem* item = new BasicBlockItem(this, OakSeblingBlockType::INSTANCE, "Oak Sebling");
|
|
|
initializeItem(item, 0, 0, 0.1f, 0, 1);
|
|
|
return item;
|
|
|
}
|
|
@@ -230,6 +299,59 @@ Item* BirchBlockItemType::createItem() const
|
|
|
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
|
|
|
+BirchSeblingBlockType::BirchSeblingBlockType()
|
|
|
+ : BasicBlockType(ID, BirchSeblingBlockItemType::ID, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1))
|
|
|
+{
|
|
|
+ hardness = 0.1f;
|
|
|
+ defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
|
|
|
+}
|
|
|
+
|
|
|
+Block* BirchSeblingBlockType::createBlock(Framework::Vec3<int> position) const
|
|
|
+{
|
|
|
+ // TODO: add sebling block
|
|
|
+ return BasicBlockType::createBlock(position);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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))
|
|
@@ -250,6 +372,59 @@ Item* BeechBlockItemType::createItem() const
|
|
|
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
|
|
|
+BeechSeblingBlockType::BeechSeblingBlockType()
|
|
|
+ : BasicBlockType(ID, BeechSeblingBlockItemType::ID, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1))
|
|
|
+{
|
|
|
+ hardness = 0.1f;
|
|
|
+ defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
|
|
|
+}
|
|
|
+
|
|
|
+Block* BeechSeblingBlockType::createBlock(Framework::Vec3<int> position) const
|
|
|
+{
|
|
|
+ // TODO: add sebling block
|
|
|
+ return BasicBlockType::createBlock(position);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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))
|
|
@@ -288,4 +463,57 @@ 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
|
|
|
+PineSeblingBlockType::PineSeblingBlockType()
|
|
|
+ : BasicBlockType(ID, PineSeblingBlockItemType::ID, ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1))
|
|
|
+{
|
|
|
+ hardness = 0.1f;
|
|
|
+ defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
|
|
|
+}
|
|
|
+
|
|
|
+Block* PineSeblingBlockType::createBlock(Framework::Vec3<int> position) const
|
|
|
+{
|
|
|
+ // TODO: add sebling block
|
|
|
+ return BasicBlockType::createBlock(position);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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;
|
|
|
}
|