aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/lodmod/renderer/LODRegion.java
blob: 695202dff135c8c941a2b2a72cb745c1326ad536 (plain)
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
package makamys.lodmod.renderer;

import net.minecraft.entity.Entity;
import net.minecraft.world.chunk.Chunk;

public class LODRegion {
	
	private LODChunk[][] data = new LODChunk[32][32];
	
	int regionX, regionZ;
	
	public LODRegion(int regionX, int regionZ) {
		this.regionX = regionX;
		this.regionZ = regionZ;
		
		for(int i = 0; i < 32; i++) {
			for(int j = 0; j < 32; j++) {
				data[i][j] = new LODChunk(regionX * 32 + i, regionZ * 32 + j);
			}
		}
	}
	
	public static LODRegion load(int regionX, int regionZ) {
		return new LODRegion(regionX, regionZ); // TODO
	}
	
	public LODChunk getChunkAbsolute(int chunkXAbs, int chunkZAbs) {
		return getChunk(chunkXAbs - regionX * 32, chunkZAbs - regionZ * 32);
	}
	
	public LODChunk getChunk(int x, int z) {
		if(x >= 0 && x < 32 && z >= 0 && z < 32) {
			return data[x][z];
		} else {
			return null;
		}
	}
	
	public LODChunk putChunk(Chunk chunk) {
		int relX = chunk.xPosition - regionX * 32;
		int relZ = chunk.zPosition - regionZ * 32;
		
		if(relX >= 0 && relX < 32 && relZ >= 0 && relZ < 32) {
			data[relX][relZ].chunk = chunk;
			data[relX][relZ].waitingForData = false;
			return data[relX][relZ];
		}
		return null;
	}
	
	public void tick(Entity player) {
		for(int i = 0; i < 32; i++) {
			for(int j = 0; j < 32; j++) {
				LODChunk chunk = data[i][j];
				if(chunk != null) {
					chunk.tick(player);
				}
			}
		}
	}
	
}