Add Outer End

This commit is contained in:
DeadVoxelx
2026-04-05 09:08:16 -04:00
committed by GitHub
parent 23e2536f27
commit 03ae7bf9a3
8 changed files with 687 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#include "stdafx.h"
#include "TheOuterEndBiome.h"
#include "TheOuterEndBiomeDecorator.h"
#include "net.minecraft.world.entity.monster.h"
TheOuterEndBiome::TheOuterEndBiome(int id) : Biome(id)
{
enemies.clear();
friendlies.clear();
friendlies_chicken.clear();
friendlies_wolf.clear();
waterFriendlies.clear();
ambientFriendlies.clear();
enemies.push_back(new MobSpawnerData(eTYPE_WATCHER, 7, 1, 1));
enemies.push_back(new MobSpawnerData(eTYPE_ENDERMAN, 10, 4, 4));
decorator = new TheOuterEndBiomeDecorator(this);
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "Biome.h"
class TheOuterEndBiome : public Biome
{
public:
TheOuterEndBiome(int id);
// 4J Stu - Don't need override
//virtual int getSkyColor(float temp);
};

View File

@@ -0,0 +1,39 @@
#define _USE_MATH_DEFINES
#include <cmath>
#include "stdafx.h"
#include "TheOuterEndBiomeDecorator.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.levelgen.feature.h"
#include "EndGatewayFeature.h"
const double M_PI = 3.14159265358979323846;
TheOuterEndBiomeDecorator::TheOuterEndBiomeDecorator(Biome *biome) : BiomeDecorator(biome)
{
endGatewayFeature = new EndGatewayFeature(Tile::unbreakable_Id);
}
void TheOuterEndBiomeDecorator::decorate()
{
decorateOres();
// this will only set the y to the top y of the chunks already processed...
int y = level->getTopSolidBlock(xo+8, zo+8);
if(y>level->GetHighestY()) level->SetHighestY(y);
if (xo == 0 && zo == 0)
{
for (int i = 0; i < 20; i++)
{
double angle = (2 * M_PI / 20) * i;
int gx = (int)(96 * cos(angle));
int gz = (int)(96 * sin(angle));
endGatewayFeature->place(level, random, gx, 75, gz);
}
}
}

View File

@@ -0,0 +1,12 @@
#include "BiomeDecorator.h"
#include "EndGatewayFeature.h"
class TheOuterEndBiomeDecorator : public BiomeDecorator
{
public:
TheOuterEndBiomeDecorator(Biome *biome);
protected:
EndGatewayFeature *endGatewayFeature;
virtual void decorate();
};

View File

@@ -0,0 +1,107 @@
#include "stdafx.h"
#include "TheOuterEndDimension.h"
#include "TheOuterEndLevelRandomLevelSource.h"
#include "FixedBiomeSource.h"
#include "net.minecraft.world.level.levelgen.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "..\Minecraft.Client\Minecraft.h"
#include "..\Minecraft.Client\Common\Colours\ColourTable.h"
void TheOuterEndDimension::init()
{
biomeSource = new FixedBiomeSource(Biome::outerIslands, 0.5f, 0);
id = 2;
hasCeiling = true;
}
float TheOuterEndDimension::getTimeOfDay(int64_t time, float a) const
{
return 0.0f;
}
float *TheOuterEndDimension::getSunriseColor(float td, float a)
{
return nullptr;
}
Vec3 *TheOuterEndDimension::getFogColor(float td, float a) const
{
int fogColor = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_End_Fog_Colour ); //0xa080a0;
float br = Mth::cos(td * PI * 2) * 2 + 0.5f;
if (br < 0.0f) br = 0.0f;
if (br > 1.0f) br = 1.0f;
float r = ((fogColor >> 16) & 0xff) / 255.0f;
float g = ((fogColor >> 8) & 0xff) / 255.0f;
float b = ((fogColor) & 0xff) / 255.0f;
r *= br * 0.0f + 0.15f;
g *= br * 0.0f + 0.15f;
b *= br * 0.0f + 0.15f;
return Vec3::newTemp(r, g, b);
}
bool TheOuterEndDimension::hasGround()
{
return false;
}
bool TheOuterEndDimension::mayRespawn() const
{
return false;
}
bool TheOuterEndDimension::isNaturalDimension()
{
return false;
}
float TheOuterEndDimension::getCloudHeight()
{
return 8;
}
bool TheOuterEndDimension::isValidSpawn(int x, int z) const
{
int topTile = level->getTopTile(x, z);
if (topTile == 0) return false;
return Tile::tiles[topTile]->material->blocksMotion();
}
Pos *TheOuterEndDimension::getSpawnPos()
{
return new Pos(0, 80, 0);
}
ChunkSource *TheOuterEndDimension::createRandomLevelSource() const
{
if (level == nullptr)
{
return nullptr; // prevents crashes if init order is wrong
}
return new TheOuterEndLevelRandomLevelSource(level, level->getSeed());
}
bool TheOuterEndDimension::isFoggyAt(int x, int z)
{
return false;
}
int TheOuterEndDimension::getSpawnYPosition()
{
return 50;
}
void TheOuterEndDimension::updateLightRamp()
{
float ambientLight = 0.10f;
for (int i = 0; i <= Level::MAX_BRIGHTNESS; i++)
{
float v = (1 - i / (float) (Level::MAX_BRIGHTNESS));
brightnessRamp[i] = ((1 - v) / (v * 3 + 1)) * (1 - ambientLight) + ambientLight;
}
}

View File

@@ -0,0 +1,23 @@
#pragma once
#include "Dimension.h"
class TheOuterEndDimension : public Dimension
{
public:
virtual void init();
virtual ChunkSource *createRandomLevelSource() const;
virtual float getTimeOfDay(int64_t time, float a) const;
virtual float *getSunriseColor(float td, float a);
virtual Vec3 *getFogColor(float td, float a) const;
virtual bool hasGround();
virtual bool mayRespawn() const;
virtual bool isNaturalDimension();
virtual float getCloudHeight();
virtual bool isValidSpawn(int x, int z) const;
virtual Pos *getSpawnPos();
virtual int getSpawnYPosition();
virtual bool isFoggyAt(int x, int z);
protected:
virtual void updateLightRamp();
};

View File

@@ -0,0 +1,415 @@
#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 "TheOuterEndLevelRandomLevelSource.h"
TheOuterEndLevelRandomLevelSource::TheOuterEndLevelRandomLevelSource(Level *level, int64_t seed)
{
m_XZSize = END_LEVEL_MIN_WIDTH;
this->level = level;
random = new Random(seed);
pprandom = new Random(seed); // 4J added
lperlinNoise1 = new PerlinNoise(random, 16);
lperlinNoise2 = new PerlinNoise(random, 16);
perlinNoise1 = new PerlinNoise(random, 8);
scaleNoise = new PerlinNoise(random, 10);
depthNoise = new PerlinNoise(random, 16);
}
TheOuterEndLevelRandomLevelSource::~TheOuterEndLevelRandomLevelSource()
{
delete random;
delete pprandom;
delete lperlinNoise1;
delete lperlinNoise2;
delete perlinNoise1;
delete scaleNoise;
delete depthNoise;
}
void TheOuterEndLevelRandomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks, BiomeArray biomes)
{
doubleArray buffer; // 4J - used to be declared with class level scope but tidying up for thread safety reasons
int xChunks = 16 / CHUNK_WIDTH;
int xSize = xChunks + 1;
int ySize = Level::genDepth / CHUNK_HEIGHT + 1;
int zSize = xChunks + 1;
buffer = getHeights(buffer, xOffs * xChunks, 0, zOffs * xChunks, xSize, ySize, zSize);
for (int xc = 0; xc < xChunks; xc++)
{
for (int zc = 0; zc < xChunks; zc++)
{
for (int yc = 0; yc < Level::genDepth / CHUNK_HEIGHT; yc++)
{
double yStep = 1 / static_cast<double>(CHUNK_HEIGHT);
double s0 = buffer[((xc + 0) * zSize + (zc + 0)) * ySize + (yc + 0)];
double s1 = buffer[((xc + 0) * zSize + (zc + 1)) * ySize + (yc + 0)];
double s2 = buffer[((xc + 1) * zSize + (zc + 0)) * ySize + (yc + 0)];
double s3 = buffer[((xc + 1) * zSize + (zc + 1)) * ySize + (yc + 0)];
double s0a = (buffer[((xc + 0) * zSize + (zc + 0)) * ySize + (yc + 1)] - s0) * yStep;
double s1a = (buffer[((xc + 0) * zSize + (zc + 1)) * ySize + (yc + 1)] - s1) * yStep;
double s2a = (buffer[((xc + 1) * zSize + (zc + 0)) * ySize + (yc + 1)] - s2) * yStep;
double s3a = (buffer[((xc + 1) * zSize + (zc + 1)) * ySize + (yc + 1)] - s3) * yStep;
for (int y = 0; y < CHUNK_HEIGHT; y++)
{
double xStep = 1 / static_cast<double>(CHUNK_WIDTH);
double _s0 = s0;
double _s1 = s1;
double _s0a = (s2 - s0) * xStep;
double _s1a = (s3 - s1) * xStep;
for (int x = 0; x < CHUNK_WIDTH; x++)
{
int offs = (x + xc * CHUNK_WIDTH) << Level::genDepthBitsPlusFour | (0 + zc * CHUNK_WIDTH) << Level::genDepthBits | (yc * CHUNK_HEIGHT + y);
int step = 1 << Level::genDepthBits;
double zStep = 1 / static_cast<double>(CHUNK_WIDTH);
double val = _s0;
double vala = (_s1 - _s0) * zStep;
for (int z = 0; z < CHUNK_WIDTH; z++)
{
int tileId = 0;
if (val > 0)
{
tileId = Tile::endStone_Id;
} else {
}
blocks[offs] = static_cast<byte>(tileId);
offs += step;
val += vala;
}
_s0 += _s0a;
_s1 += _s1a;
}
s0 += s0a;
s1 += s1a;
s2 += s2a;
s3 += s3a;
}
}
}
}
delete [] buffer.data;
}
void TheOuterEndLevelRandomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, BiomeArray biomes)
{
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
int runDepth = 1;
int run = -1;
byte top = (byte) Tile::endStone_Id;
byte material = (byte) Tile::endStone_Id;
for (int y = Level::genDepthMinusOne; y >= 0; y--)
{
int offs = (z * 16 + x) * Level::genDepth + y;
int old = blocks[offs];
if (old == 0)
{
run = -1;
}
else if (old == Tile::stone_Id)
{
if (run == -1)
{
if (runDepth <= 0)
{
top = 0;
material = static_cast<byte>(Tile::endStone_Id);
}
run = runDepth;
if (y >= 0) blocks[offs] = top;
else blocks[offs] = material;
}
else if (run > 0)
{
run--;
blocks[offs] = material;
}
}
}
}
}
}
LevelChunk *TheOuterEndLevelRandomLevelSource::create(int x, int z)
{
return getChunk(x, z);
}
LevelChunk *TheOuterEndLevelRandomLevelSource::getChunk(int xOffs, int zOffs)
{
random->setSeed(xOffs * 341873128712l + zOffs * 132897987541l);
BiomeArray biomes;
// 4J - now allocating this with a physical alloc & bypassing general memory management so that it will get cleanly freed
unsigned int blocksSize = Level::genDepth * 16 * 16;
byte *tileData = static_cast<byte *>(XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE));
XMemSet128(tileData,0,blocksSize);
byteArray blocks = byteArray(tileData,blocksSize);
// byteArray blocks = byteArray(16 * level->depth * 16);
// LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); // 4J moved below
level->getBiomeSource()->getBiomeBlock(biomes, xOffs * 16, zOffs * 16, 16, 16, true);
prepareHeights(xOffs, zOffs, blocks, biomes);
buildSurfaces(xOffs, zOffs, blocks, biomes);
// 4J - this now creates compressed block data from the blocks array passed in, so moved it until after the blocks are actually finalised. We also
// now need to free the passed in blocks as the LevelChunk doesn't use the passed in allocation anymore.
LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs);
XPhysicalFree(tileData);
levelChunk->recalcHeightmap();
//delete blocks.data; // Don't delete the blocks as the array data is actually owned by the chunk now
delete biomes.data;
return levelChunk;
}
doubleArray TheOuterEndLevelRandomLevelSource::getHeights(doubleArray buffer, int x, int y, int z, int xSize, int ySize, int zSize)
{
if (buffer.data == nullptr)
{
buffer = doubleArray(xSize * ySize * zSize);
}
double s = 1 * 684.412;
double hs = 1 * 684.412;
doubleArray pnr, ar, br, sr, dr, fi, fis; // 4J - used to be declared with class level scope but moved here for thread safety
sr = scaleNoise->getRegion(sr, x, z, xSize, zSize, 1.121, 1.121, 0.5);
dr = depthNoise->getRegion(dr, x, z, xSize, zSize, 200.0, 200.0, 0.5);
s *= 2;
pnr = perlinNoise1->getRegion(pnr, x, y, z, xSize, ySize, zSize, s / 80.0, hs / 160.0, s / 80.0);
ar = lperlinNoise1->getRegion(ar, x, y, z, xSize, ySize, zSize, s, hs, s);
br = lperlinNoise2->getRegion(br, x, y, z, xSize, ySize, zSize, s, hs, s);
int p = 0;
int pp = 0;
for (int xx = 0; xx < xSize; xx++)
{
for (int zz = 0; zz < zSize; zz++)
{
double scale = ((sr[pp] + 256.0) / 512);
if (scale > 1) scale = 1;
double depth = (dr[pp] / 8000.0);
if (depth < 0) depth = -depth * 0.3;
depth = depth * 3.0 - 2.0;
if (depth > 1) depth = 1;
depth = depth / 8;
depth = 0;
if (scale < 0) scale = 0;
scale = scale + 0.5;
depth = depth * ySize / 16;
pp++;
double yCenter = ySize / 2.0;
for (int yy = 0; yy < ySize; yy++)
{
double val = 0;
double yOffs = (yy - yCenter) * 8 / scale;
if (yOffs < 0) yOffs *= -1;
double bb = ar[p] / 512;
double cc = br[p] / 512;
double v = (pnr[p] / 10 + 1) / 2;
if (v < 0) val = bb;
else if (v > 1) val = cc;
else val = bb + (cc - bb) * v;
val -= 8;
val -= yOffs * 0.05;
// keep top/bottom fadeout from The End generator so islands stay floating
int r = 2;
if (yy > ySize / 2 - r)
{
double slide = (yy - (ySize / 2 - r)) / 64.0f;
if (slide < 0) slide = 0;
if (slide > 1) slide = 1;
val = val * (1 - slide) + -3000 * slide;
}
r = 8;
if (yy < r)
{
double slide = (r - yy) / (r - 1.0f);
val = val * (1 - slide) + -30 * slide;
}
buffer[p] = val;
p++;
}
}
}
delete [] pnr.data;
delete [] ar.data;
delete [] br.data;
delete [] sr.data;
delete [] dr.data;
delete [] fi.data;
delete [] fis.data;
return buffer;
}
bool TheOuterEndLevelRandomLevelSource::hasChunk(int x, int y)
{
return true;
}
void TheOuterEndLevelRandomLevelSource::calcWaterDepths(ChunkSource *parent, int xt, int zt)
{
int xo = xt * 16;
int zo = zt * 16;
for (int x = 0; x < 16; x++)
{
int y = level->getSeaLevel();
for (int z = 0; z < 16; z++)
{
int xp = xo + x + 7;
int zp = zo + z + 7;
int h = level->getHeightmap(xp, zp);
if (h <= 0)
{
if (level->getHeightmap(xp - 1, zp) > 0 || level->getHeightmap(xp + 1, zp) > 0 || level->getHeightmap(xp, zp - 1) > 0 || level->getHeightmap(xp, zp + 1) > 0)
{
bool hadWater = false;
if (hadWater || (level->getTile(xp - 1, y, zp) == Tile::calmWater_Id && level->getData(xp - 1, y, zp) < 7)) hadWater = true;
if (hadWater || (level->getTile(xp + 1, y, zp) == Tile::calmWater_Id && level->getData(xp + 1, y, zp) < 7)) hadWater = true;
if (hadWater || (level->getTile(xp, y, zp - 1) == Tile::calmWater_Id && level->getData(xp, y, zp - 1) < 7)) hadWater = true;
if (hadWater || (level->getTile(xp, y, zp + 1) == Tile::calmWater_Id && level->getData(xp, y, zp + 1) < 7)) hadWater = true;
if (hadWater)
{
for (int x2 = -5; x2 <= 5; x2++)
{
for (int z2 = -5; z2 <= 5; z2++)
{
int d = (x2 > 0 ? x2 : -x2) + (z2 > 0 ? z2 : -z2);
if (d <= 5)
{
d = 6 - d;
if (level->getTile(xp + x2, y, zp + z2) == Tile::calmWater_Id)
{
int od = level->getData(xp + x2, y, zp + z2);
if (od < 7 && od < d)
{
level->setData(xp + x2, y, zp + z2, d, Tile::UPDATE_CLIENTS);
}
}
}
}
}
if (hadWater)
{
level->setTileAndData(xp, y, zp, Tile::calmWater_Id, 7, Tile::UPDATE_CLIENTS);
for (int y2 = 0; y2 < y; y2++)
{
level->setTileAndData(xp, y2, zp, Tile::calmWater_Id, 8, Tile::UPDATE_CLIENTS);
}
}
}
}
}
}
}
}
void TheOuterEndLevelRandomLevelSource::postProcess(ChunkSource *parent, int xt, int zt)
{
HeavyTile::instaFall = true;
int xo = xt * 16;
int zo = zt * 16;
// 4J - added. The original java didn't do any setting of the random seed here, and passes the level random to the biome decorator.
// We'll be running our postProcess in parallel with getChunk etc. so we need to use a separate random - have used the same initialisation code as
// used in RandomLevelSource::postProcess to make sure this random value is consistent for each world generation.
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());
Biome *biome = level->getBiome(xo + 16, zo + 16);
biome->decorate(level, pprandom, xo, zo); // 4J - passing pprandom rather than level->random here to make this consistent with our parallel world generation
HeavyTile::instaFall = false;
app.processSchematics(parent->getChunk(xt,zt));
}
bool TheOuterEndLevelRandomLevelSource::save(bool force, ProgressListener *progressListener)
{
return true;
}
bool TheOuterEndLevelRandomLevelSource::tick()
{
return false;
}
bool TheOuterEndLevelRandomLevelSource::shouldSave()
{
return true;
}
wstring TheOuterEndLevelRandomLevelSource::gatherStats()
{
return L"RandomLevelSource";
}
vector<Biome::MobSpawnerData *> *TheOuterEndLevelRandomLevelSource::getMobsAt(MobCategory *mobCategory, int x, int y, int z)
{
Biome *biome = level->getBiome(x, z);
if (biome == nullptr)
{
return nullptr;
}
return biome->getMobs(mobCategory);
}
TilePos *TheOuterEndLevelRandomLevelSource::findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z)
{
return nullptr;
}
void TheOuterEndLevelRandomLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ)
{
}

View File

@@ -0,0 +1,61 @@
#pragma once
#include "ChunkSource.h"
class PerlinNoise;
class TheOuterEndLevelRandomLevelSource : public ChunkSource
{
public:
static const double SNOW_CUTOFF;
static const double SNOW_SCALE;
static const bool FLOATING_ISLANDS;
static const int CHUNK_HEIGHT = 4;
static const int CHUNK_WIDTH = 8;
private:
Random *random;
Random *pprandom;
private:
PerlinNoise *lperlinNoise1;
PerlinNoise *lperlinNoise2;
PerlinNoise *perlinNoise1;
public:
PerlinNoise *scaleNoise;
PerlinNoise *depthNoise;
PerlinNoise *forestNoise;
private:
Level *level;
public:
TheOuterEndLevelRandomLevelSource(Level *level, int64_t seed);
~TheOuterEndLevelRandomLevelSource();
void prepareHeights(int xOffs, int zOffs, byteArray blocks, BiomeArray biomes);
void buildSurfaces(int xOffs, int zOffs, byteArray blocks, BiomeArray biomes);
public:
virtual LevelChunk *create(int x, int z);
virtual LevelChunk *getChunk(int xOffs, int zOffs);
private:
doubleArray getHeights(doubleArray buffer, int x, int y, int z, int xSize, int ySize, int zSize);
public:
virtual bool hasChunk(int x, int y);
private:
void calcWaterDepths(ChunkSource *parent, int xt, int zt);
public:
virtual void postProcess(ChunkSource *parent, int xt, int zt);
virtual bool save(bool force, ProgressListener *progressListener);
virtual bool tick();
virtual bool shouldSave();
virtual wstring gatherStats();
public:
virtual vector<Biome::MobSpawnerData *> *getMobsAt(MobCategory *mobCategory, int x, int y, int z);
virtual TilePos *findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z);
virtual void recreateLogicStructuresForChunk(int chunkX, int chunkZ);
};