the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 180 lines 3.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.level.levelgen.structure.h" 4#include "StructureStart.h" 5#include "StructurePiece.h" 6#include "BoundingBox.h" 7 8 9StructureStart::StructureStart() 10{ 11 chunkX = chunkZ = 0; 12 boundingBox = NULL; // 4J added initialiser 13} 14 15StructureStart::StructureStart(int x, int z) 16{ 17 this->chunkX = x; 18 this->chunkZ = z; 19 boundingBox = NULL; 20} 21 22StructureStart::~StructureStart() 23{ 24 for(AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ ) 25 { 26 delete (*it); 27 } 28 delete boundingBox; 29} 30 31BoundingBox *StructureStart::getBoundingBox() 32{ 33 return boundingBox; 34} 35 36list<StructurePiece *> *StructureStart::getPieces() 37{ 38 return &pieces; 39} 40 41void StructureStart::postProcess(Level *level, Random *random, BoundingBox *chunkBB) 42{ 43 AUTO_VAR(it, pieces.begin()); 44 45 while( it != pieces.end() ) 46 { 47 if( (*it)->getBoundingBox()->intersects(chunkBB) && !(*it)->postProcess(level, random, chunkBB)) 48 { 49 // this piece can't be placed, so remove it to avoid future 50 // attempts 51 it = pieces.erase(it); 52 } 53 else 54 { 55 it++; 56 } 57 } 58} 59 60void StructureStart::calculateBoundingBox() 61{ 62 boundingBox = BoundingBox::getUnknownBox(); 63 64 for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ ) 65 { 66 StructurePiece *piece = *it; 67 boundingBox->expand(piece->getBoundingBox()); 68 } 69} 70 71CompoundTag *StructureStart::createTag(int chunkX, int chunkZ) 72{ 73 CompoundTag *tag = new CompoundTag(); 74 75 tag->putString(L"id", StructureFeatureIO::getEncodeId(this)); 76 tag->putInt(L"ChunkX", chunkX); 77 tag->putInt(L"ChunkZ", chunkZ); 78 tag->put(L"BB", boundingBox->createTag(L"BB")); 79 80 ListTag<CompoundTag> *childrenTags = new ListTag<CompoundTag>(L"Children"); 81 for(AUTO_VAR(it, pieces.begin()); it != pieces.end(); ++it) 82 { 83 StructurePiece *piece = *it; 84 childrenTags->add(piece->createTag()); 85 } 86 tag->put(L"Children", childrenTags); 87 88 addAdditonalSaveData(tag); 89 90 return tag; 91} 92 93void StructureStart::addAdditonalSaveData(CompoundTag *tag) 94{ 95 96} 97 98void StructureStart::load(Level *level, CompoundTag *tag) 99{ 100 chunkX = tag->getInt(L"ChunkX"); 101 chunkZ = tag->getInt(L"ChunkZ"); 102 if (tag->contains(L"BB")) 103 { 104 boundingBox = new BoundingBox(tag->getIntArray(L"BB")); 105 } 106 107 ListTag<CompoundTag> *children = (ListTag<CompoundTag> *) tag->getList(L"Children"); 108 for (int i = 0; i < children->size(); i++) 109 { 110 pieces.push_back(StructureFeatureIO::loadStaticPiece(children->get(i), level)); 111 } 112 113 readAdditonalSaveData(tag); 114} 115 116void StructureStart::readAdditonalSaveData(CompoundTag *tag) 117{ 118 119} 120 121void StructureStart::moveBelowSeaLevel(Level *level, Random *random, int offset) 122{ 123 const int MAX_Y = level->seaLevel - offset; 124 125 // set lowest possible position (at bedrock) 126 int y1Pos = boundingBox->getYSpan() + 1; 127 // move up randomly within the available span 128 if (y1Pos < MAX_Y) 129 { 130 y1Pos += random->nextInt(MAX_Y - y1Pos); 131 } 132 133 // move all bounding boxes 134 int dy = y1Pos - boundingBox->y1; 135 boundingBox->move(0, dy, 0); 136 for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ ) 137 { 138 StructurePiece *piece = *it; 139 piece->getBoundingBox()->move(0, dy, 0); 140 } 141} 142 143void StructureStart::moveInsideHeights(Level *level, Random *random, int lowestAllowed, int highestAllowed) 144{ 145 int heightSpan = highestAllowed - lowestAllowed + 1 - boundingBox->getYSpan(); 146 int y0Pos = 1; 147 148 if (heightSpan > 1) 149 { 150 y0Pos = lowestAllowed + random->nextInt(heightSpan); 151 } 152 else 153 { 154 y0Pos = lowestAllowed; 155 } 156 157 // move all bounding boxes 158 int dy = y0Pos - boundingBox->y0; 159 boundingBox->move(0, dy, 0); 160 for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ ) 161 { 162 StructurePiece *piece = *it; 163 piece->getBoundingBox()->move(0, dy, 0); 164 } 165} 166 167bool StructureStart::isValid() 168{ 169 return true; 170} 171 172int StructureStart::getChunkX() 173{ 174 return chunkX; 175} 176 177int StructureStart::getChunkZ() 178{ 179 return chunkZ; 180}