Skip to content

Commit e802fb5

Browse files
committed
fix #1
1 parent bddff54 commit e802fb5

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package io.github.lounode.eventwrapper.fabric.mixin.eventposter.entity.player.playerinteractevent;
22

3+
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
34
import net.minecraft.server.network.ServerGamePacketListenerImpl;
45
import net.minecraft.world.InteractionHand;
56
import net.minecraft.world.InteractionResult;
7+
import net.minecraft.world.entity.Entity;
8+
import net.minecraft.world.entity.player.Player;
69
import net.minecraft.world.phys.Vec3;
710

11+
import org.spongepowered.asm.mixin.Final;
812
import org.spongepowered.asm.mixin.Mixin;
913
import org.spongepowered.asm.mixin.Shadow;
1014
import org.spongepowered.asm.mixin.injection.At;
@@ -15,24 +19,28 @@
1519
import io.github.lounode.eventwrapper.fabric.EventWrapperHooks;
1620

1721
@Mixin(targets = "net.minecraft.server.network.ServerGamePacketListenerImpl$1")
18-
public abstract class PlayerInteractEventEntityInteractSpecificEventPoster {
22+
public abstract class PlayerInteractEventEntityInteractSpecificEventPoster implements ServerboundInteractPacket.Handler {
1923

2024
@Shadow
21-
protected abstract void performInteraction(InteractionHand hand, ServerGamePacketListenerImpl.EntityInteraction interaction);
25+
@Final
26+
private ServerGamePacketListenerImpl field_28963;
27+
28+
@Shadow
29+
@Final
30+
private Entity val$target;
2231

2332
@Inject(
2433
method = "onInteraction(Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/Vec3;)V",
2534
at = @At(value = "HEAD"),
2635
cancellable = true
2736
)
2837
private void onInteract(InteractionHand hand, Vec3 interactionLocation, CallbackInfo ci) {
29-
ci.cancel();
30-
this.performInteraction(hand, ((serverPlayer, entity, interactionHand) -> {
31-
InteractionResult result = EventWrapperHooks.onInteractEntityAt(serverPlayer, entity, interactionLocation, interactionHand);
32-
if (result != null) {
33-
return result;
34-
}
35-
return entity.interactAt(serverPlayer, interactionLocation, interactionHand);
36-
}));
38+
Player player = this.field_28963.getPlayer();
39+
40+
InteractionResult result = EventWrapperHooks.onInteractEntityAt(player, this.val$target, interactionLocation, hand);
41+
42+
if (result != null) {
43+
ci.cancel();
44+
}
3745
}
3846
}

0 commit comments

Comments
 (0)