-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiomeListener.java
111 lines (91 loc) · 3.01 KB
/
BiomeListener.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
103
104
105
106
107
108
109
110
111
package freeradicalx.humanbiomes;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import ttftcuts.atg.api.events.listenable.ATGBiomeGroupAssignmentEvent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeSubscribe;
public class BiomeListener {
public static int biomeScale = 8; //AVERAGE DISTANCE ACROSS A BIOME CELL, IN CHUNKS
public static int roadScale = 20;
public static long seed;
HumanBiomesPerlin perlin = new HumanBiomesPerlin();
@ForgeSubscribe
public void biomeReassign(ATGBiomeGroupAssignmentEvent event)
{
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
//int density = perlin.getDensity(event.x >> 4, event.z >> 4);
int density = biomeCheck(event.x >> 4, event.z >> 4, biomeScale);
//if (density != 130){
// System.out.println("testing " + (event.x >> 4) + ", " + (event.z >> 4) + ": " + density);
//}
/*
if (density > 127 && density < 169){
event.setGroup("Rural");
}
if (density >= 169 && density < 211){
event.setGroup("Suburban");
}
if (density >= 211){
event.setGroup("City");
}
*/
if (density == 128){
event.setGroup("Rural");
}
if (density == 186){
event.setGroup("Suburban");
}
if (density == 255){
event.setGroup("City");
}
}
}
int biomeCheck(int X, int Y, int scale){
int thisDensity;
int shortestDistance = scale * 10;
int[] nearestVertex = new int[2];
for (int checkX = -1; checkX < 2; checkX++){
for (int checkY = -1; checkY < 2; checkY++){
int otherX = (X+(checkX*scale));
int otherY = (Y+(checkY*scale));
int[] otherVertex = biomeVertex(otherX, otherY, scale);
int distanceX = Math.abs(Math.abs(X) - Math.abs(otherVertex[0]));
int distanceY = Math.abs(Math.abs(Y) - Math.abs(otherVertex[1]));
int distance = (int)Math.sqrt( Math.abs((distanceX * distanceX) + Math.abs(distanceY * distanceY)) );
if (distance < shortestDistance){
shortestDistance = distance;
nearestVertex[0] = otherVertex[0];
nearestVertex[1] = otherVertex[1];
}
}
}
thisDensity = perlin.getDensity( ((nearestVertex[0] / (scale/2))), ((nearestVertex[1] / (scale/2))) );
return thisDensity;
}
public static int[] biomeVertex(int X, int Y, int scale){
int baseX = (X / scale) * scale;
int baseY = (Y / scale) * scale;
int[] vertex = {
(int) (Math.abs(((hash(baseX) * getSeed()) + hash(Y / scale)) % scale) + baseX),
(int) (Math.abs(((hash(baseY) * getSeed()) + hash(X / scale)) % scale) + baseY)
};
return vertex;
}
public static int hash(int n) {
n = ((n >> 16) ^ n) * 0x45d9f3b;
n = ((n >> 16) ^ n) * 0x45d9f3b;
n = ((n >> 16) ^ n);
return n;
}
public static long getSeed(){
if(MinecraftServer.getServer().worldServers.length > 0){
seed = MinecraftServer.getServer().worldServers[0].getSeed();
}
else{
return 130;
}
return seed;
}
}