3
3
import com .google .common .collect .ImmutableMap ;
4
4
import com .mojang .serialization .Lifecycle ;
5
5
import net .minecraft .core .Holder ;
6
- import net .minecraft .core .IRegistry ;
7
- import net .minecraft .core .IRegistryWritable ;
8
- import net .minecraft .core .RegistryMaterials ;
9
- import net .minecraft .data .RegistryGeneration ;
10
- import net .minecraft .resources .MinecraftKey ;
6
+ import net .minecraft .core .MappedRegistry ;
7
+ import net .minecraft .core .Registry ;
8
+ import net .minecraft .core .WritableRegistry ;
9
+ import net .minecraft .data .BuiltinRegistries ;
11
10
import net .minecraft .resources .ResourceKey ;
11
+ import net .minecraft .resources .ResourceLocation ;
12
12
import net .minecraft .tags .TagKey ;
13
- import net .minecraft .world .level .biome .BiomeBase ;
14
- import net .minecraft .world .level .biome .BiomeFog ;
15
- import net .minecraft .world .level .biome .BiomeFog .GrassColor ;
16
- import net .minecraft .world .level .biome .BiomeSettingsGeneration ;
17
- import net .minecraft .world .level .biome .BiomeSettingsMobs ;
13
+ import net .minecraft .world .level .biome .Biome ;
14
+ import net .minecraft .world .level .biome .BiomeSpecialEffects ;
18
15
import org .bukkit .NamespacedKey ;
19
16
import org .slf4j .Logger ;
20
17
import org .slf4j .LoggerFactory ;
21
18
22
- import java .lang .reflect .Field ;
23
19
import java .util .ArrayList ;
24
20
import java .util .HashMap ;
25
21
import java .util .List ;
29
25
import java .util .Optional ;
30
26
31
27
import com .dfsek .terra .api .config .ConfigPack ;
32
- import com .dfsek .terra .api .world .biome .Biome ;
33
28
import com .dfsek .terra .bukkit .config .VanillaBiomeProperties ;
34
29
import com .dfsek .terra .bukkit .world .BukkitPlatformBiome ;
35
30
import com .dfsek .terra .registry .master .ConfigRegistry ;
36
31
37
32
38
33
public class NMSBiomeInjector {
39
34
private static final Logger LOGGER = LoggerFactory .getLogger (NMSBiomeInjector .class );
40
- private static final Map <MinecraftKey , List <MinecraftKey >> terraBiomeMap = new HashMap <>();
35
+ private static final Map <ResourceLocation , List <ResourceLocation >> terraBiomeMap = new HashMap <>();
41
36
42
37
43
38
public static void registerBiomes (ConfigRegistry configRegistry ) {
44
39
try {
45
40
LOGGER .info ("Hacking biome registry..." );
46
- IRegistryWritable <BiomeBase > biomeRegistry = (IRegistryWritable <BiomeBase >) Registries .biomeRegistry ();
47
- Field frozen = RegistryMaterials .class .getDeclaredField ("bL" ); // registry frozen field
48
- frozen .setAccessible (true );
49
- frozen .set (biomeRegistry , false );
41
+ WritableRegistry <Biome > biomeRegistry = (WritableRegistry <Biome >) Registries .biomeRegistry ();
50
42
51
- configRegistry .forEach (pack -> pack .getRegistry (Biome .class ).forEach ((key , biome ) -> {
43
+ Reflection .MAPPED_REGISTRY .setFrozen ((MappedRegistry <?>) biomeRegistry , false );
44
+
45
+ configRegistry .forEach (pack -> pack .getRegistry (com .dfsek .terra .api .world .biome .Biome .class ).forEach ((key , biome ) -> {
52
46
try {
53
47
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome ) biome .getPlatformBiome ();
54
48
NamespacedKey vanillaBukkitKey = platformBiome .getHandle ().getKey ();
55
- MinecraftKey vanillaMinecraftKey = new MinecraftKey (vanillaBukkitKey .getNamespace (), vanillaBukkitKey .getKey ());
56
- BiomeBase platform = createBiome (
49
+ ResourceLocation vanillaMinecraftKey = new ResourceLocation (vanillaBukkitKey .getNamespace (), vanillaBukkitKey .getKey ());
50
+ Biome platform = createBiome (
57
51
biome ,
58
- biomeRegistry .a (vanillaMinecraftKey ) // get
52
+ biomeRegistry .get (vanillaMinecraftKey ) // get
59
53
);
60
54
61
- ResourceKey <BiomeBase > delegateKey = ResourceKey .a ( IRegistry . aP , new MinecraftKey ("terra" , createBiomeID (pack , key )));
55
+ ResourceKey <Biome > delegateKey = ResourceKey .create ( Registry . BIOME_REGISTRY , new ResourceLocation ("terra" , createBiomeID (pack , key )));
62
56
63
- RegistryGeneration . a ( RegistryGeneration . i , delegateKey , platform );
64
- biomeRegistry .a (delegateKey , platform , Lifecycle .stable ());
57
+ BuiltinRegistries . register ( BuiltinRegistries . BIOME , delegateKey , platform );
58
+ biomeRegistry .register (delegateKey , platform , Lifecycle .stable ());
65
59
platformBiome .getContext ().put (new NMSBiomeInfo (delegateKey ));
66
60
67
- terraBiomeMap .computeIfAbsent (vanillaMinecraftKey , i -> new ArrayList <>()).add (delegateKey .a ());
61
+ terraBiomeMap .computeIfAbsent (vanillaMinecraftKey , i -> new ArrayList <>()).add (delegateKey .location ());
68
62
69
63
LOGGER .debug ("Registered biome: " + delegateKey );
70
64
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e ) {
71
65
throw new RuntimeException (e );
72
66
}
73
67
}));
74
-
75
- frozen . set ( biomeRegistry , true ); // freeze registry again :)
68
+
69
+ Reflection . MAPPED_REGISTRY . setFrozen (( MappedRegistry <?>) biomeRegistry , true ); // freeze registry again :)
76
70
77
71
LOGGER .info ("Doing tag garbage...." );
78
- Map <TagKey <BiomeBase >, List <Holder <BiomeBase >>> collect = biomeRegistry
79
- .g () // streamKeysAndEntries
72
+ Map <TagKey <Biome >, List <Holder <Biome >>> collect = biomeRegistry
73
+ .getTags () // streamKeysAndEntries
80
74
.collect (HashMap ::new ,
81
75
(map , pair ) ->
82
- map .put (pair .getFirst (), new ArrayList <>(pair .getSecond ().a ().toList ())),
76
+ map .put (pair .getFirst (), new ArrayList <>(pair .getSecond ().stream ().toList ())),
83
77
HashMap ::putAll );
84
78
85
79
terraBiomeMap
@@ -90,13 +84,13 @@ public static void registerBiomes(ConfigRegistry configRegistry) {
90
84
.forEach (tb -> getEntry (biomeRegistry , tb )
91
85
.ifPresentOrElse (
92
86
terra -> {
93
- LOGGER .debug (vanilla .e ().orElseThrow ().a () +
87
+ LOGGER .debug (vanilla .unwrapKey ().orElseThrow ().location () +
94
88
" (vanilla for " +
95
- terra .e ().orElseThrow ().a () +
89
+ terra .unwrapKey ().orElseThrow ().location () +
96
90
": " +
97
- vanilla .c ().toList ());
91
+ vanilla .tags ().toList ());
98
92
99
- vanilla .c ()
93
+ vanilla .tags ()
100
94
.forEach (
101
95
tag -> collect
102
96
.computeIfAbsent (tag ,
@@ -108,77 +102,63 @@ public static void registerBiomes(ConfigRegistry configRegistry) {
108
102
tb ))),
109
103
() -> LOGGER .error ("No vanilla biome: {}" , vb )));
110
104
111
- biomeRegistry .k (); // clearTags
112
- biomeRegistry .a (ImmutableMap .copyOf (collect )); // populateTags
105
+ biomeRegistry .resetTags (); // clearTags
106
+ biomeRegistry .bindTags (ImmutableMap .copyOf (collect )); // populateTags
113
107
114
- } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException exception ) {
108
+ } catch (SecurityException | IllegalArgumentException exception ) {
115
109
throw new RuntimeException (exception );
116
110
}
117
111
}
118
112
119
- public static <T > Optional <Holder <T >> getEntry (IRegistry <T > registry , MinecraftKey identifier ) {
120
- return registry .b (identifier )
121
- .flatMap (registry ::c )
122
- .map (registry ::c );
113
+ public static <T > Optional <Holder <T >> getEntry (Registry <T > registry , ResourceLocation identifier ) {
114
+ return registry .getOptional (identifier )
115
+ .flatMap (registry ::getResourceKey )
116
+ .map (registry ::getOrCreateHolder );
123
117
}
124
118
125
- private static BiomeBase createBiome (Biome biome , BiomeBase vanilla )
119
+ private static Biome createBiome (com . dfsek . terra . api . world . biome . Biome biome , Biome vanilla )
126
120
throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
127
- BiomeBase .a builder = new BiomeBase .a (); // Builder
128
-
129
- Field f = BiomeBase .class .getDeclaredField ("l" ); // category
130
- f .setAccessible (true );
131
- builder .a ((BiomeBase .Geography ) f .get (vanilla ))
132
- .a (vanilla .c ()); // getPrecipitation
133
-
134
-
135
- Field biomeSettingMobsField = BiomeBase .class .getDeclaredField ("k" ); // spawn settings
136
- biomeSettingMobsField .setAccessible (true );
137
- BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs ) biomeSettingMobsField .get (vanilla );
138
- builder .a (biomeSettingMobs );
139
-
121
+ Biome .BiomeBuilder builder = new Biome .BiomeBuilder (); // Builder
140
122
141
- BiomeSettingsGeneration .a generationBuilder = new BiomeSettingsGeneration .a (); // builder
142
- builder .a (generationBuilder .a ())
143
- .a (vanilla .c ())
144
- .b (vanilla .h ()) // precipitation
145
- .a (vanilla .i ()); // temp
146
123
124
+ builder .biomeCategory (Reflection .BIOME .getBiomeCategory (vanilla ))
125
+ .precipitation (vanilla .getPrecipitation ()) // getPrecipitation
126
+ .mobSpawnSettings (vanilla .getMobSettings ())
127
+ .generationSettings (vanilla .getGenerationSettings ())
128
+ .temperature (vanilla .getBaseTemperature ())
129
+ .downfall (vanilla .getDownfall ());
130
+
131
+
147
132
148
- BiomeFog .a effects = new BiomeFog .a (); // Builder
149
- effects .a (GrassColor .a ); // magic
150
-
133
+ BiomeSpecialEffects .Builder effects = new BiomeSpecialEffects .Builder ();
134
+
135
+ effects .grassColorModifier (vanilla .getSpecialEffects ().getGrassColorModifier ());
136
+
151
137
VanillaBiomeProperties vanillaBiomeProperties = biome .getContext ().get (VanillaBiomeProperties .class );
152
-
153
- // fog
154
- effects .a (Objects .requireNonNullElse (vanillaBiomeProperties .getFogColor (), vanilla .f ()));
155
-
156
- // water
157
- effects .b (Objects .requireNonNullElse (vanillaBiomeProperties .getWaterColor (), vanilla .k ()));
158
-
159
- // water fog
160
- effects .c (Objects .requireNonNullElse (vanillaBiomeProperties .getWaterFogColor (), vanilla .l ()));
161
-
162
- // sky
163
- effects .d (Objects .requireNonNullElse (vanillaBiomeProperties .getSkyColor (), vanilla .a ()));
164
-
138
+
139
+ effects .fogColor (Objects .requireNonNullElse (vanillaBiomeProperties .getFogColor (), vanilla .getFogColor ()))
140
+
141
+ .waterColor (Objects .requireNonNullElse (vanillaBiomeProperties .getWaterColor (), vanilla .getWaterColor ()))
142
+
143
+ .waterFogColor (Objects .requireNonNullElse (vanillaBiomeProperties .getWaterFogColor (), vanilla .getWaterFogColor ()))
144
+
145
+ .skyColor (Objects .requireNonNullElse (vanillaBiomeProperties .getSkyColor (), vanilla .getSkyColor ()));
146
+
165
147
if (vanillaBiomeProperties .getFoliageColor () == null ) {
166
- vanilla .j ().e ().ifPresent (effects ::e );
148
+ vanilla .getSpecialEffects ().getFoliageColorOverride ().ifPresent (effects ::foliageColorOverride );
167
149
} else {
168
- // foliage
169
- effects .e (vanillaBiomeProperties .getFoliageColor ());
150
+ effects .foliageColorOverride (vanillaBiomeProperties .getFoliageColor ());
170
151
}
171
-
152
+
172
153
if (vanillaBiomeProperties .getGrassColor () == null ) {
173
- vanilla .j ().f ().ifPresent (effects ::f );
154
+ vanilla .getSpecialEffects ().getGrassColorOverride ().ifPresent (effects ::grassColorOverride );
174
155
} else {
175
- // grass
176
- effects .f (vanillaBiomeProperties .getGrassColor ());
156
+ effects .grassColorOverride (vanillaBiomeProperties .getGrassColor ());
177
157
}
158
+
159
+ builder .specialEffects (effects .build ());
178
160
179
- builder .a (effects .a ()); // build()
180
-
181
- return builder .a (); // build()
161
+ return builder .build (); // build()
182
162
}
183
163
184
164
public static String createBiomeID (ConfigPack pack , com .dfsek .terra .api .registry .key .RegistryKey biomeID ) {
0 commit comments