aa0307bb
问题拆分成四个小问题(第四个已解决)
①如何做“长按右键计时”以及检测“松开鼠标事件”?(似乎Bukkit不能检测空手右键?)
②已经查到破坏方块是breakNaturally(),但是怎样设置这种行为破坏的方块不掉落物品(其它行为正常掉落)?
③如何向玩家朝向抛出方块(关键是这个掉落沙的速度矢量该怎么给出)
④已经查到getLineOfSight()、 getTargetBlock(), getTargetBlockExact()...可以显示视野方块

天辉胡萝卜
1. Bukkit只是检测不到空手对空气右键,因为空手对空气右键客户端不会发包,对方块空手右键可以检测
2. https://wiki.vg/Protocol#Block_Break_Animation
用发包播放方块破损动画,并将该方块替换为空气
3. 重力方块都有实体形式,API:https://hub.spigotmc.org/javadoc ... bukkit.util.Vector-

aa0307bb
疾风暗影 发表于 2020-6-30 09:55
1. Bukkit只是检测不到空手对空气右键,因为空手对空气右键客户端不会发包,对方块空手右键可以检测
2. http ...

1.检测是用PlayerInteractEvent?
2.怎么做到检测“连续长按右键”?
3.getLocation()得到玩家的朝向后,怎么根据玩家朝向给出掉落沙的速度矢量?
4.Protocol没用过……

天辉胡萝卜
aa0307bb 发表于 2020-6-30 15:20
1.检测是用PlayerInteractEvent?
2.怎么做到检测“连续长按右键”?
3.getLocation()得到玩家的朝向后, ...

1. PlayerInteractEvent
2. 每tick检测事件有无触发(实际需要latch逻辑判断是否中途断开)
3. setVelocity接受的是vector,也就是向量,其xyz值代表了速度和方向
速度值:sqrt(x^2+y^2+z^2)
4. 请自行阅读protocolLib的文档库

aa0307bb
疾风暗影 发表于 2020-6-30 15:26
1. PlayerInteractEvent
2. 每tick检测事件有无触发(实际需要latch逻辑判断是否中途断开)
3. setVeloci ...

2.latch逻辑该如何实现?
3.谢谢提供思路,但是算完敲代码时误打误撞才发现
public Vector getDirection()
获取本位置所面向的方向的单位向量.

这是有API的 :)
4.
Block Break Animation
0–9 are the displayable destroy stages and each other number means that there is no animation on this coordinate.

Block break animations can still be applied on air; the animation will remain visible although there is no block being broken. However, if this is applied to a transparent block, odd graphical effects may happen, including water losing its transparency. (An effect similar to this can be seen in normal gameplay when breaking ice blocks)

If you need to display several break animations at the same time you have to give each of them a unique Entity ID. The entity ID does not need to correspond to an actual entity on the client. It is valid to use a randomly generated number.

Packet ID        State        Bound To        Field Name        Field Type        Notes
0x09        Play        Client        Entity ID        VarInt        Entity ID of the entity breaking the block
Location        Position        Block Position
Destroy Stage        Byte        0–9 to set it, any other value to remove it

文档这么大,我该从哪看 有了这些信息之后怎样写成代码

天辉胡萝卜
aa0307bb 发表于 2020-6-30 17:18
2.latch逻辑该如何实现?
3.谢谢提供思路,但是算完敲代码时误打误撞才发现

2. 第一次右键将uuid和location添加至列表,之后每一tick check此列表直至方块被敲下(对应Destroy Stage>9),最后从列表中删除记录
中间任一tick不满足则删除记录

4. 你看的是协议文档,我上面说的是protocolLib的文档
https://github.com/dmulloy2/ProtocolLib/

aa0307bb
疾风暗影 发表于 2020-6-30 15:26
1. PlayerInteractEvent
2. 每tick检测事件有无触发(实际需要latch逻辑判断是否中途断开)
3. setVeloci ...

遇到一个问题:
每tick检测事件有无触发

但是似乎并没有API能够让runTaskTimer每一刻去调用某个函数查看玩家是否按下右键或者触发了PlayerInteractEvent事件

天辉胡萝卜
aa0307bb 发表于 2020-7-2 02:52
遇到一个问题:

但是似乎并没有API能够让runTaskTimer每一刻去调用某个函数查看玩家是否按下右键或者触 ...

这就是为啥要用latch逻辑。。
也就是每一tick检查上一tick的列表

aa0307bb
疾风暗影 发表于 2020-7-2 02:55
这就是为啥要用latch逻辑。。
也就是每一tick检查上一tick的列表

这句话可以问出一堆问题
第一次右键将uuid和location添加至列表,之后每一tick check此列表直至方块被敲下(对应Destroy Stage>9),最后从列表中删除记录
中间任一tick不满足则删除记录


列表该放在PlayerInteractListener类里还是插件主类里?
“check此列表”具体是check什么?check这一个tick的location和uuid是否和上一个tick的一样?
如果我设定长按右键20个tick可以敲碎一个方块,也就是这个列表第一个tick要放入第一个uuid和location,第二个tick要放入第二个uuid和location……万一我在第三个tick松开了右键,难道给列表放入一个null?

害 有无例程 否则↑的奇葩问题停不下来...

天辉胡萝卜
本帖最后由 疾风暗影 于 2020-7-2 12:47 编辑
aa0307bb 发表于 2020-7-2 12:36
这句话可以问出一堆问题

观察mc中以下现象

找一颗高一点的树,树叶恰好跳起来能够着

对树叶按住鼠标左键,然后跳,会发现树叶会随着玩家挖掘逐渐出现裂缝,而实际上玩家只有跳起来才够着树叶,落地时是够不着的,也就是挖掘会有小中断

这就是典型的latch逻辑


1. 玩家右键->list中加入玩家id,挖掘方块位置,时间戳(getTimeInMillis) ,挖掘程度=0(创建latch)
2. 之后玩家右键方块事件:检测列表中有没有entry
若无,回步骤1
若有,(1) 比较位置,不同回步骤1
(2) 比较时间戳,超过某一个值,回步骤1
(3) 更新时间戳,更新挖掘程度,发新数据包

一直到方块被挖下

以及别再给我加分了,被当刷分就麻烦了