Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ubempire.map;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.generator.BlockPopulator;
- import org.bukkit.generator.ChunkGenerator;
- import org.bukkit.Material;
- import org.bukkit.World;
- public class FlatMapGenerator extends ChunkGenerator {
- protected byte[] result;
- @SuppressWarnings("unused")
- private static final int ORE_DIAMOND = 0;
- @SuppressWarnings("unused")
- private static final int ORE_COAL = 1;
- @SuppressWarnings("unused")
- private static final int ORE_IRON = 2;
- @SuppressWarnings("unused")
- private static final int ORE_GOLD = 3;
- @SuppressWarnings("unused")
- private static final int ORE_REDSTONE = 4;
- @SuppressWarnings("unused")
- private static final int ORE_LAPISLAZULI = 5;
- private static final Material[] ORE_LIST = { Material.DIAMOND_ORE, Material.COAL_ORE, Material.IRON_ORE, Material.GOLD_ORE, Material.REDSTONE_ORE, Material.LAPIS_ORE };
- private static final int[] maxDistFromOrigin = { 2, 4, 3, 2, 2, 2 };
- private static final int[] minBlocksPerNode = { 2, 4, 3, 2, 2, 2 };
- private static final int[] maxBlocksPerNode = { 4, 8, 5, 4, 3, 3 };
- private static final int[] minNodesPerChunk = { 1, 10, 7, 4, 5, 5 };
- private static final int[] maxNodesPerChunk = { 5, 15, 10, 8, 8, 8 };
- private static final int[][] chancePer16Levels = { { 30, 65, 95, 100, 0, 0, 0, 0 }, { 12, 25, 37, 50, 62, 75, 87, 100 }, { 20, 45, 70, 80, 90, 95, 100, 0 }, { 20, 60, 80, 100, 0, 0, 0, 0 },
- { 20, 50, 80, 100, 0, 0, 0, 0 }, { 20, 50, 80, 100, 0, 0, 0, 0 } };
- public List<BlockPopulator> getDefaultPopulators(World world) {
- return Arrays.asList((BlockPopulator) new FlatMapPopulator());
- }
- public void genOreAtLayer(int layer, int currOre, Random random, int chunkx, int chunkz) {
- Material currMaterial = ORE_LIST[currOre];
- int y = random.nextInt(16) + layer;
- int x = random.nextInt(15);
- int z = random.nextInt(15);
- if (result[(x * 16 + z) * 128 + y] == (byte)Material.STONE.getId()) {
- List<int[]> candidates = new ArrayList<int[]>();
- int[] coreBlock = new int[3];
- coreBlock[0]=x;
- coreBlock[1]=y;
- coreBlock[2]=z;
- result[(x * 16 + z) * 128 + y] = (byte)currMaterial.getId();
- //coreBlock.setType(currMaterial);
- for (int xMod = -maxDistFromOrigin[currOre]; xMod <= maxDistFromOrigin[currOre]; xMod++) {
- for (int yMod = -maxDistFromOrigin[currOre]; yMod <= maxDistFromOrigin[currOre]; yMod++) {
- for (int zMod = -maxDistFromOrigin[currOre]; zMod <= maxDistFromOrigin[currOre]; zMod++) {
- if (x + xMod < 0 || x + xMod > 15 || y + yMod < 0 || y + yMod > 127 || z + zMod < 0 || z + zMod > 15) {
- continue;
- } else if (result[(x+xMod * 16 + z+zMod) * 128 + y+yMod] == (byte)Material.STONE.getId()) {
- coreBlock[0]=x+xMod;
- coreBlock[0]=y+yMod;
- coreBlock[0]=z+zMod;
- candidates.add(coreBlock);
- }
- }
- }
- }
- if (candidates.size() > 0) {
- Collections.shuffle(candidates);
- int blocksAtNode = random.nextInt(maxBlocksPerNode[currOre] - minBlocksPerNode[currOre] + 1) + minBlocksPerNode[currOre];
- while (blocksAtNode > 0 && candidates.size() > 0) {
- result[(candidates.get(0)[0] * 16 + candidates.get(0)[2] * 128 + candidates.get(0)[1])] = (byte)currMaterial.getId();
- candidates.remove(0);
- //.setType(currMaterial);
- --blocksAtNode;
- }
- }
- }
- }
- public boolean canSpawn(World world, int x, int z) {
- return true;
- }
- @Override
- public byte[] generate(World world, Random rand, int chunkx, int chunkz) {
- result = new byte[32768];
- int xbound = HeightMap.xbound;
- int zbound = HeightMap.zbound;
- for(int x=0; x<16; x++)
- {
- for(int z=0; z<16; z++)
- {
- for(int yy=55; yy>=0; yy--)
- {
- if(yy<=50) result[(x * 16 + z) * 128 + yy] = (byte)Material.STONE.getId();
- else if(yy<2) result[(x * 16 + z) * 128 + yy] = (byte)Material.BEDROCK.getId();
- else result[(x * 16 + z) * 128 + yy] = (byte)Material.WATER.getId();
- }
- }
- }
- if(chunkx>=0-xbound && chunkz>=0-zbound && chunkx<=xbound && chunkz<=zbound)
- {
- int startx = (chunkx+xbound)*16;
- int startz = (chunkz+zbound)*16;
- //System.out.print(startx+","+startz);
- int zero = 0;
- if(startx<HeightMap.width-16 && startz<HeightMap.height-16){
- for(int x=0; x<+16; x++)
- {
- for(int z=0; z<16; z++)
- {
- if(zero<HeightMap.height*HeightMap.width)
- {
- int y=50+HeightMap.pixels[(startx+x)+(startz+z)*HeightMap.width];
- if(y<55) result[(x * 16 + z) * 128 + y] = (byte)Material.DIRT.getId();
- else result[(x * 16 + z) * 128 + y] = (byte)Material.GRASS.getId();
- zero++;
- int count =0;
- for(y=y-1; y>=0;y--)
- {
- if(count<2)
- {
- result[(x * 16 + z) * 128 + y] = (byte)Material.DIRT.getId();
- count++;
- }
- else result[(x * 16 + z) * 128 + y] = (byte)Material.STONE.getId();
- }
- }
- result[(x * 16 + z) * 128 + 1] = (byte)Material.BEDROCK.getId();
- }
- }
- int layer;
- int nodeAmount;
- for (int currOre = 0; currOre < ORE_LIST.length; currOre++) {
- nodeAmount = rand.nextInt(maxNodesPerChunk[currOre] - minNodesPerChunk[currOre] + 1) + minNodesPerChunk[currOre];
- for (int currNode = 0; currNode < nodeAmount; currNode++) {
- layer = rand.nextInt(100) + 1;
- for (int currLayer = 0; currLayer < chancePer16Levels[currOre].length; currLayer++) {
- if (layer <= chancePer16Levels[currOre][currLayer]) {
- layer = 16 * currLayer;
- break;
- }
- }
- genOreAtLayer(layer, currOre, rand, chunkx,chunkz);
- }
- }
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement