/[projects]/miscJava/bukkit-minecraft-plugins/WaterWorld/src/dk/thoerup/bukkit/waterworld/WaterGenerator.java
ViewVC logotype

Contents of /miscJava/bukkit-minecraft-plugins/WaterWorld/src/dk/thoerup/bukkit/waterworld/WaterGenerator.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1655 - (show annotations) (download)
Sat Dec 10 13:07:43 2011 UTC (12 years, 5 months ago) by torben
File size: 1671 byte(s)
Import waterworld plugin

1 package dk.thoerup.bukkit.waterworld;
2
3 import java.util.*;
4
5 import org.bukkit.block.*;
6 import org.bukkit.generator.*;
7 import org.bukkit.*;
8
9 public class WaterGenerator extends ChunkGenerator {
10
11
12 //This needs to be set to return true to override minecraft's default behaviour
13 @Override
14 public boolean canSpawn(World world, int x, int z) {
15 return true;
16 }
17
18 //This converts relative chunk locations to bytes that can be written to the chunk
19 public int xyzToByte(int x, int y, int z) {
20 return (x * 16 + z) * 128 + y;
21 }
22
23 @Override
24 public byte[] generate(World world, Random rand, int chunkx, int chunkz) {
25 byte result[] = new byte[32768];
26
27 //This will set the floor of each chunk at bedrock level to bedrock
28 for(int x=0; x<16; x++){
29 for(int z=0; z<16; z++) {
30 int y=0;
31
32 for (y=0; y<6; y++) {
33 result[xyzToByte(x,y,z)] = (byte) Material.BEDROCK.getId();
34 }
35 for (y=6; y<48; y++) {
36 result[xyzToByte(x,y,z)] = (byte) Material.SAND.getId();
37 }
38 for (y=48; y<65; y++) {
39 result[xyzToByte(x,y,z)] = (byte) Material.WATER.getId();
40 }
41
42 }
43 }
44
45 return result;
46 }
47
48 /* @Override
49 public List<BlockPopulator> getDefaultPopulators(World world) {
50 return Arrays.asList((BlockPopulator) new ChessPopulator());
51 }
52
53 class ChessPopulator extends BlockPopulator {
54
55 @Override
56 public void populate(World world, Random random, Chunk source) {
57 for (int x=0; x<16; x++) {
58 for (int z=0; z<16; z++) {
59 Block b = source.getBlock(x,64,z);
60 if ( ( (x+z) % 2) == 0) {
61 b.setData( (byte)0 );
62 } else {
63 b.setData( (byte)15 );
64 }
65 }
66 }
67 }
68
69 }
70 */
71 }

  ViewVC Help
Powered by ViewVC 1.1.20