@@ -192,10 +192,10 @@ public void onInitialize() {
192
192
return Command .SINGLE_SUCCESS ;
193
193
}))));
194
194
ServerPlayNetworking .registerGlobalReceiver (GRANT_BLOCKED_ACTION_PACKET_ID , (server , player , handler , buf , responseSender ) -> {
195
- BlockedActionType action = buf .readEnumConstant (BlockedActionType .class );
195
+ BlockedActionType blockedAction = buf .readEnumConstant (BlockedActionType .class );
196
196
boolean isDemystifyOnly = buf .readBoolean ();
197
- if (action != null ) {
198
- server .execute (() -> grantBlockedAction (player , action , isDemystifyOnly ));
197
+ if (blockedAction != null ) {
198
+ server .execute (() -> grantBlockedAction (player , blockedAction , isDemystifyOnly ));
199
199
}
200
200
});
201
201
AttackBlockCallback .EVENT .register ((player , world , hand , pos , direction ) -> {
@@ -216,7 +216,7 @@ public void onInitialize() {
216
216
UseBlockCallback .EVENT .register ((player , world , hand , hitResult ) -> {
217
217
BlockState block = world .getBlockState (hitResult .getBlockPos ());
218
218
ItemStack stack = player .getStackInHand (hand );
219
- if (isBlockBlocked (player , block . getBlock () )) {
219
+ if (isBlockBlocked (player , block )) {
220
220
return ActionResult .FAIL ;
221
221
}
222
222
if (isToolBlocked (player , stack )) {
@@ -273,43 +273,20 @@ public static void grantHintsAdvancement(ServerPlayerEntity player, String pathN
273
273
}
274
274
}
275
275
276
- private boolean isItemBlocked (PlayerEntity player , ItemStack stack ) {
277
- if (isFoodBlocked (player , stack .getItem ().getFoodComponent ())) {
278
- return true ;
279
- }
280
- if (isEquipmentBlocked (player , stack )) {
281
- return true ;
282
- }
283
- if (stack .isOf (Items .SHIELD ) && isActionBlocked (player , BlockedActionType .USING_SHIELD )) {
284
- return true ;
285
- }
286
- if (stack .isOf (Items .BOW ) && isActionBlocked (player , BlockedActionType .USING_BOW )) {
287
- return true ;
288
- }
289
- if (stack .isOf (Items .FIREWORK_ROCKET ) && player .isFallFlying () && isActionBlocked (player , BlockedActionType .USING_FIREWORKS_WHILE_FLY )) {
290
- return true ;
291
- }
292
- if (stack .isOf (Items .SPYGLASS ) && player .getWorld ().isClient ) {
293
- SpyglassPanoramaDetails panoramaDetails = SpyglassPanoramaDetails .of (stack );
294
- return panoramaDetails != null && !panoramaDetails .isPanoramaReady ();
295
- }
296
- return false ;
297
- }
298
-
299
- public static boolean isActionBlocked (PlayerEntity player , BlockedActionType action ) {
300
- return isActionBlocked (player , action , false );
276
+ public static boolean isActionBlocked (PlayerEntity player , BlockedActionType blockedAction ) {
277
+ return isActionBlocked (player , blockedAction , false );
301
278
}
302
279
303
- public static boolean isActionBlocked (PlayerEntity player , BlockedActionType action , boolean isCheckOnly ) {
304
- if (action == null || player == null || player .isCreative () || action .isUnblocked (player )) {
280
+ public static boolean isActionBlocked (PlayerEntity player , BlockedActionType blockedAction , boolean isCheckOnly ) {
281
+ if (blockedAction == null || player == null || player .isCreative () || blockedAction .isUnblocked (player )) {
305
282
return false ;
306
283
}
307
284
if (!isCheckOnly ) {
308
- player .sendMessage (action .buildBlockedDescription (player ), true );
285
+ player .sendMessage (blockedAction .buildBlockedDescription (player ), true );
309
286
if (player .getWorld ().isClient ) {
310
- ClientPlayNetworking .send (GRANT_BLOCKED_ACTION_PACKET_ID , PacketByteBufs .create ().writeEnumConstant (action ).writeBoolean (true ));
287
+ ClientPlayNetworking .send (GRANT_BLOCKED_ACTION_PACKET_ID , PacketByteBufs .create ().writeEnumConstant (blockedAction ).writeBoolean (true ));
311
288
} else if (player instanceof ServerPlayerEntity serverPlayer ) {
312
- grantBlockedAction (serverPlayer , action , true );
289
+ grantBlockedAction (serverPlayer , blockedAction , true );
313
290
}
314
291
}
315
292
return true ;
@@ -319,20 +296,43 @@ public static boolean isFoodBlocked(PlayerEntity player, FoodComponent food) {
319
296
if (food == null ) {
320
297
return false ;
321
298
}
322
- BlockedActionType action = BlockedActionType .findBlockedFood (food );
323
- if (action != null ) {
324
- return isActionBlocked (player , action );
299
+ BlockedActionType blockedAction = BlockedActionType .findBlockedFood (food );
300
+ if (blockedAction != null ) {
301
+ return isActionBlocked (player , blockedAction );
302
+ }
303
+ return false ;
304
+ }
305
+
306
+ private boolean isItemBlocked (PlayerEntity player , ItemStack stack ) {
307
+ if (stack == null ) {
308
+ return false ;
309
+ }
310
+ if (stack .isOf (Items .SPYGLASS ) && player .getWorld ().isClient ) {
311
+ SpyglassPanoramaDetails panoramaDetails = SpyglassPanoramaDetails .of (stack );
312
+ if (panoramaDetails != null ) {
313
+ return !panoramaDetails .isPanoramaReady ();
314
+ }
315
+ }
316
+ if (isFoodBlocked (player , stack .getItem ().getFoodComponent ())) {
317
+ return true ;
318
+ }
319
+ if (isEquipmentBlocked (player , stack )) {
320
+ return true ;
321
+ }
322
+ BlockedActionType blockedAction = BlockedActionType .findBlockedItem (player , stack );
323
+ if (blockedAction != null ) {
324
+ return isActionBlocked (player , blockedAction );
325
325
}
326
326
return false ;
327
327
}
328
328
329
- public static boolean isBlockBlocked (PlayerEntity player , Block block ) {
330
- if (block == null ) {
329
+ public static boolean isBlockBlocked (PlayerEntity player , BlockState blockState ) {
330
+ if (blockState == null ) {
331
331
return false ;
332
332
}
333
- BlockedActionType action = BlockedActionType .findBlockedBlock (block );
334
- if (action != null ) {
335
- return isActionBlocked (player , action );
333
+ BlockedActionType blockedAction = BlockedActionType .findBlockedBlock (blockState );
334
+ if (blockedAction != null ) {
335
+ return isActionBlocked (player , blockedAction );
336
336
}
337
337
return false ;
338
338
}
@@ -341,9 +341,9 @@ private boolean isToolBlocked(PlayerEntity player, ItemStack stack) {
341
341
if (stack == null ) {
342
342
return false ;
343
343
}
344
- BlockedActionType action = BlockedActionType .findBlockedTool (stack .getItem ());
345
- if (action != null ) {
346
- return isActionBlocked (player , action );
344
+ BlockedActionType blockedAction = BlockedActionType .findBlockedTool (stack .getItem ());
345
+ if (blockedAction != null ) {
346
+ return isActionBlocked (player , blockedAction );
347
347
}
348
348
return false ;
349
349
}
@@ -352,9 +352,9 @@ public static boolean isEquipmentBlocked(PlayerEntity player, ItemStack stack) {
352
352
if (stack == null ) {
353
353
return false ;
354
354
}
355
- BlockedActionType action = BlockedActionType .findBlockedEquipment (stack .getItem ());
356
- if (action != null ) {
357
- return isActionBlocked (player , action );
355
+ BlockedActionType blockedAction = BlockedActionType .findBlockedEquipment (stack .getItem ());
356
+ if (blockedAction != null ) {
357
+ return isActionBlocked (player , blockedAction );
358
358
}
359
359
return false ;
360
360
}
@@ -363,9 +363,9 @@ public static boolean isDimensionBlocked(PlayerEntity player, RegistryKey<World>
363
363
if (dimension == null ) {
364
364
return false ;
365
365
}
366
- BlockedActionType action = BlockedActionType .findBlockedDimension (dimension );
367
- if (action != null ) {
368
- return isActionBlocked (player , action );
366
+ BlockedActionType blockedAction = BlockedActionType .findBlockedDimension (dimension );
367
+ if (blockedAction != null ) {
368
+ return isActionBlocked (player , blockedAction );
369
369
}
370
370
return false ;
371
371
}
@@ -374,9 +374,9 @@ private boolean isVillagerBlocked(PlayerEntity player, VillagerProfession profes
374
374
if (profession == null ) {
375
375
return false ;
376
376
}
377
- BlockedActionType action = BlockedActionType .findBlockedVillager (profession );
378
- if (action != null ) {
379
- return isActionBlocked (player , action );
377
+ BlockedActionType blockedAction = BlockedActionType .findBlockedVillager (profession );
378
+ if (blockedAction != null ) {
379
+ return isActionBlocked (player , blockedAction );
380
380
}
381
381
return false ;
382
382
}
@@ -390,20 +390,20 @@ public static void setAdvancementsCount(int count) {
390
390
int oldCount = advancementsCount ;
391
391
advancementsCount = count ;
392
392
if (oldCount != 0 ) {
393
- for (BlockedActionType action : BlockedActionType .values ()) {
394
- if (advancementsCount >= action .getUnblockAdvancementsCount () && oldCount < action .getUnblockAdvancementsCount ()) {
395
- ClientPlayNetworking .send (GRANT_BLOCKED_ACTION_PACKET_ID , PacketByteBufs .create ().writeEnumConstant (action ).writeBoolean (false ));
393
+ for (BlockedActionType blockedAction : BlockedActionType .values ()) {
394
+ if (advancementsCount >= blockedAction .getUnblockAdvancementsCount () && oldCount < blockedAction .getUnblockAdvancementsCount ()) {
395
+ ClientPlayNetworking .send (GRANT_BLOCKED_ACTION_PACKET_ID , PacketByteBufs .create ().writeEnumConstant (blockedAction ).writeBoolean (false ));
396
396
}
397
397
}
398
398
}
399
399
}
400
400
401
- private static void grantBlockedAction (ServerPlayerEntity player , BlockedActionType action , boolean isDemystifyOnly ) {
402
- AdvancementEntry advancement = player .server .getAdvancementLoader ().get (action .buildAdvancementId ());
401
+ private static void grantBlockedAction (ServerPlayerEntity player , BlockedActionType blockedAction , boolean isDemystifyOnly ) {
402
+ AdvancementEntry advancement = player .server .getAdvancementLoader ().get (blockedAction .buildAdvancementId ());
403
403
if (isDemystifyOnly ) {
404
404
player .getAdvancementTracker ().grantCriterion (
405
405
advancement ,
406
- AdvancementsGenerator .BLOCKED_ACTION_DEMYSTIFIED_CRITERION_PREFIX + action .getName ()
406
+ AdvancementsGenerator .BLOCKED_ACTION_DEMYSTIFIED_CRITERION_PREFIX + blockedAction .getName ()
407
407
);
408
408
} else {
409
409
for (String criterion : player .getAdvancementTracker ().getProgress (advancement ).getUnobtainedCriteria ()) {
0 commit comments