diff --git a/gradle.properties b/gradle.properties index 488c519..62675d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ translations4j_version=2.11.0 # subproject versions kibu-fabric-hooks-version=0.5.1 -kibu-hooks-version=0.55.0 +kibu-hooks-version=0.56.0 kibu-command-api-version=0.9.0 kibu-scheduler-api-version=0.9.0 kibu-hook-api-version=1.4.0 diff --git a/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/KibuHooks.java b/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/KibuHooks.java index a4cb97a..2380840 100644 --- a/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/KibuHooks.java +++ b/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/KibuHooks.java @@ -18,6 +18,9 @@ import org.jetbrains.annotations.Nullable; import work.lclpnet.kibu.hook.player.PlayerDeathCallback; import work.lclpnet.kibu.hook.player.PlayerInventoryHooks; +import work.lclpnet.kibu.hook.player.PlayerJumpCallback; +import work.lclpnet.kibu.hook.player.PlayerMoveCallback; +import work.lclpnet.kibu.hook.util.OnGroundDetector; import work.lclpnet.kibu.hook.util.PlayerUtils; import work.lclpnet.kibu.hook.world.BlockModificationHooks; @@ -69,6 +72,12 @@ public void onInitialize() { PlayerInventoryHooks.DROPPED_ITEM.invoker().onDroppedItem(event.player(), event.slot()); }); + + PlayerMoveCallback.HOOK.register((player, from, to) -> player.getPlayerInput().jump() + && to.getY() > from.getY() + && player.isOnGround() + && OnGroundDetector.isOnGroundServer(player) + && PlayerJumpCallback.HOOK.invoker().onJump(player)); } @NotNull diff --git a/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/player/PlayerJumpCallback.java b/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/player/PlayerJumpCallback.java new file mode 100644 index 0000000..78bc67c --- /dev/null +++ b/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/player/PlayerJumpCallback.java @@ -0,0 +1,22 @@ +package work.lclpnet.kibu.hook.player; + +import net.minecraft.server.network.ServerPlayerEntity; +import work.lclpnet.kibu.hook.Hook; +import work.lclpnet.kibu.hook.HookFactory; + +public interface PlayerJumpCallback { + + Hook HOOK = HookFactory.createArrayBacked(PlayerJumpCallback.class, callbacks -> (player) -> { + boolean cancel = false; + + for (var cb : callbacks) { + if (cb.onJump(player)) { + cancel = true; + } + } + + return cancel; + }); + + boolean onJump(ServerPlayerEntity player); +} diff --git a/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/util/OnGroundDetector.java b/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/util/OnGroundDetector.java new file mode 100644 index 0000000..4886250 --- /dev/null +++ b/kibu-hooks/src/main/java/work/lclpnet/kibu/hook/util/OnGroundDetector.java @@ -0,0 +1,18 @@ +package work.lclpnet.kibu.hook.util; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.Box; + +public class OnGroundDetector { + + public static boolean isOnGroundServer(ServerPlayerEntity player) { + return isOnGroundServer(player, 0.02); + } + + public static boolean isOnGroundServer(ServerPlayerEntity player, double tol) { + double y = player.getY(); + Box box = player.getBoundingBox().withMinY(y - tol).withMaxY(y + 1e-5); + + return player.getWorld().getBlockCollisions(player, box).iterator().hasNext(); + } +} diff --git a/src/testmod/java/work/lclpnet/test/KibuTestMod.java b/src/testmod/java/work/lclpnet/test/KibuTestMod.java index 93fa227..5c3f5e7 100644 --- a/src/testmod/java/work/lclpnet/test/KibuTestMod.java +++ b/src/testmod/java/work/lclpnet/test/KibuTestMod.java @@ -21,6 +21,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; import net.minecraft.util.ActionResult; import net.minecraft.util.DyeColor; import net.minecraft.util.Hand; @@ -331,8 +333,17 @@ private void misc() { PlayerInputCallback.HOOK.register((player, input) -> { if (player.getMainHandStack().isOf(Items.FEATHER)) { - System.out.println("JUMP"); + System.out.println("input " + input); } }); + + PlayerJumpCallback.HOOK.register(player -> { + if (player.getMainHandStack().isOf(Items.FEATHER)) { + player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_PLING.value(), SoundCategory.MASTER, 0.2f, 1f); + return player.getOffHandStack().isOf(STICK); + } + + return false; + }); } }