Create a 3x3x3 whole every 10 blocks

Discussion in 'Plugin Development' started by MooshViolet, Dec 9, 2014.

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

    Skionz

  2. Offline

    MooshViolet

    @Skionz
    Thanks. So after I call the event, how would I find a chunk and replace that with air and put a piece of glowstone in the middle?
     
  3. Offline

    Skionz

    @MooshViolet Probably iterate through all of the blocks, replace them with air, or glowst0ne when necessary.
     
  4. Offline

    MooshViolet

    @Skionz
    Not sure how to do that :/
     
  5. Offline

    Skionz

    @MooshViolet 3 Nested for loops incrementing x, y, and z. You can look for the specific Block methods in the Javadocs. This is going to be pretty inefficient though.
     
  6. Offline

    Rocoty

    No no no. Don't call the event, that's no good. Listen for it. And use event.get Chuck() to get the chunk.
     
    AdamQpzm likes this.
  7. To create a 3x3 hole with glowstone in the middle:
    1. define a start-Location
    Code:Java
    1. Location loc = new Location(world, 0, 100, 0);

    2. Iterate through all the variables 3 times
    Code:java
    1. for (int x = loc.getX(); x < loc.getX() + 3, x++) {
    2. for (int y = loc.getY(); y < loc.getY() + 3; y++) {
    3. for (int z = loc.getZ(); z < loc.getZ() + 3; z++) {
    4.  
    5. }
    6. }
    7. }
    8.  

    3. set the block type to air (in the for-loops)
    Code:java
    1.  
    2. //Get the block on the location
    3. Block block = new Location(world, x, y, z).getBlock();
    4.  
    5. //Set it to air
    6. block.setType(Material.AIR);
    7.  

    4. Add x + 1, y + 1 and z + 1 to get the middle block (after the for-loops)
    Code:java
    1.  
    2. loc.add(1, 1, 1);
    3.  

    5. Set the middle block to glowstone.
    Code:java
    1.  
    2. loc.getBlock().setType(Material.GLOWSTONE);
    3.  
     
    MooshViolet and indyetoile like this.
  8. Offline

    MooshViolet

    @FisheyLP
    Thank you for the explanation and the example!! You helped me so much, thanks

    @FisheyLP
    One error, it will not let me use "world"
    when trying to create a location, any help?

    EDIT by TImtower: merged posts
     
    Last edited by a moderator: Dec 12, 2014
  9. Offline

    Monkey_Swag

    Last edited by a moderator: Dec 12, 2014
  10. Offline

    Skionz

    It actually turns out we can't tell, or suggest people learn Java anymore. I was muted / my posts had to be accepted for a bit because telling, or suggesting people learn Java is considered flaming now. :confused:
     
  11. Offline

    Monkey_Swag

    Rocoty likes this.
  12. Offline

    teej107

    It does help a lot more to explain why and post a link as well.
     
    MooshViolet and Skionz like this.
  13. Offline

    Skionz

    @teej107 Not like they ever read them :(
     
    teej107 likes this.
  14. Offline

    FabeGabeMC

  15. example:
    Code:
    Bukkit.getWorld("worldName")
     
  16. Offline

    MooshViolet

    @FisheyLP
    thanks, I'll compile everything when I get home and tell you if it works
     
  17. Offline

    mythbusterma

    @KingFaris11

    So...this thread has already been (more or less) solved. So you think it's a good idea to post code that will legitimately freeze the server for hours, and call that "contributing?" That code will force the server to generate every chunk from -32M to 32M, or about 16000000000000 chunks, more than filling any hard drive currently available on the market. Then, as a "fix" for this terrible idea, you suggest running it on a thread other than the main thread, completely violating the thread safety of the server in pretty much the most dangerous way possible.
     
  18. Offline

    MisterErwin

    @mythbusterma
    psch..... Let him spoonfeed (the disk) ;)

    But back to topic: I suggest (also) to do that during the World-Generation (to be more exact: Chunk-Decoration - or however it is named where i.E. trees generate)
     
    mythbusterma likes this.
  19. Offline

    mythbusterma

    MisterErwin likes this.
  20. Yeah I realised it was solved, just decided to see if this way would work.

    1. I never called it contributing.
    2. I've already done something similar in a test for worlds, it hardly took any time at all...
    3. He wanted every single every-10 blocks to have a 3x3x3 hole did he not?
    4. Nah m8.
     
  21. Offline

    mythbusterma

    @KingFaris11

    Fair enough, I suppose you didn't.

    And yes, that is pretty much the most dangerous way to violate thread safety on a Minecraft server, in my opinion. There may be a worse example, but that is still world corruptingly awful.
     
    KingFaris11 likes this.
  22. Offline

    MooshViolet

    @KingFaris11
    If you could help, this is crashing everytime I try to create it:
    Code:
    package me.MooshViolet.CustomWorldGen;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.generator.BlockPopulator;
    import org.bukkit.generator.ChunkGenerator;
    
    public class FlatLandGenerator extends ChunkGenerator {
    
        CustomWorldGen plugin;
       
        public FlatLandGenerator(CustomWorldGen instance) {
            plugin = instance;
        }
        public Location getFixedSpawnLocation(World world, Random random){
            return new Location(world, 0,64,0);
        }
        public List<BlockPopulator> getDefaultPopulators(World world){
            return new ArrayList<BlockPopulator>();
        }
       
       
       
        @SuppressWarnings("deprecation")
        public byte[][] generateBlockSections(World world, Random random, int chunkX, int chunkY, BiomeGrid biomegrid){
            byte[][] result = new byte[256 / 16] [];
            int x, y, z;
           
            for (x = 0; x<16; x++) {
                for (z = 0; z<16; z++) {
                    setBlock(result, x, 0, z, (byte) Material.STONE.getId());
                   
                }
            }
    
            for (x = 0; x<16; x++) {   
                for (z = 0; z<16; z++) {
                    for(y = 1; y<=64; y++){
                    setBlock(result, x, y, z, (byte) Material.STONE.getId());
                   
                }
            }
            }
           
            Location loc = new Location(Bukkit.getWorld("world"), 0, 64, 0);
            for (double x1 = loc.getX(); x1 < loc.getX() + 3; x1++) {
                for (double y1 = loc.getY(); y1 < loc.getY() + 3; y1++) {
                for (double z1 = loc.getZ(); z1 < loc.getZ() + 3; z1++) {
                   
                    Block block = new Location(Bukkit.getWorld("world"), x1, y1, z1).getBlock();
                    block.setType(Material.AIR);
                    loc.add(1, 1, 1);
                    loc.getBlock().setType(Material.GLOWSTONE);
                
                }
                }
                }
           
               
            return result;
           
        }
    
        @SuppressWarnings("deprecation")
        @Override
        public short[][] generateExtBlockSections(World world, Random random,
                int chunkX, int chunkZ, BiomeGrid biomes) {
                short[][] result = new short[256 / 16] [];
                int x, y, z;
               
                for (x = 0; x<16; x++) {
                    for (z = 0; z<16; z++) {
                        setBlock(result, x, 0, z, (short) Material.STONE.getId());
                       
                    }
                }
                for (x = 0; x<16; x++) {
                    for (z = 0; z<16; z++) {
                        for(y = 1; y<=64; y++){
                        setBlock(result, x, y, z, (short) Material.STONE.getId());
                       
                    }
                }
                }
               
               
               
                return result;
               
            }
    
       
       
        private void setBlock(byte[][] result, int x, int y, int z, byte blockId){
            if(result[y >> 4] == null){
                result[y >> 4] = new byte[4096];
            }
            result[y>>4][((y&0xF)<<8) | (z <<4) | x] = blockId;
           
        }
        private void setBlock(short[][] result, int x, int y, int z, short blockId){
            if(result[y >> 4] == null){
                result[y >> 4] = new short[4096];
            }
            result[y>>4][((y&0xF)<<8) | (z <<4) | x] = blockId;
           
        }
       
       
    }
    
     
  23. Offline

    mythbusterma

  24. Offline

    MooshViolet

Thread Status:
Not open for further replies.

Share This Page