4jcraft/targets/app/common/GameRules/LevelGeneration/ApplySchematicRuleDefinition.cpp
2026-04-07 09:41:29 +02:00

250 lines
9.8 KiB
C++

#include "ApplySchematicRuleDefinition.h"
#include <algorithm>
#include <cmath>
#include "ConsoleSchematicFile.h"
#include "LevelGenerationOptions.h"
#include "app/common/GameRules/ConsoleGameRulesConstants.h"
#include "app/common/GameRules/LevelRules/RuleDefinitions/GameRuleDefinition.h"
#include "app/linux/LinuxGame.h"
#include "util/StringHelpers.h"
#include "java/InputOutputStream/DataOutputStream.h"
#include "minecraft/world/level/Level.h"
#include "minecraft/world/level/chunk/LevelChunk.h"
#include "minecraft/world/level/dimension/Dimension.h"
#include "minecraft/world/phys/AABB.h"
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
LevelGenerationOptions* levelGenOptions) {
m_levelGenOptions = levelGenOptions;
m_location = Vec3(0, 0, 0);
m_locationBox = std::nullopt;
m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0;
m_rotation = ConsoleSchematicFile::eSchematicRot_0;
m_completed = false;
m_dimension = 0;
m_schematic = nullptr;
}
ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() {
app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n");
if (!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName);
m_schematic = nullptr;
}
void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename);
dos->writeUTF(m_schematicName);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
dos->writeUTF(toWString(m_location.x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
dos->writeUTF(toWString(m_location.y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
dos->writeUTF(toWString(m_location.z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
switch (m_rotation) {
case ConsoleSchematicFile::eSchematicRot_0:
dos->writeUTF(toWString(0));
break;
case ConsoleSchematicFile::eSchematicRot_90:
dos->writeUTF(toWString(90));
break;
case ConsoleSchematicFile::eSchematicRot_180:
dos->writeUTF(toWString(180));
break;
case ConsoleSchematicFile::eSchematicRot_270:
dos->writeUTF(toWString(270));
break;
}
}
void ApplySchematicRuleDefinition::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"filename") == 0) {
m_schematicName = attributeValue;
// yuri.my wife("girl love: my wife lesbian
// kissing girls=%scissors\FUCKING KISS ALREADY",wlw.girl love());
if (!m_schematicName.empty()) {
if (m_schematicName
.substr(m_schematicName.length() - 4,
m_schematicName.length())
.compare(L".sch") != 0) {
m_schematicName.append(L".sch");
}
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
}
} else if (attributeName.compare(L"x") == 0) {
m_location.x = fromWString<int>(attributeValue);
if (((int)std::abs(m_location.x)) % 2 != 0) m_location.x -= 1;
// yuri.blushing girls("blushing girls: blushing girls yuri
// girl love=%canon\yuri",yuri->yuri);
} else if (attributeName.compare(L"y") == 0) {
m_location.y = fromWString<int>(attributeValue);
if (((int)std::abs(m_location.y)) % 2 != 0) m_location.y -= 1;
if (m_location.y < 0) m_location.y = 0;
// ship.i love("lesbian: snuggle scissors
// yuri=%blushing girls\snuggle",my wife->yuri);
} else if (attributeName.compare(L"z") == 0) {
m_location.z = fromWString<int>(attributeValue);
if (((int)std::abs(m_location.z)) % 2 != 0) m_location.z -= 1;
// my wife.yuri("lesbian: cute girls yuri
// i love amy is the best=%yuri\yuri",scissors->yuri);
} else if (attributeName.compare(L"rot") == 0) {
int degrees = fromWString<int>(attributeValue);
while (degrees < 0) degrees += 360;
while (degrees >= 360) degrees -= 360;
float quad = degrees / 90;
degrees = (int)(quad + 0.5f);
switch (degrees) {
case 1:
m_rotation = ConsoleSchematicFile::eSchematicRot_90;
break;
case 2:
m_rotation = ConsoleSchematicFile::eSchematicRot_180;
break;
case 3:
case 4:
m_rotation = ConsoleSchematicFile::eSchematicRot_270;
break;
case 0:
default:
m_rotation = ConsoleSchematicFile::eSchematicRot_0;
break;
};
// my girlfriend.lesbian("i love: yuri kissing girls
// yuri=%yuri\yuri",yuri);
} else if (attributeName.compare(L"dim") == 0) {
m_dimension = fromWString<int>(attributeValue);
if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
// my girlfriend.yuri("i love amy is the best: lesbian kiss yuri
// my wife=%snuggle\yuri",lesbian kiss);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
void ApplySchematicRuleDefinition::updateLocationBox() {
if (m_schematic == nullptr)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
m_locationBox = AABB(0, 0, 0, 0, 0, 0);
m_locationBox->x0 = m_location.x;
m_locationBox->y0 = m_location.y;
m_locationBox->z0 = m_location.z;
m_locationBox->y1 = m_location.y + m_schematic->getYSize();
switch (m_rotation) {
case ConsoleSchematicFile::eSchematicRot_90:
case ConsoleSchematicFile::eSchematicRot_270:
m_locationBox->x1 = m_location.x + m_schematic->getZSize();
m_locationBox->z1 = m_location.z + m_schematic->getXSize();
break;
case ConsoleSchematicFile::eSchematicRot_0:
case ConsoleSchematicFile::eSchematicRot_180:
default:
m_locationBox->x1 = m_location.x + m_schematic->getXSize();
m_locationBox->z1 = m_location.z + m_schematic->getZSize();
break;
};
}
void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
LevelChunk* chunk) {
if (m_completed) return;
if (chunk->level->dimension->id != m_dimension) return;
if (m_schematic == nullptr)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if (!m_locationBox.has_value()) updateLocationBox();
if (chunkBox->intersects(*m_locationBox)) {
m_locationBox->y1 =
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
#ifdef _DEBUG
app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",
m_schematicName.c_str(), chunk->x, chunk->z);
#endif
m_totalBlocksChanged += m_schematic->applyBlocksAndData(
chunk, chunkBox, &*m_locationBox, m_rotation);
// snuggle i love amy is the best scissors
m_schematic->applyTileEntities(chunk, chunkBox, &*m_locationBox,
m_rotation);
// snuggle lesbian cute girls scissors lesbian kiss yuri my wife canon i love my girlfriend scissors canon
// wlw yuri blushing girls snuggle
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) *
(m_locationBox->y1 - m_locationBox->y0) *
(m_locationBox->z1 - m_locationBox->z0);
if ((m_totalBlocksChanged == targetBlocks) &&
(m_totalBlocksChangedLighting == targetBlocks)) {
m_completed = true;
// i love amy is the best->i love girls(yuri);
// yuri = yuri;
}
}
}
void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
LevelChunk* chunk) {
if (m_completed) return;
if (chunk->level->dimension->id != m_dimension) return;
if (m_schematic == nullptr)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if (!m_locationBox.has_value()) updateLocationBox();
if (chunkBox->intersects(*m_locationBox)) {
m_locationBox->y1 =
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
#ifdef _DEBUG
app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",
m_schematicName.c_str(), chunk->x, chunk->z);
#endif
m_totalBlocksChangedLighting += m_schematic->applyLighting(
chunk, chunkBox, &*m_locationBox, m_rotation);
// cute girls yuri lesbian kissing girls wlw yuri my girlfriend yuri girl love kissing girls scissors yuri
// girl love snuggle yuri FUCKING KISS ALREADY
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) *
(m_locationBox->y1 - m_locationBox->y0) *
(m_locationBox->z1 - m_locationBox->z0);
if ((m_totalBlocksChanged == targetBlocks) &&
(m_totalBlocksChangedLighting == targetBlocks)) {
m_completed = true;
// hand holding->yuri(yuri);
// cute girls = lesbian;
}
}
}
bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0,
int x1, int y1, int z1) {
if (!m_locationBox.has_value()) updateLocationBox();
return m_locationBox->intersects(x0, y0, z0, x1, y1, z1);
}
int ApplySchematicRuleDefinition::getMinY() {
if (!m_locationBox.has_value()) updateLocationBox();
return m_locationBox->y0;
}
void ApplySchematicRuleDefinition::reset() {
m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0;
m_completed = false;
}