1818package com .lambda .mixin .entity ;
1919
2020import com .lambda .event .EventFlow ;
21- import com .lambda .event .events .LocalPlayerEvent ;
21+ import com .lambda .event .events .PlayerEvent ;
2222import net .minecraft .client .MinecraftClient ;
2323import net .minecraft .client .network .ClientPlayerEntity ;
2424import net .minecraft .client .network .ClientPlayerInteractionManager ;
2828import net .minecraft .util .ActionResult ;
2929import net .minecraft .util .Hand ;
3030import net .minecraft .util .hit .BlockHitResult ;
31+ import net .minecraft .util .hit .EntityHitResult ;
3132import net .minecraft .util .math .BlockPos ;
3233import net .minecraft .util .math .Direction ;
3334import org .spongepowered .asm .mixin .Final ;
@@ -43,38 +44,55 @@ public class ClientPlayInteractionManagerMixin {
4344
4445 @ Shadow
4546 public float currentBreakingProgress ;
46- @ Final
47- @ Shadow
48- private MinecraftClient client ;
4947
50- @ Inject (method = "interactBlock" , at = @ At ("HEAD" ))
48+ @ Inject (method = "interactBlock" , at = @ At ("HEAD" ), cancellable = true )
5149 public void interactBlockHead (final ClientPlayerEntity player , final Hand hand , final BlockHitResult hitResult , final CallbackInfoReturnable <ActionResult > cir ) {
52- if (client .world == null ) return ;
53- EventFlow .post (new LocalPlayerEvent .BlockInteract (client .world , hitResult ));
50+ if (EventFlow .post (new PlayerEvent .Interact .Block (hand , hitResult )).isCanceled ()) {
51+ cir .setReturnValue (ActionResult .FAIL );
52+ }
5453 }
5554
56- @ Inject (method = "clickSlot" , at = @ At ("HEAD" ), cancellable = true )
57- public void clickSlotHead (int syncId , int slotId , int button , SlotActionType actionType , PlayerEntity player , CallbackInfo ci ) {
58- if (syncId != player .currentScreenHandler .syncId ) return ;
59- var click = new LocalPlayerEvent .SlotClick (syncId , slotId , button , actionType , player .currentScreenHandler );
60- if (EventFlow .post (click ).isCanceled ()) ci .cancel ();
55+ @ Inject (method = "interactEntityAtLocation" , at = @ At ("HEAD" ), cancellable = true )
56+ public void interactEntityAtLocation (PlayerEntity player , Entity entity , EntityHitResult hitResult , Hand hand , CallbackInfoReturnable <ActionResult > cir ) {
57+ if (EventFlow .post (new PlayerEvent .Interact .Entity (hand , entity , hitResult )).isCanceled ()) {
58+ cir .setReturnValue (ActionResult .FAIL );
59+ }
60+ }
61+
62+ @ Inject (method = "interactItem" , at = @ At ("HEAD" ), cancellable = true )
63+ public void interactItemHead (PlayerEntity player , Hand hand , CallbackInfoReturnable <ActionResult > cir ) {
64+ if (EventFlow .post (new PlayerEvent .Interact .Item (hand )).isCanceled ()) {
65+ cir .setReturnValue (ActionResult .FAIL );
66+ }
67+ }
68+
69+ @ Inject (method = "attackBlock" , at = @ At ("HEAD" ))
70+ public void onAttackBlock (BlockPos pos , Direction side , CallbackInfoReturnable <Boolean > cir ) {
71+ if (EventFlow .post (new PlayerEvent .Attack .Block (pos , side )).isCanceled ()) cir .cancel ();
6172 }
6273
6374 @ Inject (method = "attackEntity" , at = @ At ("HEAD" ), cancellable = true )
6475 void onAttackPre (PlayerEntity player , Entity target , CallbackInfo ci ) {
65- if (EventFlow .post (new LocalPlayerEvent . EntityAttack (target )).isCanceled ()) ci .cancel ();
76+ if (EventFlow .post (new PlayerEvent . Attack . Entity (target )).isCanceled ()) ci .cancel ();
6677 }
6778
68- @ Inject (method = "attackBlock" , at = @ At ("HEAD" ), cancellable = true )
69- public void onAttackBlock (BlockPos pos , Direction side , CallbackInfoReturnable <Boolean > cir ) {
70- if (EventFlow .post (new LocalPlayerEvent .BlockAttack (pos , side )).isCanceled ()) cir .cancel ();
79+ @ Inject (method = "clickSlot" , at = @ At ("HEAD" ), cancellable = true )
80+ public void clickSlotHead (int syncId , int slotId , int button , SlotActionType actionType , PlayerEntity player , CallbackInfo ci ) {
81+ if (syncId != player .currentScreenHandler .syncId ) return ;
82+ var click = new PlayerEvent .SlotClick (syncId , slotId , button , actionType , player .currentScreenHandler );
83+ if (EventFlow .post (click ).isCanceled ()) ci .cancel ();
7184 }
7285
7386 @ Inject (method = "updateBlockBreakingProgress" , at = @ At ("HEAD" ), cancellable = true )
7487 private void updateBlockBreakingProgressPre (BlockPos pos , Direction side , CallbackInfoReturnable <Boolean > cir ) {
75- var event = EventFlow .post (new LocalPlayerEvent . BreakingProgress (pos , side , currentBreakingProgress ));
76- if (event .isCanceled ()) cir .cancel ( );
88+ var event = EventFlow .post (new PlayerEvent . Breaking . Update (pos , side , currentBreakingProgress ));
89+ if (event .isCanceled ()) cir .setReturnValue ( false );
7790
7891 currentBreakingProgress = event .getProgress ();
7992 }
93+
94+ @ Inject (method = "cancelBlockBreaking" , at = @ At ("HEAD" ), cancellable = true )
95+ private void cancelBlockBreakingPre (CallbackInfo ci ) {
96+ if (EventFlow .post (new PlayerEvent .Breaking .Cancel (currentBreakingProgress )).isCanceled ()) ci .cancel ();
97+ }
8098}
0 commit comments