Best way to generate a blank world with floating skyblock-esque islands?

Discussion in 'Plugin Development' started by ElkTF2, Feb 18, 2020.

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

    ElkTF2

    I'm trying to make a world generator that creates an empty world (easy enough) and randomly places islands when generating new chunks.

    I have made a few variations of islands and I have them saved as schematics, but after trying for hours on end, I couldn't get it working.

    This is a screenshot of the code I had in my generator (with the code that stops the server from loading in the red bracket), and here is a screenshot of the server console which never loads (this was taken 2 hours after originally trying to start).



    If my above problem is unfixable, I don't mind, I'm just looking for any way to spawn islands like what I want. What would be the most effective way to do this? I'm hoping to have a list with a bunch of different schematic file addresses and it chooses one from random to place.

    Are there any more effective ways to do this (possibly custom block populators)? How would I go about this?

    (I don't want sample code or anything I just need some pointers on where to go because I'm stuck)
     
  2. Offline

    bowlerguy66

    @ElkTF2 What I ended up doing to generate my own custom structures in the world was by using the ChunkPopulateEvent, maybe you could generate an empty world and generate your islands using that event instead?

    Also, I though using the WorldEdit api was gross so I wrote my own simple library for loading schematics (No chest or entity support)
    It has an issue with loading the file from the internal jar that needs to be fixed, but otherwise it does its job pretty well.
    Schematic library (open)

    Code:
    import java.io.InputStream;
    import java.util.HashMap;
    
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    
    import net.minecraft.server.v1_15_R1.NBTBase;
    import net.minecraft.server.v1_15_R1.NBTCompressedStreamTools;
    import net.minecraft.server.v1_15_R1.NBTTagCompound;
    
    public class Schematics {
    
        public boolean loadSchematic(String filePath, World world, int placeX, int placeY, int placeZ) {
            try {
                InputStream fis = pullFileFromJar(filePath);
                if(fis == null) {
                    System.err.println("InputStream is null");
                    return false;
                }
                NBTTagCompound nbtdata = NBTCompressedStreamTools.a(fis);
                short width = nbtdata.getShort("Width");
                short height = nbtdata.getShort("Height");
                short length = nbtdata.getShort("Length");
       
                byte[] blocks = nbtdata.getByteArray("BlockData");
    
                NBTBase paletteBase = nbtdata.get("Palette");
                HashMap<Integer, Material> palette = getPalette(paletteBase.asString());
                NBTTagCompound cmpd = nbtdata.getCompound("Metadata");
                int xOffset = cmpd.getInt("WEOffsetX");
                int yOffset = cmpd.getInt("WEOffsetY");
                int zOffset = cmpd.getInt("WEOffsetZ");
               
                if(palette == null) {
                    System.err.println("Failed to load palette");
                    return false;
                }
               
                int i = 0;
                           
                for(int y = 0; y < (int)height; y++) {
                    for(int z = -1; z < (int)length - 1; z++) {
                        for(int x = 0; x < (int)width; x++) {
                            Material type = palette.get(((Byte)blocks[i]).intValue());
                            if(type == Material.AIR) {
                                i++;
                                continue;
                            } else if(type == Material.SPONGE) {
                                type = Material.AIR;
                            }
                            new Location(world, placeX + xOffset + x, placeY + yOffset + y, placeZ + zOffset + z + 1).getBlock().setType(type);
                            i++;
                        }
                    }
                }
               
                return true;
               
            } catch(Exception e) {
                e.printStackTrace();
                return false;
            }
           
        }
       
        private static HashMap<Integer, Material> getPalette(String paletteString) {
    
            if(paletteString == null || paletteString.length() == 0) {
                return null;
            }
    
            HashMap<Integer, Material> palette = new HashMap<Integer, Material>();
            paletteString = paletteString.substring(1, paletteString.length() - 1);
            paletteString = paletteString.replaceAll("minecraft:", "");
            paletteString = paletteString.replaceAll("\"", "");
            String[] values = paletteString.split(",");
           
            for(String s : values) {
                String[] set = s.split(":");
                palette.put(Integer.parseInt(set[1]), Material.valueOf(set[0].toUpperCase()));
            }
           
            return palette;
           
        }
    
        public InputStream pullFileFromJar(String path) {
            return getClass().getResourceAsStream(path);
        }
       
    }
    
     
Thread Status:
Not open for further replies.

Share This Page