2011-06-07 09:34:23 +02:00
|
|
|
package org.bukkit.craftbukkit;
|
|
|
|
|
|
|
|
import org.bukkit.ChunkSnapshot;
|
2011-06-17 15:23:19 +02:00
|
|
|
import org.bukkit.block.Biome;
|
2011-07-14 21:05:43 +02:00
|
|
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
2011-06-17 15:23:19 +02:00
|
|
|
|
|
|
|
import net.minecraft.server.BiomeBase;
|
2012-01-14 23:02:10 +01:00
|
|
|
|
2011-06-07 09:34:23 +02:00
|
|
|
/**
|
|
|
|
* Represents a static, thread-safe snapshot of chunk of blocks
|
|
|
|
* Purpose is to allow clean, efficient copy of a chunk data to be made, and then handed off for processing in another thread (e.g. map rendering)
|
|
|
|
*/
|
|
|
|
public class CraftChunkSnapshot implements ChunkSnapshot {
|
|
|
|
private final int x, z;
|
|
|
|
private final String worldname;
|
|
|
|
private final byte[] buf; // Flat buffer in uncompressed chunk file format
|
|
|
|
private final byte[] hmap; // Height map
|
2011-06-17 15:23:19 +02:00
|
|
|
private final long captureFulltime;
|
|
|
|
private final BiomeBase[] biome;
|
|
|
|
private final double[] biomeTemp;
|
|
|
|
private final double[] biomeRain;
|
2011-06-07 09:34:23 +02:00
|
|
|
|
|
|
|
private static final int BLOCKDATA_OFF = 32768;
|
|
|
|
private static final int BLOCKLIGHT_OFF = BLOCKDATA_OFF + 16384;
|
|
|
|
private static final int SKYLIGHT_OFF = BLOCKLIGHT_OFF + 16384;
|
|
|
|
|
2011-06-17 15:23:19 +02:00
|
|
|
CraftChunkSnapshot(int x, int z, String wname, long wtime, byte[] buf, byte[] hmap, BiomeBase[] biome, double[] biomeTemp, double[] biomeRain) {
|
2011-06-07 09:34:23 +02:00
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
this.worldname = wname;
|
2011-06-17 15:23:19 +02:00
|
|
|
this.captureFulltime = wtime;
|
2011-06-07 09:34:23 +02:00
|
|
|
this.buf = buf;
|
|
|
|
this.hmap = hmap;
|
2011-06-17 15:23:19 +02:00
|
|
|
this.biome = biome;
|
|
|
|
this.biomeTemp = biomeTemp;
|
|
|
|
this.biomeRain = biomeRain;
|
2011-06-07 09:34:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getZ() {
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getWorldName() {
|
|
|
|
return worldname;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockTypeId(int x, int y, int z) {
|
|
|
|
return buf[x << 11 | z << 7 | y] & 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockData(int x, int y, int z) {
|
|
|
|
int off = ((x << 10) | (z << 6) | (y >> 1)) + BLOCKDATA_OFF;
|
|
|
|
|
|
|
|
return ((y & 1) == 0) ? (buf[off] & 0xF) : ((buf[off] >> 4) & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockSkyLight(int x, int y, int z) {
|
|
|
|
int off = ((x << 10) | (z << 6) | (y >> 1)) + SKYLIGHT_OFF;
|
|
|
|
|
|
|
|
return ((y & 1) == 0) ? (buf[off] & 0xF) : ((buf[off] >> 4) & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockEmittedLight(int x, int y, int z) {
|
|
|
|
int off = ((x << 10) | (z << 6) | (y >> 1)) + BLOCKLIGHT_OFF;
|
|
|
|
|
|
|
|
return ((y & 1) == 0) ? (buf[off] & 0xF) : ((buf[off] >> 4) & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHighestBlockYAt(int x, int z) {
|
|
|
|
return hmap[z << 4 | x] & 255;
|
|
|
|
}
|
|
|
|
|
2011-06-17 15:23:19 +02:00
|
|
|
public Biome getBiome(int x, int z) {
|
2011-09-15 22:57:37 +02:00
|
|
|
return CraftBlock.biomeBaseToBiome(biome[z << 4 | x]);
|
2011-06-17 15:23:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public double getRawBiomeTemperature(int x, int z) {
|
2011-09-15 22:57:37 +02:00
|
|
|
return biomeTemp[z << 4 | x];
|
2011-06-17 15:23:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public double getRawBiomeRainfall(int x, int z) {
|
2011-09-15 22:57:37 +02:00
|
|
|
return biomeRain[z << 4 | x];
|
2011-06-17 15:23:19 +02:00
|
|
|
}
|
|
|
|
|
2011-06-07 09:34:23 +02:00
|
|
|
public long getCaptureFullTime() {
|
2011-06-17 15:23:19 +02:00
|
|
|
return captureFulltime;
|
2011-06-07 09:34:23 +02:00
|
|
|
}
|
|
|
|
}
|