8
8
import me .shedaniel .clothconfig2 .impl .builders .BooleanToggleBuilder ;
9
9
import me .shedaniel .clothconfig2 .impl .builders .IntSliderBuilder ;
10
10
import me .shedaniel .clothconfig2 .impl .builders .SubCategoryBuilder ;
11
+ import net .fabricmc .loader .api .FabricLoader ;
11
12
import net .minecraft .block .Block ;
13
+ import net .minecraft .registry .Registries ;
12
14
import net .minecraft .text .MutableText ;
13
15
import net .minecraft .text .Text ;
14
16
import net .minecraft .util .Identifier ;
15
17
import randommcsomethin .fallingleaves .config .ConfigDefaults ;
16
18
import randommcsomethin .fallingleaves .config .LeafSettingsEntry ;
17
- import randommcsomethin .fallingleaves .util .ModUtil ;
18
19
import randommcsomethin .fallingleaves .util .TranslationComparator ;
19
20
20
21
import java .lang .reflect .Field ;
24
25
import java .util .Map ;
25
26
26
27
import static randommcsomethin .fallingleaves .FallingLeavesClient .LOGGER ;
27
- import static randommcsomethin .fallingleaves .util .RegistryUtil .getBlock ;
28
28
29
29
public class LeafSettingsGuiProvider implements GuiProvider {
30
30
private static final MutableText RESET_TEXT = Text .translatable ("text.cloth-config.reset_value" );
31
31
32
+ public static String getModName (String modId ) {
33
+ return FabricLoader .getInstance ().getModContainer (modId ).map (c -> c .getMetadata ().getName ()).orElse (modId );
34
+ }
35
+
32
36
@ SuppressWarnings ({"rawtypes" , "unchecked" , "ConstantConditions" })
33
37
@ Override
34
38
public List <AbstractConfigListEntry > get (String i13n , Field field , Object config , Object defaults , GuiRegistryAccess registry ) {
@@ -38,20 +42,20 @@ public List<AbstractConfigListEntry> get(String i13n, Field field, Object config
38
42
39
43
// Insert per-leaf settings ordered by translation name
40
44
leafSettings .entrySet ().stream ()
41
- .filter (( e ) -> getBlock (e .getKey ()) != null ) // Only insert registered blocks
42
- .sorted ((e1 , e2 ) -> TranslationComparator .INST .compare (getBlock (e1 .getKey ()).getTranslationKey (), getBlock (e2 .getKey ()).getTranslationKey ()))
45
+ .filter (e -> Registries . BLOCK . containsId (e .getKey ())) // Only insert registered blocks
46
+ .sorted ((e1 , e2 ) -> TranslationComparator .INST .compare (Registries . BLOCK . get (e1 .getKey ()).getTranslationKey (), Registries . BLOCK . get (e2 .getKey ()).getTranslationKey ()))
43
47
.forEachOrdered ((e ) -> {
44
48
Identifier blockId = e .getKey ();
45
49
LeafSettingsEntry leafEntry = e .getValue ();
46
- Block block = getBlock (blockId );
50
+ Block block = Registries . BLOCK . get (blockId );
47
51
48
52
MutableText text = Text .translatable (block .getTranslationKey ());
49
53
if (!leafEntry .isDefault (blockId )) {
50
54
text .append ("*" );
51
55
}
52
56
53
57
SubCategoryBuilder builder = new SubCategoryBuilder (RESET_TEXT , text )
54
- .setTooltip (Text .of (ModUtil . getModName (block )));
58
+ .setTooltip (Text .of (getModName (blockId . getNamespace () )));
55
59
56
60
builder .add (buildSpawnRateFactorSlider (blockId , leafEntry ));
57
61
builder .add (buildIsConiferLeavesToggle (blockId , leafEntry ));
0 commit comments