123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- #pragma once
- #include <Either.h>
- #include <Trie.h>
- #include <Vec3.h>
- #include <VecN.h>
- #include "Inventory.h"
- #include "Item.h"
- #include "MultiblockStructure.h"
- #include "NetworkMessage.h"
- #include "ReferenceCounter.h"
- #include "Tickable.h"
- #define CONST_BLOCK(maybeBlock, type) \
- (maybeBlock ? maybeBlock \
- : Game::INSTANCE->zBlockType((int)type)->zDefault())
- class ItemType;
- class Chunk;
- class BasicBlockItemType;
- class PlaceableProof;
- 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;
- 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<MultiblockStructure> structures;
- /// <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;
- virtual void onDestroy();
- virtual void onDialogClosed(Framework::Text dialogId);
- void broadcastModelInfoChange();
- void broadcastMessage(NetworkMessage* message);
- public:
- Block(int typeId,
- Framework::Vec3<int> 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<Block*, int> 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;
- float getSpeedModifier() const;
- const Framework::Vec3<int> 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* zInfo) const;
- int getMapColor() const;
- friend BlockType;
- };
- class BasicBlockItem : public Item
- {
- protected:
- bool transparent;
- bool passable;
- float hardness;
- float speedModifier;
- bool interactable;
- PlaceableProof* placeableProof;
- public:
- BasicBlockItem(int itemTypeId,
- int blockTypeId,
- Framework::Text name,
- PlaceableProof* placeableProof);
- ~BasicBlockItem();
- virtual bool canBeStackedWith(const Item* zItem) const override;
- virtual bool canBePlacedAt(
- int dimensionId, Framework::Vec3<int> worldPos) const override;
- friend BasicBlockItemType;
- friend BlockType;
- };
- class BasicBlockItemType : public ItemType
- {
- private:
- bool transparent;
- bool passable;
- float hardness;
- float speedModifier;
- Framework::Text blockTypeName;
- int blockTypeId;
- PlaceableProof* placeableProof;
- public:
- BasicBlockItemType();
- BasicBlockItemType(Framework::Text name,
- ModelInfo* model,
- bool transparent,
- bool passable,
- float hardness,
- float speedModifier,
- Framework::Text blockTypeName,
- PlaceableProof* placeableProof,
- int maxStackSize,
- Framework::RCArray<Framework::Text> groups);
- ~BasicBlockItemType();
- protected:
- 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:
- virtual bool initialize(Game* zGame) override;
- int getBlockTypeId() const;
- void setTransparent(bool transparent);
- bool isTransparent() const;
- void setPassable(bool passable);
- bool isPassable() const;
- void setHardness(float hardness);
- float getHardness() const;
- void setSpeedModifier(float speedModifier);
- float getSpeedModifier() const;
- void setBlockTypeName(Framework::Text blockTypeName);
- Framework::Text getBlockTypeName() const;
- void setPlaceableProof(PlaceableProof* placeableProof);
- PlaceableProof* zPlaceableProof() const;
- };
- class BasicBlockItemTypeFactory : public ItemTypeFactoryBase<BasicBlockItemType>
- {
- public:
- BasicBlockItemTypeFactory();
- BasicBlockItemType* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(BasicBlockItemType* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(BasicBlockItemType* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
|