0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[1.20.4]Spigot Pluginで「水ブロック」がクリックされたことを検知する

Posted at

結論

kotlin
    @EventHandler
    fun onPlayerInteract(event: PlayerInteractEvent) {
        if (event.action != Action.RIGHT_CLICK_AIR && event.action != Action.RIGHT_CLICK_BLOCK) return
        val block: Block? = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY)
        if (block != null && block.type == Material.WATER) {
            //ここに処理
        }
    }

詳細

ガラス瓶で水を汲んだことを検知しようとした際に発生。
PlayerInteractEvent.clickedBlock()では水が検知できない。

代替手段として、getTargetBlockExact()を使用。

用意された関数通りの使い方をしているので詳細はJavaDocに任せる

最大距離は4だと検知漏れがあった。

CauldronLevelChangeEventとかPlayerBucketEventとかはあるのにがPlayerGrassBottleFillEvent(仮称)がないのはなんで...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?