restructure codebase according to vcproj filters

This commit is contained in:
Tropical
2026-03-30 09:50:58 -05:00
parent d5cf90c713
commit 451682693e
3015 changed files with 46858 additions and 54635 deletions

View File

@@ -0,0 +1,254 @@
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
#include "../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "../../../../../Minecraft.World/net/minecraft/world/phys/net.minecraft.world.phys.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/net.minecraft.world.level.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/dimension/net.minecraft.world.level.dimension.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/chunk/net.minecraft.world.level.chunk.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/tile/entity/net.minecraft.world.level.tile.entity.h"
#include "ApplySchematicRuleDefinition.h"
#include "LevelGenerationOptions.h"
#include "ConsoleSchematicFile.h"
#include "../../../../../Minecraft.World/net/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(_toString(m_location.x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
dos->writeUTF(_toString(m_location.y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
dos->writeUTF(_toString(m_location.z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
switch (m_rotation) {
case ConsoleSchematicFile::eSchematicRot_0:
dos->writeUTF(_toString(0));
break;
case ConsoleSchematicFile::eSchematicRot_90:
dos->writeUTF(_toString(90));
break;
case ConsoleSchematicFile::eSchematicRot_180:
dos->writeUTF(_toString(180));
break;
case ConsoleSchematicFile::eSchematicRot_270:
dos->writeUTF(_toString(270));
break;
}
}
void ApplySchematicRuleDefinition::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"filename") == 0) {
m_schematicName = attributeValue;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// filename=%s\n",m_schematicName.c_str());
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 = _fromString<int>(attributeValue);
if (((int)abs(m_location.x)) % 2 != 0) m_location.x -= 1;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// x=%f\n",m_location->x);
} else if (attributeName.compare(L"y") == 0) {
m_location.y = _fromString<int>(attributeValue);
if (((int)abs(m_location.y)) % 2 != 0) m_location.y -= 1;
if (m_location.y < 0) m_location.y = 0;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// y=%f\n",m_location->y);
} else if (attributeName.compare(L"z") == 0) {
m_location.z = _fromString<int>(attributeValue);
if (((int)abs(m_location.z)) % 2 != 0) m_location.z -= 1;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// z=%f\n",m_location->z);
} else if (attributeName.compare(L"rot") == 0) {
int degrees = _fromString<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;
};
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// rot=%d\n",m_rotation);
} else if (attributeName.compare(L"dim") == 0) {
m_dimension = _fromString<int>(attributeValue);
if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// dimension=%d\n",m_dimension);
} 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;
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition");
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
PIXBeginNamedEvent(0, "Applying blocks and data");
m_totalBlocksChanged += m_schematic->applyBlocksAndData(
chunk, chunkBox, &*m_locationBox, m_rotation);
PIXEndNamedEvent();
// Add the tileEntities
PIXBeginNamedEvent(0, "Applying tile entities");
m_schematic->applyTileEntities(chunk, chunkBox, &*m_locationBox,
m_rotation);
PIXEndNamedEvent();
// TODO This does not take into account things that go outside the
// bounds of the world
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;
// m_levelGenOptions->releaseSchematicFile(m_schematicName);
// m_schematic = nullptr;
}
}
PIXEndNamedEvent();
}
void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
LevelChunk* chunk) {
if (m_completed) return;
if (chunk->level->dimension->id != m_dimension) return;
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)");
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
PIXBeginNamedEvent(0, "Patching lighting");
m_totalBlocksChangedLighting += m_schematic->applyLighting(
chunk, chunkBox, &*m_locationBox, m_rotation);
PIXEndNamedEvent();
// TODO This does not take into account things that go outside the
// bounds of the world
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;
// m_levelGenOptions->releaseSchematicFile(m_schematicName);
// m_schematic = nullptr;
}
}
PIXEndNamedEvent();
}
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;
}

View File

@@ -0,0 +1,56 @@
#pragma once
#include <optional>
#include "../LevelRules/RuleDefinitions/GameRuleDefinition.h"
#include "ConsoleSchematicFile.h"
#include "../../../../../Minecraft.World/net/minecraft/world/phys/AABB.h"
class AABB;
class Vec3;
class LevelChunk;
class LevelGenerationOptions;
class GRFObject;
class ApplySchematicRuleDefinition : public GameRuleDefinition {
private:
LevelGenerationOptions* m_levelGenOptions;
std::wstring m_schematicName;
ConsoleSchematicFile* m_schematic;
Vec3 m_location;
std::optional<AABB> m_locationBox;
ConsoleSchematicFile::ESchematicRotation m_rotation;
int m_dimension;
int64_t m_totalBlocksChanged;
int64_t m_totalBlocksChangedLighting;
bool m_completed;
void updateLocationBox();
public:
ApplySchematicRuleDefinition(LevelGenerationOptions* levelGenOptions);
~ApplySchematicRuleDefinition();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_ApplySchematic;
}
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
void processSchematic(AABB* chunkBox, LevelChunk* chunk);
void processSchematicLighting(AABB* chunkBox, LevelChunk* chunk);
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
int getMinY();
bool isComplete() { return m_completed; }
std::wstring getSchematicName() { return m_schematicName; }
/** 4J-JEV:
* This GameRuleDefinition contains limited game state.
* Reset any state to how it should be before a new game.
*/
void reset();
};

View File

@@ -0,0 +1,49 @@
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
#include "../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "BiomeOverride.h"
BiomeOverride::BiomeOverride() {
m_tile = 0;
m_topTile = 0;
m_biomeId = 0;
}
void BiomeOverride::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId);
dos->writeUTF(_toString(m_biomeId));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
dos->writeUTF(_toString(m_tile));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_topTileId);
dos->writeUTF(_toString(m_topTile));
}
void BiomeOverride::addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue) {
if (attributeName.compare(L"tileId") == 0) {
int value = _fromString<int>(attributeValue);
m_tile = value;
app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n", m_tile);
} else if (attributeName.compare(L"topTileId") == 0) {
int value = _fromString<int>(attributeValue);
m_topTile = value;
app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n",
m_topTile);
} else if (attributeName.compare(L"biomeId") == 0) {
int value = _fromString<int>(attributeValue);
m_biomeId = value;
app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n",
m_biomeId);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
bool BiomeOverride::isBiome(int id) { return m_biomeId == id; }
void BiomeOverride::getTileValues(std::uint8_t& tile, std::uint8_t& topTile) {
if (m_tile != 0) tile = m_tile;
if (m_topTile != 0) topTile = m_topTile;
}

View File

@@ -0,0 +1,25 @@
#pragma once
// using namespace std;
#include "../LevelRules/RuleDefinitions/GameRuleDefinition.h"
class BiomeOverride : public GameRuleDefinition {
private:
std::uint8_t m_topTile;
std::uint8_t m_tile;
int m_biomeId;
public:
BiomeOverride();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_BiomeOverride;
}
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool isBiome(int id);
void getTileValues(std::uint8_t& tile, std::uint8_t& topTile);
};

View File

@@ -0,0 +1,161 @@
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
#include "ConsoleGenerateStructure.h"
#include "../ConsoleGameRules.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/net.minecraft.world.level.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/dimension/net.minecraft.world.level.dimension.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/net.minecraft.world.level.levelgen.structure.h"
#include "../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "../../../../../Minecraft.World/net/minecraft/net.minecraft.h"
ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0) {
m_x = m_y = m_z = 0;
boundingBox = nullptr;
orientation = Direction::NORTH;
m_dimension = 0;
}
void ConsoleGenerateStructure::getChildren(
std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren(children);
for (auto it = m_actions.begin(); it != m_actions.end(); it++)
children->push_back(*it);
}
GameRuleDefinition* ConsoleGenerateStructure::addChild(
ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition* rule = nullptr;
if (ruleType == ConsoleGameRules::eGameRuleType_GenerateBox) {
rule = new XboxStructureActionGenerateBox();
m_actions.push_back((XboxStructureActionGenerateBox*)rule);
} else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock) {
rule = new XboxStructureActionPlaceBlock();
m_actions.push_back((XboxStructureActionPlaceBlock*)rule);
} else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer) {
rule = new XboxStructureActionPlaceContainer();
m_actions.push_back((XboxStructureActionPlaceContainer*)rule);
} else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner) {
rule = new XboxStructureActionPlaceSpawner();
m_actions.push_back((XboxStructureActionPlaceSpawner*)rule);
} else {
#ifndef _CONTENT_PACKAGE
wprintf(
L"ConsoleGenerateStructure: Attempted to add invalid child rule - "
L"%d\n",
ruleType);
#endif
}
return rule;
}
void ConsoleGenerateStructure::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
dos->writeUTF(_toString(m_x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
dos->writeUTF(_toString(m_y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
dos->writeUTF(_toString(m_z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation);
dos->writeUTF(_toString(orientation));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dimension);
dos->writeUTF(_toString(m_dimension));
}
void ConsoleGenerateStructure::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"x") == 0) {
int value = _fromString<int>(attributeValue);
m_x = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",
m_x);
} else if (attributeName.compare(L"y") == 0) {
int value = _fromString<int>(attributeValue);
m_y = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",
m_y);
} else if (attributeName.compare(L"z") == 0) {
int value = _fromString<int>(attributeValue);
m_z = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",
m_z);
} else if (attributeName.compare(L"orientation") == 0) {
int value = _fromString<int>(attributeValue);
orientation = value;
app.DebugPrintf(
"ConsoleGenerateStructure: Adding parameter orientation=%d\n",
orientation);
} else if (attributeName.compare(L"dim") == 0) {
m_dimension = _fromString<int>(attributeValue);
if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
app.DebugPrintf(
"ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",
m_dimension);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
BoundingBox* ConsoleGenerateStructure::getBoundingBox() {
if (boundingBox == nullptr) {
// Find the max bounds
int maxX, maxY, maxZ;
maxX = maxY = maxZ = 1;
for (auto it = m_actions.begin(); it != m_actions.end(); ++it) {
ConsoleGenerateStructureAction* action = *it;
maxX = std::max(maxX, action->getEndX());
maxY = std::max(maxY, action->getEndY());
maxZ = std::max(maxZ, action->getEndZ());
}
boundingBox =
new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ);
}
return boundingBox;
}
bool ConsoleGenerateStructure::postProcess(Level* level, Random* random,
BoundingBox* chunkBB) {
if (level->dimension->id != m_dimension) return false;
for (auto it = m_actions.begin(); it != m_actions.end(); ++it) {
ConsoleGenerateStructureAction* action = *it;
switch (action->getActionType()) {
case ConsoleGameRules::eGameRuleType_GenerateBox: {
XboxStructureActionGenerateBox* genBox =
(XboxStructureActionGenerateBox*)action;
genBox->generateBoxInLevel(this, level, chunkBB);
} break;
case ConsoleGameRules::eGameRuleType_PlaceBlock: {
XboxStructureActionPlaceBlock* pPlaceBlock =
(XboxStructureActionPlaceBlock*)action;
pPlaceBlock->placeBlockInLevel(this, level, chunkBB);
} break;
case ConsoleGameRules::eGameRuleType_PlaceContainer: {
XboxStructureActionPlaceContainer* pPlaceContainer =
(XboxStructureActionPlaceContainer*)action;
pPlaceContainer->placeContainerInLevel(this, level, chunkBB);
} break;
case ConsoleGameRules::eGameRuleType_PlaceSpawner: {
XboxStructureActionPlaceSpawner* pPlaceSpawner =
(XboxStructureActionPlaceSpawner*)action;
pPlaceSpawner->placeSpawnerInLevel(this, level, chunkBB);
} break;
default:
break;
};
}
return false;
}
bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1,
int y1, int z1) {
return getBoundingBox()->intersects(x0, y0, z0, x1, y1, z1);
}
int ConsoleGenerateStructure::getMinY() { return getBoundingBox()->y0; }

View File

@@ -0,0 +1,49 @@
#pragma once
#include "../LevelRules/RuleDefinitions/GameRuleDefinition.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.h"
class Level;
class Random;
class BoundingBox;
class ConsoleGenerateStructureAction;
class XboxStructureActionPlaceContainer;
class GRFObject;
class ConsoleGenerateStructure : public GameRuleDefinition,
public StructurePiece {
private:
int m_x, m_y, m_z;
std::vector<ConsoleGenerateStructureAction*> m_actions;
int m_dimension;
public:
ConsoleGenerateStructure();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_GenerateStructure;
}
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
// StructurePiece
virtual BoundingBox* getBoundingBox();
virtual bool postProcess(Level* level, Random* random,
BoundingBox* chunkBB);
void createContainer(XboxStructureActionPlaceContainer* action,
Level* level, BoundingBox* chunkBB);
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
virtual int getMinY();
EStructurePiece GetType() { return (EStructurePiece)0; }
void addAdditonalSaveData(CompoundTag* tag) {}
void readAdditonalSaveData(CompoundTag* tag) {}
};

View File

@@ -0,0 +1,10 @@
#pragma once
#include "../LevelRules/RuleDefinitions/GameRuleDefinition.h"
class ConsoleGenerateStructureAction : public GameRuleDefinition {
public:
virtual int getEndX() = 0;
virtual int getEndY() = 0;
virtual int getEndZ() = 0;
};

View File

@@ -0,0 +1,108 @@
#pragma once
// using namespace std;
#define XBOX_SCHEMATIC_ORIGINAL_VERSION 1
#define XBOX_SCHEMATIC_CURRENT_VERSION 2
#include "../../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h"
class Level;
class DataOutputStream;
class DataInputStream;
class TileEntity;
class LevelChunk;
class AABB;
class Vec3;
class ConsoleSchematicFile {
public:
enum ESchematicRotation {
eSchematicRot_0,
eSchematicRot_90,
eSchematicRot_180,
eSchematicRot_270
};
private:
int m_refCount;
public:
void incrementRefCount() { ++m_refCount; }
void decrementRefCount() { --m_refCount; }
bool shouldDelete() { return m_refCount <= 0; }
typedef struct _XboxSchematicInitParam {
wchar_t name[64];
int startX;
int startY;
int startZ;
int endX;
int endY;
int endZ;
bool bSaveMobs;
Compression::ECompressionTypes compressionType;
_XboxSchematicInitParam() {
ZeroMemory(name, 64 * (sizeof(wchar_t)));
startX = startY = startZ = endX = endY = endZ = 0;
bSaveMobs = false;
compressionType = Compression::eCompressionType_None;
}
} XboxSchematicInitParam;
private:
int m_xSize, m_ySize, m_zSize;
std::vector<std::shared_ptr<TileEntity> > m_tileEntities;
std::vector<std::pair<Vec3, CompoundTag*> > m_entities;
public:
byteArray m_data;
public:
ConsoleSchematicFile();
~ConsoleSchematicFile();
int getXSize() { return m_xSize; }
int getYSize() { return m_ySize; }
int getZSize() { return m_zSize; }
void save(DataOutputStream* dos);
void load(DataInputStream* dis);
int64_t applyBlocksAndData(LevelChunk* chunk, AABB* chunkBox,
AABB* destinationBox, ESchematicRotation rot);
int64_t applyLighting(LevelChunk* chunk, AABB* chunkBox,
AABB* destinationBox, ESchematicRotation rot);
void applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
AABB* destinationBox, ESchematicRotation rot);
static void generateSchematicFile(DataOutputStream* dos, Level* level,
int xStart, int yStart, int zStart,
int xEnd, int yEnd, int zEnd,
bool bSaveMobs,
Compression::ECompressionTypes);
static void setBlocksAndData(LevelChunk* chunk, byteArray blockData,
byteArray dataData, byteArray data, int x0,
int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP,
int& skyLightP);
private:
void save_tags(DataOutputStream* dos);
void load_tags(DataInputStream* dis);
static void getBlocksAndData(LevelChunk* chunk, byteArray* data, int x0,
int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP,
int& skyLightP);
static std::vector<std::shared_ptr<TileEntity> >* getTileEntitiesInRegion(
LevelChunk* chunk, int x0, int y0, int z0, int x1, int y1, int z1);
void chunkCoordToSchematicCoord(AABB* destinationBox, int chunkX,
int chunkZ, ESchematicRotation rot,
int& schematicX, int& schematicZ);
void schematicCoordToChunkCoord(AABB* destinationBox, double schematicX,
double schematicZ, ESchematicRotation rot,
double& chunkX, double& chunkZ);
};

View File

@@ -0,0 +1,764 @@
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
#include <unordered_set>
#include "../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "../../../../../Minecraft.World/net/minecraft/Pos.h"
#include "../../../../../Minecraft.World/net/minecraft/world/phys/net.minecraft.world.phys.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/net.minecraft.world.level.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/chunk/net.minecraft.world.level.chunk.h"
#include "../../Localisation/StringTable.h"
#include "LevelGenerationOptions.h"
#include "../ConsoleGameRules.h"
JustGrSource::JustGrSource() {
m_displayName = L"Default_DisplayName";
m_worldName = L"Default_WorldName";
m_defaultSaveName = L"Default_DefaultSaveName";
m_bRequiresTexturePack = false;
m_requiredTexturePackId = 0;
m_grfPath = L"__NO_GRF_PATH__";
m_bRequiresBaseSave = false;
}
bool JustGrSource::requiresTexturePack() { return m_bRequiresTexturePack; }
std::uint32_t JustGrSource::getRequiredTexturePackId() {
return m_requiredTexturePackId;
}
std::wstring JustGrSource::getDefaultSaveName() { return m_defaultSaveName; }
const wchar_t* JustGrSource::getWorldName() { return m_worldName.c_str(); }
const wchar_t* JustGrSource::getDisplayName() { return m_displayName.c_str(); }
std::wstring JustGrSource::getGrfPath() { return m_grfPath; }
bool JustGrSource::requiresBaseSave() { return m_bRequiresBaseSave; };
std::wstring JustGrSource::getBaseSavePath() { return m_baseSavePath; };
void JustGrSource::setRequiresTexturePack(bool x) {
m_bRequiresTexturePack = x;
}
void JustGrSource::setRequiredTexturePackId(std::uint32_t x) {
m_requiredTexturePackId = x;
}
void JustGrSource::setDefaultSaveName(const std::wstring& x) {
m_defaultSaveName = x;
}
void JustGrSource::setWorldName(const std::wstring& x) { m_worldName = x; }
void JustGrSource::setDisplayName(const std::wstring& x) { m_displayName = x; }
void JustGrSource::setGrfPath(const std::wstring& x) { m_grfPath = x; }
void JustGrSource::setBaseSavePath(const std::wstring& x) {
m_baseSavePath = x;
m_bRequiresBaseSave = true;
}
bool JustGrSource::ready() { return true; }
LevelGenerationOptions::LevelGenerationOptions(DLCPack* parentPack) {
m_spawnPos = nullptr;
m_stringTable = nullptr;
m_hasLoadedData = false;
m_seed = 0;
m_bHasBeenInCreative = true;
m_useFlatWorld = false;
m_bHaveMinY = false;
m_minY = INT_MAX;
m_bRequiresGameRules = false;
m_pbBaseSaveData = nullptr;
m_baseSaveSize = 0;
m_parentDLCPack = parentPack;
m_bLoadingData = false;
}
LevelGenerationOptions::~LevelGenerationOptions() {
clearSchematics();
if (m_spawnPos != nullptr) delete m_spawnPos;
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end();
++it) {
delete *it;
}
for (auto it = m_structureRules.begin(); it != m_structureRules.end();
++it) {
delete *it;
}
for (auto it = m_biomeOverrides.begin(); it != m_biomeOverrides.end();
++it) {
delete *it;
}
for (auto it = m_features.begin(); it != m_features.end(); ++it) {
delete *it;
}
if (m_stringTable)
if (!isTutorial()) delete m_stringTable;
if (isFromSave()) delete m_pSrc;
}
ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() {
return ConsoleGameRules::eGameRuleType_LevelGenerationOptions;
}
void LevelGenerationOptions::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
dos->writeUTF(_toString(m_spawnPos->x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY);
dos->writeUTF(_toString(m_spawnPos->y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ);
dos->writeUTF(_toString(m_spawnPos->z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_seed);
dos->writeUTF(_toString(m_seed));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_flatworld);
dos->writeUTF(_toString(m_useFlatWorld));
}
void LevelGenerationOptions::getChildren(
std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren(children);
std::vector<ApplySchematicRuleDefinition*> used_schematics;
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end(); it++)
if (!(*it)->isComplete()) used_schematics.push_back(*it);
for (auto it = m_structureRules.begin(); it != m_structureRules.end(); it++)
children->push_back(*it);
for (auto it = used_schematics.begin(); it != used_schematics.end(); it++)
children->push_back(*it);
for (auto it = m_biomeOverrides.begin(); it != m_biomeOverrides.end(); ++it)
children->push_back(*it);
for (auto it = m_features.begin(); it != m_features.end(); ++it)
children->push_back(*it);
}
GameRuleDefinition* LevelGenerationOptions::addChild(
ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition* rule = nullptr;
if (ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic) {
rule = new ApplySchematicRuleDefinition(this);
m_schematicRules.push_back((ApplySchematicRuleDefinition*)rule);
} else if (ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure) {
rule = new ConsoleGenerateStructure();
m_structureRules.push_back((ConsoleGenerateStructure*)rule);
} else if (ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride) {
rule = new BiomeOverride();
m_biomeOverrides.push_back((BiomeOverride*)rule);
} else if (ruleType == ConsoleGameRules::eGameRuleType_StartFeature) {
rule = new StartFeature();
m_features.push_back((StartFeature*)rule);
} else {
#if !defined(_CONTENT_PACKAGE)
wprintf(
L"LevelGenerationOptions: Attempted to add invalid child rule - "
L"%d\n",
ruleType);
#endif
}
return rule;
}
void LevelGenerationOptions::addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue) {
if (attributeName.compare(L"seed") == 0) {
m_seed = _fromString<int64_t>(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter m_seed=%I64d\n", m_seed);
} else if (attributeName.compare(L"spawnX") == 0) {
if (m_spawnPos == nullptr) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue);
m_spawnPos->x = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",
value);
} else if (attributeName.compare(L"spawnY") == 0) {
if (m_spawnPos == nullptr) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue);
m_spawnPos->y = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",
value);
} else if (attributeName.compare(L"spawnZ") == 0) {
if (m_spawnPos == nullptr) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue);
m_spawnPos->z = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",
value);
} else if (attributeName.compare(L"flatworld") == 0) {
if (attributeValue.compare(L"true") == 0) m_useFlatWorld = true;
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter flatworld=%s\n",
m_useFlatWorld ? "true" : "false");
} else if (attributeName.compare(L"saveName") == 0) {
std::wstring string(getString(attributeValue));
if (!string.empty())
setDefaultSaveName(string);
else
setDefaultSaveName(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter saveName=%ls\n",
getDefaultSaveName().c_str());
} else if (attributeName.compare(L"worldName") == 0) {
std::wstring string(getString(attributeValue));
if (!string.empty())
setWorldName(string);
else
setWorldName(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter worldName=%ls\n",
getWorldName());
} else if (attributeName.compare(L"displayName") == 0) {
std::wstring string(getString(attributeValue));
if (!string.empty())
setDisplayName(string);
else
setDisplayName(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter displayName=%ls\n",
getDisplayName());
} else if (attributeName.compare(L"texturePackId") == 0) {
setRequiredTexturePackId(_fromString<unsigned int>(attributeValue));
setRequiresTexturePack(true);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter texturePackId=%0x\n",
getRequiredTexturePackId());
} else if (attributeName.compare(L"isTutorial") == 0) {
if (attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter isTutorial=%s\n",
isTutorial() ? "true" : "false");
} else if (attributeName.compare(L"baseSaveName") == 0) {
setBaseSavePath(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter baseSaveName=%ls\n",
getBaseSavePath().c_str());
} else if (attributeName.compare(L"hasBeenInCreative") == 0) {
bool value = _fromString<bool>(attributeValue);
m_bHasBeenInCreative = value;
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter gameMode=%d\n",
m_bHasBeenInCreative);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
void LevelGenerationOptions::processSchematics(LevelChunk* chunk) {
PIXBeginNamedEvent(0, "Processing schematics for chunk (%d,%d)", chunk->x,
chunk->z);
AABB chunkBox(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16,
Level::maxBuildHeight, chunk->z * 16 + 16);
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end();
++it) {
ApplySchematicRuleDefinition* rule = *it;
rule->processSchematic(&chunkBox, chunk);
}
int cx = (chunk->x << 4);
int cz = (chunk->z << 4);
for (auto it = m_structureRules.begin(); it != m_structureRules.end();
it++) {
ConsoleGenerateStructure* structureStart = *it;
if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15,
cz + 15)) {
BoundingBox* bb = new BoundingBox(cx, cz, cx + 15, cz + 15);
structureStart->postProcess(chunk->level, nullptr, bb);
delete bb;
}
}
PIXEndNamedEvent();
}
void LevelGenerationOptions::processSchematicsLighting(LevelChunk* chunk) {
PIXBeginNamedEvent(0, "Processing schematics (lighting) for chunk (%d,%d)",
chunk->x, chunk->z);
AABB chunkBox(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16,
Level::maxBuildHeight, chunk->z * 16 + 16);
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end();
++it) {
ApplySchematicRuleDefinition* rule = *it;
rule->processSchematicLighting(&chunkBox, chunk);
}
PIXEndNamedEvent();
}
bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1,
int y1, int z1) {
PIXBeginNamedEvent(0, "Check Intersects");
// As an optimisation, we can quickly discard things below a certain y which
// makes most ore checks faster due to a) ores generally being below
// ground/sea level and b) tutorial world additions generally being above
// ground/sea level
if (!m_bHaveMinY) {
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end();
++it) {
ApplySchematicRuleDefinition* rule = *it;
int minY = rule->getMinY();
if (minY < m_minY) m_minY = minY;
}
for (auto it = m_structureRules.begin(); it != m_structureRules.end();
it++) {
ConsoleGenerateStructure* structureStart = *it;
int minY = structureStart->getMinY();
if (minY < m_minY) m_minY = minY;
}
m_bHaveMinY = true;
}
// 4J Stu - We DO NOT intersect if our upper bound is below the lower bound
// for all schematics
if (y1 < m_minY) return false;
bool intersects = false;
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end();
++it) {
ApplySchematicRuleDefinition* rule = *it;
intersects = rule->checkIntersects(x0, y0, z0, x1, y1, z1);
if (intersects) break;
}
if (!intersects) {
for (auto it = m_structureRules.begin(); it != m_structureRules.end();
it++) {
ConsoleGenerateStructure* structureStart = *it;
intersects =
structureStart->checkIntersects(x0, y0, z0, x1, y1, z1);
if (intersects) break;
}
}
PIXEndNamedEvent();
return intersects;
}
void LevelGenerationOptions::clearSchematics() {
for (auto it = m_schematics.begin(); it != m_schematics.end(); ++it) {
delete it->second;
}
m_schematics.clear();
}
ConsoleSchematicFile* LevelGenerationOptions::loadSchematicFile(
const std::wstring& filename, std::uint8_t* pbData,
unsigned int dataLength) {
// If we have already loaded this, just return
auto it = m_schematics.find(filename);
if (it != m_schematics.end()) {
#if !defined(_CONTENT_PACKAGE)
wprintf(L"We have already loaded schematic file %ls\n",
filename.c_str());
#endif
it->second->incrementRefCount();
return it->second;
}
ConsoleSchematicFile* schematic = nullptr;
byteArray data(pbData, dataLength);
ByteArrayInputStream bais(data);
DataInputStream dis(&bais);
schematic = new ConsoleSchematicFile();
schematic->load(&dis);
m_schematics[filename] = schematic;
bais.reset();
return schematic;
}
ConsoleSchematicFile* LevelGenerationOptions::getSchematicFile(
const std::wstring& filename) {
ConsoleSchematicFile* schematic = nullptr;
// If we have already loaded this, just return
auto it = m_schematics.find(filename);
if (it != m_schematics.end()) {
schematic = it->second;
}
return schematic;
}
void LevelGenerationOptions::releaseSchematicFile(
const std::wstring& filename) {
// 4J Stu - We don't want to delete them when done, but probably want to
// keep a set of active schematics for the current world
// auto it = m_schematics.find(filename);
// if(it != m_schematics.end())
//{
// ConsoleSchematicFile *schematic = it->second;
// schematic->decrementRefCount();
// if(schematic->shouldDelete())
// {
// delete schematic;
// m_schematics.erase(it);
// }
//}
}
void LevelGenerationOptions::loadStringTable(StringTable* table) {
m_stringTable = table;
}
const wchar_t* LevelGenerationOptions::getString(const std::wstring& key) {
if (m_stringTable == nullptr) {
return L"";
} else {
return m_stringTable->getString(key);
}
}
void LevelGenerationOptions::getBiomeOverride(int biomeId, std::uint8_t& tile,
std::uint8_t& topTile) {
for (auto it = m_biomeOverrides.begin(); it != m_biomeOverrides.end();
++it) {
BiomeOverride* bo = *it;
if (bo->isBiome(biomeId)) {
bo->getTileValues(tile, topTile);
break;
}
}
}
bool LevelGenerationOptions::isFeatureChunk(
int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature,
int* orientation) {
bool isFeature = false;
for (auto it = m_features.begin(); it != m_features.end(); ++it) {
StartFeature* sf = *it;
if (sf->isFeatureChunk(chunkX, chunkZ, feature, orientation)) {
isFeature = true;
break;
}
}
return isFeature;
}
std::unordered_map<std::wstring, ConsoleSchematicFile*>*
LevelGenerationOptions::getUnfinishedSchematicFiles() {
// Clean schematic rules.
std::unordered_set<std::wstring> usedFiles =
std::unordered_set<std::wstring>();
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end(); it++)
if (!(*it)->isComplete()) usedFiles.insert((*it)->getSchematicName());
// Clean schematic files.
std::unordered_map<std::wstring, ConsoleSchematicFile*>* out =
new std::unordered_map<std::wstring, ConsoleSchematicFile*>();
for (auto it = usedFiles.begin(); it != usedFiles.end(); it++)
out->insert(std::pair<std::wstring, ConsoleSchematicFile*>(
*it, getSchematicFile(*it)));
return out;
}
void LevelGenerationOptions::loadBaseSaveData() {
int mountIndex = -1;
if (m_parentDLCPack != nullptr)
mountIndex = m_parentDLCPack->GetDLCMountIndex();
if (mountIndex > -1) {
if (StorageManager.MountInstalledDLC(
ProfileManager.GetPrimaryPad(), mountIndex,
&LevelGenerationOptions::packMounted, this,
"WPACK") != ERROR_IO_PENDING) {
// corrupt DLC
setLoadedData();
app.DebugPrintf("Failed to mount LGO DLC %d for pad %d\n",
mountIndex, ProfileManager.GetPrimaryPad());
} else {
m_bLoadingData = true;
app.DebugPrintf("Attempted to mount DLC data for LGO %d\n",
mountIndex);
}
} else {
setLoadedData();
app.SetAction(ProfileManager.GetPrimaryPad(),
eAppAction_ReloadTexturePack);
}
}
int LevelGenerationOptions::packMounted(void* pParam, int iPad, uint32_t dwErr,
uint32_t dwLicenceMask) {
LevelGenerationOptions* lgo = (LevelGenerationOptions*)pParam;
lgo->m_bLoadingData = false;
if (dwErr != ERROR_SUCCESS) {
// corrupt DLC
app.DebugPrintf("Failed to mount LGO DLC for pad %d: %d\n", iPad,
dwErr);
} else {
app.DebugPrintf("Mounted DLC for LGO, attempting to load data\n");
uint32_t dwFilesProcessed = 0;
int gameRulesCount = lgo->m_parentDLCPack->getDLCItemsCount(
DLCManager::e_DLCType_GameRulesHeader);
for (int i = 0; i < gameRulesCount; ++i) {
DLCGameRulesHeader* dlcFile =
(DLCGameRulesHeader*)lgo->m_parentDLCPack->getFile(
DLCManager::e_DLCType_GameRulesHeader, i);
if (!dlcFile->getGrfPath().empty()) {
File grf(app.getFilePath(lgo->m_parentDLCPack->GetPackID(),
dlcFile->getGrfPath(), true,
L"WPACK:"));
if (grf.exists()) {
#if defined(_UNICODE)
std::wstring path = grf.getPath();
const wchar_t* pchFilename = path.c_str();
void* fileHandle = CreateFile(
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share
// file? Probably not but...
nullptr, // Unused
OPEN_EXISTING, // how to create // TODO 4J Stu -
// Assuming that the file already exists
// if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
nullptr // Unsupported
);
#else
const char* pchFilename = wstringtofilename(grf.getPath());
void* fileHandle = CreateFile(
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share
// file? Probably not but...
nullptr, // Unused
OPEN_EXISTING, // how to create // TODO 4J Stu -
// Assuming that the file already exists
// if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
nullptr // Unsupported
);
#endif
if (fileHandle != INVALID_HANDLE_VALUE) {
uint32_t dwFileSize = grf.length();
uint32_t bytesRead;
uint8_t* pbData = (uint8_t*)new uint8_t[dwFileSize];
bool bSuccess = ReadFile(fileHandle, pbData, dwFileSize,
&bytesRead, nullptr);
if (bSuccess == false) {
app.FatalLoadError();
}
CloseHandle(fileHandle);
// 4J-PB - is it possible that we can get here after a
// read fail and it's not an error?
dlcFile->setGrfData(pbData, dwFileSize,
lgo->m_stringTable);
delete[] pbData;
app.m_gameRules.setLevelGenerationOptions(dlcFile->lgo);
}
}
}
}
if (lgo->requiresBaseSave() && !lgo->getBaseSavePath().empty()) {
File save(app.getFilePath(lgo->m_parentDLCPack->GetPackID(),
lgo->getBaseSavePath(), true, L"WPACK:"));
if (save.exists()) {
#if defined(_UNICODE)
std::wstring path = save.getPath();
const wchar_t* pchFilename = path.c_str();
void* fileHandle = CreateFile(
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share
// file? Probably not but...
nullptr, // Unused
OPEN_EXISTING, // how to create // TODO 4J Stu - Assuming
// that the file already exists if we are
// opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
nullptr // Unsupported
);
#else
const char* pchFilename = wstringtofilename(save.getPath());
void* fileHandle = CreateFile(
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share
// file? Probably not but...
nullptr, // Unused
OPEN_EXISTING, // how to create // TODO 4J Stu - Assuming
// that the file already exists if we are
// opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
nullptr // Unsupported
);
#endif
if (fileHandle != INVALID_HANDLE_VALUE) {
uint32_t bytesRead,
dwFileSize = GetFileSize(fileHandle, nullptr);
uint8_t* pbData = (uint8_t*)new uint8_t[dwFileSize];
bool bSuccess = ReadFile(fileHandle, pbData, dwFileSize,
&bytesRead, nullptr);
if (bSuccess == false) {
app.FatalLoadError();
}
CloseHandle(fileHandle);
// 4J-PB - is it possible that we can get here after a read
// fail and it's not an error?
lgo->setBaseSaveData(pbData, dwFileSize);
}
}
}
uint32_t result = StorageManager.UnmountInstalledDLC("WPACK");
}
lgo->setLoadedData();
return 0;
}
void LevelGenerationOptions::reset_start() {
for (auto it = m_schematicRules.begin(); it != m_schematicRules.end();
it++) {
(*it)->reset();
}
}
void LevelGenerationOptions::reset_finish() {
// if (m_spawnPos) { delete m_spawnPos; m_spawnPos
// = nullptr; } if (m_stringTable) { delete m_stringTable;
// m_stringTable = nullptr; }
if (isFromDLC()) {
m_hasLoadedData = false;
}
}
GrSource* LevelGenerationOptions::info() { return m_pSrc; }
void LevelGenerationOptions::setSrc(eSrc src) { m_src = src; }
LevelGenerationOptions::eSrc LevelGenerationOptions::getSrc() { return m_src; }
bool LevelGenerationOptions::isTutorial() { return getSrc() == eSrc_tutorial; }
bool LevelGenerationOptions::isFromSave() { return getSrc() == eSrc_fromSave; }
bool LevelGenerationOptions::isFromDLC() { return getSrc() == eSrc_fromDLC; }
bool LevelGenerationOptions::requiresTexturePack() {
return info()->requiresTexturePack();
}
std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() {
return info()->getRequiredTexturePackId();
}
std::wstring LevelGenerationOptions::getDefaultSaveName() {
switch (getSrc()) {
case eSrc_fromSave:
return getString(info()->getDefaultSaveName());
case eSrc_fromDLC:
return getString(info()->getDefaultSaveName());
case eSrc_tutorial:
return app.GetString(IDS_TUTORIALSAVENAME);
default:
break;
}
return L"";
}
const wchar_t* LevelGenerationOptions::getWorldName() {
switch (getSrc()) {
case eSrc_fromSave:
return getString(info()->getWorldName());
case eSrc_fromDLC:
return getString(info()->getWorldName());
case eSrc_tutorial:
return app.GetString(IDS_PLAY_TUTORIAL);
default:
break;
}
return L"";
}
const wchar_t* LevelGenerationOptions::getDisplayName() {
switch (getSrc()) {
case eSrc_fromSave:
return getString(info()->getDisplayName());
case eSrc_fromDLC:
return getString(info()->getDisplayName());
case eSrc_tutorial:
return L"";
default:
break;
}
return L"";
}
std::wstring LevelGenerationOptions::getGrfPath() {
return info()->getGrfPath();
}
bool LevelGenerationOptions::requiresBaseSave() {
return info()->requiresBaseSave();
}
std::wstring LevelGenerationOptions::getBaseSavePath() {
return info()->getBaseSavePath();
}
void LevelGenerationOptions::setGrSource(GrSource* grs) { m_pSrc = grs; }
void LevelGenerationOptions::setRequiresTexturePack(bool x) {
info()->setRequiresTexturePack(x);
}
void LevelGenerationOptions::setRequiredTexturePackId(std::uint32_t x) {
info()->setRequiredTexturePackId(x);
}
void LevelGenerationOptions::setDefaultSaveName(const std::wstring& x) {
info()->setDefaultSaveName(x);
}
void LevelGenerationOptions::setWorldName(const std::wstring& x) {
info()->setWorldName(x);
}
void LevelGenerationOptions::setDisplayName(const std::wstring& x) {
info()->setDisplayName(x);
}
void LevelGenerationOptions::setGrfPath(const std::wstring& x) {
info()->setGrfPath(x);
}
void LevelGenerationOptions::setBaseSavePath(const std::wstring& x) {
info()->setBaseSavePath(x);
}
bool LevelGenerationOptions::ready() { return info()->ready(); }
void LevelGenerationOptions::setBaseSaveData(std::uint8_t* pbData,
unsigned int dataSize) {
m_pbBaseSaveData = pbData;
m_baseSaveSize = dataSize;
}
std::uint8_t* LevelGenerationOptions::getBaseSaveData(unsigned int& size) {
size = m_baseSaveSize;
return m_pbBaseSaveData;
}
bool LevelGenerationOptions::hasBaseSaveData() {
return m_baseSaveSize > 0 && m_pbBaseSaveData != nullptr;
}
void LevelGenerationOptions::deleteBaseSaveData() {
delete[] m_pbBaseSaveData;
m_pbBaseSaveData = nullptr;
m_baseSaveSize = 0;
}
bool LevelGenerationOptions::hasLoadedData() { return m_hasLoadedData; }
void LevelGenerationOptions::setLoadedData() { m_hasLoadedData = true; }
int64_t LevelGenerationOptions::getLevelSeed() { return m_seed; }
int LevelGenerationOptions::getLevelHasBeenInCreative() {
return m_bHasBeenInCreative;
}
Pos* LevelGenerationOptions::getSpawnPos() { return m_spawnPos; }
bool LevelGenerationOptions::getuseFlatWorld() { return m_useFlatWorld; }
bool LevelGenerationOptions::requiresGameRules() {
return m_bRequiresGameRules;
}
void LevelGenerationOptions::setRequiredGameRules(LevelRuleset* rules) {
m_requiredGameRules = rules;
m_bRequiresGameRules = true;
}
LevelRuleset* LevelGenerationOptions::getRequiredGameRules() {
return m_requiredGameRules;
}

View File

@@ -0,0 +1,234 @@
#pragma once
// using namespace std;
// #pragma message("LevelGenerationOptions.h ")
#include <cstdint>
#include "../LevelRules/RuleDefinitions/GameRuleDefinition.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.h"
class ApplySchematicRuleDefinition;
class LevelChunk;
class ConsoleGenerateStructure;
class ConsoleSchematicFile;
class LevelRuleset;
class BiomeOverride;
class StartFeature;
class GrSource {
public:
// 4J-JEV:
// Moved all this here; I didn't like that all this header information
// was being mixed in with all the game information as they have
// completely different lifespans.
virtual ~GrSource() {}
virtual bool requiresTexturePack() = 0;
virtual std::uint32_t getRequiredTexturePackId() = 0;
virtual std::wstring getDefaultSaveName() = 0;
virtual const wchar_t* getWorldName() = 0;
virtual const wchar_t* getDisplayName() = 0;
virtual std::wstring getGrfPath() = 0;
virtual bool requiresBaseSave() = 0;
virtual std::wstring getBaseSavePath() = 0;
virtual void setRequiresTexturePack(bool) = 0;
virtual void setRequiredTexturePackId(std::uint32_t) = 0;
virtual void setDefaultSaveName(const std::wstring&) = 0;
virtual void setWorldName(const std::wstring&) = 0;
virtual void setDisplayName(const std::wstring&) = 0;
virtual void setGrfPath(const std::wstring&) = 0;
virtual void setBaseSavePath(const std::wstring&) = 0;
virtual bool ready() = 0;
// virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0;
};
class JustGrSource : public GrSource {
protected:
std::wstring m_worldName;
std::wstring m_displayName;
std::wstring m_defaultSaveName;
bool m_bRequiresTexturePack;
std::uint32_t m_requiredTexturePackId;
std::wstring m_grfPath;
std::wstring m_baseSavePath;
bool m_bRequiresBaseSave;
public:
virtual bool requiresTexturePack();
virtual std::uint32_t getRequiredTexturePackId();
virtual std::wstring getDefaultSaveName();
virtual const wchar_t* getWorldName();
virtual const wchar_t* getDisplayName();
virtual std::wstring getGrfPath();
virtual bool requiresBaseSave();
virtual std::wstring getBaseSavePath();
virtual void setRequiresTexturePack(bool x);
virtual void setRequiredTexturePackId(std::uint32_t x);
virtual void setDefaultSaveName(const std::wstring& x);
virtual void setWorldName(const std::wstring& x);
virtual void setDisplayName(const std::wstring& x);
virtual void setGrfPath(const std::wstring& x);
virtual void setBaseSavePath(const std::wstring& x);
virtual bool ready();
JustGrSource();
};
class LevelGenerationOptions : public GameRuleDefinition {
public:
enum eSrc {
eSrc_none,
eSrc_fromSave, // Neither content or header is persistent.
eSrc_fromDLC, // Header is persistent, content should be deleted to
// conserve space.
eSrc_tutorial, // Both header and content is persistent, content cannot
// be reloaded.
eSrc_MAX
};
private:
eSrc m_src;
GrSource* m_pSrc;
GrSource* info();
bool m_hasLoadedData;
std::uint8_t* m_pbBaseSaveData;
unsigned int m_baseSaveSize;
public:
void setSrc(eSrc src);
eSrc getSrc();
bool isTutorial();
bool isFromSave();
bool isFromDLC();
bool requiresTexturePack();
std::uint32_t getRequiredTexturePackId();
std::wstring getDefaultSaveName();
const wchar_t* getWorldName();
const wchar_t* getDisplayName();
std::wstring getGrfPath();
bool requiresBaseSave();
std::wstring getBaseSavePath();
void setGrSource(GrSource* grs);
void setRequiresTexturePack(bool x);
void setRequiredTexturePackId(std::uint32_t x);
void setDefaultSaveName(const std::wstring& x);
void setWorldName(const std::wstring& x);
void setDisplayName(const std::wstring& x);
void setGrfPath(const std::wstring& x);
void setBaseSavePath(const std::wstring& x);
bool ready();
void setBaseSaveData(std::uint8_t* pbData, unsigned int dataSize);
std::uint8_t* getBaseSaveData(unsigned int& size);
bool hasBaseSaveData();
void deleteBaseSaveData();
bool hasLoadedData();
void setLoadedData();
private:
// This should match the "MapOptionsRule" definition in the XML schema
int64_t m_seed;
bool m_useFlatWorld;
Pos* m_spawnPos;
int m_bHasBeenInCreative;
std::vector<ApplySchematicRuleDefinition*> m_schematicRules;
std::vector<ConsoleGenerateStructure*> m_structureRules;
bool m_bHaveMinY;
int m_minY;
std::unordered_map<std::wstring, ConsoleSchematicFile*> m_schematics;
std::vector<BiomeOverride*> m_biomeOverrides;
std::vector<StartFeature*> m_features;
bool m_bRequiresGameRules;
LevelRuleset* m_requiredGameRules;
StringTable* m_stringTable;
DLCPack* m_parentDLCPack;
bool m_bLoadingData;
public:
LevelGenerationOptions(DLCPack* parentPack = nullptr);
~LevelGenerationOptions();
virtual ConsoleGameRules::EGameRuleType getActionType();
virtual void writeAttributes(DataOutputStream* dos,
unsigned int numAttributes);
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
int64_t getLevelSeed();
int getLevelHasBeenInCreative();
Pos* getSpawnPos();
bool getuseFlatWorld();
void processSchematics(LevelChunk* chunk);
void processSchematicsLighting(LevelChunk* chunk);
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
private:
void clearSchematics();
public:
ConsoleSchematicFile* loadSchematicFile(const std::wstring& filename,
std::uint8_t* pbData,
unsigned int dataLength);
public:
ConsoleSchematicFile* getSchematicFile(const std::wstring& filename);
void releaseSchematicFile(const std::wstring& filename);
bool requiresGameRules();
void setRequiredGameRules(LevelRuleset* rules);
LevelRuleset* getRequiredGameRules();
void getBiomeOverride(int biomeId, std::uint8_t& tile,
std::uint8_t& topTile);
bool isFeatureChunk(int chunkX, int chunkZ,
StructureFeature::EFeatureTypes feature,
int* orientation = nullptr);
void loadStringTable(StringTable* table);
const wchar_t* getString(const std::wstring& key);
std::unordered_map<std::wstring, ConsoleSchematicFile*>*
getUnfinishedSchematicFiles();
void loadBaseSaveData();
static int packMounted(void* pParam, int iPad, uint32_t dwErr,
uint32_t dwLicenceMask);
// 4J-JEV:
// ApplySchematicRules contain limited state
// which needs to be reset BEFORE a new game starts.
void reset_start();
// 4J-JEV:
// This file contains state that needs to be deleted
// or reset once a game has finished.
void reset_finish();
};

View File

@@ -0,0 +1,19 @@
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
#include "LevelGenerationOptions.h"
#include "LevelGenerators.h"
LevelGenerators::LevelGenerators() {}
void LevelGenerators::addLevelGenerator(const std::wstring& displayName,
LevelGenerationOptions* generator) {
if (!displayName.empty()) generator->setDisplayName(displayName);
m_levelGenerators.push_back(generator);
}
void LevelGenerators::removeLevelGenerator(LevelGenerationOptions* generator) {
std::vector<LevelGenerationOptions*>::iterator it;
while ((it = find(m_levelGenerators.begin(), m_levelGenerators.end(),
generator)) != m_levelGenerators.end()) {
m_levelGenerators.erase(it);
}
}

View File

@@ -0,0 +1,21 @@
#pragma once
// using namespace std;
class LevelGenerationOptions;
class LevelGenerators {
private:
std::vector<LevelGenerationOptions*> m_levelGenerators;
public:
LevelGenerators();
void addLevelGenerator(const std::wstring& displayName,
LevelGenerationOptions* generator);
void removeLevelGenerator(LevelGenerationOptions* generator);
std::vector<LevelGenerationOptions*>* getLevelGenerators() {
return &m_levelGenerators;
}
};

View File

@@ -0,0 +1,56 @@
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
#include "../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "StartFeature.h"
StartFeature::StartFeature() {
m_chunkX = 0;
m_chunkZ = 0;
m_orientation = 0;
m_feature = StructureFeature::eFeature_Temples;
}
void StartFeature::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 4);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX);
dos->writeUTF(_toString(m_chunkX));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkZ);
dos->writeUTF(_toString(m_chunkZ));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_feature);
dos->writeUTF(_toString((int)m_feature));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation);
dos->writeUTF(_toString(m_orientation));
}
void StartFeature::addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue) {
if (attributeName.compare(L"chunkX") == 0) {
int value = _fromString<int>(attributeValue);
m_chunkX = value;
app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n", m_chunkX);
} else if (attributeName.compare(L"chunkZ") == 0) {
int value = _fromString<int>(attributeValue);
m_chunkZ = value;
app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n", m_chunkZ);
} else if (attributeName.compare(L"orientation") == 0) {
int value = _fromString<int>(attributeValue);
m_orientation = value;
app.DebugPrintf("StartFeature: Adding parameter orientation=%d\n",
m_orientation);
} else if (attributeName.compare(L"feature") == 0) {
int value = _fromString<int>(attributeValue);
m_feature = (StructureFeature::EFeatureTypes)value;
app.DebugPrintf("StartFeature: Adding parameter feature=%d\n",
m_feature);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
bool StartFeature::isFeatureChunk(int chunkX, int chunkZ,
StructureFeature::EFeatureTypes feature,
int* orientation) {
if (orientation != nullptr) *orientation = m_orientation;
return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature;
}

View File

@@ -0,0 +1,26 @@
#pragma once
// using namespace std;
#include "../LevelRules/RuleDefinitions/GameRuleDefinition.h"
#include "../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.h"
class StartFeature : public GameRuleDefinition {
private:
int m_chunkX, m_chunkZ, m_orientation;
StructureFeature::EFeatureTypes m_feature;
public:
StartFeature();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_StartFeature;
}
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool isFeatureChunk(int chunkX, int chunkZ,
StructureFeature::EFeatureTypes feature,
int* orientation);
};

View File

@@ -0,0 +1,97 @@
#include "../../../../../../Minecraft.World/Header Files/stdafx.h"
#include "XboxStructureActionGenerateBox.h"
#include "../../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/net.minecraft.world.level.levelgen.structure.h"
XboxStructureActionGenerateBox::XboxStructureActionGenerateBox() {
m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0;
m_skipAir = false;
}
void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
dos->writeUTF(_toString(m_x0));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0);
dos->writeUTF(_toString(m_y0));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0);
dos->writeUTF(_toString(m_z0));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1);
dos->writeUTF(_toString(m_x1));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1);
dos->writeUTF(_toString(m_y1));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1);
dos->writeUTF(_toString(m_z1));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_edgeTile);
dos->writeUTF(_toString(m_edgeTile));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_fillTile);
dos->writeUTF(_toString(m_fillTile));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_skipAir);
dos->writeUTF(_toString(m_skipAir));
}
void XboxStructureActionGenerateBox::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"x0") == 0) {
int value = _fromString<int>(attributeValue);
m_x0 = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter x0=%d\n", m_x0);
} else if (attributeName.compare(L"y0") == 0) {
int value = _fromString<int>(attributeValue);
m_y0 = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter y0=%d\n", m_y0);
} else if (attributeName.compare(L"z0") == 0) {
int value = _fromString<int>(attributeValue);
m_z0 = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter z0=%d\n", m_z0);
} else if (attributeName.compare(L"x1") == 0) {
int value = _fromString<int>(attributeValue);
m_x1 = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter x1=%d\n", m_x1);
} else if (attributeName.compare(L"y1") == 0) {
int value = _fromString<int>(attributeValue);
m_y1 = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter y1=%d\n", m_y1);
} else if (attributeName.compare(L"z1") == 0) {
int value = _fromString<int>(attributeValue);
m_z1 = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter z1=%d\n", m_z1);
} else if (attributeName.compare(L"edgeTile") == 0) {
int value = _fromString<int>(attributeValue);
m_edgeTile = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n",
m_edgeTile);
} else if (attributeName.compare(L"fillTile") == 0) {
int value = _fromString<int>(attributeValue);
m_fillTile = value;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n",
m_fillTile);
} else if (attributeName.compare(L"skipAir") == 0) {
if (attributeValue.compare(L"true") == 0) m_skipAir = true;
app.DebugPrintf(
"XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n",
m_skipAir ? "true" : "false");
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
bool XboxStructureActionGenerateBox::generateBoxInLevel(
StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
app.DebugPrintf("XboxStructureActionGenerateBox - generating a box\n");
structure->generateBox(level, chunkBB, m_x0, m_y0, m_z0, m_x1, m_y1, m_z1,
m_edgeTile, m_fillTile, m_skipAir);
return true;
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "../ConsoleGenerateStructureAction.h"
class StructurePiece;
class Level;
class BoundingBox;
class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction {
private:
int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile;
bool m_skipAir;
public:
XboxStructureActionGenerateBox();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_GenerateBox;
}
virtual int getEndX() { return m_x1; }
virtual int getEndY() { return m_y1; }
virtual int getEndZ() { return m_z1; }
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool generateBoxInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
};

View File

@@ -0,0 +1,67 @@
#include "../../../../../../Minecraft.World/Header Files/stdafx.h"
#include "XboxStructureActionPlaceBlock.h"
#include "../../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/net.minecraft.world.level.levelgen.structure.h"
XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock() {
m_x = m_y = m_z = m_tile = m_data = 0;
}
void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
dos->writeUTF(_toString(m_x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
dos->writeUTF(_toString(m_y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
dos->writeUTF(_toString(m_z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_data);
dos->writeUTF(_toString(m_data));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_block);
dos->writeUTF(_toString(m_tile));
}
void XboxStructureActionPlaceBlock::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"x") == 0) {
int value = _fromString<int>(attributeValue);
m_x = value;
app.DebugPrintf(
"XboxStructureActionPlaceBlock: Adding parameter x=%d\n", m_x);
} else if (attributeName.compare(L"y") == 0) {
int value = _fromString<int>(attributeValue);
m_y = value;
app.DebugPrintf(
"XboxStructureActionPlaceBlock: Adding parameter y=%d\n", m_y);
} else if (attributeName.compare(L"z") == 0) {
int value = _fromString<int>(attributeValue);
m_z = value;
app.DebugPrintf(
"XboxStructureActionPlaceBlock: Adding parameter z=%d\n", m_z);
} else if (attributeName.compare(L"block") == 0) {
int value = _fromString<int>(attributeValue);
m_tile = value;
app.DebugPrintf(
"XboxStructureActionPlaceBlock: Adding parameter block=%d\n",
m_tile);
} else if (attributeName.compare(L"data") == 0) {
int value = _fromString<int>(attributeValue);
m_data = value;
app.DebugPrintf(
"XboxStructureActionPlaceBlock: Adding parameter data=%d\n",
m_data);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue);
}
}
bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece* structure,
Level* level,
BoundingBox* chunkBB) {
app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n");
structure->placeBlock(level, m_tile, m_data, m_x, m_y, m_z, chunkBB);
return true;
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include "../ConsoleGenerateStructureAction.h"
class StructurePiece;
class Level;
class BoundingBox;
class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction {
protected:
int m_x, m_y, m_z, m_tile, m_data;
public:
XboxStructureActionPlaceBlock();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_PlaceBlock;
}
virtual int getEndX() { return m_x; }
virtual int getEndY() { return m_y; }
virtual int getEndZ() { return m_z; }
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool placeBlockInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
};

View File

@@ -0,0 +1,103 @@
#include "../../../../../../Minecraft.World/Header Files/stdafx.h"
#include "../../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "XboxStructureActionPlaceContainer.h"
#include "../../LevelRules/RuleDefinitions/AddItemRuleDefinition.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/net.minecraft.world.level.levelgen.structure.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/net.minecraft.world.level.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/tile/net.minecraft.world.level.tile.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/inventory/net.minecraft.world.inventory.h"
XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer() {
m_tile = Tile::chest_Id;
}
XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer() {
for (auto it = m_items.begin(); it != m_items.end(); ++it) {
delete *it;
}
}
// 4J-JEV: Super class handles attr-facing fine.
// void XboxStructureActionPlaceContainer::writeAttributes(DataOutputStream
// *dos, uint32_t numAttrs)
void XboxStructureActionPlaceContainer::getChildren(
std::vector<GameRuleDefinition*>* children) {
XboxStructureActionPlaceBlock::getChildren(children);
for (auto it = m_items.begin(); it != m_items.end(); it++)
children->push_back(*it);
}
GameRuleDefinition* XboxStructureActionPlaceContainer::addChild(
ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition* rule = nullptr;
if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) {
rule = new AddItemRuleDefinition();
m_items.push_back((AddItemRuleDefinition*)rule);
} else {
#ifndef _CONTENT_PACKAGE
wprintf(
L"XboxStructureActionPlaceContainer: Attempted to add invalid "
L"child rule - %d\n",
ruleType);
#endif
}
return rule;
}
void XboxStructureActionPlaceContainer::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"facing") == 0) {
int value = _fromString<int>(attributeValue);
m_data = value;
app.DebugPrintf(
"XboxStructureActionPlaceContainer: Adding parameter facing=%d\n",
m_data);
} else {
XboxStructureActionPlaceBlock::addAttribute(attributeName,
attributeValue);
}
}
bool XboxStructureActionPlaceContainer::placeContainerInLevel(
StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
int worldX = structure->getWorldX(m_x, m_z);
int worldY = structure->getWorldY(m_y);
int worldZ = structure->getWorldZ(m_x, m_z);
if (chunkBB->isInside(worldX, worldY, worldZ)) {
if (level->getTileEntity(worldX, worldY, worldZ) != nullptr) {
// Remove the current tile entity
level->removeTileEntity(worldX, worldY, worldZ);
level->setTileAndData(worldX, worldY, worldZ, 0, 0,
Tile::UPDATE_ALL);
}
level->setTileAndData(worldX, worldY, worldZ, m_tile, 0,
Tile::UPDATE_ALL);
std::shared_ptr<Container> container =
std::dynamic_pointer_cast<Container>(
level->getTileEntity(worldX, worldY, worldZ));
app.DebugPrintf(
"XboxStructureActionPlaceContainer - placing a container at "
"(%d,%d,%d)\n",
worldX, worldY, worldZ);
if (container != nullptr) {
level->setData(worldX, worldY, worldZ, m_data,
Tile::UPDATE_CLIENTS);
// Add items
int slotId = 0;
for (auto it = m_items.begin();
it != m_items.end() &&
(slotId < container->getContainerSize());
++it, ++slotId) {
AddItemRuleDefinition* addItem = *it;
addItem->addItemToContainer(container, slotId);
}
}
return true;
}
return false;
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "XboxStructureActionPlaceBlock.h"
class AddItemRuleDefinition;
class StructurePiece;
class Level;
class BoundingBox;
class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock {
private:
std::vector<AddItemRuleDefinition*> m_items;
public:
XboxStructureActionPlaceContainer();
~XboxStructureActionPlaceContainer();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_PlaceContainer;
}
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
// 4J-JEV: Super class handles attr-facing fine.
// virtual void writeAttributes(DataOutputStream *dos, uint32_t
// numAttributes);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool placeContainerInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
};

View File

@@ -0,0 +1,70 @@
#include "../../../../../../Minecraft.World/Header Files/stdafx.h"
#include "../../../../../../Minecraft.World/ConsoleHelpers/StringHelpers.h"
#include "XboxStructureActionPlaceSpawner.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/levelgen/structure/net.minecraft.world.level.levelgen.structure.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/net.minecraft.world.level.h"
#include "../../../../../../Minecraft.World/net/minecraft/world/level/tile/entity/net.minecraft.world.level.tile.entity.h"
XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner() {
m_tile = Tile::mobSpawner_Id;
m_entityId = L"Pig";
}
XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner() {}
void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream* dos,
unsigned int numAttrs) {
XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity);
dos->writeUTF(m_entityId);
}
void XboxStructureActionPlaceSpawner::addAttribute(
const std::wstring& attributeName, const std::wstring& attributeValue) {
if (attributeName.compare(L"entity") == 0) {
m_entityId = attributeValue;
#ifndef _CONTENT_PACKAGE
wprintf(
L"XboxStructureActionPlaceSpawner: Adding parameter entity=%ls\n",
m_entityId.c_str());
#endif
} else {
XboxStructureActionPlaceBlock::addAttribute(attributeName,
attributeValue);
}
}
bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(
StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
int worldX = structure->getWorldX(m_x, m_z);
int worldY = structure->getWorldY(m_y);
int worldZ = structure->getWorldZ(m_x, m_z);
if (chunkBB->isInside(worldX, worldY, worldZ)) {
if (level->getTileEntity(worldX, worldY, worldZ) != nullptr) {
// Remove the current tile entity
level->removeTileEntity(worldX, worldY, worldZ);
level->setTileAndData(worldX, worldY, worldZ, 0, 0,
Tile::UPDATE_ALL);
}
level->setTileAndData(worldX, worldY, worldZ, m_tile, 0,
Tile::UPDATE_ALL);
std::shared_ptr<MobSpawnerTileEntity> entity =
std::dynamic_pointer_cast<MobSpawnerTileEntity>(
level->getTileEntity(worldX, worldY, worldZ));
#ifndef _CONTENT_PACKAGE
wprintf(
L"XboxStructureActionPlaceSpawner - placing a %ls spawner at "
L"(%d,%d,%d)\n",
m_entityId.c_str(), worldX, worldY, worldZ);
#endif
if (entity != nullptr) {
entity->setEntityId(m_entityId);
}
return true;
}
return false;
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "XboxStructureActionPlaceBlock.h"
class StructurePiece;
class Level;
class BoundingBox;
class GRFObject;
class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock {
private:
std::wstring m_entityId;
public:
XboxStructureActionPlaceSpawner();
~XboxStructureActionPlaceSpawner();
virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_PlaceSpawner;
}
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool placeSpawnerInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
};