#pragma once #include #include #include #include #include "Inventory.h" #include "Item.h" #include "NetworkMessage.h" #include "ReferenceCounter.h" #include "Tickable.h" #define CONST_BLOCK(maybeBlock, type) \ (maybeBlock ? maybeBlock \ : StaticRegistry::INSTANCE.zElement((int)type) \ ->zDefault()) class ItemType; class Chunk; class BasicBlockItemType; class MultiblockStructure; class TickQueue; class Block : public Inventory, public Tickable { private: int ticksLeftCounter; int currentTickTimeout; bool wasTicked; bool onTickCalled; protected: bool transparent; bool passable; float hp; float maxHP; float hardness; int typeId; const 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]; int mapColor; Framework::RCArray structures; /// /// 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(); virtual void onDialogClosed(Framework::Text dialogId); void broadcastModelInfoChange(); void broadcastMessage(NetworkMessage *message); public: Block(int typeId, const ItemType* zTool, Framework::Vec3 pos, int dimensionId, bool hasInventory); virtual ~Block(); void tick(TickQueue* zQueue) override; void postTick() override; void addToStructure(MultiblockStructure* structure); virtual void onLoaded(); virtual void onUnloaded(); virtual void setNeighbour( Direction dir, Framework::Either neighbor); virtual void setNeighbourBlock(Direction dir, Block* zN); virtual void setNeighbourType(Direction dir, int type); virtual Framework::Text getTargetUIML(); virtual void sendModelInfo(NetworkMessage* zMessage); virtual bool interact(Item* zItem, Entity* zActor); void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse); bool isTickSource() const; const BlockType* zBlockType() const; bool isTransparent() const; bool isPassable() const; virtual bool isInteractable(const Item *zItem) const; float getHP() const; float getMaxHP() const; float getHardness() const; const ItemType* zEffectiveTool() const; float getSpeedModifier() const; const Framework::Vec3 getPos() const; bool isVisible() const; void setHP(float hp); bool isDeadAndRemoved() const; const unsigned char* getLightEmisionColor() const; virtual void filterPassingLight(unsigned char rgb[3]) const; Block* zNeighbor(Direction dir) const; void updateModel(ModelInfo info) const; int getMapColor() const; friend BlockType; }; class BasicBlockItem : public Item { protected: bool transparent; bool passable; float hardness; int toolId; float speedModifier; bool interactable; std::function)> placableProof; public: BasicBlockItem(int itemTypeId, int blockTypeId, const char* name); void setPlacableProof( std::function)> condition, bool andDefault); virtual bool canBeStackedWith(const Item* zItem) const override; virtual bool canBePlacedAt( int dimensionId, Framework::Vec3 worldPos) const override; friend BasicBlockItemType; friend BlockType; }; class BasicBlockItemType : public ItemType { protected: bool transparent; bool passable; float hardness; int toolId; float speedModifier; int blockTypeId; char placableProofState; std::function)> placableProof; virtual void loadSuperItem( Item* zItem, Framework::StreamReader* zReader) const override; virtual void saveSuperItem( const Item* zItem, Framework::StreamWriter* zWriter) const override; virtual Item* createItem() const override; public: BasicBlockItemType(int id, const char* name, ItemSkillLevelUpRule* levelUpRule, int brokenTypeId, ModelInfo model, int blockTypeId); BasicBlockItemType* setHardness(float hardness); BasicBlockItemType* setPlacableProof( std::function)> condition, bool andDefault); }; #include "MultiblockStructure.h"