mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 11:43:36 +00:00
# Conflicts: # Minecraft.Client/Network/PlayerChunkMap.cpp # Minecraft.Client/Network/PlayerList.cpp # Minecraft.Client/Network/ServerChunkCache.cpp # Minecraft.Client/Platform/Common/Consoles_App.cpp # Minecraft.Client/Platform/Common/DLC/DLCManager.cpp # Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp # Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp # Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp # Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp # Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp # Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp # Minecraft.Client/Platform/Common/UI/UIController.cpp # Minecraft.Client/Platform/Common/UI/UIController.h # Minecraft.Client/Platform/Extrax64Stubs.cpp # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h # Minecraft.Client/Player/EntityTracker.cpp # Minecraft.Client/Player/ServerPlayer.cpp # Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp # Minecraft.Client/Textures/Packs/DLCTexturePack.cpp # Minecraft.Client/Textures/Stitching/StitchedTexture.cpp # Minecraft.Client/Textures/Stitching/TextureMap.cpp # Minecraft.Client/Textures/Textures.cpp # Minecraft.World/Blocks/NotGateTile.cpp # Minecraft.World/Blocks/PressurePlateTile.cpp # Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp # Minecraft.World/Enchantments/EnchantmentHelper.cpp # Minecraft.World/Entities/HangingEntity.cpp # Minecraft.World/Entities/LeashFenceKnotEntity.cpp # Minecraft.World/Entities/LivingEntity.cpp # Minecraft.World/Entities/Mobs/Boat.cpp # Minecraft.World/Entities/Mobs/Minecart.cpp # Minecraft.World/Entities/Mobs/Witch.cpp # Minecraft.World/Entities/SyncedEntityData.cpp # Minecraft.World/Items/LeashItem.cpp # Minecraft.World/Items/PotionItem.cpp # Minecraft.World/Level/BaseMobSpawner.cpp # Minecraft.World/Level/CustomLevelSource.cpp # Minecraft.World/Level/Level.cpp # Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp # Minecraft.World/Level/Storage/McRegionLevelStorage.cpp # Minecraft.World/Level/Storage/RegionFileCache.cpp # Minecraft.World/Player/Player.cpp # Minecraft.World/WorldGen/Biomes/BiomeCache.cpp # Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp # Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
142 lines
4.2 KiB
C++
142 lines
4.2 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.level.h"
|
|
#include "../../Headers/net.minecraft.world.level.levelgen.structure.h"
|
|
#include "StructureStart.h"
|
|
#include "StructurePiece.h"
|
|
#include "../../Util/BoundingBox.h"
|
|
|
|
StructureStart::StructureStart() {
|
|
chunkX = chunkZ = 0;
|
|
boundingBox = nullptr; // 4J added initialiser
|
|
}
|
|
|
|
StructureStart::StructureStart(int x, int z) {
|
|
this->chunkX = x;
|
|
this->chunkZ = z;
|
|
boundingBox = nullptr;
|
|
}
|
|
|
|
StructureStart::~StructureStart() {
|
|
for (auto it = pieces.begin(); it != pieces.end(); it++) {
|
|
delete (*it);
|
|
}
|
|
delete boundingBox;
|
|
}
|
|
|
|
BoundingBox* StructureStart::getBoundingBox() { return boundingBox; }
|
|
|
|
std::list<StructurePiece*>* StructureStart::getPieces() { return &pieces; }
|
|
|
|
void StructureStart::postProcess(Level* level, Random* random,
|
|
BoundingBox* chunkBB) {
|
|
auto it = pieces.begin();
|
|
|
|
while (it != pieces.end()) {
|
|
if ((*it)->getBoundingBox()->intersects(chunkBB) &&
|
|
!(*it)->postProcess(level, random, chunkBB)) {
|
|
// this piece can't be placed, so remove it to avoid future
|
|
// attempts
|
|
it = pieces.erase(it);
|
|
} else {
|
|
it++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void StructureStart::calculateBoundingBox() {
|
|
boundingBox = BoundingBox::getUnknownBox();
|
|
|
|
for (auto it = pieces.begin(); it != pieces.end(); it++) {
|
|
StructurePiece* piece = *it;
|
|
boundingBox->expand(piece->getBoundingBox());
|
|
}
|
|
}
|
|
|
|
CompoundTag* StructureStart::createTag(int chunkX, int chunkZ) {
|
|
CompoundTag* tag = new CompoundTag();
|
|
|
|
tag->putString(L"id", StructureFeatureIO::getEncodeId(this));
|
|
tag->putInt(L"ChunkX", chunkX);
|
|
tag->putInt(L"ChunkZ", chunkZ);
|
|
tag->put(L"BB", boundingBox->createTag(L"BB"));
|
|
|
|
ListTag<CompoundTag>* childrenTags = new ListTag<CompoundTag>(L"Children");
|
|
for (auto it = pieces.begin(); it != pieces.end(); ++it) {
|
|
StructurePiece* piece = *it;
|
|
childrenTags->add(piece->createTag());
|
|
}
|
|
tag->put(L"Children", childrenTags);
|
|
|
|
addAdditonalSaveData(tag);
|
|
|
|
return tag;
|
|
}
|
|
|
|
void StructureStart::addAdditonalSaveData(CompoundTag* tag) {}
|
|
|
|
void StructureStart::load(Level* level, CompoundTag* tag) {
|
|
chunkX = tag->getInt(L"ChunkX");
|
|
chunkZ = tag->getInt(L"ChunkZ");
|
|
if (tag->contains(L"BB")) {
|
|
boundingBox = new BoundingBox(tag->getIntArray(L"BB"));
|
|
}
|
|
|
|
ListTag<CompoundTag>* children =
|
|
(ListTag<CompoundTag>*)tag->getList(L"Children");
|
|
for (int i = 0; i < children->size(); i++) {
|
|
pieces.push_back(
|
|
StructureFeatureIO::loadStaticPiece(children->get(i), level));
|
|
}
|
|
|
|
readAdditonalSaveData(tag);
|
|
}
|
|
|
|
void StructureStart::readAdditonalSaveData(CompoundTag* tag) {}
|
|
|
|
void StructureStart::moveBelowSeaLevel(Level* level, Random* random,
|
|
int offset) {
|
|
const int MAX_Y = level->seaLevel - offset;
|
|
|
|
// set lowest possible position (at bedrock)
|
|
int y1Pos = boundingBox->getYSpan() + 1;
|
|
// move up randomly within the available span
|
|
if (y1Pos < MAX_Y) {
|
|
y1Pos += random->nextInt(MAX_Y - y1Pos);
|
|
}
|
|
|
|
// move all bounding boxes
|
|
int dy = y1Pos - boundingBox->y1;
|
|
boundingBox->move(0, dy, 0);
|
|
for (auto it = pieces.begin(); it != pieces.end(); it++) {
|
|
StructurePiece* piece = *it;
|
|
piece->getBoundingBox()->move(0, dy, 0);
|
|
}
|
|
}
|
|
|
|
void StructureStart::moveInsideHeights(Level* level, Random* random,
|
|
int lowestAllowed, int highestAllowed) {
|
|
int heightSpan =
|
|
highestAllowed - lowestAllowed + 1 - boundingBox->getYSpan();
|
|
int y0Pos = 1;
|
|
|
|
if (heightSpan > 1) {
|
|
y0Pos = lowestAllowed + random->nextInt(heightSpan);
|
|
} else {
|
|
y0Pos = lowestAllowed;
|
|
}
|
|
|
|
// move all bounding boxes
|
|
int dy = y0Pos - boundingBox->y0;
|
|
boundingBox->move(0, dy, 0);
|
|
for (auto it = pieces.begin(); it != pieces.end(); it++) {
|
|
StructurePiece* piece = *it;
|
|
piece->getBoundingBox()->move(0, dy, 0);
|
|
}
|
|
}
|
|
|
|
bool StructureStart::isValid() { return true; }
|
|
|
|
int StructureStart::getChunkX() { return chunkX; }
|
|
|
|
int StructureStart::getChunkZ() { return chunkZ; }
|