123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- #include "BasicBlocks.h"
- #include "Game.h"
- #include "ItemEntity.h"
- #include "ItemStack.h"
- #include "ModelInfo.h"
- #include "TreeSeblingBlock.h"
- BasicBlock::BasicBlock(int typeId, Framework::Vec3<int> pos, int dimensionId)
- : BasicBlock(typeId, pos, dimensionId, false)
- {}
- BasicBlock::BasicBlock(
- int typeId, Framework::Vec3<int> pos, int dimensionId, bool hasInventory)
- : Block(typeId, pos, dimensionId, hasInventory)
- {}
- bool BasicBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
- {
- return 0;
- }
- void BasicBlock::onPostTick() {}
- BasicBlockType::BasicBlockType()
- : BlockType(),
- itemTypeName(),
- transparent(0),
- passable(0),
- speedModifier(1.f),
- interactable(1)
- {}
- bool BasicBlockType::initialize(Game* zGame)
- {
- if (itemTypeName.getLength())
- {
- itemTypeId = zGame->getItemTypeId(itemTypeName);
- }
- else
- {
- itemTypeId = 0;
- }
- return itemTypeId >= 0 && BlockType::initialize(zGame);
- }
- void BasicBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
- {
- BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
- block->transparent = transparent;
- block->passable = passable;
- block->hp = (float)getInitialMaxHP();
- block->maxHP = (float)getInitialMaxHP();
- block->hardness = getHardness();
- block->speedModifier = speedModifier;
- block->interactable = interactable;
- BlockType::createSuperBlock(zBlock, zItem);
- }
- Block* BasicBlockType::createBlock(
- Framework::Vec3<int> position, int dimensionId) const
- {
- return new BasicBlock(getId(), position, dimensionId);
- }
- Item* BasicBlockType::createItem() const
- {
- if (getItemTypeName().istGleich(""))
- {
- return 0;
- }
- return Game::INSTANCE->zItemType(itemTypeId)->createItem();
- }
- Framework::Text BasicBlockType::getItemTypeName() const
- {
- return itemTypeName;
- }
- ItemType* BasicBlockType::createItemType() const
- {
- if (getItemTypeName().istGleich(""))
- {
- return 0;
- }
- return new BasicBlockItemType(getItemTypeName(),
- new ModelInfo(zModel()->getModelPath(),
- zModel()->getTexturePaths(),
- zModel()->isTransparent(),
- zModel()->getSize() / 2.f),
- transparent,
- passable,
- getHardness(),
- speedModifier,
- getItemTypeName(),
- 0,
- 50,
- getGroupNames());
- }
- void BasicBlockType::setItemTypeName(Framework::Text itemTypeName)
- {
- this->itemTypeName = itemTypeName;
- }
- int BasicBlockType::getItemTypeId() const
- {
- return itemTypeId;
- }
- void BasicBlockType::setTransparent(bool transparent)
- {
- this->transparent = transparent;
- }
- bool BasicBlockType::isTransparent() const
- {
- return transparent;
- }
- void BasicBlockType::setPassable(bool passable)
- {
- this->passable = passable;
- }
- bool BasicBlockType::isPassable() const
- {
- return passable;
- }
- void BasicBlockType::setSpeedModifier(float speedModifier)
- {
- this->speedModifier = speedModifier;
- }
- float BasicBlockType::getSpeedModifier() const
- {
- return speedModifier;
- }
- void BasicBlockType::setInteractable(bool interactable)
- {
- this->interactable = interactable;
- }
- bool BasicBlockType::isInteractable() const
- {
- return interactable;
- }
- BasicBlockTypeFactory::BasicBlockTypeFactory()
- : BlockTypeFactoryBase()
- {}
- BasicBlockType* BasicBlockTypeFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BasicBlockType();
- }
- BasicBlockType* BasicBlockTypeFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- BasicBlockType* result = BlockTypeFactoryBase::fromJson(zJson);
- if (zJson->zValue("itemType")->getType() == Framework::AbstractType::STRING)
- {
- result->setItemTypeName(
- zJson->zValue("itemType")->asString()->getString());
- }
- else
- {
- result->setItemTypeName("");
- }
- result->setTransparent(zJson->zValue("transparent")->asBool()->getBool());
- result->setPassable(zJson->zValue("passable")->asBool()->getBool());
- result->setSpeedModifier(
- (float)zJson->zValue("speedModifier")->asNumber()->getNumber());
- result->setInteractable(
- (float)zJson->zValue("interactable")->asBool()->getBool());
- return result;
- }
- Framework::JSON::JSONObject* BasicBlockTypeFactory::toJsonObject(
- BasicBlockType* zObject) const
- {
- Framework::JSON::JSONObject* result
- = BlockTypeFactoryBase::toJsonObject(zObject);
- if (zObject->getItemTypeName().istGleich(""))
- {
- result->addValue("itemType", new Framework::JSON::JSONValue());
- }
- else
- {
- result->addValue("itemType",
- new Framework::JSON::JSONString(zObject->getItemTypeName()));
- }
- result->addValue(
- "transparent", new Framework::JSON::JSONBool(zObject->isTransparent()));
- result->addValue(
- "passable", new Framework::JSON::JSONBool(zObject->isPassable()));
- result->addValue("speedModifier",
- new Framework::JSON::JSONNumber(zObject->getSpeedModifier()));
- result->addValue("interactable",
- new Framework::JSON::JSONBool(zObject->isInteractable()));
- return result;
- }
- JSONObjectValidationBuilder* BasicBlockTypeFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return BlockTypeFactoryBase::addToValidator(builder
- ->withRequiredAttribute("itemType",
- Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
- ItemTypeNameFactory::TYPE_ID),
- true,
- false)
- ->withRequiredBool("transparent")
- ->withDefault(false)
- ->finishBool()
- ->withRequiredBool("passable")
- ->withDefault(false)
- ->finishBool()
- ->withRequiredNumber("speedModifier")
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredBool("interactable")
- ->withDefault(true)
- ->finishBool());
- }
- const char* BasicBlockTypeFactory::getTypeToken() const
- {
- return "basicBlock";
- }
|