Solved BlockPopulator not finishing before moving on

Discussion in 'Plugin Development' started by bowlerguy66, Jan 19, 2020.

  1. Offline

    bowlerguy66

    Hi all, I am using blockpopulators to generate ores in each chunk. A problem I'm running into is the BlockPopulator doesn't seem to finish before moving on to a new chunk, leaving my world generated with fewer ores than I'd like.

    Here's my populator class:
    Block Populator Class (open)

    Code:
    package me.bowlerguy66.etweaks.miningdimension.generator;
    
    import java.util.HashMap;
    import java.util.Random;
    
    import org.bukkit.Chunk;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.generator.BlockPopulator;
    
    import me.bowlerguy66.etweaks.utils.MaterialTable;
    
    public class DimensionOrePopulator extends BlockPopulator {
    
        HashMap<Material, Integer> maxVeinSize;
        MaterialTable ores;
        
        public DimensionOrePopulator() {
    
        }
    
        @Override
        public void populate(World world, Random rand, Chunk chunk) {
                        
            fillTables();
        
            int x, y, z;
                        
            for(int i = 0; i < 1000000; i++) { // Number of tries        
            
                System.out.println("i: " + i);
            
                Material orePlaced = ores.getDrop();
                double maxVeinSize = this.maxVeinSize.get(orePlaced);
                        
                x = rand.nextInt(15);
                z = rand.nextInt(15);
                y = rand.nextInt(DimensionChunkGenerator.worldHeight); // Get randomized coordinates
            
                int veinSize = (int) ((maxVeinSize * 2/3) - rand.nextInt((int) (maxVeinSize / 4)) + 1);                
                for(int a = 0; a < veinSize; a++) {
                
                    if(chunk.getBlock(x, y, z).getType() == Material.AIR || chunk.getBlock(x, y, z).getType() == Material.BEDROCK) {
                        continue;
                    }
                
                    chunk.getBlock(x, y, z).setType(orePlaced, false);
                
                    int dir = rand.nextInt(3);
                    int pos = rand.nextInt(2);
                                
                    if(dir == 0) {
                        if(pos == 1 && x + 1 <= 15) {
                            x++;
                        } else if(pos == 0 && x - 1 >= 0) {
                            x--;
                        } else {
                            y += pos - 1;
                        }
                    } else if(dir == 1) {
                        y += pos - 1;
                    } else if(dir == 2) {
                        if(pos == 1 && z + 1 <= 15) {
                            z++;
                        } else if(pos == 0 && z - 1 >= 0) {
                            z--;
                        } else {
                            y += pos - 1;
                        }                
                    }
                }
            }
        
            System.out.println("got to finish populating");
        
        }
    
        public void fillTables() {
        
            maxVeinSize = new HashMap<Material, Integer>();
            maxVeinSize.put(Material.COAL_ORE, 25);
            maxVeinSize.put(Material.IRON_ORE, 12);
            maxVeinSize.put(Material.GOLD_ORE, 10);
            maxVeinSize.put(Material.LAPIS_ORE, 8);
            maxVeinSize.put(Material.REDSTONE_ORE, 8);
            maxVeinSize.put(Material.DIAMOND_ORE, 8);
            maxVeinSize.put(Material.EMERALD_ORE, 1);
        
            ores = new MaterialTable("Ore table");
            ores.addPart(40, Material.COAL_ORE);
            ores.addPart(20, Material.IRON_ORE);
            ores.addPart(10, Material.GOLD_ORE);
            ores.addPart(10, Material.LAPIS_ORE);
            ores.addPart(10, Material.REDSTONE_ORE);
            ores.addPart(7, Material.DIAMOND_ORE);
            ores.addPart(3, Material.EMERALD_ORE);
        
        }
    
    }
    

    Console readout (open)

    Code:
    [22:55:18] [Server thread/INFO]: created a blockpopulator
    [22:55:18] [Server thread/INFO]: Preparing start region for dimension 'MiningDimension'/minecraft:the_end
    [22:55:18] [Server-Worker-4/INFO]: Preparing spawn area: 0%
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 7
    [22:55:18] [Server thread/INFO]: i: 8
    [22:55:18] [Server thread/INFO]: i: 9
    [22:55:18] [Server thread/INFO]: i: 10
    [22:55:18] [Server thread/INFO]: i: 11
    [22:55:18] [Server thread/INFO]: i: 12
    [22:55:18] [Server thread/INFO]: i: 13
    [22:55:18] [Server thread/INFO]: i: 14
    [22:55:18] [Server thread/INFO]: i: 15
    [22:55:18] [Server thread/INFO]: i: 16
    [22:55:18] [Server thread/INFO]: i: 17
    [22:55:18] [Server thread/INFO]: i: 18
    [22:55:18] [Server thread/INFO]: i: 19
    [22:55:18] [Server thread/INFO]: i: 20
    [22:55:18] [Server thread/INFO]: i: 21
    [22:55:18] [Server thread/INFO]: i: 22
    [22:55:18] [Server thread/INFO]: i: 23
    [22:55:18] [Server thread/INFO]: i: 24
    [22:55:18] [Server thread/INFO]: i: 25
    [22:55:18] [Server thread/INFO]: i: 26
    [22:55:18] [Server thread/INFO]: i: 27
    [22:55:18] [Server thread/INFO]: i: 28
    [22:55:18] [Server thread/INFO]: i: 29
    [22:55:18] [Server thread/INFO]: i: 30
    [22:55:18] [Server thread/INFO]: i: 31
    [22:55:18] [Server thread/INFO]: i: 32
    [22:55:18] [Server thread/INFO]: i: 33
    [22:55:18] [Server thread/INFO]: i: 34
    [22:55:18] [Server thread/INFO]: i: 35
    [22:55:18] [Server thread/INFO]: i: 36
    [22:55:18] [Server thread/INFO]: i: 37
    [22:55:18] [Server-Worker-10/INFO]: Preparing spawn area: 0%
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 7
    [22:55:18] [Server thread/INFO]: i: 8
    [22:55:18] [Server thread/INFO]: i: 9
    [22:55:18] [Server thread/INFO]: i: 10
    [22:55:18] [Server thread/INFO]: i: 11
    [22:55:18] [Server thread/INFO]: i: 12
    [22:55:18] [Server thread/INFO]: i: 13
    [22:55:18] [Server thread/INFO]: i: 14
    [22:55:18] [Server thread/INFO]: i: 15
    [22:55:18] [Server thread/INFO]: i: 16
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 7
    [22:55:18] [Server thread/INFO]: i: 8
    [22:55:18] [Server thread/INFO]: i: 9
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 7
    [22:55:18] [Server thread/INFO]: i: 8
    [22:55:18] [Server thread/INFO]: i: 9
    [22:55:18] [Server thread/INFO]: i: 10
    [22:55:18] [Server thread/INFO]: i: 11
    [22:55:18] [Server thread/INFO]: i: 12
    [22:55:18] [Server thread/INFO]: i: 13
    [22:55:18] [Server thread/INFO]: i: 14
    [22:55:18] [Server thread/INFO]: i: 15
    [22:55:18] [Server thread/INFO]: i: 16
    [22:55:18] [Server thread/INFO]: i: 17
    [22:55:18] [Server thread/INFO]: i: 18
    [22:55:18] [Server thread/INFO]: i: 19
    [22:55:18] [Server thread/INFO]: i: 20
    [22:55:18] [Server thread/INFO]: i: 21
    [22:55:18] [Server thread/INFO]: i: 22
    [22:55:18] [Server thread/INFO]: i: 23
    [22:55:18] [Server thread/INFO]: i: 24
    [22:55:18] [Server thread/INFO]: i: 25
    [22:55:18] [Server thread/INFO]: i: 26
    [22:55:18] [Server thread/INFO]: i: 27
    [22:55:18] [Server thread/INFO]: i: 28
    [22:55:18] [Server thread/INFO]: i: 29
    [22:55:18] [Server thread/INFO]: i: 30
    [22:55:18] [Server thread/INFO]: i: 31
    [22:55:18] [Server thread/INFO]: i: 32
    [22:55:18] [Server thread/INFO]: i: 33
    [22:55:18] [Server thread/INFO]: i: 34
    [22:55:18] [Server thread/INFO]: i: 35
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 7
    [22:55:18] [Server thread/INFO]: i: 8
    [22:55:18] [Server thread/INFO]: i: 9
    [22:55:18] [Server thread/INFO]: i: 10
    [22:55:18] [Server thread/INFO]: i: 11
    [22:55:18] [Server thread/INFO]: i: 12
    [22:55:18] [Server thread/INFO]: i: 13
    [22:55:18] [Server thread/INFO]: i: 14
    [22:55:18] [Server thread/INFO]: i: 15
    [22:55:18] [Server thread/INFO]: i: 16
    [22:55:18] [Server thread/INFO]: i: 17
    [22:55:18] [Server thread/INFO]: i: 18
    [22:55:18] [Server thread/INFO]: i: 19
    [22:55:18] [Server thread/INFO]: i: 20
    [22:55:18] [Server thread/INFO]: i: 21
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 0
    [22:55:18] [Server thread/INFO]: i: 1
    [22:55:18] [Server thread/INFO]: i: 2
    [22:55:18] [Server thread/INFO]: i: 3
    [22:55:18] [Server thread/INFO]: i: 4
    [22:55:18] [Server thread/INFO]: i: 5
    [22:55:18] [Server thread/INFO]: i: 6
    [22:55:18] [Server thread/INFO]: i: 7
    [22:55:18] [Server thread/INFO]: i: 8
    [22:55:18] [Server thread/INFO]: i: 9
    [22:55:18] [Server thread/INFO]: i: 10
    [22:55:18] [Server thread/INFO]: i: 11
    [22:55:18] [Server thread/INFO]: i: 12
    [22:55:18] [Server thread/INFO]: i: 13
    [22:55:18] [Server thread/INFO]: i: 14
    [22:55:18] [Server thread/INFO]: i: 15
    [22:55:19] [Server thread/INFO]: i: 0
    [22:55:19] [Server thread/INFO]: i: 1
    [22:55:19] [Server thread/INFO]: i: 2
    [22:55:19] [Server thread/INFO]: i: 3
    [22:55:19] [Server thread/INFO]: i: 4
    [22:55:19] [Server thread/INFO]: i: 5
    [22:55:19] [Server thread/INFO]: i: 6
    [22:55:19] [Server thread/INFO]: i: 7
    [22:55:19] [Server thread/INFO]: i: 8
    [22:55:19] [Server thread/INFO]: i: 9
    [22:55:19] [Server thread/INFO]: i: 10
    [22:55:19] [Server thread/INFO]: i: 11
    [22:55:19] [Server thread/INFO]: i: 0
    [22:55:19] [Server thread/INFO]: i: 1
    [22:55:19] [Server thread/INFO]: i: 2
    [22:55:19] [Server thread/INFO]: i: 3
    [22:55:19] [Server thread/INFO]: i: 4
    [22:55:19] [Server thread/INFO]: i: 5
    [22:55:19] [Server thread/INFO]: i: 6
    [22:55:19] [Server thread/INFO]: i: 7
    [22:55:19] [Server thread/INFO]: i: 8
    [22:55:19] [Server thread/INFO]: i: 9
    [22:55:19] [Server thread/INFO]: i: 10
    [22:55:19] [Server thread/INFO]: i: 11
    [22:55:19] [Server thread/INFO]: i: 12
    [22:55:19] [Server thread/INFO]: i: 13
    [22:55:19] [Server thread/INFO]: i: 14
    [22:55:19] [Server thread/INFO]: i: 15
    [22:55:19] [Server thread/INFO]: i: 18
    [22:55:19] [Server thread/INFO]: i: 19
    [22:55:19] [Server thread/INFO]: i: 20
    [22:55:19] [Server thread/INFO]: i: 21
    [22:55:19] [Server thread/INFO]: i: 22
    [22:55:19] [Server thread/INFO]: i: 23
    [22:55:19] [Server thread/INFO]: i: 24
    [22:55:19] [Server thread/INFO]: i: 25
    [22:55:19] [Server thread/INFO]: i: 26
    [22:55:19] [Server thread/INFO]: i: 27
    [22:55:19] [Server thread/INFO]: i: 28
    [22:55:19] [Server thread/INFO]: i: 29
    [22:55:19] [Server thread/INFO]: i: 30
    [22:55:19] [Server thread/INFO]: i: 31
    [22:55:19] [Server thread/INFO]: i: 32
    [22:55:19] [Server thread/INFO]: i: 33
    [22:55:19] [Server thread/INFO]: i: 34
    [22:55:19] [Server thread/INFO]: i: 35
    [22:55:19] [Server thread/INFO]: i: 36
    [22:55:19] [Server thread/INFO]: i: 37
    [22:55:19] [Server thread/INFO]: i: 38
    [22:55:19] [Server thread/INFO]: i: 39
    [22:55:19] [Server thread/INFO]: i: 40
    [22:55:19] [Server thread/INFO]: i: 41
    [22:55:19] [Server thread/INFO]: i: 42
    [22:55:19] [Server thread/INFO]: i: 43
    [22:55:19] [Server thread/INFO]: i: 44
    [22:55:19] [Server thread/INFO]: i: 45
    [22:55:19] [Server thread/INFO]: i: 46
    [22:55:19] [Server thread/INFO]: i: 47
    [22:55:19] [Server thread/INFO]: i: 48
    [22:55:19] [Server thread/INFO]: i: 49
    [22:55:19] [Server thread/INFO]: i: 0
    [22:55:19] [Server thread/INFO]: i: 1
    [22:55:19] [Server thread/INFO]: i: 2
    [22:55:19] [Server thread/INFO]: i: 3
    [22:55:19] [Server thread/INFO]: i: 4
    [22:55:19] [Server thread/INFO]: i: 5
    [22:55:19] [Server thread/INFO]: i: 6
    [22:55:19] [Server thread/INFO]: i: 7
    [22:55:19] [Server thread/INFO]: i: 8
    [22:55:19] [Server thread/INFO]: i: 9
    [22:55:19] [Server thread/INFO]: i: 10
    [22:55:19] [Server thread/INFO]: i: 0
    [22:55:19] [Server thread/INFO]: i: 1
    [22:55:19] [Server thread/INFO]: i: 2
    [22:55:19] [Server thread/INFO]: i: 3
    [22:55:19] [Server thread/INFO]: i: 4
    [22:55:19] [Server thread/INFO]: i: 5
    [22:55:19] [Server thread/INFO]: i: 6
    [22:55:19] [Server thread/INFO]: i: 7
    [22:55:19] [Server thread/INFO]: i: 8
    [22:55:19] [Server thread/INFO]: i: 9
    [22:55:19] [Server thread/INFO]: i: 10
    [22:55:19] [Server thread/INFO]: i: 11
    [22:55:19] [Server thread/INFO]: i: 12
    [22:55:19] [Server thread/INFO]: i: 13
    [22:55:19] [Server thread/INFO]: i: 14
    [22:55:19] [Server thread/INFO]: i: 15
    [22:55:19] [Server thread/INFO]: i: 16
    [22:55:19] [Server thread/INFO]: i: 17
    [22:55:19] [Server thread/INFO]: i: 18
    [22:55:19] [Server thread/INFO]: i: 19
    [22:55:19] [Server thread/INFO]: i: 20
    [22:55:19] [Server thread/INFO]: i: 21
    [22:55:19] [Server thread/INFO]: i: 22
    [22:55:19] [Server thread/INFO]: i: 0
    [22:55:19] [Server thread/INFO]: i: 1
    [22:55:19] [Server thread/INFO]: i: 2
    [22:55:19] [Server thread/INFO]: i: 3
    [22:55:19] [Server thread/INFO]: i: 4
    [22:55:19] [Server thread/INFO]: i: 5
    [22:55:19] [Server thread/INFO]: i: 6
    [22:55:19] [Server thread/INFO]: i: 7
    [22:55:19] [Server thread/INFO]: i: 8
    [22:55:19] [Server thread/INFO]: i: 9
    [22:55:19] [Server thread/INFO]: i: 10
    [22:55:19] [Server thread/INFO]: i: 11
    [22:55:19] [Server thread/INFO]: i: 12
    [22:55:19] [Server thread/INFO]: i: 13
    [22:55:19] [Server thread/INFO]: i: 14
    [22:55:19] [Server thread/INFO]: i: 15
    [22:55:19] [Server thread/INFO]: i: 16
    [22:55:19] [Server thread/INFO]: i: 17
    [22:55:19] [Server thread/INFO]: i: 18
    [22:55:19] [Server thread/INFO]: i: 19
    [22:55:19] [Server thread/INFO]: i: 20
    [22:55:19] [Server thread/INFO]: i: 21
    [22:55:19] [Server thread/INFO]: i: 22
    [22:55:19] [Server thread/INFO]: i: 23
    [22:55:19] [Server thread/INFO]: i: 54
    [22:55:19] [Server thread/INFO]: i: 55
    [22:55:19] [Server thread/INFO]: i: 56
    [22:55:19] [Server thread/INFO]: i: 57
    [22:55:19] [Server thread/INFO]: i: 58
    [22:55:19] [Server thread/INFO]: i: 59
    [22:55:19] [Server thread/INFO]: i: 60
    [22:55:19] [Server thread/INFO]: i: 61
    [22:55:19] [Server thread/INFO]: i: 62
    [22:55:19] [Server thread/INFO]: i: 63
    [22:55:19] [Server thread/INFO]: i: 64
    [22:55:19] [Server thread/INFO]: i: 32
    [22:55:19] [Server thread/INFO]: i: 33
    [22:55:19] [Server thread/INFO]: i: 34
    [22:55:19] [Server thread/INFO]: i: 35
    [22:55:19] [Server thread/INFO]: i: 36
    [22:55:19] [Server thread/INFO]: i: 37
    [22:55:19] [Server thread/INFO]: i: 38
    [22:55:19] [Server thread/INFO]: i: 39
    [22:55:19] [Server thread/INFO]: i: 40
    [22:55:19] [Server thread/INFO]: i: 41
    [22:55:19] [Server thread/INFO]: i: 42
    [22:55:19] [Server thread/INFO]: i: 43
    [22:55:19] [Server thread/INFO]: i: 44
    [22:55:19] [Server thread/INFO]: i: 45
    [22:55:19] [Server thread/INFO]: i: 46
    [22:55:19] [Server thread/INFO]: i: 47
    [22:55:19] [Server thread/INFO]: i: 48
    [22:55:19] [Server thread/INFO]: i: 49
    [22:55:19] [Server thread/INFO]: i: 50
    [22:55:19] [Server thread/INFO]: i: 51
    [22:55:19] [Server thread/INFO]: i: 52
    [22:55:19] [Server thread/INFO]: i: 53
    [22:55:19] [Server thread/INFO]: i: 54
    [22:55:19] [Server thread/INFO]: i: 55
    [22:55:19] [Server thread/INFO]: i: 56
    [22:55:19] [Server thread/INFO]: i: 57
    [22:55:19] [Server thread/INFO]: i: 58
    [22:55:19] [Server thread/INFO]: i: 59
    [22:55:19] [Server thread/INFO]: i: 60
    [22:55:19] [Server thread/INFO]: i: 61
    [22:55:19] [Server thread/INFO]: i: 62
    [22:55:19] [Server thread/INFO]: i: 63
    [22:55:19] [Server thread/INFO]: i: 64
    [22:55:19] [Server thread/INFO]: i: 65
    [22:55:19] [Server thread/INFO]: i: 66
    [22:55:19] [Server thread/INFO]: i: 67
    [22:55:19] [Server thread/INFO]: i: 68
    [22:55:19] [Server thread/INFO]: i: 69
    [22:55:19] [Server thread/INFO]: i: 70
    [22:55:19] [Server thread/INFO]: i: 71
    [22:55:19] [Server thread/INFO]: i: 72
    [22:55:19] [Server thread/INFO]: i: 73
    [22:55:19] [Server thread/INFO]: i: 74
    [22:55:19] [Server thread/INFO]: i: 75
    [22:55:19] [Server thread/INFO]: i: 76
    [22:55:19] [Server thread/INFO]: i: 77
    [22:55:19] [Server thread/INFO]: i: 78
    [22:55:19] [Server thread/INFO]: i: 79
    [22:55:19] [Server thread/INFO]: i: 80
    [22:55:19] [Server thread/INFO]: i: 81
    [22:55:19] [Server thread/INFO]: i: 82
    [22:55:19] [Server thread/INFO]: i: 83
    [22:55:19] [Server thread/INFO]: i: 84
    [22:55:19] [Server thread/INFO]: i: 85
    [22:55:19] [Server thread/INFO]: i: 86
    [22:55:19] [Server thread/INFO]: i: 87
    [22:55:19] [Server thread/INFO]: i: 88
    [22:55:19] [Server thread/INFO]: i: 89
    [22:55:19] [Server thread/INFO]: i: 90
    [22:55:19] [Server thread/INFO]: i: 91
    [22:55:19] [Server thread/INFO]: i: 92
    [22:55:19] [Server thread/INFO]: i: 93
    [22:55:19] [Server thread/INFO]: i: 94
    [22:55:19] [Server thread/INFO]: i: 95
    [22:55:19] [Server thread/INFO]: i: 96
    [22:55:19] [Server thread/INFO]: i: 97
    [22:55:19] [Server thread/INFO]: i: 98
    [22:55:19] [Server thread/INFO]: i: 99
    [22:55:19] [Server thread/INFO]: i: 100
    [22:55:19] [Server thread/INFO]: i: 101
    [22:55:19] [Server thread/INFO]: i: 102
    [22:55:19] [Server thread/INFO]: i: 103
    [22:55:19] [Server thread/INFO]: i: 104
    [22:55:19] [Server thread/INFO]: i: 105
    [22:55:19] [Server thread/INFO]: i: 106
    [22:55:19] [Server thread/INFO]: i: 107
    [22:55:19] [Server thread/INFO]: i: 108
    [22:55:19] [Server thread/INFO]: i: 109
    [22:55:19] [Server thread/INFO]: i: 110
    [22:55:19] [Server thread/INFO]: i: 111
    [22:55:19] [Server thread/INFO]: i: 112
    [22:55:19] [Server thread/INFO]: i: 113
    [22:55:19] [Server thread/INFO]: i: 114
    [22:55:19] [Server thread/INFO]: i: 115
    [22:55:19] [Server thread/INFO]: i: 116
    [22:55:19] [Server thread/INFO]: i: 117
    [22:55:19] [Server thread/INFO]: i: 118
    [22:55:19] [Server thread/INFO]: i: 119
    [22:55:19] [Server thread/INFO]: i: 120
    [22:55:19] [Server thread/INFO]: i: 121
    [22:55:19] [Server thread/INFO]: i: 122
    [22:55:19] [Server thread/INFO]: i: 123
    [22:55:19] [Server thread/INFO]: i: 124
    [22:55:19] [Server thread/INFO]: i: 125
    [22:55:19] [Server thread/INFO]: i: 126
    [22:55:19] [Server thread/INFO]: i: 127
    [22:55:19] [Server thread/INFO]: i: 128
    [22:55:19] [Server-Worker-4/INFO]: Preparing spawn area: 9%


    As you can see from the console snippet, the amount of loops gone through doesn't meet my limit. Usually reaching about 15-30 and then resetting back to 0 instead of making it all the way to 1000000 like it's supposed to (1000000 is an exaggeration just to test the problem). Is there any way to prioritize my blockpopulators so that the loop is completed before it moves on? If not, is there a way I could buy more time so I can generate at least 3x the amount of ores that are currently being generated? Thanks in advance!
     
  2. Offline

    Symphonic

    Can we see the rest of the code?
     
  3. Offline

    bowlerguy66

    @Symphonic
    World Generator Class (open)

    Code:
    package me.bowlerguy66.etweaks.miningdimension.generator;
    
    import java.util.Arrays;
    import java.util.List;
    import java.util.Random;
    
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.generator.BlockPopulator;
    import org.bukkit.generator.ChunkGenerator;
    import org.bukkit.util.noise.SimplexOctaveGenerator;
    
    public class DimensionChunkGenerator extends ChunkGenerator {
    
        static int size = 10;
        public static final int sizeOffset = 8;
        public static final int worldHeight = 150;
     
        @Override
        public ChunkData generateChunkData(World world, Random rand, int chunkX, int chunkZ, BiomeGrid biome) {
         
            ChunkData chunk = createChunkData(world);
            SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
            generator.setScale(0.075);
         
    //        SimplexOctaveGenerator caveGenerator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
    //        caveGenerator.setScale(0.05);
         
            for(int x = 0; x < 16; x++) {
                for(int z = 0; z < 16; z++) {
    
                    for(int i = 1; i < worldHeight; i++) {
                        chunk.setBlock(x, i, z, Material.STONE);
                    }
                 
                    chunk.setBlock(x, 0, z, Material.BEDROCK);
                    chunk.setBlock(x, worldHeight, z, Material.BEDROCK);
    
                    size = (int) ((generator.noise(chunkX * 16 + x, chunkZ * 16 + z, 0.5, 0.5, true) + 1) * 10d);
    
                    for(int y = (worldHeight / 2) - size + sizeOffset; y < (worldHeight / 2) + size - sizeOffset; y++) {
                        chunk.setBlock(x, y, z, Material.AIR);
                    }
                 
                }
            }
         
            return chunk;
         
        }
    
        @Override
        public List<BlockPopulator> getDefaultPopulators(World world) {
            return Arrays.asList((BlockPopulator)new DimensionOrePopulator());
        }
     
    }
    

    Where the world is generated (open)

    Code:
    package me.bowlerguy66.etweaks.miningdimension;
    
    import org.bukkit.Bukkit;
    import org.bukkit.GameRule;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.World.Environment;
    import org.bukkit.WorldCreator;
    import org.bukkit.entity.Entity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.bowlerguy66.etweaks.ETweaks;
    import me.bowlerguy66.etweaks.miningdimension.generator.DimensionChunkGenerator;
    
    public class PortalListener implements Listener {
    
        private final String dimensionName = "MiningDimension";
        private ETweaks plugin;
     
        public PortalListener(ETweaks plugin) {
            this.plugin = plugin;
        }
     
        @EventHandler
        public void playerPortalEvent(PlayerInteractEvent event) {
            if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
                return;
            }
            if(event.getPlayer().getEquipment().getItemInMainHand().getType() != Material.BLAZE_ROD) {
                return;
            }
            event.setCancelled(true);
            sendThroughPortal(event.getPlayer());
        }
     
        public void sendThroughPortal(Entity e) {
    
            World w = Bukkit.getWorld(dimensionName);
         
            if(w == null) {
                WorldCreator creator = new WorldCreator(dimensionName); // World generated here
                creator.generator(new DimensionChunkGenerator());
                creator.environment(Environment.THE_END);
                w = plugin.getServer().createWorld(creator);
                w.setGameRule(GameRule.DO_MOB_SPAWNING, false);
                return;
            }
                 
            Location worldSpawn = new Location(plugin.getServer().getWorld(dimensionName), 0, DimensionChunkGenerator.worldHeight / 2, 0);
            Location dragonInhibitBlock = worldSpawn.clone();
            dragonInhibitBlock.setY(DimensionChunkGenerator.worldHeight);
         
            if(dragonInhibitBlock.getBlock().getType() != Material.END_PORTAL) {
             
                dragonInhibitBlock.getBlock().setType(Material.END_PORTAL);
                dragonInhibitBlock.add(0, -1, 0).getBlock().setType(Material.BEDROCK);
             
                int spawnSize = 10;
             
                for(int x = -spawnSize; x < spawnSize; x++) {
                    for(int y = -spawnSize; y < spawnSize; y++) {
                        for(int z = -spawnSize; z < spawnSize; z++) {
                            Location loc = new Location(w, worldSpawn.getBlockX() + x, worldSpawn.getBlockY() + y, worldSpawn.getBlockZ() + z);
                            if(loc.distance(worldSpawn) < spawnSize) {
                                loc.getBlock().setType(Material.AIR);
                            }
                        }
                    }
                }
             
                for(int x = -1; x < 2; x++) {
                    for(int z = -1; z < 2; z++) {
                        worldSpawn.clone().add(x, -1, z).getBlock().setType(Material.OBSIDIAN);
                    }
                }
             
            }
    
            e.teleport(worldSpawn.clone().add(0.5, 0.2, 0.5));
         
        }
     
    }
    


    Edit: Another solution I tried was creating a separate instance of a blockpopulator for each type of ore, but when I added them all to my getDefaultBlockPopulators() the first ore that was added to the list seemed to override all of the others.
     
    Last edited: Jan 20, 2020
  4. Offline

    bowlerguy66

    Bump~ Any technique to load ores into a custom generated world would help
     
  5. Offline

    CraftCreeper6

    @bowlerguy66
    I'm not particularly good with BlockPopulators (I used them once and instantly made my own alternative because of frustration.)

    So, it's possible to create your own populator. Load the world as you do with your custom generation, then wait for a chunk to load (ChunkPopulateEvent) and in the most efficient way you can, repopulate the chunk manually.

    I'm sure there's a way to do it with BlockPopulators but I won't be of any assistance with that.

    EDIT: I just read the BlockPopulator in the API and it says
    "A block populator is responsible for generating a small area of blocks.

    For example, generating glowstone inside the nether or generating dungeons full of treasure"

    This could be the reason that you are experiencing the effect you are. Chunks are not particularly "small".

    I also read:
    "The chunks on each side of the specified chunk must already exist; that is, there must be one north, east, south and west of the specified chunk. The "corner" chunks may not exist, in which scenario the populator should record any changes required for those chunks and perform the changes when they are ready."

    Which could also mean that it's trying to populate the blocks, but running into problems because the chunks beside it are not yet loaded. But this is just speculation, and again, I am not an expert in BlockPopulators.
     
  6. Offline

    bowlerguy66

    That ChunkPopulateEvent sounds promising, I will give it a shot tomorrow when I have time. Thanks!

    Update: It works perfectly. Thanks @CraftCreeper6
     
    Last edited: Jan 24, 2020

Share This Page