Skip to content

Commit

Permalink
add PlayerSwingHandHook
Browse files Browse the repository at this point in the history
  • Loading branch information
LCLPYT committed Sep 5, 2024
1 parent 755bd88 commit 780415b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mixin_extras_version=0.3.3

# subproject versions
kibu-fabric-hooks-version=0.5.1
kibu-hooks-version=0.52.0
kibu-hooks-version=0.53.0
kibu-command-api-version=0.9.0
kibu-scheduler-api-version=0.8.0
kibu-hook-api-version=1.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,15 @@ private static double clampVertical(double d) {
public void kibu$onTeleportConfirm(TeleportConfirmC2SPacket packet, CallbackInfo ci) {
PlayerTeleportedCallback.HOOK.invoker().onTeleported(player);
}

@Inject(
method = "onHandSwing",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V"
)
)
public void kibu$onHandSwing(HandSwingC2SPacket packet, CallbackInfo ci) {
PlayerSwingHandHook.HOOK.invoker().onSwingHand(player, packet.getHand());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package work.lclpnet.kibu.hook.player;

import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Hand;
import work.lclpnet.kibu.hook.Hook;
import work.lclpnet.kibu.hook.HookFactory;

/**
* Called when the player swings an arm.
*/
public interface PlayerSwingHandHook {

Hook<PlayerSwingHandHook> HOOK = HookFactory.createArrayBacked(PlayerSwingHandHook.class, callbacks -> (player, hand) -> {
for (var cb : callbacks) {
cb.onSwingHand(player, hand);
}
});

void onSwingHand(ServerPlayerEntity player, Hand hand);
}
5 changes: 5 additions & 0 deletions src/testmod/java/work/lclpnet/test/KibuTestMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void onInitialize() {
entityEditor();
preventBeyond300();
teleportWithBrick();
misc();
}

private void teleportWithBrick() {
Expand Down Expand Up @@ -304,4 +305,8 @@ private void preventWithStick() {
WorldPhysicsHooks.REPLACE_DISK_ENCHANTMENT.register((world, pos, entity, state)
-> entity instanceof ServerPlayerEntity player && player.getMainHandStack().isOf(STICK));
}

private void misc() {
PlayerSwingHandHook.HOOK.register((player, hand) -> System.out.println("player swings " + hand));
}
}

0 comments on commit 780415b

Please sign in to comment.