42
42
import net .minecraft .network .codec .StreamCodec ;
43
43
import net .minecraft .resources .ResourceLocation ;
44
44
import net .minecraft .tags .TagKey ;
45
- import net .minecraft .world .Container ;
46
45
import net .minecraft .world .entity .EntityType ;
47
46
import net .minecraft .world .item .ItemStack ;
48
47
import net .minecraft .world .item .crafting .*;
49
48
import net .minecraft .world .level .Level ;
49
+ import org .jetbrains .annotations .NotNull ;
50
+ import org .jetbrains .annotations .Nullable ;
50
51
51
52
import java .util .Optional ;
52
53
import java .util .function .Supplier ;
@@ -59,6 +60,7 @@ public class RitualRecipe implements Recipe<SingleRecipeInput> {
59
60
ItemStack .STRICT_CODEC .fieldOf ("ritual_dummy" ).forGetter ((r ) -> r .ritualDummy ),
60
61
ItemStack .OPTIONAL_CODEC .fieldOf ("result" ).forGetter ((r ) -> r .result ),
61
62
BuiltInRegistries .ENTITY_TYPE .byNameCodec ().optionalFieldOf ("entity_to_summon" ).forGetter (r -> Optional .ofNullable (r .entityToSummon )),
63
+ TagKey .codec (Registries .ENTITY_TYPE ).optionalFieldOf ("entity_tag_to_summon" ).forGetter (r -> Optional .ofNullable (r .entityTagToSummon )),
62
64
CompoundTag .CODEC .optionalFieldOf ("entity_nbt" ).forGetter (r -> Optional .ofNullable (r .entityNbt )),
63
65
Ingredient .CODEC .fieldOf ("activation_item" ).forGetter ((r ) -> r .activationItem ),
64
66
Ingredient .LIST_CODEC .fieldOf ("ingredients" ).forGetter ((r ) -> r .ingredients ),
@@ -69,7 +71,7 @@ public class RitualRecipe implements Recipe<SingleRecipeInput> {
69
71
EntityToSacrifice .CODEC .optionalFieldOf ("entity_to_sacrifice" ).forGetter (r -> Optional .ofNullable (r .entityToSacrifice )),
70
72
Ingredient .CODEC .optionalFieldOf ("item_to_use" ).forGetter (r -> Optional .ofNullable (r .itemToUse )),
71
73
Codec .STRING .optionalFieldOf ("command" ).forGetter (r -> Optional .ofNullable (r .command ))
72
- ).apply (instance , (pentacleId , ritualType , ritualDummy , result , entityToSummon , entityNbt , activationItem , ingredients , duration , spiritMaxAge , summonNumber , spiritJobType , entityToSacrifice , itemToUse , command ) -> new RitualRecipe (pentacleId , ritualType , ritualDummy , result , entityToSummon .orElse (null ), entityNbt .orElse (null ), activationItem ,
74
+ ).apply (instance , (pentacleId , ritualType , ritualDummy , result , entityToSummon , entityTagToSummon , entityNbt , activationItem , ingredients , duration , spiritMaxAge , summonNumber , spiritJobType , entityToSacrifice , itemToUse , command ) -> new RitualRecipe (pentacleId , ritualType , ritualDummy , result , entityToSummon . orElse ( null ), entityTagToSummon .orElse (null ), entityNbt .orElse (null ), activationItem ,
73
75
NonNullList .copyOf (ingredients ), duration , spiritMaxAge , summonNumber , spiritJobType .orElse (null ), entityToSacrifice .orElse (null ), itemToUse .orElse (Ingredient .EMPTY ), command .orElse (null )))
74
76
);
75
77
@@ -84,6 +86,8 @@ public class RitualRecipe implements Recipe<SingleRecipeInput> {
84
86
(r ) -> r .result ,
85
87
ByteBufCodecs .optional (ByteBufCodecs .registry (Registries .ENTITY_TYPE )),
86
88
(r ) -> Optional .ofNullable (r .entityToSummon ),
89
+ ByteBufCodecs .optional (OccultismExtraStreamCodecs .tagKey (Registries .ENTITY_TYPE )),
90
+ (r ) -> Optional .ofNullable (r .entityTagToSummon ),
87
91
ByteBufCodecs .optional (ByteBufCodecs .COMPOUND_TAG ),
88
92
(r ) -> Optional .ofNullable (r .entityNbt ),
89
93
Ingredient .CONTENTS_STREAM_CODEC ,
@@ -104,8 +108,8 @@ public class RitualRecipe implements Recipe<SingleRecipeInput> {
104
108
(r ) -> Optional .ofNullable (r .itemToUse ),
105
109
ByteBufCodecs .optional (ByteBufCodecs .STRING_UTF8 ),
106
110
(r ) -> Optional .ofNullable (r .command ),
107
- (pentacleId , ritualType , ritualDummy , result , entityToSummon , entityNbt , activationItem , ingredients , duration , spiritMaxAge , summonNumber , spiritJobType , entityToSacrifice , itemToUse , command ) ->
108
- new RitualRecipe (pentacleId , ritualType , ritualDummy , result , entityToSummon .orElse (null ), entityNbt .orElse (null ), activationItem ,
111
+ (pentacleId , ritualType , ritualDummy , result , entityToSummon , entityTagToSummon , entityNbt , activationItem , ingredients , duration , spiritMaxAge , summonNumber , spiritJobType , entityToSacrifice , itemToUse , command ) ->
112
+ new RitualRecipe (pentacleId , ritualType , ritualDummy , result , entityToSummon .orElse (null ), entityTagToSummon . orElse ( null ), entityNbt .orElse (null ), activationItem ,
109
113
NonNullList .copyOf (ingredients ), duration , spiritMaxAge , summonNumber , spiritJobType .orElse (null ), entityToSacrifice .orElse (null ), itemToUse .orElse (Ingredient .EMPTY ), command .orElse (null ))
110
114
);
111
115
@@ -114,25 +118,34 @@ public class RitualRecipe implements Recipe<SingleRecipeInput> {
114
118
final NonNullList <Ingredient > ingredients ;
115
119
private final ResourceLocation pentacleId ;
116
120
private final ResourceLocation ritualType ;
121
+ @ Nullable
117
122
private final ResourceLocation spiritJobType ;
118
123
private final Supplier <Ritual > ritual ;
119
124
private final ItemStack ritualDummy ;
120
125
private final Ingredient activationItem ;
126
+ @ Nullable
121
127
private final EntityToSacrifice entityToSacrifice ;
128
+ @ Nullable
122
129
private final EntityType <?> entityToSummon ;
130
+ @ Nullable
131
+ private final TagKey <EntityType <?>> entityTagToSummon ;
132
+ @ Nullable
123
133
private final CompoundTag entityNbt ;
134
+ @ Nullable
124
135
private final Ingredient itemToUse ;
125
136
private final int duration ;
126
137
private final int spiritMaxAge ;
127
138
private final int summonNumber ;
128
139
private final float durationPerIngredient ;
140
+ @ Nullable
129
141
private final String command ;
130
142
131
143
public RitualRecipe (ResourceLocation pentacleId , ResourceLocation ritualType , ItemStack ritualDummy ,
132
- ItemStack result , EntityType <?> entityToSummon , CompoundTag entityNbt , Ingredient activationItem , NonNullList <Ingredient > ingredients , int duration , int spiritMaxAge , int summonNumber , ResourceLocation spiritJobType , EntityToSacrifice entityToSacrifice , Ingredient itemToUse , String command ) {
144
+ ItemStack result , @ Nullable EntityType <?> entityToSummon , @ Nullable TagKey < EntityType <?>> entityTagToSummon , @ Nullable CompoundTag entityNbt , Ingredient activationItem , NonNullList <Ingredient > ingredients , int duration , int spiritMaxAge , int summonNumber , @ Nullable ResourceLocation spiritJobType , @ Nullable EntityToSacrifice entityToSacrifice , @ Nullable Ingredient itemToUse , @ Nullable String command ) {
133
145
this .result = result ;
134
146
this .ingredients = ingredients ;
135
147
this .entityToSummon = entityToSummon ;
148
+ this .entityTagToSummon = entityTagToSummon ;
136
149
this .entityNbt = entityNbt ;
137
150
this .pentacleId = pentacleId ;
138
151
this .ritualType = ritualType ;
@@ -154,11 +167,11 @@ public boolean isSpecial() {
154
167
return true ;
155
168
}
156
169
157
- public String getCommand () {
170
+ public @ Nullable String getCommand () {
158
171
return this .command ;
159
172
}
160
173
161
- public CompoundTag getEntityNbt () {
174
+ public @ Nullable CompoundTag getEntityNbt () {
162
175
return this .entityNbt ;
163
176
}
164
177
@@ -187,20 +200,20 @@ public float getDurationPerIngredient() {
187
200
}
188
201
189
202
@ Override
190
- public RecipeSerializer <?> getSerializer () {
203
+ public @ NotNull RecipeSerializer <?> getSerializer () {
191
204
return SERIALIZER ;
192
205
}
193
206
194
207
@ Override
195
- public boolean matches (SingleRecipeInput pInv , Level pLevel ) {
208
+ public boolean matches (@ NotNull SingleRecipeInput pInv , @ NotNull Level pLevel ) {
196
209
return false ;
197
210
}
198
211
199
212
200
213
@ Override
201
- public ItemStack assemble (SingleRecipeInput pCraftingContainer , HolderLookup .Provider pRegistries ) {
214
+ public @ NotNull ItemStack assemble (@ NotNull SingleRecipeInput pCraftingContainer , HolderLookup .@ NotNull Provider pRegistries ) {
202
215
//as we don't have an inventory this is ignored.
203
- return null ;
216
+ return ItemStack . EMPTY ;
204
217
}
205
218
206
219
@@ -210,12 +223,12 @@ public boolean canCraftInDimensions(int i, int i1) {
210
223
}
211
224
212
225
@ Override
213
- public ItemStack getResultItem (HolderLookup .Provider pRegistries ) {
226
+ public @ NotNull ItemStack getResultItem (HolderLookup .@ NotNull Provider pRegistries ) {
214
227
return this .result ;
215
228
}
216
229
217
230
@ Override
218
- public NonNullList <Ingredient > getIngredients () {
231
+ public @ NotNull NonNullList <Ingredient > getIngredients () {
219
232
return this .ingredients ;
220
233
}
221
234
@@ -232,7 +245,7 @@ public boolean matches(Level level, BlockPos goldenBowlPosition, ItemStack activ
232
245
}
233
246
234
247
@ Override
235
- public RecipeType <?> getType () {
248
+ public @ NotNull RecipeType <?> getType () {
236
249
return OccultismRecipes .RITUAL_TYPE .get ();
237
250
}
238
251
@@ -244,18 +257,22 @@ public boolean requiresSacrifice() {
244
257
return this .entityToSacrifice != null ;
245
258
}
246
259
247
- public Ingredient getItemToUse () {
260
+ public @ Nullable Ingredient getItemToUse () {
248
261
return this .itemToUse ;
249
262
}
250
263
251
264
public boolean requiresItemUse () {
252
265
return this .itemToUse != Ingredient .EMPTY ;
253
266
}
254
267
255
- public EntityType <?> getEntityToSummon () {
268
+ public @ Nullable EntityType <?> getEntityToSummon () {
256
269
return this .entityToSummon ;
257
270
}
258
271
272
+ public @ Nullable TagKey <EntityType <?>> getEntityTagToSummon () {
273
+ return this .entityTagToSummon ;
274
+ }
275
+
259
276
public ResourceLocation getRitualType () {
260
277
return this .ritualType ;
261
278
}
@@ -268,7 +285,7 @@ public String getEntityToSacrificeDisplayName() {
268
285
return this .entityToSacrifice != null ? this .entityToSacrifice .displayName () : "" ;
269
286
}
270
287
271
- public ResourceLocation getSpiritJobType () {
288
+ public @ Nullable ResourceLocation getSpiritJobType () {
272
289
return this .spiritJobType ;
273
290
}
274
291
@@ -298,12 +315,12 @@ public record EntityToSacrifice(TagKey<EntityType<?>> tag, String displayName) {
298
315
public static class Serializer implements RecipeSerializer <RitualRecipe > {
299
316
300
317
@ Override
301
- public MapCodec <RitualRecipe > codec () {
318
+ public @ NotNull MapCodec <RitualRecipe > codec () {
302
319
return CODEC ;
303
320
}
304
321
305
322
@ Override
306
- public StreamCodec <RegistryFriendlyByteBuf , RitualRecipe > streamCodec () {
323
+ public @ NotNull StreamCodec <RegistryFriendlyByteBuf , RitualRecipe > streamCodec () {
307
324
return STREAM_CODEC ;
308
325
}
309
326
}
0 commit comments