the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 138 lines 5.8 kB view raw
1#pragma once 2#include "WeighedRandom.h" 3#include "BoundingBox.h" 4#include "StructureFeatureIO.h" 5 6class Level; 7class Random; 8class ChunkPos; 9class BlockSelector; 10class ChestTileEntity; 11class TilePos; 12 13/** 14* 15* A structure piece is a construction or room, located somewhere in the world 16* with a given orientatino (out of Direction.java). Structure pieces have a 17* bounding box that says where the piece is located and its bounds, and the 18* orientation is used to translate local coordinates into world coordinates. 19* <p> 20* The default orientation is Direction.UNDEFINED, in which case no translation 21* will occur. If the orientation is Direction.NORTH, coordinate (0, 0, 0) will 22* be at (boundingBox.x0, boundingBox.y0, boundingBox.z1). In other words, (1, 23* 1, 1) will be translated to (boundingBox.x0 + 1, boundingBox.y0 + 1, 24* boundingBox.z1 - 1). 25* <p> 26* When using Direction.SOUTH, the x coordinate will be the same, and the z 27* coordinate will be flipped. In other words, the bounding box is NOT rotated! 28* It is only flipped along the z axis. Also note that the bounding box is in 29* world coordinates, so the local drawing must never reach outside of this. 30* <p> 31* When using east and west coordinates, the local z coordinate will be swapped 32* with the local x coordinate. For example, (0, 0, 0) is (boundingBox.z1, 33* boundingBox.y0, boundingBox.z0), and (1, 1, 1) becomes (boundingBox.x1 - 1, 34* boundingBox.y0 + 1, boundingBox.z0 + 1) when using Direction.WEST. 35* <p> 36* When-ever a structure piece is placing blocks, it is VERY IMPORTANT to always 37* make sure that all getTile and setTile calls are within the chunk's bounding 38* box. Failing to check this will cause the level generator to create new 39* chunks, leading to infinite loops and other errors. 40*/ 41class StructurePiece 42{ 43public: 44 virtual EStructurePiece GetType() = 0; 45 46public: 47 class BlockSelector 48 { 49 50 protected: 51 int nextId; 52 int nextData; 53 54 public: 55 virtual void next(Random *random, int worldX, int worldY, int worldZ, bool isEdge) {} 56 57 virtual int getNextId() { return nextId; } 58 virtual int getNextData() { return nextData; } 59 }; 60 61public: // 4J is protected in java, but accessed from VillagePieces, not sure how 62 BoundingBox *boundingBox; 63protected: 64 int orientation; 65 int genDepth; 66 67public: 68 StructurePiece(); 69 70protected: 71 StructurePiece(int genDepth); 72 73public: 74 virtual ~StructurePiece(); 75 76 virtual CompoundTag *createTag(); 77 78protected: 79 virtual void addAdditonalSaveData(CompoundTag *tag) = 0; 80 81public: 82 virtual void load(Level *level, CompoundTag *tag); 83 84protected: 85 virtual void readAdditonalSaveData(CompoundTag *tag) = 0; 86 87public: 88 virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random); 89 virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB) = 0; 90 91 virtual BoundingBox *getBoundingBox(); 92 93 int getGenDepth(); 94 95public: 96 bool isInChunk(ChunkPos *pos); 97 static StructurePiece *findCollisionPiece(list<StructurePiece *> *pieces, BoundingBox *box); 98 virtual TilePos *getLocatorPosition(); 99protected: 100 bool edgesLiquid(Level *level, BoundingBox *chunkBB); 101public: 102 // 4J Stu - Made these public to use in game rules 103 int getWorldX(int x, int z); 104 int getWorldY(int y); 105 int getWorldZ(int x, int z); 106 int getOrientationData(int tile, int data); 107 virtual void placeBlock(Level *level, int block, int data, int x, int y, int z, BoundingBox *chunkBB); 108 109 /** 110 * The purpose of this method is to wrap the getTile call on Level, in order 111 * to prevent the level from generating chunks that shouldn't be loaded yet. 112 * Returns 0 if the call is out of bounds. 113 * 114 * @param level 115 * @param x 116 * @param y 117 * @param z 118 * @param chunkPosition 119 * @return 120 */ 121 virtual int getBlock(Level *level, int x, int y, int z, BoundingBox *chunkBB); 122 virtual void generateAirBox(Level *level, BoundingBox *chunkBB, int x0, int y0, int z0, int x1, int y1, int z1); 123 virtual void generateBox(Level *level, BoundingBox *chunkBB, int x0, int y0, int z0, int x1, int y1, int z1, int edgeTile, int fillTile, bool skipAir); 124 virtual void generateBox(Level *level, BoundingBox *chunkBB, int x0, int y0, int z0, int x1, int y1, int z1, int edgeTile, int edgeData, int fillTile, int fillData, bool skipAir); 125 virtual void generateBox(Level *level, BoundingBox *chunkBB, BoundingBox *boxBB, int edgeTile, int fillTile, bool skipAir); 126 virtual void generateBox(Level *level, BoundingBox *chunkBB, int x0, int y0, int z0, int x1, int y1, int z1, bool skipAir, Random *random, BlockSelector *selector); 127 virtual void generateBox(Level *level, BoundingBox *chunkBB, BoundingBox *boxBB, bool skipAir, Random *random, BlockSelector *selector); 128 virtual void generateMaybeBox(Level *level, BoundingBox *chunkBB, Random *random, float probability, int x0, int y0, int z0, int x1, int y1, int z1, int edgeTile, int fillTile, bool skipAir); 129 virtual void maybeGenerateBlock(Level *level, BoundingBox *chunkBB, Random *random, float probability, int x, int y, int z, int tile, int data); 130 virtual void generateUpperHalfSphere(Level *level, BoundingBox *chunkBB, int x0, int y0, int z0, int x1, int y1, int z1, int fillTile, bool skipAir); 131 virtual void generateAirColumnUp(Level *level, int x, int startY, int z, BoundingBox *chunkBB); 132 virtual void fillColumnDown(Level *level, int tile, int tileData, int x, int startY, int z, BoundingBox *chunkBB); 133 virtual bool createChest(Level *level, BoundingBox *chunkBB, Random *random, int x, int y, int z, WeighedTreasureArray treasure, int numRolls); 134 virtual bool createDispenser(Level *level, BoundingBox *chunkBB, Random *random, int x, int y, int z, int facing, WeighedTreasureArray items, int numRolls); 135 136protected: 137 void createDoor(Level *level, BoundingBox *chunkBB, Random *random, int x, int y, int z, int orientation); 138};