77import falseresync .vivatech .compat .anshar .AnsharCompat ;
88import net .minecraft .block .Blocks ;
99import net .minecraft .block .pattern .CachedBlockPosition ;
10- import net .minecraft .client .network .ClientPlayerEntity ;
1110import net .minecraft .component .DataComponentTypes ;
1211import net .minecraft .entity .EquipmentSlot ;
1312import net .minecraft .entity .player .PlayerEntity ;
@@ -64,19 +63,24 @@ public void focusOnUnequipped(ItemStack gadgetStack, ItemStack focusStack, Playe
6463
6564 @ Override
6665 public ActionResult focusUseOnBlock (ItemStack gadgetStack , ItemStack focusStack , ItemUsageContext context ) {
66+ var world = context .getWorld ();
67+ var player = context .getPlayer ();
68+ if (player == null ) {
69+ return ActionResult .PASS ;
70+ }
71+
6772 // Do not override lodestones
6873 var persistentAnchor = gadgetStack .get (VivatechComponents .WARP_FOCUS_PERSISTENT_ANCHOR );
6974 if (persistentAnchor != null && !focusStack .contains (VivatechComponents .WARP_FOCUS_BLOCK_ONLY_MODE )) {
70- if (context . getPlayer () instanceof ClientPlayerEntity player && player .isSneaking ()) {
75+ if (world . isClient && player .isSneaking ()) {
7176 reportPermanentlyBound (player , persistentAnchor );
7277 }
7378 return ActionResult .PASS ;
7479 }
7580
76- var world = context .getWorld ();
7781 var pos = context .getBlockPos ();
7882 if (focusStack .canPlaceOn (new CachedBlockPosition (world , pos , false ))) {
79- if (context . getPlayer () instanceof ServerPlayerEntity player && player .isSneaking ()) {
83+ if (! world . isClient && player .isSneaking ()) {
8084 if (!Vivatech .getChargeManager ().tryExpendGadgetCharge (gadgetStack , DEFAULT_PLACEMENT_COST * PERSISTENT_ANCHOR_COST_COEFFICIENT , player )) {
8185 Reports .insufficientCharge (player );
8286 return ActionResult .FAIL ;
@@ -91,7 +95,7 @@ public ActionResult focusUseOnBlock(ItemStack gadgetStack, ItemStack focusStack,
9195
9296 return ActionResult .CONSUME ;
9397 } else if (focusStack .contains (VivatechComponents .WARP_FOCUS_BLOCK_ONLY_MODE )) {
94- if (context . getPlayer () instanceof ClientPlayerEntity player ) {
98+ if (world . isClient ) {
9599 player .sendMessage (Text .translatable ("hud.vivatech.focus.comet_warp.cannot_anchor_here" ), true );
96100 }
97101 return ActionResult .FAIL ;
0 commit comments