123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #pragma once
- #include "BlockType.h"
- #include "ReferenceCounter.h"
- #include "Item.h"
- #include "Inventory.h"
- #include "NetworkResponse.h"
- #include <Trie.h>
- #include <Vec3.h>
- class ItemType;
- class Chunk;
- class BasicBlockItemType;
- class TickQueue;
- #define AIR_BLOCK -1
- #define IS_BLOCK(b) (((__int64)b) > 0)
- class Block : public Inventory
- {
- private:
- int ticksLeftCounter;
- int currentTickTimeout;
- bool wasTicked;
- bool onTickCalled;
- int dimansionId;
- protected:
- bool transparent;
- bool passable;
- float hp;
- float maxHP;
- float hardness;
- const BlockType *zType;
- ItemType *zTool;
- float speedModifier;
- Block *zNeighbours[ 6 ];
- int minTickTimeout;
- int maxTickTimeout;
- bool tickSource;
- /// <summary>
- /// executes block specific things
- /// </summary>
- /// <param name="zqueue">a queue to add neighbor blocks that should be ticked after this block</param>
- /// <param name="numTicks">the number of ticks passed since the last call (only for tickSources)</param>
- /// <param name="blocked">can be set to one to tell that this block needs to be tickt again later in the queue of this tick</param>
- /// <returns>true, iff the block needs to be ticked more often</returns>
- virtual bool onTick( TickQueue *zQueue, int numTicks, bool &blocked ) = 0;
- /// <summary>
- /// gets called after each block was tickt.
- /// the order of blocks called will be exactly the same as onTick
- /// </summary>
- virtual void onPostTick() = 0;
- public:
- Block( const BlockType *zType, ItemType *zTool, Framework::Vec3<int> pos, bool hasInventory );
- virtual ~Block();
- void tick( TickQueue *zQueue );
- void postTick();
- void setDimensionId( int id );
- virtual void setNeighbour( Direction dir, Block *zN );
- void api( Framework::StreamReader *zRequest, NetworkResponse *zResponse );
- bool isTickSource() const;
- const BlockType *zBlockType() const;
- bool isTransparent() const;
- bool isPassable() const;
- float getHP() const;
- float getMaxHP() const;
- float getHardness() const;
- ItemType *zEffectiveTool() const;
- float getSpeedModifier() const;
- const Framework::Vec3<int> getPos() const;
- int getDimensionId() const;
- bool isVisible() const;
- friend BlockType;
- };
- class BasicBlockItem : public Item
- {
- protected:
- bool transparent;
- bool passable;
- float hp;
- float maxHP;
- float hardness;
- int toolId;
- float speedModifier;
- public:
- BasicBlockItem( const ItemType *zType, const char *name );
- virtual bool canBeStackedWith( Item *zItem ) const override;
- friend BasicBlockItemType;
- friend BlockType;
- };
- class BasicBlockItemType : public ItemType
- {
- protected:
- BasicBlockItemType( int id, ItemSkillLevelUpRule *levelUpRule, const ItemType *zBrokenType );
- 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 hp, float maxHP, float hardness, int toolId, float speedModifier ) const;
- };
|