BlockPopulator/ ChunkGenerator help

Discussion in 'Plugin Development' started by Hazematman, Apr 7, 2012.

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

    Hazematman

    Using spout I have created a new copper ore block and I want it to be generated into the world as common as coal. My question is which should I use and can you point me in the direction on how to use it properly? I have attempted to make a block populator that generates it and my plugin keeps crashing.

    Heres the orepop.java file:
    Code:
    package com.gmail.nercos7.SpoutMachines;
     
    import java.util.Random;
     
    import org.bukkit.Chunk;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.generator.BlockPopulator;
    import org.getspout.spoutapi.Spout;
     
    public class OrePop extends BlockPopulator {
       
        SpoutMachines plugin = new SpoutMachines();
     
        @Override
        public void populate(World world, Random random, Chunk chunk) {
           
            for(int i=1; i<30; i++){
                Random generator = new Random();
                int xloc = generator.nextInt(16);
                int yloc = generator.nextInt(16);
                int zloc = generator.nextInt(16);
                Block block = chunk.getBlock(xloc, yloc, zloc);
               
                if(block.getType() == Material.STONE){
                    Spout.getServer().getWorld(world.getName()).getChunkAt(chunk.getX(),chunk.getZ()).setCustomBlock(xloc, yloc, zloc, plugin.copperOre);
                }
               
            }
        }
     
    }
    
    and here is the error I keep getting:
    Code:
    at com.gmail.nercos7.SpoutMachines.WorldEvent.<init>(WorldEvent.java:11)
        at com.gmail.nercos7.SpoutMachines.SpoutMachines.<init>(SpoutMachines.java:12)
    Update:
    I got the blockpopulator to work(I think) but I can't seem to find my custom copper block anywhere in the world, heres my new OrePop.java:
    Code:
    package com.gmail.nercos7.SpoutMachines;
     
    import java.util.Random;
     
    import org.bukkit.Chunk;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.generator.BlockPopulator;
    import org.getspout.spoutapi.Spout;
     
    public class OrePop extends BlockPopulator {
     
        SpoutMachines plugin;
        CopperOre block;
     
        public OrePop(SpoutMachines p, CopperOre b){
            plugin = p;
            block = b;
        }
     
        @Override
        public void populate(World world, Random random, Chunk chunk) {
       
            for(int i=1; i<30; i++){
                int xloc = random.nextInt(15);
                int yloc = random.nextInt(80);
                int zloc = random.nextInt(15);
                Block block = chunk.getBlock(xloc, yloc, zloc);
                Location locs = chunk.getBlock(xloc, yloc, zloc).getLocation();
                int x = locs.getBlockX();
                int y = locs.getBlockY();
                int z = locs.getBlockZ();
           
           
                if(block.getType() == Material.STONE){
                    Spout.getServer().getWorld(world.getName()).getChunkAt(block).setCustomBlock(xloc, yloc, zloc, this.block);
                    plugin.log.info("generated at"+Integer.toString(x)+ " " +Integer.toString(y)+ " " +Integer.toString(z));
                }
           
            }
        }
     
    }
    Update 2:
    Okay the block populator is working really good, except for it wont generate any ores around the spawn, you have to go to an ungenerated area to have the ores generate, does anyone know how to fix this?

    Heres my new orepop.java:

    Code:
    package com.gmail.nercos7.SpoutMachines;
     
    import java.util.Random;
     
    import org.bukkit.Chunk;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.generator.BlockPopulator;
    import org.getspout.spoutapi.SpoutManager;
     
    public class OrePop extends BlockPopulator {
     
        SpoutMachines plugin;
        CopperOre copper;
        TinOre tin;
     
        public OrePop(SpoutMachines p, CopperOre b,TinOre t){
            plugin = p;
            copper = b;
            tin = t;
        }
     
        @Override
        public void populate(World world, Random random, Chunk chunk) {
         
            for(int i=1; i<200; i++){
                int xloc = random.nextInt(15);
                int yloc = random.nextInt(80);
                int zloc = random.nextInt(15);
                Block[] blocks = new Block[]{
                chunk.getBlock(xloc, yloc, zloc),
                chunk.getBlock(xloc-1, yloc, zloc),
                chunk.getBlock(xloc, yloc-1, zloc),
                chunk.getBlock(xloc, yloc, zloc-1),
                chunk.getBlock(xloc+1, yloc, zloc),
                chunk.getBlock(xloc, yloc+1, zloc),
                chunk.getBlock(xloc, yloc, zloc+1)};
             
             
                if(blocks[0].getType() == Material.STONE){
                    int check = random.nextInt(2);
                    if (check == 0){
                        for (int r=0;r<7;r++){
                            SpoutManager.getMaterialManager().overrideBlock(blocks[r], this.copper);
                        }
                    } else {
                        for (int r=0;r<7;r++){
                            SpoutManager.getMaterialManager().overrideBlock(blocks[r], this.tin);
                        }
                    }
                }
             
            }
        }
     
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
Thread Status:
Not open for further replies.

Share This Page