|
@@ -0,0 +1,155 @@
|
|
|
+#include "TreeSeblingBlock.h"
|
|
|
+#include "BasicBlocks.h"
|
|
|
+#include "TreeTemplate.h"
|
|
|
+#include "RandNoise.h"
|
|
|
+#include "Game.h"
|
|
|
+#include "NoBlock.h"
|
|
|
+
|
|
|
+
|
|
|
+TreeSeblingBlock::TreeSeblingBlock(const BlockType* zType, const ItemType* zTool, Framework::Vec3<int> pos, const BlockType* wood, const BlockType* leaves)
|
|
|
+ : Block(zType, zTool, pos, 0),
|
|
|
+ wood(wood),
|
|
|
+ leaves(leaves)
|
|
|
+{
|
|
|
+ tickSource = 1;
|
|
|
+}
|
|
|
+
|
|
|
+bool TreeSeblingBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
|
|
|
+{
|
|
|
+ seblingTicks += 1;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+void TreeSeblingBlock::onPostTick()
|
|
|
+{
|
|
|
+ if (seblingTicks >= seblingTicksMax)
|
|
|
+ {
|
|
|
+ Game::INSTANCE->doLater([wood = wood, leaves = leaves, pos = getPos(), dim = getDimensionId()]()
|
|
|
+ {
|
|
|
+ // the tree sebling object will be deleted during this operation
|
|
|
+ RandNoise noise((int)time(0));
|
|
|
+ if (!Game::INSTANCE->zGenerator()->spawnStructure(pos, dim, [wood = wood, leaves = leaves](GenerationTemplate* tmpl)
|
|
|
+ {
|
|
|
+ TreeTemplate* tree = dynamic_cast<TreeTemplate*>(tmpl);
|
|
|
+ return tree && tree->getWoodType() == wood && tree->getLeavesType() == leaves;
|
|
|
+ }))
|
|
|
+ {
|
|
|
+ Game::INSTANCE->zDimension(dim)->placeBlock(pos, AirBlockBlockType::ID);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+TreeSeblingBlockType::TreeSeblingBlockType(int typeId, int itemTypeId, ModelInfo model)
|
|
|
+ : BlockType(typeId, 0, model, 1, 10, 0),
|
|
|
+ itemType(itemTypeId),
|
|
|
+ transparent(true),
|
|
|
+ passable(true),
|
|
|
+ hardness(0.1f),
|
|
|
+ zTool(0),
|
|
|
+ speedModifier(0.5f),
|
|
|
+ interactable(1)
|
|
|
+{}
|
|
|
+
|
|
|
+void TreeSeblingBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
|
|
|
+{
|
|
|
+ TreeSeblingBlock* block = dynamic_cast<TreeSeblingBlock*>(zBlock);
|
|
|
+ if (!block)
|
|
|
+ throw "TreeSeblingBlockType::createSuperBlock was called with a block witch is not an instance of TreeSeblingBlock";
|
|
|
+ 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 TreeSeblingBlockType::loadSuperBlock(Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const
|
|
|
+{
|
|
|
+ TreeSeblingBlock* block = dynamic_cast<TreeSeblingBlock*>(zBlock);
|
|
|
+ if (!block)
|
|
|
+ throw "TreeSeblingBlockType::loadSuperBlock was called with a block witch is not an instance of TreeSeblingBlock";
|
|
|
+ zReader->lese((char*)&block->seblingTicks, 4);
|
|
|
+ zReader->lese((char*)&block->seblingTicksMax, 4);
|
|
|
+ int id;
|
|
|
+ zReader->lese((char*)&id, 4);
|
|
|
+ block->wood = StaticRegistry<BlockType>::INSTANCE.zElement(id);
|
|
|
+ zReader->lese((char*)&id, 4);
|
|
|
+ block->leaves = StaticRegistry<BlockType>::INSTANCE.zElement(id);
|
|
|
+ BlockType::loadSuperBlock(zBlock, zReader, dimensionId);
|
|
|
+}
|
|
|
+
|
|
|
+void TreeSeblingBlockType::saveSuperBlock(Block* zBlock, Framework::StreamWriter* zWriter) const
|
|
|
+{
|
|
|
+ TreeSeblingBlock* block = dynamic_cast<TreeSeblingBlock*>(zBlock);
|
|
|
+ if (!block)
|
|
|
+ throw "TreeSeblingBlockType::saveSuperBlock was called with a block witch is not an instance of TreeSeblingBlock";
|
|
|
+ zWriter->schreibe((char*)&block->seblingTicks, 4);
|
|
|
+ zWriter->schreibe((char*)&block->seblingTicksMax, 4);
|
|
|
+ int id = block->wood->getId();
|
|
|
+ zWriter->schreibe((char*)&id, 4);
|
|
|
+ int id = block->leaves->getId();
|
|
|
+ zWriter->schreibe((char*)&id, 4);
|
|
|
+ BlockType::saveSuperBlock(zBlock, zWriter);
|
|
|
+}
|
|
|
+
|
|
|
+Item* TreeSeblingBlockType::createItem() const
|
|
|
+{
|
|
|
+ return StaticRegistry<ItemType>::INSTANCE.zElement(itemType)->createItem();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+OakSeblingBlockType::OakSeblingBlockType()
|
|
|
+ : TreeSeblingBlockType(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
|
|
|
+{
|
|
|
+ return new TreeSeblingBlock(this, zTool, position, OakBlockType::INSTANCE, OakLeavesBlockType::INSTANCE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+BirchSeblingBlockType::BirchSeblingBlockType()
|
|
|
+ : TreeSeblingBlockType(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
|
|
|
+{
|
|
|
+ return new TreeSeblingBlock(this, zTool, position, BirchBlockType::INSTANCE, BirchLeavesBlockType::INSTANCE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+BeechSeblingBlockType::BeechSeblingBlockType()
|
|
|
+ : TreeSeblingBlockType(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
|
|
|
+{
|
|
|
+ return new TreeSeblingBlock(this, zTool, position, BeechBlockType::INSTANCE, BeechLeavesBlockType::INSTANCE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+PineSeblingBlockType::PineSeblingBlockType()
|
|
|
+ : TreeSeblingBlockType(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
|
|
|
+{
|
|
|
+ return new TreeSeblingBlock(this, zTool, position, PineBlockType::INSTANCE, PineLeavesBlockType::INSTANCE);
|
|
|
+}
|