-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
BiomeNMSImpl.java
91 lines (75 loc) · 2.7 KB
/
BiomeNMSImpl.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
package com.denizenscript.denizen.nms.v1_14.impl;
import com.denizenscript.denizen.nms.abstracts.BiomeNMS;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import net.minecraft.server.v1_14_R1.*;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class BiomeNMSImpl extends BiomeNMS {
private final BiomeBase biomeBase;
public BiomeNMSImpl(Biome biome) {
super(biome);
this.biomeBase = CraftBlock.biomeToBiomeBase(biome);
}
@Override
public float getHumidity() {
return biomeBase.getHumidity();
}
@Override
public float getTemperature() {
return biomeBase.getTemperature();
}
@Override
public List<EntityType> getAmbientEntities() {
return getSpawnableEntities(EnumCreatureType.AMBIENT);
}
@Override
public List<EntityType> getCreatureEntities() {
return getSpawnableEntities(EnumCreatureType.CREATURE);
}
@Override
public List<EntityType> getMonsterEntities() {
return getSpawnableEntities(EnumCreatureType.MONSTER);
}
@Override
public List<EntityType> getWaterEntities() {
return getSpawnableEntities(EnumCreatureType.WATER_CREATURE);
}
@Override
public void setHumidity(float humidity) {
ReflectionHelper.setFieldValue(BiomeBase.class, "j", biomeBase, humidity);
}
@Override
public void setTemperature(float temperature) {
ReflectionHelper.setFieldValue(BiomeBase.class, "i", biomeBase, temperature);
}
@Override
protected boolean getDoesRain() {
return biomeBase.b() == BiomeBase.Precipitation.RAIN;
}
@Override
protected boolean getDoesSnow() {
return biomeBase.b() == BiomeBase.Precipitation.SNOW;
}
private List<EntityType> getSpawnableEntities(EnumCreatureType creatureType) {
List<EntityType> entityTypes = new ArrayList<>();
for (BiomeBase.BiomeMeta meta : biomeBase.getMobs(creatureType)) {
// TODO: check if this works
try {
String n = EntityTypes.getName(meta.b).getKey();
EntityType et = EntityType.fromName(n);
if (et == null) {
et = EntityType.valueOf(n.toUpperCase(Locale.ENGLISH));
}
entityTypes.add(et);
}
catch (Throwable e) {
// Ignore the error. Likely from invalid entity type name output.
}
}
return entityTypes;
}
}