|
|
@@ -37,6 +37,10 @@ PlantConfig::~PlantConfig()
|
|
|
{
|
|
|
orientationConfig->release();
|
|
|
}
|
|
|
+ if (plantHeight)
|
|
|
+ {
|
|
|
+ plantHeight->release();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void PlantConfig::initialize(JExpressionMemory* zMemory)
|
|
|
@@ -77,10 +81,6 @@ double PlantConfig::doesGeneratePlant(int x,
|
|
|
{
|
|
|
return 0.0;
|
|
|
}
|
|
|
- if (z + plantHeight > WORLD_HEIGHT)
|
|
|
- {
|
|
|
- return 0.0;
|
|
|
- }
|
|
|
if (!condition->getValue())
|
|
|
{
|
|
|
return 0.0;
|
|
|
@@ -99,7 +99,8 @@ void PlantConfig::generatePlantAt(
|
|
|
? orientationConfig->calculateOrientation(
|
|
|
{x, y, z}, dimensionId, zChunk)
|
|
|
: NO_DIRECTION;
|
|
|
- for (int i = 0; i < plantHeight; i++)
|
|
|
+ int height = (int)round(plantHeight->getValue(x, y, z, dimensionId, noise));
|
|
|
+ for (int i = 0; i < height; i++)
|
|
|
{
|
|
|
Framework::Vec3<int> pos(x, y, z);
|
|
|
if (direction == PlantDirection::UP)
|
|
|
@@ -110,6 +111,10 @@ void PlantConfig::generatePlantAt(
|
|
|
{
|
|
|
pos = {x, y, z - i};
|
|
|
}
|
|
|
+ if (pos.z < 0 || pos.z >= WORLD_HEIGHT)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
int currentType = zChunk->getBlockTypeAtWC(pos.x, pos.y, pos.z);
|
|
|
if (currentType != BlockTypeEnum::AIR
|
|
|
&& currentType != BlockTypeEnum::NO_BLOCK)
|
|
|
@@ -192,12 +197,12 @@ Framework::Text PlantConfig::getPlantBlockTypeName() const
|
|
|
return plantBlockTypeName;
|
|
|
}
|
|
|
|
|
|
-void PlantConfig::setPlantHeight(int height)
|
|
|
+void PlantConfig::setPlantHeight(FloatDistribution* height)
|
|
|
{
|
|
|
this->plantHeight = height;
|
|
|
}
|
|
|
|
|
|
-int PlantConfig::getPlantHeight() const
|
|
|
+FloatDistribution* PlantConfig::getPlantHeight() const
|
|
|
{
|
|
|
return plantHeight;
|
|
|
}
|
|
|
@@ -269,7 +274,8 @@ PlantConfig* PlantConfigFactory::fromJson(
|
|
|
config->setPlantBlockTypeName(
|
|
|
zJson->zValue("plantBlock")->asString()->getString());
|
|
|
config->setPlantHeight(
|
|
|
- (int)zJson->zValue("plantHeight")->asNumber()->getNumber());
|
|
|
+ Game::INSTANCE->zTypeRegistry()->fromJson<FloatDistribution>(
|
|
|
+ zJson->zValue("plantHeight")));
|
|
|
Framework::Text locationStr
|
|
|
= zJson->zValue("direction")->asString()->getString();
|
|
|
if (locationStr.isEqual("UP"))
|
|
|
@@ -326,7 +332,8 @@ Framework::JSON::JSONObject* PlantConfigFactory::toJsonObject(
|
|
|
zJson->addValue("plantBlock",
|
|
|
new Framework::JSON::JSONString(zObject->getPlantBlockTypeName()));
|
|
|
zJson->addValue("plantHeight",
|
|
|
- new Framework::JSON::JSONNumber(zObject->getPlantHeight()));
|
|
|
+ Game::INSTANCE->zTypeRegistry()->toJson<FloatDistribution>(
|
|
|
+ zObject->getPlantHeight()));
|
|
|
if (zObject->getDirection() == PlantDirection::UP)
|
|
|
{
|
|
|
zJson->addValue("direction", new Framework::JSON::JSONString("UP"));
|
|
|
@@ -362,9 +369,8 @@ JSONObjectValidationBuilder* PlantConfigFactory::addToValidator(
|
|
|
->withRequiredAttribute("plantBlock",
|
|
|
Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
BlockTypeNameFactory::TYPE_ID))
|
|
|
- ->withRequiredNumber("plantHeight")
|
|
|
- ->whichIsGreaterOrEqual(1)
|
|
|
- ->finishNumber()
|
|
|
+ ->withRequiredAttribute("plantHeight",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<FloatDistribution>())
|
|
|
->withRequiredString("direction")
|
|
|
->whichIsOneOf({"UP", "DOWN"})
|
|
|
->withDefault("UP")
|