Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.Random;
- import org.bukkit.generator.ChunkGenerator;
- import org.bukkit.ChunkSnapshot;
- import org.bukkit.World;
- public class TemplateGenerator extends ChunkGenerator {
- protected World world;
- public TemplateGenerator(World templateWorld) {
- this.world = templateWorld;
- }
- /*
- void setBlock(short[][] result, int x, int y, int z, short blkid) {
- if (result[y >> 4] == null) {
- result[y >> 4] = new short[4096];
- }
- result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
- }
- */
- @Override
- public short[][] generateExtBlockSections(World contextWorld, Random worldRandom, int cx, int cz, BiomeGrid biomes) {
- ChunkSnapshot templateChunk = world.getChunkAt(cx, cz).getChunkSnapshot();
- // Pure-bukkit impl - can be optimized via NMS
- // Load block IDs
- short[][] result = new short[256 / 16][];
- for (int y = 0; y < 256; y += 16) {
- short[] locres = new short[4096];
- for (int py = y; py < y + 16; py++) {
- for (int px = 0; px < 16; px++) {
- for (int pz = 0; pz < 16; pz++) {
- locres[((py & 0xF) << 8) | (pz << 4) | px] = (short) templateChunk.getBlockTypeId(px, py, pz);
- }
- }
- }
- result[y >> 4] = locres;
- }
- loadBiomesIntoGrid(biomes, templateChunk);
- return result;
- }
- public void loadBiomesIntoGrid(BiomeGrid biomes, ChunkSnapshot template) {
- for (int px = 0; px < 16; px++) {
- for (int pz = 0; pz < 16; pz++) {
- biomes.setBiome(px, pz, template.getBiome(px, pz));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement