1919import java .util .Collections ;
2020import java .util .HashSet ;
2121import java .util .Objects ;
22+ import java .util .Optional ;
2223import java .util .Set ;
2324import java .util .function .Function ;
2425
@@ -90,30 +91,30 @@ public NamespaceID getName() {
9091
9192 public enum BasicType {
9293 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 )),
9495 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 )),
9697 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 )),
9899 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 )),
100101 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 )),
102103 SOUND_EVENTS ("minecraft:sound_event" , null , null ), // Seems not to be included in server data
103104 POTION_EFFECTS ("minecraft:sound_event" , null , null ), // Seems not to be included in server data
104105
105106 //todo this is cursed. it does not update as the registry changes. Fix later.
106107 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 )), ;
108109
109110 private final static BasicType [] VALUES = values ();
110111 private final String identifier ;
111112 private final Registry .Resource resource ;
112- private final Function <String , Integer > function ;
113+ private final Function <String , Optional < Integer > > function ;
113114
114115 BasicType (@ NotNull String identifier ,
115116 @ Nullable Registry .Resource resource ,
116- @ Nullable Function <String , Integer > function ) {
117+ @ Nullable Function <String , Optional < Integer > > function ) {
117118 this .identifier = identifier ;
118119 this .resource = resource ;
119120 this .function = function ;
@@ -127,7 +128,7 @@ public Registry.Resource getResource() {
127128 return resource ;
128129 }
129130
130- public Function <String , Integer > getFunction () {
131+ public Function <String , Optional < Integer > > getFunction () {
131132 return function ;
132133 }
133134
0 commit comments