Files
BluTac10-Xbox_Neo/Minecraft.World/DoublePlantFeature.cpp
2026-03-26 14:14:42 +03:00

43 lines
1.3 KiB
C++

#include "stdafx.h"
#include "DoublePlantFeature.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "TallGrass2.h"
DoublePlantFeature::DoublePlantFeature(bool doUpdate)
: Feature(doUpdate), m_plantType(1)
{
}
void DoublePlantFeature::setPlantType(int plantType)
{
m_plantType = (plantType < 1) ? 1 : plantType;
}
bool DoublePlantFeature::place(Level* level, Random* rand, int x, int y, int z)
{
bool placed = false;
for (int i = 0; i < 64; ++i)
{
int bx = x + rand->nextInt(8) - rand->nextInt(8);
int by = y + rand->nextInt(4) - rand->nextInt(4);
int bz = z + rand->nextInt(8) - rand->nextInt(8);
if (by >= Level::maxBuildHeight - 1) continue;
if (by < 1) continue;
if (level->getTile(bx, by, bz) != 0) continue;
if (level->getTile(bx, by + 1, bz) != 0) continue;
if (!static_cast<TallGrass2*>(Tile::tiles[Tile::tallgrass2_Id])->mayPlace(level, bx, by, bz)) continue;
level->setTileAndData(bx, by, bz, Tile::tallgrass2_Id, m_plantType, Tile::UPDATE_ALL);
level->setTileAndData(bx, by + 1, bz, Tile::tallgrass2_Id, m_plantType | TallGrass2::UPPER_BIT, Tile::UPDATE_ALL);
placed = true;
}
return placed;
}