Jtjj222's list of awesome block populators

Discussion in 'Resources' started by jtjj222, Oct 23, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    jtjj222

    Schematics populator(630 lines) (open)

    This one loads a schematic file from string filepath, and puts it into the world every 3 chunks. All the code that would need to be modified is at the top. Credit jtjj222. If it doesn't make sense to you (it is a bit messy seeing as it has been moved into one file) I will be writing a tutorial on it. You can have the clean source code here.
    Code:java
    1.  
    2. /** @author jtjj222 */
    3. import java.io.DataInput;
    4. import java.io.DataInputStream;
    5. import java.io.DataOutput;
    6. import java.io.DataOutputStream;
    7. import java.io.File;
    8. import java.io.FileInputStream;
    9. import java.io.FileOutputStream;
    10. import java.io.IOException;
    11. import java.util.ArrayList;
    12. import java.util.HashMap;
    13. import java.util.Random;
    14. import java.util.zip.GZIPInputStream;
    15. import java.util.zip.GZIPOutputStream;
    16.  
    17. import org.bukkit.Chunk;
    18. import org.bukkit.World;
    19. import org.bukkit.generator.BlockPopulator;
    20.  
    21. public class SchematicsPopulator extends BlockPopulator {
    22.  
    23. public String filepath;
    24.  
    25. @Override
    26. public void populate(World world, Random rand, Chunk chunk) {
    27.  
    28. if (chunk.getX() % 3 == 0 && chunk.getZ() % 3 == 0) {
    29.  
    30. try {
    31. File file = new File(this.filepath);
    32. SchematicsManager man = new SchematicsManager();
    33. man.loadGzipedSchematic(file);
    34.  
    35. int width = man.getWidth();
    36. int height = man.getHeight();
    37. int length = man.getLength();
    38.  
    39. int starty = world.getHighestBlockAt(chunk.getX() * 16, chunk.getZ() * 16).getY();
    40. int endy = starty + height;
    41.  
    42. for (int x = 0; x < width; x++) {
    43. for (int z = 0; z < length; z++) {
    44. int realX = x + chunk.getX() * 16;
    45. int realZ = z + chunk.getZ() * 16;
    46.  
    47. for (int y = starty; y<=endy && y <255; y++) {
    48.  
    49. int rely = y - starty;
    50. int id = man.getBlockIdAt(x, rely, z);
    51. byte data = man.getMetadataAt(x, rely, z);
    52.  
    53. if (id != -1) world.getBlockAt(realX, y, realZ).setTypeId(id);
    54. if (id != -1) world.getBlockAt(realX, y, realZ).setData(data);
    55. }
    56. }
    57. }
    58.  
    59. } catch (IOException e) {
    60. System.out.println("Could not read the schematic file");
    61. e.printStackTrace();
    62. }
    63. }
    64. }
    65.  
    66. }
    67.  
    68. class SchematicsManager {
    69.  
    70. private byte[] blocks,metadata;
    71. private short width,height,length;
    72.  
    73. public void loadUncompressedSchematic(DataInput in) throws IOException{
    74. NBT_Tag compound = NBT_Tag.readTag(in);
    75. NBT_Tag_Compound tag = (NBT_Tag_Compound) compound;
    76.  
    77. this.width = ((NBT_Tag_Short)tag.payload.get("Width")).payload;///x axis
    78. this.height = ((NBT_Tag_Short)tag.payload.get("Height")).payload;//y axis
    79. this.length = ((NBT_Tag_Short)tag.payload.get("Length")).payload;//z axis
    80.  
    81. this.blocks = ((NBT_Tag_Byte_Array)tag.payload.get("Blocks")).payload;
    82. this.metadata = ((NBT_Tag_Byte_Array)tag.payload.get("Data")).payload;
    83. }
    84.  
    85. public void writeUncompressedSchematic(DataOutput out) throws IOException {
    86. NBT_Tag_Compound root = new NBT_Tag_Compound("Schematic");
    87. root.payload.put("Width", new NBT_Tag_Short("Width",this.width));
    88. root.payload.put("Height", new NBT_Tag_Short("Height",this.height));
    89. root.payload.put("Length", new NBT_Tag_Short("Length",this.length));
    90.  
    91. root.payload.put("Blocks", new NBT_Tag_Byte_Array("Blocks",this.blocks));
    92. root.payload.put("Data", new NBT_Tag_Byte_Array("Data",this.metadata));
    93. root.writeTag(out);
    94. }
    95.  
    96. public void writeUncompressedSchematic(File f) throws IOException {
    97. writeUncompressedSchematic(out);
    98. out.close();
    99. }
    100.  
    101. public void writeGzipedSchematic(File f) throws IOException {
    102. writeUncompressedSchematic(out);
    103. out.close();
    104. }
    105.  
    106. //Most schematics are gzipped
    107. public void loadGzipedSchematic(File f) throws IOException {
    108. loadUncompressedSchematic(in);
    109. in.close();
    110. }
    111.  
    112. public void loadUncompressedSchematic(File f) throws IOException {
    113. loadUncompressedSchematic(in);
    114. in.close();
    115. }
    116.  
    117. private int getBlockOffset(int x, int y, int z) {
    118. return y * width * length + z * width + x;
    119. }
    120.  
    121. public byte getBlockIdAt(int x, int y, int z) {
    122. int offset = getBlockOffset(x, y, z);
    123. if (offset < this.blocks.length && offset >= 0) return this.blocks[offset];
    124. else return -1;
    125. }
    126.  
    127. public void setBlockIdAt(int x, int y, int z, byte id) {
    128. int offset = getBlockOffset(x, y, z);
    129. if (offset < this.blocks.length && offset >= 0) this.blocks[offset] = id;
    130. }
    131.  
    132. public byte getMetadataAt(int x, int y, int z) {
    133. int offset = getBlockOffset(x, y, z);
    134. if (offset < this.metadata.length && offset >= 0) return this.metadata[offset];
    135. else return 0;
    136. }
    137.  
    138. public void setMetadataIdAt(int x, int y, int z, byte data) {
    139. int offset = getBlockOffset(x, y, z);
    140. if (offset < this.metadata.length && offset >= 0) this.metadata[offset] = data;
    141. }
    142.  
    143.  
    144. public short getWidth() {
    145. return width;
    146. }
    147.  
    148. public void setWidth(short width) {
    149. this.width = width;
    150. }
    151.  
    152. public short getHeight() {
    153. return height;
    154. }
    155.  
    156. public void setHeight(short height) {
    157. this.height = height;
    158. }
    159.  
    160. public short getLength() {
    161. return length;
    162. }
    163.  
    164. public void setLength(short length) {
    165. this.length = length;
    166. }
    167.  
    168. public byte[] getBlocks() {
    169. return blocks;
    170. }
    171.  
    172. public void setBlocks(byte[] blocks) {
    173. this.blocks = blocks;
    174. }
    175.  
    176. public byte[] getMetadata() {
    177. return metadata;
    178. }
    179.  
    180. public void setMetadata(byte[] metadata) {
    181. this.metadata = metadata;
    182. }
    183. }
    184.  
    185.  
    186. //This marks the end of compound tags.
    187. //It has no name, and is only ever a single byte
    188. class NBT_Tag_End extends NBT_Tag{
    189.  
    190. public NBT_Tag_End(String name){
    191. super(0, "");
    192. }
    193.  
    194. public NBT_Tag_End(String name, int payload){
    195. super(8, name);
    196. }
    197.  
    198. @Override
    199. public void readTagPayload(DataInput in) throws IOException {
    200. System.out.println("An error has occoured. An named binary tree tag 'end' has had it's payload read. It doesn't have a payload. Fix your code :D");
    201. }
    202.  
    203. @Override
    204. public void writeTag(DataOutput out) throws IOException {
    205. out.write(this.id);
    206. }
    207.  
    208. public void writePayload(DataOutput out) throws IOException {}
    209.  
    210. }
    211.  
    212. class NBT_Tag_Double extends NBT_Tag{
    213.  
    214. public double payload;
    215.  
    216. public NBT_Tag_Double(String name){
    217. super(6, name);
    218. }
    219.  
    220. public NBT_Tag_Double(String name, double payload){
    221. super(8, name);
    222. this.payload = payload;
    223. }
    224.  
    225. @Override
    226. public void readTagPayload(DataInput in) throws IOException {
    227. this.payload = in.readDouble();
    228. }
    229.  
    230. public void writeTag(DataOutput out) throws IOException {
    231. out.write(this.id);
    232. out.writeUTF(this.name);
    233. this.writePayload(out);
    234. }
    235. public void writePayload(DataOutput out) throws IOException {
    236. out.writeDouble(this.payload);
    237. }
    238. }
    239.  
    240. class NBT_Tag_Compound extends NBT_Tag{
    241.  
    242. public HashMap<String,NBT_Tag> payload;
    243.  
    244. public NBT_Tag_Compound(String name){
    245. super(10, name);
    246. }
    247. public NBT_Tag_Compound(String name, HashMap<String,NBT_Tag> payload){
    248. super(8, name);
    249. this.payload = payload;
    250. }
    251.  
    252. @Override
    253. public void readTagPayload(DataInput in) throws IOException {
    254. payload = new HashMap<String,NBT_Tag>();
    255. NBT_Tag tag;
    256. //while it isn't Tag_End
    257. while ((tag = NBT_Tag.readTag(in)).id != 0) {
    258. this.payload.put(tag.name,tag);
    259. }
    260. this.payload.put("__end",new NBT_Tag_End("__end"));
    261. }
    262.  
    263. public void writeTag(DataOutput out) throws IOException {
    264. out.write(this.id);
    265. out.writeUTF(this.name);
    266. this.writePayload(out);
    267. }
    268.  
    269. public void writePayload(DataOutput out) throws IOException {
    270. for(String key : payload.keySet()) {
    271. NBT_Tag tag = payload.get(key);
    272. tag.writeTag(out);
    273. }
    274. }
    275. }
    276.  
    277. class NBT_Tag_Byte extends NBT_Tag{
    278.  
    279. public byte payload;
    280.  
    281. public NBT_Tag_Byte(String name){
    282. super(1,name);
    283. }
    284. public NBT_Tag_Byte(String name, byte payload){
    285. super(8, name);
    286. this.payload = payload;
    287. }
    288.  
    289. @Override
    290. public void readTagPayload(DataInput in) throws IOException {
    291. this.payload = in.readByte();
    292. }
    293.  
    294. public void writeTag(DataOutput out) throws IOException {
    295. out.write(this.id);
    296. out.writeUTF(this.name);
    297. this.writePayload(out);
    298. }
    299.  
    300. public void writePayload(DataOutput out) throws IOException {
    301. out.write(this.payload);
    302. }
    303. }
    304.  
    305. class NBT_Tag_Byte_Array extends NBT_Tag{
    306.  
    307. public int size;
    308. public byte[] payload;
    309.  
    310. public NBT_Tag_Byte_Array(String name){
    311. super(7, name);
    312. }
    313.  
    314. public NBT_Tag_Byte_Array(String name, byte[] payload){
    315. super(8, name);
    316. this.payload = payload;
    317. }
    318.  
    319. @Override
    320. public void readTagPayload(DataInput in) throws IOException {
    321. int size = in.readInt();
    322. this.size = size;
    323. this.payload = new byte[size];
    324.  
    325. in.readFully(this.payload);
    326. }
    327.  
    328. public void writeTag(DataOutput out) throws IOException {
    329. out.write(this.id);
    330. out.writeUTF(this.name);
    331. out.writeInt(this.size);
    332. this.writePayload(out);
    333. }
    334.  
    335. public void writePayload(DataOutput out) throws IOException {
    336. for (byte i: this.payload) {
    337. out.writeByte(i);
    338. }
    339. }
    340. }
    341.  
    342. class NBT_Tag_String extends NBT_Tag{
    343.  
    344. public String payload;
    345.  
    346. public NBT_Tag_String(String name){
    347. super(8, name);
    348. }
    349. public NBT_Tag_String(String name, String payload){
    350. super(8, name);
    351. this.payload = payload;
    352. }
    353.  
    354. @Override
    355. public void readTagPayload(DataInput in) throws IOException {
    356. this.payload = in.readUTF();
    357. }
    358.  
    359. public void writeTag(DataOutput out) throws IOException {
    360. out.write(this.id);
    361. out.writeUTF(this.name);
    362. this.writePayload(out);
    363. }
    364.  
    365. public void writePayload(DataOutput out) throws IOException {
    366. out.writeUTF(this.payload);
    367. }
    368. }
    369.  
    370. class NBT_Tag_Short extends NBT_Tag{
    371.  
    372. public short payload;
    373.  
    374. public NBT_Tag_Short(String name){
    375. super(2, name);
    376. }
    377. public NBT_Tag_Short(String name, short payload){
    378. super(8, name);
    379. this.payload = payload;
    380. }
    381.  
    382. @Override
    383. public void readTagPayload(DataInput in) throws IOException {
    384. this.payload = in.readShort();
    385. }
    386.  
    387. public void writeTag(DataOutput out) throws IOException {
    388. out.write(this.id);
    389. out.writeUTF(this.name);
    390. this.writePayload(out);
    391. }
    392.  
    393. public void writePayload(DataOutput out) throws IOException {
    394. out.writeShort(this.payload);
    395. }
    396.  
    397. }
    398.  
    399. class NBT_Tag_Long extends NBT_Tag{
    400.  
    401. public long payload;
    402.  
    403. public NBT_Tag_Long(String name){
    404. super(4, name);
    405. }
    406.  
    407. public NBT_Tag_Long(String name, Long payload){
    408. super(8, name);
    409. this.payload = payload;
    410. }
    411.  
    412. @Override
    413. public void readTagPayload(DataInput in) throws IOException {
    414. this.payload = in.readLong();
    415. }
    416.  
    417. public void writeTag(DataOutput out) throws IOException {
    418. out.write(this.id);
    419. out.writeUTF(this.name);
    420. this.writePayload(out);
    421. }
    422.  
    423. public void writePayload(DataOutput out) throws IOException {
    424. out.writeLong(this.payload);
    425. }
    426.  
    427. }
    428.  
    429. class NBT_Tag_List extends NBT_Tag{
    430.  
    431. public byte tag_type;
    432. public int size;
    433. public ArrayList<NBT_Tag> payload;
    434.  
    435. public NBT_Tag_List(String name){
    436. super(9, name);
    437. }
    438.  
    439. public NBT_Tag_List(String name, ArrayList<NBT_Tag> payload){
    440. super(8, name);
    441. this.payload = payload;
    442. }
    443.  
    444. @Override
    445. public void readTagPayload(DataInput in) throws IOException {
    446. this.tag_type = in.readByte();
    447. int size = in.readInt();
    448. this.size = size;
    449. this.payload = new ArrayList<NBT_Tag>();
    450.  
    451. for (int i = 0; i < size; i++) {
    452. NBT_Tag tag = NBT_Tag.getNewTag(this.tag_type, "");
    453. tag.readTagPayload(in);
    454. this.payload.add(tag);
    455. }
    456. }
    457.  
    458. public void writeTag(DataOutput out) throws IOException {
    459. out.write(this.id);
    460. out.writeUTF(this.name);
    461. out.writeInt(this.size);
    462.  
    463. this.writePayload(out);
    464. }
    465.  
    466. public void writePayload(DataOutput out) throws IOException {
    467. for (NBT_Tag tag : this.payload) {
    468. tag.writePayload(out);
    469. }
    470. }
    471. }
    472.  
    473. class NBT_Tag_Int extends NBT_Tag{
    474.  
    475. public int payload;
    476.  
    477. public NBT_Tag_Int(String name){
    478. super(3, name);
    479. }
    480.  
    481. @Override
    482. public void readTagPayload(DataInput in) throws IOException {
    483. this.payload = in.readInt();
    484. }
    485.  
    486. public NBT_Tag_Int(String name, int payload){
    487. super(8, name);
    488. this.payload = payload;
    489. }
    490.  
    491. public void writeTag(DataOutput out) throws IOException {
    492. out.write(this.id);
    493. out.writeUTF(this.name);
    494. this.writePayload(out);
    495. }
    496.  
    497. public void writePayload(DataOutput out) throws IOException {
    498. out.writeInt(this.payload);
    499. }
    500.  
    501. }
    502.  
    503. class NBT_Tag_Int_Array extends NBT_Tag{
    504.  
    505. public int size;
    506. public int[] payload;
    507.  
    508. public NBT_Tag_Int_Array(String name){
    509. super(11, name);
    510. }
    511.  
    512. public NBT_Tag_Int_Array(String name, int[] payload){
    513. super(8, name);
    514. this.payload = payload;
    515. }
    516.  
    517. @Override
    518. public void readTagPayload(DataInput in) throws IOException {
    519. int size = in.readInt();
    520. this.size = size;
    521. this.payload = new int[size];
    522.  
    523. for (int i = 0; i < size; i++) {
    524. this.payload[i] = in.readInt();
    525. }
    526. }
    527.  
    528. public void writeTag(DataOutput out) throws IOException {
    529. out.write(this.id);
    530. out.writeUTF(this.name);
    531. out.writeInt(this.size);
    532. this.writePayload(out);
    533. }
    534.  
    535. public void writePayload(DataOutput out) throws IOException {
    536. for (int i: this.payload) {
    537. out.writeInt(i);
    538. }
    539. }
    540. }
    541.  
    542. class NBT_Tag_Float extends NBT_Tag{
    543.  
    544. public float payload;
    545.  
    546. public NBT_Tag_Float(String name){
    547. super(5, name);
    548. }
    549. public NBT_Tag_Float(String name, float payload){
    550. super(8, name);
    551. this.payload = payload;
    552. }
    553.  
    554. @Override
    555. public void readTagPayload(DataInput in) throws IOException {
    556. this.payload = in.readFloat();
    557. }
    558.  
    559. public void writeTag(DataOutput out) throws IOException {
    560. out.write(this.id);
    561. out.writeUTF(this.name);
    562. this.writePayload(out);
    563. }
    564.  
    565. public void writePayload(DataOutput out) throws IOException {
    566. out.writeFloat(this.payload);
    567. }
    568.  
    569. }
    570.  
    571. abstract class NBT_Tag {
    572.  
    573. public static NBT_Tag getNewTag(int id,String name) {
    574. switch (id) {
    575. case 0 : return new NBT_Tag_End("");
    576. case 1 : return new NBT_Tag_Byte(name);
    577. case 2 : return new NBT_Tag_Short(name);
    578. case 3 : return new NBT_Tag_Int(name);
    579. case 4 : return new NBT_Tag_Long(name);
    580. case 5 : return new NBT_Tag_Float(name);
    581. case 6 : return new NBT_Tag_Double(name);
    582. case 7 : return new NBT_Tag_Byte_Array(name);
    583. case 8 : return new NBT_Tag_String(name);
    584. case 9 : return new NBT_Tag_List(name);
    585. case 10 : return new NBT_Tag_Compound(name);
    586. case 11 : return new NBT_Tag_Int_Array(name);
    587. default : return null;
    588. }
    589. }
    590. public static NBT_Tag readTag(DataInput in) throws IOException {
    591. NBT_Tag tag;
    592. byte tag_id = in.readByte();
    593. if (tag_id == 0) return new NBT_Tag_End("");
    594. String tag_name = in.readUTF();
    595. tag = getNewTag(tag_id,tag_name);
    596. tag.readTagPayload(in);
    597. return tag;
    598. }
    599.  
    600. //First byte of the tag is the type id
    601. byte id;
    602.  
    603. //Then the name of the tag in UTF-8
    604. String name;
    605.  
    606. //Then the tag-specific payload...
    607.  
    608. public NBT_Tag(String name) {
    609. this.id = 0; //overwritten
    610. this.name = name;
    611. }
    612. protected NBT_Tag(int id, String name) {
    613. this.id = (byte) id;
    614. this.name = name;
    615. }
    616.  
    617. //Read the tag's payload (assumes that the id,
    618. //name_length and name have already been read
    619. //in order to identfy the tag
    620. public abstract void readTagPayload(DataInput in) throws IOException;
    621.  
    622. public abstract void writeTag(DataOutput out) throws IOException;
    623.  
    624. public abstract void writePayload(DataOutput out) throws IOException;
    625. }
    626.  
    627. [/i]

    Here is an image:
    2012-10-23_17.47.45.png

    This will grow as I (and hopefully other people) contribute this list. You may use any populator you want for anything, but it would be nice if you thanked the person who wrote it, that way the have more incentive to keep making block populators.
    Just leave a post below with the code for the populator, and a picture, and the best/most useful ones will come up here :D
    Let the coding begin!
     
  2. This might just be what I need Jtjj222, do you know how to get a populater to remove blocks?
     
  3. Offline

    jtjj222

    world.getBlockAt(x,y,z).setType(Material.AIR)?
     
  4. I tried that I think... it locked up... I'll fire up my ide later and have a look again
     
  5. Offline

    jtjj222

    I really hoped more people would contribute. I'll get this started by tagging a few people active in terrain generation:
    codename_B Courier snap64 Empty2k12 Icyene TechGuard NSArray sd5 Kodfod Thumbz
    Hope that covers everyone :D
    Hopefully some people can add a few cool block populators. I am working on a castle populator as I write, so I will add that shortly.
     
  6. Offline

    Uniclaw

    WOW, awesome! Just a Question: How can i "proccess" the schematic before spawning? Because i would change all signs with in the first line "wool" to wool, and then spawn the schematic..
    And is the spawning random, ore every x blocks? jtjj222 (And how can is use this awesome code xD ?)
     
    jtjj222 likes this.
  7. Offline

    mncat77 Retired Staff

    Okay, I tried to create an oreveinpopulator, I don't know if it'll work (maybe someone can test it).
    I think I'll improve it tomorrow because I am a little short on time now (make it less block, add checks make efeeshaant(vechs fault xD), like the comments say)...
    Show Spoiler
    Code:java
    1. package me.mncat77.plugins.mnimageterrain.populators;
    2.  
    3. import java.util.Random;
    4. import org.bukkit.Chunk;
    5. import org.bukkit.World;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.generator.BlockPopulator;
    8. import org.bukkit.util.Vector;
    9.  
    10. public class MnOreVeinPopulator extends BlockPopulator {
    11.  
    12. private int attempts;
    13. private int individualNumber;
    14. private int blockId;
    15. private int[] replaceBlockId;
    16. private int minVeinSize;
    17. private int maxVeinSize;
    18.  
    19. public MnOreVeinPopulator(int attempts, int individualNumber, int blockId, int[] replaceBlockId, int minVeinSize, int maxVeinSize){
    20. this.attempts = attempts;
    21. this.individualNumber = individualNumber;
    22. this.blockId = blockId;
    23. this.replaceBlockId = replaceBlockId;
    24. this.minVeinSize = minVeinSize;
    25. this.maxVeinSize = maxVeinSize;
    26. }
    27.  
    28. @Override
    29. public void populate(World world, Random random, Chunk chunk) {
    30. if((attempts==0)||maxVeinSize==0){
    31. return;
    32. }
    33. for(int i=0;i<=attempts;i++){
    34. Block startblock = chunk.getBlock(random.nextInt(16), random.nextInt(world.getMaxHeight()-1)+1, random.nextInt(16));
    35. boolean place = false;
    36. for(int j=0;j<replaceBlockId.length;j++){
    37. if(startblock.getTypeId()==this.replaceBlockId[j]){
    38. place=true;
    39. break;
    40. }
    41. }
    42. if(place){
    43. startblock.setTypeId(this.blockId);
    44. int length = (int)Math.floor(Math.cbrt((double)this.maxVeinSize))+1;
    45. // I know I should check somewhere below if the vein would go out of the chunk and replace it, but
    46. // I was too lazy... ...for now...
    47. // Also I should shape it a little less ugly and blocky
    48. // I think I'll fix that tomorrow ^^
    49. int blocks = 0;
    50. for(int offsetX=0;offsetX<=length;offsetX++){
    51. for(int offsetZ=0;offsetZ<=length;offsetZ++){
    52. for(int offsetY=0;offsetY<=length;offsetY++){
    53. try{
    54. Block newBlock = startblock.getLocation().add(new Vector(offsetX,offsetY,offsetZ)).getBlock();
    55. boolean nplace = false;
    56. for(int j=0;j<replaceBlockId.length;j++){
    57. if(newBlock.getTypeId()==this.replaceBlockId[j]){
    58. nplace=true;
    59. break;
    60. }
    61. }
    62. if(nplace){startblock.getLocation().add(new Vector(offsetX,offsetY,offsetZ)).getBlock().setTypeId(this.blockId);}
    63. blocks++;
    64. if(blocks==this.maxVeinSize){offsetX=10000;offsetY=10000;offsetZ=10000;}// Lazy, I know will improve it :D
    65. }
    66. catch(Exception e){}
    67. }
    68. }
    69. }
    70. }
    71. else{
    72. break;
    73. }
    74. }
    75. }
    76.  
    77. }
     
    jtjj222 likes this.
  8. Offline

    Uniclaw

    Hm, how can i spawn a schematic random? I've tryed:

    (deleting if(chunk.getX()%3==0&& chunk.getZ()%3==0){ )
    and then making a thing like int random = Math.random *99;if(random <= 50)


    but doesn't works..
     
  9. Offline

    jtjj222

    You can't use Math.random for multi-chunk structures, because there is the possibility that two structures will be generated next to each other (in adjacent chunks). You have to use a noise function that returns the same value based on a seed, x and z co-ordinate. For smaller structures, you would do:
    Code:java
    1.  
    2. Random rand = new Random(world.getSeed());
    3. ...
    4. if (rand.nextInt(100)<=60)//59% chance
    5. ...
    6.  
     
  10. Offline

    Uniclaw

    Thanks!

    (Little Question: What the code is exaclty doing?)
     
  11. Offline

    jtjj222

    It generates a random number between 0 and 100. If that numeber is below 60, it does something. That is a 60% chance. Put that instead of (if chunkx % 3... to generate structures by chance.
     
  12. Offline

    Uniclaw

    Thanks :D! And another thing: How can i get the block direclty under the middle from the schematic, and check if its something - if not, cancel?
     
  13. Offline

    jtjj222

    Let x,y and z be the block you start placing the schematic at. The middle would be (x + width/2) , (y-1), and (z + length/2). You would get the block type using world.getBlockAt(x,y,z).getType().
    Code:java
    1.  
    2. if (world.getBlockAt(x + width/2, y-1, z + length/2) //do something
    3. else //cancel
    4.  
     
  14. Offline

    Uniclaw

    But how can i get the start coords xD ? Sorry for this noob questions :'(
     
  15. Offline

    jtjj222

    chunk.getX() * 16 + rand.nextInt(16);
    chunk.getZ() * 16 + rand.nextInt(16);
     
  16. Offline

    Uniclaw

    jtjj222 Thanks! Another question: I will set snowblocks under the schematic, but just in the middle. For that i've done that:
    Code:
    Location loc = world.getBlockAt(chunk.getX() * 16 + rand.nextInt(16) + width/2, starty -2, chunk.getZ() * 16 + rand.nextInt(16) + length/2).getLocation();
    loc.getBlock().setTypeId(80);loc.add(1,0,0).getBlock().setTypeId(80);loc.add(1,0,1).getBlock().setTypeId(80);loc.add(-1,0,0).getBlock().setTypeId(80);loc.add(-1,0,-1).getBlock().setTypeId(80);loc.add(0,0,-1).getBlock().setTypeId(80);loc.add(0,0,1).getBlock().setTypeId(80);
    loc.add(2,0,0).getBlock().setTypeId(80);loc.add(2,0,2).getBlock().setTypeId(80);loc.add(-2,0,0).getBlock().setTypeId(80);loc.add(-2,0,-2).getBlock().setTypeId(80);loc.add(0,0,-2).getBlock().setTypeId(80);loc.add(0,0,2).getBlock().setTypeId(80);
    But doesn't works!
     
  17. Offline

    El_Minadero

    super old thread.. but I think this has what I'm looking for. So basically I'm wondering how to use the default mineshaft populators (if MC uses populators to make mineshafts) to make a mineshaft complex where an opening is on the surface at a specific x,y,z cord with an initial placement vector, but no blocks are placed in the shaft complex that are above the original highest stone block? jtjj222 have any ideas?
     
Thread Status:
Not open for further replies.

Share This Page