#include "BlockInstanceGeneratorRule.h" BlockInstanceGeneratorRule::BlockInstanceGeneratorRule( Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory) : GeneratorRule(zConfig, zMemory) { blockType = BlockType::getTypeId( zConfig->asObject()->zValue("blockType")->asString()->getString()); } Framework::Either BlockInstanceGeneratorRule::createBlock( int x, int y, int z, int dimensionId) { return StaticRegistry::INSTANCE.zElement(blockType)->createBlockAt(Framework::Vec3(x, y, z), dimensionId, 0); } BlockInstanceGeneratorRuleFactory::BlockInstanceGeneratorRuleFactory() : ReferenceCounter() {} GeneratorRule* BlockInstanceGeneratorRuleFactory::createRule( Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory) { return new BlockInstanceGeneratorRule(zConfig, zMemory); } Framework::JSON::Validator::JSONValidator* BlockInstanceGeneratorRuleFactory::getValidator() { Framework::RCArray blockTypeNames; for (int i = 0; i < StaticRegistry::INSTANCE.getCount(); i++) { if (StaticRegistry::INSTANCE.zElement(i)) { blockTypeNames.add(new Framework::Text( StaticRegistry::INSTANCE.zElement(i)->getName())); } } return GeneratorRule::addToValidator( Framework::JSON::Validator::JSONValidator::buildForObject() ->withRequiredString("type") ->withExactMatch("blockInstance") ->finishString() ->withRequiredString("blockType") ->whichIsOneOf(blockTypeNames) ->finishString()) ->finishObject(); }