-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
BiomeNMSImpl.java
107 lines (89 loc) · 3.21 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.denizenscript.denizen.nms.v1_16.impl;
import com.denizenscript.denizen.nms.abstracts.BiomeNMS;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import net.minecraft.server.v1_16_R3.*;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class BiomeNMSImpl extends BiomeNMS {
public BiomeBase biomeBase;
public Biome bukkitBiome;
public BiomeNMSImpl(World world, Biome biome) {
super(world, biome.name());
bukkitBiome = biome;
this.biomeBase = CraftBlock.biomeToBiomeBase(((CraftWorld) world).getHandle().r().b(IRegistry.ay), biome);
}
@Override
public float getHumidity() {
return biomeBase.getHumidity();
}
@Override
public float getTemperature() {
return biomeBase.k();
}
@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.c() == BiomeBase.Precipitation.RAIN;
}
@Override
protected boolean getDoesSnow() {
return biomeBase.c() == BiomeBase.Precipitation.SNOW;
}
private List<EntityType> getSpawnableEntities(EnumCreatureType creatureType) {
BiomeSettingsMobs mobs = biomeBase.b();
List<BiomeSettingsMobs.c> typeSettingList = mobs.a(creatureType);
List<EntityType> entityTypes = new ArrayList<>();
if (typeSettingList == null) {
return entityTypes;
}
for (BiomeSettingsMobs.c meta : typeSettingList) {
// TODO: check if this works
try {
String n = EntityTypes.getName(meta.c).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;
}
@Override
public void setTo(Block block) {
block.setBiome(bukkitBiome);
}
}