/
BiomeNMS.java
123 lines (94 loc) · 3.72 KB
/
BiomeNMS.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
112
113
114
115
116
117
118
119
120
121
122
123
package com.denizenscript.denizen.nms.abstracts;
import com.denizenscript.denizencore.objects.core.ColorTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
import java.util.List;
public abstract class BiomeNMS {
public String name;
public World world;
public BiomeNMS(World world, String name) {
this.world = world;
this.name = CoreUtilities.toLowerCase(name);
}
public String getName() {
return name;
}
public DownfallType getDownfallType() {
if (!hasDownfall()) {
return DownfallType.NONE;
}
return getBaseTemperature() > 0.15f ? DownfallType.RAIN : DownfallType.SNOW;
}
public DownfallType getDownfallTypeAt(Location location) {
throw new UnsupportedOperationException();
}
public abstract float getHumidity();
public abstract float getBaseTemperature();
public float getTemperatureAt(Location location) {
throw new UnsupportedOperationException();
}
public boolean hasDownfall() {
throw new UnsupportedOperationException();
}
public List<EntityType> getAllEntities() {
List<EntityType> entityTypes = new ArrayList<>();
entityTypes.addAll(getAmbientEntities());
entityTypes.addAll(getCreatureEntities());
entityTypes.addAll(getMonsterEntities());
entityTypes.addAll(getWaterEntities());
return entityTypes;
}
public abstract List<EntityType> getAmbientEntities();
public abstract List<EntityType> getCreatureEntities();
public abstract List<EntityType> getMonsterEntities();
public abstract List<EntityType> getWaterEntities();
public abstract int getFoliageColor();
public abstract void setHumidity(float humidity);
public abstract void setBaseTemperature(float temperature);
public void setPrecipitation(DownfallType type) {
throw new UnsupportedOperationException();
}
public void setHasDownfall(boolean hasDownfall) {
throw new UnsupportedOperationException();
}
public enum DownfallType {
RAIN, SNOW, NONE
}
public abstract void setFoliageColor(int color);
public abstract void setTo(Block block);
public ColorTag getColor(int x, int y) {
ColorTag topLeft = new ColorTag(26, 191, 0);
ColorTag topRight = new ColorTag(28, 164, 73);
ColorTag bottomLeft = new ColorTag(174, 164, 42);
ColorTag bottomRight = new ColorTag(96, 161, 123);
float normalizedX = x / 255.0f;
float normalizedY = y / 255.0f;
ColorTag lu = scaleColor(topLeft, (1 - normalizedX) * (1 - normalizedY));
ColorTag ru = scaleColor(topRight, normalizedX * (1 - normalizedY));
ColorTag ld = scaleColor(bottomLeft, (1 - normalizedX) * normalizedY);
ColorTag rd = scaleColor(bottomRight, normalizedX * normalizedY);
int r = lu.red + ld.red + rd.red + ru.red;
int g = lu.green + ld.green + rd.green + ru.green;
int b = lu.blue + ld.blue + rd.blue + ru.blue;
return new ColorTag(r, g, b);
}
public float clampColor(float n) {
if (n < 0.0f) {
return 0.0f;
}
else if (n > 1.0f) {
return 1.0f;
}
return n;
}
private ColorTag scaleColor(ColorTag color, float scale) {
float r = color.red * scale;
float g = color.green * scale;
float b = color.blue * scale;
return new ColorTag((int) r, (int) g, (int) b);
}
}