Chunk Generation

Discussion in 'Plugin Development' started by oscarshi1995, Apr 19, 2014.

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

    oscarshi1995

    So right now I'm just iterating through the required area and using World.loadChunk(x,y,true)

    But when I iterate through the chunk, there is only grass dirt stone air and bedrock, No ores or anything else. Kinda like a flat grass map

    Anybody know how to fix this?

    edit: I think I need to rephrase my problem. The ores are not generated when i use World.loadchunk since when I loop through the blocks there are no ores. But when I join the game with an account there ARE ores.

    My goal was to remove all ore veins that are not connected to air. But since the ores dont exist when I loop through the blocks in the chunk it does nothing, But when i join the game and xray. all the ores are still there
     
  2. Offline

    RawCode

    post code
     
  3. Offline

    oscarshi1995

    Code:java
    1. package com.hotmail.ooosssososos.Tasks;
    2.  
    3. import com.hotmail.ooosssososos.Managers.GameManager;
    4. import com.hotmail.ooosssososos.Managers.VarManager;
    5. import com.hotmail.ooosssososos.Managers.WorldManager;
    6. import com.hotmail.ooosssososos.Util.ChunkCoord;
    7. import com.wimbli.WorldBorder.Config;
    8. import com.wimbli.WorldBorder.WorldFillTask;
    9. import org.bukkit.*;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.block.BlockFace;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.Plugin;
    14. import org.bukkit.scheduler.BukkitRunnable;
    15. import org.bukkit.scheduler.BukkitTask;
    16.  
    17. import java.util.ArrayList;
    18. import java.util.List;
    19.  
    20. /**
    21. * Created with IntelliJ IDEA.
    22. * User: oscar
    23. * Date: 3/22/14
    24. * Time: 12:21 AM
    25. * To change this template use File | Settings | File Templates.
    26. */
    27. /*
    28. ID: ooossso1
    29. LANG: JAVA
    30. TASK: MyWorldFillTask
    31. */
    32. public class MyWorldFillTask extends BukkitRunnable{
    33. public int xStart = (int)-(VarManager.worldDimensions.getWidth()/32)-3;
    34. public int zStart = (int)-VarManager.worldDimensions.getHeight()/32-3;
    35. public long lastReport = GameManager.startTime;
    36. public boolean Generating = true;
    37. public static final Material[] ores = {Material.GOLD_ORE, Material.IRON_ORE, Material.DIAMOND_ORE, Material.COAL_ORE, Material.EMERALD_ORE, Material.REDSTONE_ORE, Material.LAPIS_ORE, Material.REDSTONE_ORE};
    38.  
    39. public int completed = 0;
    40. List<ChunkCoord> chunks = new ArrayList<ChunkCoord>();
    41.  
    42. @Override
    43. public void run() {
    44.  
    45.  
    46. int thisRun = 0;
    47. World w = Bukkit.getWorld(VarManager.worldName);
    48. for (int x = xStart; x < VarManager.worldDimensions.getWidth()/32+3;x++){
    49. for(int z = zStart; z < VarManager.worldDimensions.getHeight()/32+3;z++){
    50. completed++;
    51. thisRun++;
    52. if(thisRun > VarManager.chunksPerRun){
    53. xStart = x;
    54. zStart = z;
    55. return;
    56. }
    57. if((System.currentTimeMillis()-lastReport)>10000){
    58. lastReport = System.currentTimeMillis();
    59. System.out.println((double)completed/((VarManager.worldDimensions.getWidth()/16+3)*(VarManager.worldDimensions.getHeight()/16+3))*100 + "% Complete World Generation");
    60. }
    61.  
    62. chunks.add(new ChunkCoord(x,z));
    63. w.loadChunk(x,z,true);
    64. if(VarManager.CaveOresOnly){
    65. Block d;
    66. Chunk c = w.getChunkAt(x,z);
    67. for(int ax = 0; ax < 16; ax++){
    68. for(int az = 0; az < 16; az++){
    69. for(int ay = 0; ay < 256; ay++){
    70. d = c.getBlock(ax,ay,az);
    71. System.out.println(d.getType());
    72. if(isOre(d)){
    73. fixVein(d);
    74. }
    75. }
    76. }
    77. }
    78.  
    79. }
    80.  
    81.  
    82. if(chunks.size() > 12){
    83. w.unloadChunk(chunks.get(0).x,chunks.get(0).z);
    84. chunks.remove(0);
    85. }
    86. }
    87. zStart = (int)-VarManager.worldDimensions.getHeight()/32-3;
    88. }
    89. for(ChunkCoord d : chunks){
    90. w.unloadChunk(d.x,d.z,true);
    91. }
    92. System.out.println("FillingCompleted");
    93. WorldManager.prepWorld();
    94. Bukkit.getScheduler().cancelTask(this.getTaskId());
    95. }
    96.  
    97. public boolean isOre(Block d){
    98. Material type = d.getType();
    99. for(Material s : ores){
    100. if(type == s) return true;
    101. }
    102. return false;
    103. }
    104. BlockFace[] blockFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
    105. public void fixVein(Block d){
    106. List<Block> inVein = new ArrayList<Block>();
    107. if(recurse(inVein, d)){
    108. for(Block z : inVein){
    109. z.setType(Material.STONE);
    110. }
    111. }
    112. }
    113.  
    114. public boolean recurse(List<Block> inVein, Block d){
    115. inVein.add(d);
    116. Block c;
    117. boolean ret = true;
    118. for(BlockFace i : blockFaces){
    119. c = d.getRelative(i);
    120. if(inVein.contains(c)) return true;
    121. if(c.getType().equals(Material.AIR))ret = false;
    122. if(isOre(c)){
    123. boolean tmp = recurse(inVein, c);
    124. if(!tmp) ret = false;
    125. }
    126. }
    127. return ret;
    128. }
    129. }
    130.  


    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    RawCode

    there is no entry point, you code have no chance to run.
     
  5. Offline

    blablubbabc

    @oscarshi1995The code you posted removes ore veins. So why do you wonder that there are no ores?
     
  6. Offline

    oscarshi1995

    RawCode I did not post all code. but there is an entry point
    blablubbabc I put a println in the triple for loop that loops through the blocks.

    I think I need to rephrase my problem. The ores are not generated when i use World.loadchunk since when I loop through the blocks there are no ores. But when I join the game with an account there ARE ores.

    My goal was to remove all ore veins that are not connected to air. But since the ores dont exist when I loop through the blocks in the chunk it does nothing, But when i join the game and xray. all the ores are still there

    bump

    nobody?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  7. Offline

    Lactem

  8. Offline

    oscarshi1995

    Update I wrote a quick program to render the surface:
    [​IMG]
    the black stuff that are in columns are supposed to be trees. (ignore black splotches in middle)
     
  9. Offline

    RawCode

    then give me entrypoint line, i checked again and not noticed one oscarshi1995
     
  10. Offline

    oscarshi1995

    Entry Line:


    Code:java
    1.  
    2. public static void loadWorld(){
    3. Config.setBorder(VarManager.worldName, VarManager.worldDimensions.width, VarManager.worldDimensions.height, 0, 0);
    4. /*Config.fillTask = new com.wimbli.WorldBorder.WorldFillTask(Bukkit.getServer(), Bukkit.getPlayer("Mr_CreeperSSS"), VarManager.worldName, 0, VarManager.chunksPerRun, 1);
    5.   int task = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("AutoUHC"), Config.fillTask, 1,1);
    6.   Config.fillTask.setTaskID(task);
    7.   System.out.println(Config.fillTask.valid()); */
    8. BukkitRunnable r = new MyWorldFillTask();
    9. r.runTaskTimer(Bukkit.getPluginManager().getPlugin("AutoUHC"), 10, 1);
    10. }
    11.  


    Load world is called from another method that prep class and that's called from the onEnable I know for a fact it runs and all the config vars are initialized

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Offline

    RawCode

    you shoud read carefully javadocs and (or) source about chunk generation process - chunk shaping and feature population.

    your code logic is invalid, you shoud alter feature populator list, how you can read in javadocs.
     
  12. Offline

    oscarshi1995

    I havnt found any good resources on the chunk generation process. ive looked throught he bukkit javadocs as well as craftbukkit chunk files :/ I see in the cb Chunk file there is the "done" boolean but the method names dont tell me anything about the method ;/
     
  13. Offline

    RawCode

    if you noticed field, what about searching all cases of that field usage?
     
Thread Status:
Not open for further replies.

Share This Page