Files
neoLegacy/Minecraft.World/FlatLevelSource.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

321 lines
9.8 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.biome.h"
#include "net.minecraft.world.level.levelgen.h"
#include "net.minecraft.world.level.levelgen.feature.h"
#include "net.minecraft.world.level.levelgen.structure.h"
#include "net.minecraft.world.level.levelgen.synth.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.storage.h"
#include "net.minecraft.world.entity.h"
#include "FlatLevelSource.h"
#include "OceanMonumentFeature.h"
FlatLevelSource::FlatLevelSource(Level *level, int64_t seed, bool generateStructures)
{
m_XZSize = level->getLevelData()->getXZSize();
this->level = level;
this->generateStructures = generateStructures;
this->random = new Random(seed);
this->pprandom = new Random(seed);
generatorInfo = FlatGeneratorInfo::fromValue(level->getLevelData()->getGeneratorOptions());
memset(layerIds, 0, sizeof(layerIds));
memset(layerData, 0, sizeof(layerData));
hasLayerData = false;
int seaLevel = 0;
int airRun = 0;
for (auto &layer : *generatorInfo.getLayers())
{
for (int y = layer.getStart(); y < layer.getStart() + layer.getHeight() && y < FlatGeneratorInfo::MAX_HEIGHT; ++y)
{
layerIds[y] = static_cast<unsigned char>(layer.getId());
layerData[y] = static_cast<unsigned char>(layer.getData() & 15);
if (layerData[y] != 0)
hasLayerData = true;
}
if (layer.getId() == 0)
{
airRun += layer.getHeight();
}
else
{
seaLevel += layer.getHeight() + airRun;
airRun = 0;
}
}
level->seaLevel = seaLevel;
caveFeature = generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_CAVES) ? new LargeCaveFeature() : nullptr;
canyonFeature = generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_RAVINES) ? new CanyonFeature() : nullptr;
auto *structures = generatorInfo.getStructures();
villageFeature = nullptr;
strongholdFeature = nullptr;
mineShaftFeature = nullptr;
scatteredFeature = nullptr;
oceanMonument = nullptr;
if (generateStructures)
{
if (generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_VILLAGE))
villageFeature = new VillageFeature((*structures)[FlatGeneratorInfo::STRUCTURE_VILLAGE], m_XZSize);
if (generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_STRONGHOLD))
strongholdFeature = new StrongholdFeature((*structures)[FlatGeneratorInfo::STRUCTURE_STRONGHOLD]);
if (generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_MINESHAFT))
mineShaftFeature = new MineShaftFeature((*structures)[FlatGeneratorInfo::STRUCTURE_MINESHAFT]);
if (generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_BIOME_SPECIFIC))
scatteredFeature = new RandomScatteredLargeFeature((*structures)[FlatGeneratorInfo::STRUCTURE_BIOME_SPECIFIC]);
if (generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_OCEAN_MONUMENT))
oceanMonument = new OceanMonumentFeature((*structures)[FlatGeneratorInfo::STRUCTURE_OCEAN_MONUMENT]);
}
decorations = generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_BIOME_DECORATION);
dungeons = generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_DUNGEON);
lakes = generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_LAKE);
lavaLakes = generatorInfo.hasStructure(FlatGeneratorInfo::STRUCTURE_LAVA_LAKE);
}
FlatLevelSource::~FlatLevelSource()
{
delete random;
delete pprandom;
delete caveFeature;
delete canyonFeature;
delete villageFeature;
delete strongholdFeature;
delete mineShaftFeature;
delete scatteredFeature;
delete oceanMonument;
}
void FlatLevelSource::prepareHeights(byteArray blocks)
{
int height = blocks.length / (16 * 16);
if (height > FlatGeneratorInfo::MAX_HEIGHT)
height = FlatGeneratorInfo::MAX_HEIGHT;
for (int xc = 0; xc < 16; xc++)
{
for (int zc = 0; zc < 16; zc++)
{
for (int yc = 0; yc < height; yc++)
{
blocks[xc << 11 | zc << 7 | yc] = static_cast<byte>(layerIds[yc]);
}
}
}
}
LevelChunk *FlatLevelSource::create(int x, int z)
{
return getChunk(x, z);
}
LevelChunk *FlatLevelSource::getChunk(int xOffs, int zOffs)
{
random->setSeed(xOffs * 341873128712l + zOffs * 132897987541l);
int chunksSize = Level::genDepth * 16 * 16;
byte *tileData = static_cast<byte *>(XPhysicalAlloc(chunksSize, MAXULONG_PTR, 4096, PAGE_READWRITE));
XMemSet128(tileData,0,chunksSize);
byteArray blocks = byteArray(tileData,chunksSize);
prepareHeights(blocks);
if (caveFeature != nullptr)
caveFeature->apply(this, level, xOffs, zOffs, blocks);
if (canyonFeature != nullptr)
canyonFeature->apply(this, level, xOffs, zOffs, blocks);
if (mineShaftFeature != nullptr)
mineShaftFeature->apply(this, level, xOffs, zOffs, blocks);
if (villageFeature != nullptr)
villageFeature->apply(this, level, xOffs, zOffs, blocks);
if (strongholdFeature != nullptr)
strongholdFeature->apply(this, level, xOffs, zOffs, blocks);
if (scatteredFeature != nullptr)
scatteredFeature->apply(this, level, xOffs, zOffs, blocks);
if (oceanMonument != nullptr)
oceanMonument->apply(this, level, xOffs, zOffs, blocks);
byteArray nibbleData;
if (hasLayerData)
{
nibbleData = byteArray(chunksSize);
memset(nibbleData.data, 0, chunksSize);
for (int z = 0; z < 16; ++z)
{
for (int x = 0; x < 16; ++x)
{
for (int y = 0; y < FlatGeneratorInfo::MAX_HEIGHT && y < Level::genDepth; ++y)
{
int rawIdx = (x << 11) | (z << 7) | y;
byte val = layerData[y];
if (val == 0 || blocks[rawIdx] != static_cast<byte>(layerIds[y]))
continue;
int byteIdx = rawIdx >> 1;
if (rawIdx & 1)
nibbleData.data[byteIdx] = static_cast<byte>((nibbleData.data[byteIdx] & 0x0F) | (val << 4));
else
nibbleData.data[byteIdx] = static_cast<byte>((nibbleData.data[byteIdx] & 0xF0) | val);
}
}
}
}
LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs);
if (hasLayerData)
{
levelChunk->setDataData(nibbleData);
delete [] nibbleData.data;
}
XPhysicalFree(tileData);
byteArray chunkBiomes = levelChunk->getBiomes();
if (chunkBiomes.data != nullptr)
{
for (int z = 0; z < 16; ++z)
for (int x = 0; x < 16; ++x)
{
Biome *biome = level->getBiomeSource()->getBiome(xOffs * 16 + x, zOffs * 16 + z);
if (biome != nullptr && (z << 4 | x) < static_cast<int>(chunkBiomes.length))
chunkBiomes[(z << 4) | x] = static_cast<byte>(biome->id & 0xff);
}
}
levelChunk->recalcHeightmap();
return levelChunk;
}
bool FlatLevelSource::hasChunk(int x, int y)
{
return true;
}
void FlatLevelSource::postProcess(ChunkSource *parent, int xt, int zt)
{
HeavyTile::instaFall = true;
int xo = xt * 16;
int zo = zt * 16;
Biome *biome = level->getBiome(xo + 16, zo + 16);
pprandom->setSeed(level->getSeed());
int64_t xScale = pprandom->nextLong() / 2 * 2 + 1;
int64_t zScale = pprandom->nextLong() / 2 * 2 + 1;
pprandom->setSeed(((xt * xScale) + (zt * zScale)) ^ level->getSeed());
bool hasVillage = false;
if (mineShaftFeature != nullptr)
mineShaftFeature->postProcess(level, pprandom, xt, zt);
if (villageFeature != nullptr)
hasVillage = villageFeature->postProcess(level, pprandom, xt, zt);
if (strongholdFeature != nullptr)
strongholdFeature->postProcess(level, pprandom, xt, zt);
if (scatteredFeature != nullptr)
scatteredFeature->postProcess(level, pprandom, xt, zt);
if (oceanMonument != nullptr)
oceanMonument->postProcess(level, pprandom, xt, zt);
if (lakes && !hasVillage && pprandom->nextInt(4) == 0)
{
int x = xo + pprandom->nextInt(16) + 8;
int y = pprandom->nextInt(Level::genDepth);
int z = zo + pprandom->nextInt(16) + 8;
LakeFeature calmWater(Tile::water_Id);
calmWater.place(level, pprandom, x, y, z);
}
if (lavaLakes && !hasVillage && pprandom->nextInt(8) == 0)
{
int x = xo + pprandom->nextInt(16) + 8;
int y = pprandom->nextInt(pprandom->nextInt(Level::genDepth - 8) + 8);
int z = zo + pprandom->nextInt(16) + 8;
if (y < level->seaLevel || pprandom->nextInt(10) == 0)
{
LakeFeature calmLava(Tile::lava_Id);
calmLava.place(level, pprandom, x, y, z);
}
}
if (dungeons)
{
for (int i = 0; i < 8; i++)
{
int x = xo + pprandom->nextInt(16) + 8;
int y = pprandom->nextInt(Level::genDepth);
int z = zo + pprandom->nextInt(16) + 8;
MonsterRoomFeature mrf;
mrf.place(level, pprandom, x, y, z);
}
}
if (decorations && biome != nullptr)
{
biome->decorate(level, pprandom, xo, zo);
}
app.processSchematics(parent->getChunk(xt,zt));
HeavyTile::instaFall = false;
}
bool FlatLevelSource::save(bool force, ProgressListener *progressListener)
{
return true;
}
bool FlatLevelSource::tick()
{
return false;
}
bool FlatLevelSource::shouldSave()
{
return true;
}
wstring FlatLevelSource::gatherStats()
{
return L"FlatLevelSource";
}
vector<Biome::MobSpawnerData *> *FlatLevelSource::getMobsAt(MobCategory *mobCategory, int x, int y, int z)
{
Biome *biome = level->getBiome(x, z);
if (biome == NULL)
{
return nullptr;
}
if (mobCategory == MobCategory::monster)
{
if (scatteredFeature != nullptr && scatteredFeature->isSwamphut(x, y, z))
return scatteredFeature->getSwamphutEnemies();
if (oceanMonument != nullptr && oceanMonument->isInsideFeature(x, y, z))
return oceanMonument->getMonumentEnemies();
}
return biome->getMobs(mobCategory);
}
TilePos *FlatLevelSource::findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z)
{
if (LargeFeature::STRONGHOLD == featureName && strongholdFeature != nullptr)
{
return strongholdFeature->getNearestGeneratedFeature(level, x, y, z);
}
return nullptr;
}
void FlatLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ)
{
if (mineShaftFeature != nullptr)
mineShaftFeature->apply(this, level, chunkX, chunkZ, byteArray());
if (villageFeature != nullptr)
villageFeature->apply(this, level, chunkX, chunkZ, byteArray());
if (strongholdFeature != nullptr)
strongholdFeature->apply(this, level, chunkX, chunkZ, byteArray());
if (scatteredFeature != nullptr)
scatteredFeature->apply(this, level, chunkX, chunkZ, byteArray());
}