#pragma once #include "BlockType.h" #include "ReferenceCounter.h" #include "Item.h" #include "Inventory.h" #include "NetworkMessage.h" #include #include #include #include #define CONST_BLOCK(maybeBlock, type) (maybeBlock ? maybeBlock : StaticRegistry::INSTANCE.zElement((int)type)->zDefault()) class ItemType; class Chunk; class BasicBlockItemType; class TickQueue; class Block : public Inventory { private: int ticksLeftCounter; int currentTickTimeout; bool wasTicked; bool onTickCalled; int dimensionId; protected: bool transparent; bool passable; float hp; float maxHP; float hardness; const BlockType* zType; ItemType* zTool; float speedModifier; Block* zNeighbours[6]; int neighbourTypes[6]; int minTickTimeout; int maxTickTimeout; bool tickSource; bool interactable; bool transmissionRequested; bool deadAndRemoved; unsigned char lightEmisionColor[3]; /// /// executes block specific things /// /// a queue to add neighbor blocks that should be ticked after this block /// the number of ticks passed since the last call (only for tickSources) /// can be set to one to tell that this block needs to be tickt again later in the queue of this tick /// true, iff the block needs to be ticked more often virtual bool onTick(TickQueue* zQueue, int numTicks, bool& blocked) = 0; /// /// gets called after each block was tickt. /// the order of blocks called will be exactly the same as onTick /// virtual void onPostTick() = 0; virtual void onDestroy(); public: Block(const BlockType* zType, ItemType* zTool, Framework::Vec3 pos, bool hasInventory); virtual ~Block(); void tick(TickQueue* zQueue); void postTick(); void setDimensionId(int id); virtual void setNeighbour(Direction dir, Framework::Either neighbor); virtual void setNeighbourBlock(Direction dir, Block* zN); virtual void setNeighbourType(Direction dir, int type); void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse); bool isTickSource() const; const BlockType* zBlockType() const; bool isTransparent() const; bool isPassable() const; bool isInteractable() const; float getHP() const; float getMaxHP() const; float getHardness() const; ItemType* zEffectiveTool() const; float getSpeedModifier() const; const Framework::Vec3 getPos() const; int getDimensionId() const; bool isVisible() const; void setHP(float hp); bool isDeadAndRemoved() const; const unsigned char* getLightEmisionColor() const; virtual void filterPassingLight(unsigned char rgb[3]) const; friend BlockType; }; class BasicBlockItem : public Item { protected: bool transparent; bool passable; float hardness; int toolId; float speedModifier; bool interactable; public: BasicBlockItem(const ItemType* zType, const BlockType* zPlacedBlockType, const char* name); virtual bool canBeStackedWith(const Item* zItem) const override; friend BasicBlockItemType; friend BlockType; }; class BasicBlockItemType : public ItemType { protected: BasicBlockItemType(int id, const char* name, ItemSkillLevelUpRule* levelUpRule, const ItemType* zBrokenType, ModelInfo model); virtual void loadSuperItem(Item* zItem, Framework::StreamReader* zReader) const override; virtual void saveSuperItem(const Item* zItem, Framework::StreamWriter* zWriter) const override; void initializeItem(BasicBlockItem* zItem, bool transparent, bool passable, float hardness, int toolId, float speedModifier) const; };