-
Notifications
You must be signed in to change notification settings - Fork 0
/
CraftChunkSnapshot.java
102 lines (85 loc) · 3.24 KB
/
CraftChunkSnapshot.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.bukkit.craftbukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.BlockStateContainer;
import net.minecraft.server.HeightMap;
import net.minecraft.block.state.IBlockState;
/**
* 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 BlockStateContainer<IBlockState>[] blockids;
private final byte[][] skylight;
private final byte[][] emitlight;
private final boolean[] empty;
private final HeightMap hmap; // Height map
private final long captureFulltime;
private final Biome[] biome;
private final double[] biomeTemp;
CraftChunkSnapshot(int x, int z, String wname, long wtime, BlockStateContainer<IBlockState>[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, HeightMap hmap, Biome[] biome, double[] biomeTemp) {
this.x = x;
this.z = z;
this.worldname = wname;
this.captureFulltime = wtime;
this.blockids = sectionBlockIDs;
this.skylight = sectionSkyLights;
this.emitlight = sectionEmitLights;
this.empty = sectionEmpty;
this.hmap = hmap;
this.biome = biome;
this.biomeTemp = biomeTemp;
}
public int getX() {
return x;
}
public int getZ() {
return z;
}
public String getWorldName() {
return worldname;
}
@Override
public Material getBlockType(int x, int y, int z) {
return CraftMagicNumbers.getMaterial(blockids[y >> 4].a(x, y & 0xF, z).getBlock());
}
@Override
public final BlockData getBlockData(int x, int y, int z) {
return CraftBlockData.fromData(blockids[y >> 4].a(x, y & 0xF, z));
}
@Override
public final int getData(int x, int y, int z) {
return CraftMagicNumbers.toLegacyData(blockids[y >> 4].a(x, y & 0xF, z));
}
public final int getBlockSkyLight(int x, int y, int z) {
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (skylight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
}
public final int getBlockEmittedLight(int x, int y, int z) {
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (emitlight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
}
public final int getHighestBlockYAt(int x, int z) {
return hmap.a(x, z);
}
public final Biome getBiome(int x, int z) {
return CraftBlock.biomeBaseToBiome(biome[z << 4 | x]);
}
public final double getRawBiomeTemperature(int x, int z) {
return biomeTemp[z << 4 | x];
}
public final long getCaptureFullTime() {
return captureFulltime;
}
public final boolean isSectionEmpty(int sy) {
return empty[sy];
}
}