#include "BlockReplacementDrop.h" #include "Block.h" #include "BlockType.h" #include "Dimension.h" BlockReplacementDrop::BlockReplacementDrop(Framework::Text blockTypeName) : DropConfig(), blockTypeName(blockTypeName), zBlockType(0) {} void BlockReplacementDrop::initialize() { int id = Game::INSTANCE->getBlockTypeId(blockTypeName); zBlockType = Game::INSTANCE->zBlockType(id < 0 ? BlockTypeEnum::AIR : id); } Framework::Text BlockReplacementDrop::getBlockTypeName() const { return blockTypeName; } void BlockReplacementDrop::doDrop(Entity* zActor, Item* zItem, ItemSkill* zUsedSkill, Framework::Either zDestroyedObject) const { if (zBlockType && zDestroyedObject.isA()) { Game::INSTANCE->zDimension(zDestroyedObject.getA()->getDimensionId()) ->placeBlock( zDestroyedObject.getA()->getPos(), zBlockType->getId()); } } BlockReplacementDropFactory::BlockReplacementDropFactory() : DropConfigFactory() {} JSONObjectValidationBuilder* BlockReplacementDropFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return DropConfigFactory::addToValidator(builder)->withRequiredAttribute( "blockType", Game::INSTANCE->zTypeRegistry()->getValidator( BlockTypeNameFactory::TYPE_ID)); } const char* BlockReplacementDropFactory::getTypeToken() const { return "blockReplacement"; } BlockReplacementDrop* BlockReplacementDropFactory::createInstance( Framework::JSON::JSONObject* zJson) const { return new BlockReplacementDrop( zJson->zValue("blockType")->asString()->getString()); } void BlockReplacementDropFactory::addToJson( Framework::JSON::JSONObject* zJson, BlockReplacementDrop* zObject) const { zJson->addValue("blockTypeName", new Framework::JSON::JSONString(zObject->getBlockTypeName())); }