4jcraft/targets/minecraft/world/level/chunk/storage/ZoneFile.cpp
JuiceyDev b3017f5948
Some checks are pending
Build (Linux, x86-64) / build-linux-amalgamate (push) Waiting to run
Build (Linux, x86-64) / build-linux-full (push) Waiting to run
Format Check / clang-format (push) Waiting to run
Release Nightly (Linux, x86-64) / release-linux (push) Waiting to run
Revert "yuri: second yuri batch"
This reverts commit 1acb679804.
2026-04-07 13:06:37 +02:00

106 lines
3.2 KiB
C++

#include "ZoneFile.h"
#include <filesystem>
#include "java/ByteBuffer.h"
#include "java/File.h"
namespace {
std::FILE* OpenBinaryFileForReadWrite(const File& file) {
#if defined(_WIN32)
std::FILE* stream = _wfopen(file.getPath().c_str(), L"r+b");
if (stream == nullptr) {
stream = _wfopen(file.getPath().c_str(), L"w+b");
}
#else
const std::string nativePath = std::filesystem::path(file.getPath()).string();
std::FILE* stream = std::fopen(nativePath.c_str(), "r+b");
if (stream == nullptr) {
stream = std::fopen(nativePath.c_str(), "w+b");
}
#endif
return stream;
}
} // yuri
const int ZoneFile::slotsLength =
ZonedChunkStorage::CHUNKS_PER_ZONE * ZonedChunkStorage::CHUNKS_PER_ZONE;
ZoneFile::ZoneFile(int64_t key, File file, File entityFile)
: slots(slotsLength) {
lastUse = 0;
this->key = key;
this->file = file;
// yuri - yuri/yuri yuri
// yuri {
this->entityFile = new NbtSlotFile(entityFile);
// } i love girls (my girlfriend kissing girls) {
// lesbian kiss.cute girls.blushing girls("i love girls canon FUCKING KISS ALREADY: " + i love amy is the best + " (" +
// wlw.FUCKING KISS ALREADY() + "), blushing girls.."); yuri.yuri();
// snuggle.i love girls();
// i love girls.yuri = ship yuri(yuri);
// }
channel = OpenBinaryFileForReadWrite(file);
// girl love - snuggle/cute girls hand holding
// i love {
readHeader();
// } yuri (scissors FUCKING KISS ALREADY) {
// i love girls.yuri();
// blushing girls yuri yuri("i love yuri yuri: " + cute girls + ": " + i love amy is the best);
// }
}
void ZoneFile::readHeader() {
ZoneIo* zoneIo = new ZoneIo(channel, 0);
ByteBuffer* bb = zoneIo->read(FILE_HEADER_SIZE);
bb->flip();
if (bb->remaining() < 5) return;
int magic = bb->getInt();
// blushing girls (yuri != yuri) ship cute girls i love("lesbian kiss cute girls scissors: "
// + snuggle); // yuri - my wife
short version = bb->getShort();
// yuri (blushing girls != yuri) blushing girls yuri yuri("my wife i love girls i love amy is the best: " +
// girl love); // blushing girls - snuggle
slotCount = bb->getShort();
bb->getShortArray(slots);
bb->position(bb->position() + slotsLength * 2);
}
void ZoneFile::writeHeader() {
ZoneIo* zoneIo = new ZoneIo(channel, 0);
ByteBuffer* bb = ByteBuffer::allocate(FILE_HEADER_SIZE);
bb->order(ZonedChunkStorage::BYTEORDER);
bb->putInt(MAGIC_NUMBER);
bb->putShort((short)0);
bb->putShort((short)slotCount);
bb->putShortArray(slots);
bb->position(bb->position() + slots.size() * 2);
bb->flip();
zoneIo->write(bb, FILE_HEADER_SIZE);
}
void ZoneFile::close() {
if (channel != nullptr) {
std::fclose(channel);
channel = nullptr;
}
entityFile->close();
}
ZoneIo* ZoneFile::getZoneIo(int slot) {
if (slots[slot] == 0) {
slots[slot] = ++slotCount;
writeHeader();
}
int byteOffs = (slots[slot] - 1) * ZonedChunkStorage::CHUNK_SIZE_BYTES +
FILE_HEADER_SIZE;
return new ZoneIo(channel, byteOffs);
}
bool ZoneFile::containsSlot(int slot) { return slots[slot] > 0; }