19
19
import java .util .Collections ;
20
20
import java .util .HashSet ;
21
21
import java .util .Objects ;
22
+ import java .util .Optional ;
22
23
import java .util .Set ;
23
24
import java .util .function .Function ;
24
25
@@ -90,30 +91,30 @@ public NamespaceID getName() {
90
91
91
92
public enum BasicType {
92
93
BLOCKS ("minecraft:block" , Registry .Resource .BLOCK_TAGS ,
93
- name -> Objects . requireNonNull (Block .fromNamespaceId (name )).id ( )),
94
+ name -> Optional . ofNullable (Block .fromNamespaceId (name )).map ( Block :: id )),
94
95
ITEMS ("minecraft:item" , Registry .Resource .ITEM_TAGS ,
95
- name -> Objects . requireNonNull (Material .fromNamespaceId (name )).id ( )),
96
+ name -> Optional . ofNullable (Material .fromNamespaceId (name )).map ( Material :: id )),
96
97
FLUIDS ("minecraft:fluid" , Registry .Resource .FLUID_TAGS ,
97
- name -> Objects . requireNonNull (Fluid .fromNamespaceId (name )).id ( )),
98
+ name -> Optional . ofNullable (Fluid .fromNamespaceId (name )).map ( Fluid :: id )),
98
99
ENTITY_TYPES ("minecraft:entity_type" , Registry .Resource .ENTITY_TYPE_TAGS ,
99
- name -> Objects . requireNonNull (EntityType .fromNamespaceId (name )).id ( )),
100
+ name -> Optional . ofNullable (EntityType .fromNamespaceId (name )).map ( EntityType :: id )),
100
101
GAME_EVENTS ("minecraft:game_event" , Registry .Resource .GAMEPLAY_TAGS ,
101
- name -> Objects . requireNonNull ( GameEvent .fromNamespaceId (name )).id ( )),
102
+ name -> Optional . ofNullable ( EntityType .fromNamespaceId (name )).map ( EntityType :: id )),
102
103
SOUND_EVENTS ("minecraft:sound_event" , null , null ), // Seems not to be included in server data
103
104
POTION_EFFECTS ("minecraft:sound_event" , null , null ), // Seems not to be included in server data
104
105
105
106
//todo this is cursed. it does not update as the registry changes. Fix later.
106
107
ENCHANTMENTS ("minecraft:enchantment" , Registry .Resource .ENCHANTMENT_TAGS ,
107
- name -> MinecraftServer . getEnchantmentRegistry (). getId (DynamicRegistry .Key . of ( name ))) ;
108
+ name -> Optional . of ( DynamicRegistry . Key . of ( name )). map (DynamicRegistry .Key :: namespace ). map ( MinecraftServer . getEnchantmentRegistry ():: getId )), ;
108
109
109
110
private final static BasicType [] VALUES = values ();
110
111
private final String identifier ;
111
112
private final Registry .Resource resource ;
112
- private final Function <String , Integer > function ;
113
+ private final Function <String , Optional < Integer > > function ;
113
114
114
115
BasicType (@ NotNull String identifier ,
115
116
@ Nullable Registry .Resource resource ,
116
- @ Nullable Function <String , Integer > function ) {
117
+ @ Nullable Function <String , Optional < Integer > > function ) {
117
118
this .identifier = identifier ;
118
119
this .resource = resource ;
119
120
this .function = function ;
@@ -127,7 +128,7 @@ public Registry.Resource getResource() {
127
128
return resource ;
128
129
}
129
130
130
- public Function <String , Integer > getFunction () {
131
+ public Function <String , Optional < Integer > > getFunction () {
131
132
return function ;
132
133
}
133
134
0 commit comments