Skip to content
Open
181 changes: 90 additions & 91 deletions data/mcswitch_functions.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include "Minecraft.Client/net/minecraft/client/multiplayer/ClientChunkCache.h"
#include "net/minecraft/world/level/Level.h"
#include "net/minecraft/world/level/block/Blocks.h"
#include "net/minecraft/world/level/dimension/Dimension.h"
#include "net/minecraft/world/level/dimension/DimensionType.h"
#include "net/minecraft/world/level/levelgen/ChunkPrimer.h"
#include "net/minecraft/world/level/storage/LevelData.h"

// NON_MATCHING | Score: 16235 (lower is better)
ClientChunkCache::ClientChunkCache(Level* lvl) : m_chunkPos(ChunkPos(0, 0)) {
this->unk3 = nullptr;
this->unk9 = nullptr;
this->unk10 = nullptr;
this->unk10 = nullptr;
this->unk11 = nullptr;
this->unk12 = nullptr;
this->unk13 = nullptr;
this->unk14 = nullptr;
this->unk16 = nullptr;
this->unk17 = nullptr;
this->unk18 = nullptr;
this->unk19 = nullptr;
this->unk20 = nullptr;
this->unk21 = nullptr;

int bounds;

int xzSize = lvl->mDimension->getXZSize();
if (xzSize >= 0)
bounds = xzSize;
else
bounds = xzSize + 1;

this->m_xzSize2 = xzSize;
this->unk27 = bounds >> 1;
this->mXZSize = xzSize;

this->unk28 = new char[xzSize * xzSize];
memset(this->unk28, 0, this->m_xzSize2 * this->m_xzSize2);

this->m_emptyChunk = new EmptyLevelChunk(lvl, 0, 0);
this->unk1 = nullptr;
this->unk4 = 0;
this->unk2 = nullptr;

if (lvl->mDimension->getType() == DimensionType::OVERWORLD) {
arrayWithLength<unsigned char> blocks = arrayWithLength<unsigned char>(0x8000u, true);
arrayWithLength<unsigned char> data = arrayWithLength<unsigned char>(0x4000u, true);

LevelData* dat = lvl->getLevelData();
if (dat->getGeneratorType() == LevelType::FLAT) { // If flat world
for (int x = 0; x != 16; ++x) // from 0 to 16 chunk coords x
{
for (int y = 0; y != 128; ++y) // from 0 to 128 chunk coords y (old height limit)
{
if (y == 3) // if y is 3, which is the grass layer height on a superflat world
{
for (int z = 0; z != 16; z++) // from 0 to 16 chunk coords z
{
blocks[y | (x << 11) | (z << 7)] = Blocks::GRASS->getId(); // place a grass block
}
} else if (y > 2) // if y is larger than 2, but not 3, we are above the topmost layer of
// the superflat world
{
for (int z = 0; z != 16; z++) { // from 0 to 16 chunk coords z
blocks[y | (x << 11) | (z << 7)] = 0; // place an air block
}
} else // otherwise, y is below the grass layer
{
for (int z = 0; z != 16; z++) // from 0 to 16 chunk coords z
{
blocks[y | (x << 11) | (z << 7)] = Blocks::DIRT->getId(); // place a dirt block
}
}
}
}
} else { // otherwise, we're in a normal generator (e.g. Default, Large Biomes)
for (int z = 0; z != 16; ++z) // from 0 to 16 chunk coords z
{
for (int y = 0; y != 128; ++y) // from 0 to 128 chunk coords y (old height limit)
{
for (int x = 0; x != 16; ++x) // from 0 to 16 chunk coords x
{
int sl = lvl->getSeaLevel(); // get sea level
int id;

// TODO can't get this to look neat without mismatching
Block* blk = Blocks::STONE; // default block is stone

// if we are above 10 blocks below sea level, set the block to water, then check if y
// is higher than sea level if it is, we will fall through to set ID to 0, which is
// AIR otherwise, blk is now water, so we will fall through and get the ID of our
// water block
if (y > sl - 10 && (blk = Blocks::WATER, y >= sl))
id = 0; // set block to air
else
id = blk->getId(); // set block to Water, if between sea level and 10 blocks
// below sea level, otherwise Stone.

blocks[y | (z << 11) | (x << 7)] = id; // set the ID in the array
}
}
}
}

ChunkPrimer primer = ChunkPrimer(false, blocks, data);
this->m_waterChunk = new WaterLevelChunk(lvl, &primer, 0, 0);

delete blocks.data;
delete data.data;

// sets skylight
if (dat->getGeneratorType() == LevelType::FLAT) {
for (int x = 0; x != 16; x++) { // from 0 to 16 chunk coords x
for (int y = 0; y != 128; y++) { // from 0 to 128 chunk coords y (old world height)
if (y
>= 3) { // if y is bigger or equal to 3, which is any block at or above the top block
for (int z = 0; z != 16; z++) { // from 0 to 16 chunk coords z
m_waterChunk->setLevelChunkBrightness(LightLayer::SKY, x, y, z,
15); // set light level to 16
}
}
}
}
} else {
for (int x = 0; x != 16; x++) { // from 0 to 16 chunk coords x
for (int y = 0; y != 128; y++) { // from 0 to 128 chunk coords y (old world height)
for (int z = 0; z != 16; z++) { // from 0 to 16 chunk coords z
int brightness = 2; // underwater/in-block brightness

if (y >= lvl->getSeaLevel() - 1) // if we are above the sea level minus 1
brightness = 15; // set our brightness to max, as this is skylight

m_waterChunk->setLevelChunkBrightness(LightLayer::SKY, x, y, z,
brightness); // set the brightness
}
}
}
}
} else {
this->m_waterChunk = nullptr; // no need for a water chunk when not in the overworld
}

this->m_level = lvl;
this->m_dimension = lvl->mDimension;

this->unk15 = new char[8 * (this->m_xzSize2 * this->m_xzSize2)];
memset(this->unk15, 0, 8 * (this->m_xzSize2 * this->m_xzSize2));

InitializeCriticalSectionAndSpinCount(&this->m_mutex, 0);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include "net/minecraft/world/level/chunk/ChunkPos.h"
#include "net/minecraft/world/level/chunk/ChunkSource.h"
#include "net/minecraft/world/level/chunk/EmptyLevelChunk.h"
#include "net/minecraft/world/level/chunk/WaterLevelChunk.h"
#include "net/minecraft/world/level/dimension/Dimension.h"

class ChunkStorage;

Expand Down Expand Up @@ -28,6 +32,38 @@ class ClientChunkCache : public ChunkSource {
int getLoadedChunks() override;
void recreateLogicStructuresForChunk(LevelChunk*, int, int) override;

private:
char size[0x110 - sizeof(ChunkSource)];
EmptyLevelChunk* m_emptyChunk;
WaterLevelChunk* m_waterChunk;

void* unk1;
void* unk2;

ChunkPos m_chunkPos;

void* unk3;
int unk4;
int unk45;
void* unk5;
void* unk6;
void* unk7;
void* unk8;
void* unk9;
void* unk10;
void* unk11;
void* unk12;
void* unk13;
void* unk14;
char* unk15;
void* unk16;
void* unk17;
void* unk18;
void* unk19;
void* unk20;
void* unk21;
nn::os::MutexType m_mutex;
int m_xzSize2;
int unk27;
char* unk28;
Level* m_level;
Dimension* m_dimension;
};
3 changes: 3 additions & 0 deletions src/Minecraft.Client/net/minecraft/client/ui/xui/eXuiAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

enum eXuiAction {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

enum eXuiServerAction {};
10 changes: 5 additions & 5 deletions src/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class LevelChunk {
virtual Block* getBlock(const BlockPos&);
virtual const BlockState* getBlockState(const BlockPos&);
virtual void getData(const BlockPos&);
virtual void setData(int, int, int, int, int, bool*);
virtual void setBlock(const BlockPos&, const BlockState*);
virtual void setBlockAndData(int, int, int, int, int, bool);
virtual bool setData(int, int, int, int, int, bool*);
virtual const BlockState* setBlock(const BlockPos&, const BlockState*);
virtual bool setBlockAndData(int, int, int, int, int, bool);
virtual int getBrightness(LightLayer::variety, const BlockPos&);
virtual void getNeighbourBrightnesses(int*, LightLayer::variety, int, int, int);
virtual void setBrightness(LightLayer::variety, const BlockPos&, int);
Expand All @@ -84,14 +84,14 @@ class LevelChunk {
virtual void removeBlockEntity(const BlockPos&);
virtual void load(bool);
virtual void unload(bool, bool);
virtual void containsPlayer();
virtual bool containsPlayer();
virtual void field_160();
virtual void markUnsaved();
virtual void getEntities(std::shared_ptr<Entity>, AABB const*, std::vector<std::shared_ptr<Entity>>&,
const Predicate<std::shared_ptr<Entity>>*);
virtual void getEntitiesOfClass(const std::type_info&, AABB const*, std::vector<std::shared_ptr<Entity>>&,
const Predicate<std::shared_ptr<Entity>>*, bool);
virtual void countEntities();
virtual int countEntities();
virtual bool shouldSave(bool);
virtual void getBlocksAndData(arrayWithLength<unsigned char>*, int, int, int, int, int, int, int, bool);
virtual void setBlocksAndData(arrayWithLength<unsigned char>, int, int, int, int, int, int, int, bool);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.h"
#include "net/minecraft/core/BlockPos.h"

void WaterLevelChunk::reSyncLighting() {}
void WaterLevelChunk::dropLighting() {}
void WaterLevelChunk::recalcBlockLights() {}
void WaterLevelChunk::recalcHeightmapOnly() {}
void WaterLevelChunk::recalcHeightmap() {}
void WaterLevelChunk::lightLava() {}
bool WaterLevelChunk::setData(int i, int i1, int i2, int i3, int i4, bool* p) {
*p = true;
return true;
}

const BlockState* WaterLevelChunk::setBlock(const BlockPos& block_pos, const BlockState* block_state) {
return block_state;
}
bool WaterLevelChunk::setBlockAndData(int i, int i1, int i2, int i3, int i4, bool cond) {
return true;
}
void WaterLevelChunk::setBrightness(LightLayer::variety variety, const BlockPos& block_pos, int i) {}
void WaterLevelChunk::addEntity(std::shared_ptr<Entity> entity) {}
void WaterLevelChunk::removeEntity(std::shared_ptr<Entity> entity) {}
void WaterLevelChunk::removeEntity(std::shared_ptr<Entity> entity, int i) {}
void WaterLevelChunk::addBlockEntity(std::shared_ptr<BlockEntity> block_entity) {}
void WaterLevelChunk::setBlockEntity(const BlockPos& block_pos, std::shared_ptr<BlockEntity> block_entity) {}
void WaterLevelChunk::removeBlockEntity(const BlockPos& block_pos) {}
void WaterLevelChunk::load(bool cond) {}
void WaterLevelChunk::unload(bool cond, bool cond1) {}
bool WaterLevelChunk::containsPlayer() {
return false;
}

void WaterLevelChunk::markUnsaved() {}
void WaterLevelChunk::getEntities(std::shared_ptr<Entity> entity, AABB const* aabb,
std::vector<std::shared_ptr<Entity>>& shared_ptrs,
const Predicate<std::shared_ptr<Entity>>* predicate) {}
void WaterLevelChunk::getEntitiesOfClass(const std::type_info& type_info, AABB const* aabb,
std::vector<std::shared_ptr<Entity>>& shared_ptrs,
const Predicate<std::shared_ptr<Entity>>* predicate, bool cond) {}
int WaterLevelChunk::countEntities() {
return 0;
}

bool WaterLevelChunk::shouldSave(bool) {
return false;
}

void WaterLevelChunk::setLevelChunkBrightness(LightLayer::variety variety, int x, int y, int z,
int brightness) {
LevelChunk::setBrightness(variety, BlockPos(x, y, z), brightness);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "net/minecraft/world/level/chunk/LevelChunk.h"

/** Immutable chunk holding only layers of air, water, and stone, */
class WaterLevelChunk : public LevelChunk {
public:
WaterLevelChunk(Level*, ChunkPrimer*, int, int);

void reSyncLighting() override;
void dropLighting() override;
void recalcBlockLights() override;
void recalcHeightmapOnly() override;
void recalcHeightmap() override;
void lightLava() override;
bool setData(int, int, int, int, int, bool*) override;
const BlockState* setBlock(const BlockPos&, const BlockState*) override;
bool setBlockAndData(int, int, int, int, int, bool) override;
void setBrightness(LightLayer::variety, const BlockPos&, int) override;
void addEntity(std::shared_ptr<Entity>) override;
void removeEntity(std::shared_ptr<Entity>) override;
void removeEntity(std::shared_ptr<Entity>, int) override;
void getBlockEntity(const BlockPos&, LevelChunk::EntityCreationType) override;
void addBlockEntity(std::shared_ptr<BlockEntity>) override;
void setBlockEntity(const BlockPos&, std::shared_ptr<BlockEntity>) override;
void removeBlockEntity(const BlockPos&) override;
void load(bool) override;
void unload(bool, bool) override;
bool containsPlayer() override;
void markUnsaved() override;
void getEntities(std::shared_ptr<Entity>, AABB const*, std::vector<std::shared_ptr<Entity>>&,
const Predicate<std::shared_ptr<Entity>>*) override;
void getEntitiesOfClass(const std::type_info&, AABB const*, std::vector<std::shared_ptr<Entity>>&,
const Predicate<std::shared_ptr<Entity>>*, bool) override;
int countEntities() override;
bool shouldSave(bool) override;
void setBlocksAndData(arrayWithLength<unsigned char>, int, int, int, int, int, int, int, bool) override;
void testSetBlocksAndData(arrayWithLength<unsigned char>, int, int, int, int, int, int, int) override;
void getRandom(long long) override;
Biome* getBiome(const BlockPos&, BiomeSource*) override;

void setLevelChunkBrightness(LightLayer::variety, int x, int y, int z, int brightness);
};