使 Minecraft 模组能够控制某些原版特性的数据包制作
功能
本模组为游戏添加了命令,以揭示数据包的一些特性。
根命令是 /deltatime:
-
tickdelta -> 上一刻的持续时间(微秒)
-
tickstoadd -> 要添加到计数器的数值,该计数器不会受到延迟的影响(有关如何有效使用它的更多信息见下文)
-
setitemcooldown <目标(玩家)> <物品> <持续时间(以刻为单位)> → 使指定类型的物品无法被玩家使用,并在玩家身上显示冷却动画(类似于使用末影珍珠后的效果)。
-
setability <目标(玩家)> <玩家能力> <值:布尔值|浮点数> → 基本上会更改玩家能力的 NBT 值。具体效果请参见下文。
-
setproperty <目标(玩家)> <属性> -> 基本上会更改玩家该属性的 NBT 值。有关可用属性列表,请阅读下文
如何使用 /deltatime tickstoadd
示例:
execute store result score tickstoadd objective run deltatime tickstoadd
scoreboard players operation untilactionprevious objective = untilaction objective
scoreboard players operation untilaction objective -= tickstoadd objective
execute if score untilaction objective matches ..0 unless score untilactionp objective matches ..0 run function my:action
在此示例中,我们尝试在 untilaction objective 经过一定刻数后运行“function my:action”。为了使计时独立于服务器性能,如果服务器卡顿,我们需要向计数器添加更多的刻数。这意味着计数器有可能跳过 0。为了防止操作未执行,我们需要另一个变量来记录在添加(或减去)tickstoadd 之前的刻数。然后,我们需要检查先前的计数是否大于 0,而当前计数是否等于或少于 0。
(请注意,如果在计数器计数过程中将计数值设置为更低/更高(根据计数方向)的值,并且您不更改之前的计数,它将执行之前值和当前值之间的所有操作。)
玩家能力
- flying(飞行)
- 布尔值
- true:无论任何情况,使玩家处于飞行状态。如果玩家离地面较近,玩家可能会立即切换回非飞行状态。
- false:无论任何情况,使玩家停止飞行。如果玩家处于旁观者模式,玩家可能会立即切换回飞行状态。
- instabuild(即时建造)
- 布尔值
- true:
- 生存/冒险模式:玩家可以像在创造模式中一样拾取方块(不适用于冒险模式),但物品实际上与服务器不同步,因此玩家无法放置它。然而,如果玩家已经持有某物品,该物品在使用时不会消耗(这不适用于不死图腾、刷怪蛋,也可能不适用于其他一些物品)。
- false:
- 创造模式:玩家无法拾取方块,并且会像生存模式那样消耗部分物品(食物会消耗,桶的使用方式如同生存模式,工具可能会损坏——放置方块时不会消耗方块)。
- invulnerable(无敌)
- 布尔值
- true:
- 按预期工作——玩家无法被击中,也不会受到伤害,除了 out_of_world 和 generic_kill。
- mayBuild(允许建造)
- 布尔值
- true:
- 生存/创造模式:这些模式的默认值。
- 旁观者模式:无效果。
- 冒险模式:使玩家能够放置矿车、将音乐唱片放入唱片机中(唱片会立即弹出,即使破坏唱片机,音乐仍会继续播放)、从唱片机中取出音乐唱片、将书放入讲台、以两级为单位改变红石比较器的持续时间、熄灭并点燃营火,可能还有其他功能。
- false:
- 冒险/旁观者模式:这些模式的默认值。
- 创造/生存模式:使玩家放置的方块立即消失,如果 instabuild 为 false,方块也会消耗,但仅客户端可见。使玩家无法放置盔甲架*、放置矿车*、将唱片放入唱片机、改变阳光传感器的状态、在讲台中放入或取出书籍、改变比较器**、中继器和红石的状态、熄灭*并点燃** * 营火。
- * 在客户端消耗物品。
- ** 更改在客户端短暂可见。
- mayfly(允许飞行)
- 布尔值
- true:使玩家能够在双击跳跃键时切换飞行状态(旁观者模式除外)。玩家还对坠落伤害免疫。
- false:禁用双击跳跃键时切换飞行状态的能力。
- flySpeed(飞行速度)
- 浮点值
- 改变玩家飞行时的速度(此值在更换游戏模式、死亡或重新连接时不会改变)。
- walkSpeed(行走速度)
- 浮点值
- 改变玩家的视野角度(如果开启了 fov 效果),并在玩家重新连接时改变行走/疾跑速度(此值在更换游戏模式、死亡或重新连接时不会改变)。
(请注意,这些值在重新连接或切换游戏模式后会发生变化(除非它们不受影响))
玩家属性
- health
- foodExhaustionLevel
- foodSaturationLevel
- foodLevel
其他说明
- tickdelta 子命令还包括等待下一次刻的时间
- tickstoadd 子命令也考虑了波动的 tickdelta,因为它并不总是精确的 50 毫秒;它会每次刻将 tickdelta 的值累加到一个变量中,然后从该变量中减去每次刻所需的时间,直到该变量低于此次刻所需时间为止,并统计减去的次数——这个减法计数即为返回值
如果您在更改这些值时发现任何未记录的异常行为,请提交问题报告,以便我将其记录下来。
Minecraft mod making datapacks able to take control of some vanilla features
Features
this mod adds commands to the game, which uncover some features to datapacks
the root command is /deltatime
- tickdelta -> previous tick duration in microseconds
- tickstoadd -> number to add to a counter, which you don't want to be affected by lags (more info below on how to use it effectively)
- setitemcooldown <targets (players)> <item> <duration (in ticks)> -> makes an item of that kind not be usable by the player and displays a cooldown animation on them (just like after the use of enderpearls)
- setability <targets (players)> <player ability> <value: Boolean|Float> -> basically changes the NBT value of abilities of the player. For actual effects read below
- setproperty <targets (players)> <property> -> basically changes the NBT value of the property on the player. For a list of available properties, read below
How to use /deltatime tickstoadd
example:
execute store result score tickstoadd objective run deltatime tickstoadd
scoreboard players operation untilactionprevious objective = untilaction objective
scoreboard players operation untilaction objective -= tickstoadd objective
execute if score untilaction objective matches ..0 unless score untilactionp objective matches ..0 run function my:action
In this example, we are trying to run "function my:action" after "untilaction objective" ticks run. If we want to make it independant of server performance, we need to add a larger number of ticks to the counter, if the server lags. This means that there is a possibility that the counter jumps over the 0. In order to prevent the action from not executing, we need to have another variable, which tells us the tickcount before the tickstoadd get added (subtracted). Then we need to check if the previous count is higher than 0 and the current count is exactly or less than 0.
(note that if you set the counter to a lower/higher (according to the direction of counting) value while the counter is counting and you won't also change the previous count, it will execute everything in between the previous and current value)
Player abilities
- flying
- boolean value
- true: makes the player fly regardless of anything. If the player is low to the ground, the player may instantly switch back to not flying
- false: makes the player stop flying regardless of anything. If the player is in spectator mode, the player may instantly switch back to flying.
- instabuild
- boolean value
- true:
- Survival/adventure mode: player can pick block like in creative mode (doesn't apply to adventure mode) but the item is actually desynced from server and so the player can't place it. If the player already has an item however, the item doesn't deplete if it's used (this doesn't apply to totems of undying, spawn eggs and may also not apply to some other items)
- false:
- Creative mode: player can't pick block and depletes some items just like in survival (food depletes, buckets work like in survival and tools may break - blocks don't deplete when placed)
- invulnerable
- boolean value
- true:
- works as expected - player can't be hit and doesn't take damage other than out_of_world and generic_kill
- mayBuild
- boolean value
- true:
- Survival/creative mode: default value for these modes
- Spectator mode: no effect
- Adventure mode: makes the player able to place minecarts, place music discs into jukeboxes (they immediately pop out and the music remains playing even after breaking the jukebox), take music discs out of jukeboxes, put books into lecterns, change the duration of repeaters by two levels, put out and light up campfires and maybe more
- false:
- Adventure/spectator mode: default value for these modes
- Creative/survival mode: makes the player's placed blocks immediately disappear and if instabuild is false, blocks will also deplete but only client-side. Makes players not able to place armor stands*, place minecarts*, put discs into jukeboxes, change the state of daylight sensors, put and take out books from a lectern, change comparators**, repeaters** and redstone** states, put out* and light up** * a campfire
- * consumes the item client-side
- ** changes are visible client-side for a short while
- mayfly
- boolean value
- true: makes the player able to change their flying state when double-pressing the jump key (except spectator mode). The player is also immune to fall damage
- false: disables the ability to change flying state when double-pressing the jump key
- flySpeed
- float value
- changes the speed of the player when flying (this value doesn't change when changing gamemodes, getting killed or reconnecting)
- walkSpeed
- float value
- changes the fov of the player (if they have fov effects turned on) and changes the walking/sprinting speed of the player when the player reconnects (this value doesn't change when changing gamemodes, getting killed or reconnecting)
(note that these values change after reconnect or changing gamemodes (except those that don't))
Player properties
- health
- float value
- it is automatically clamped to the valid values
- foodExhaustionLevel
- foodSaturationLevel
- foodLevel
Additional notes
- tickdelta subcommand also includes the time waiting for next tick
- tickstoadd subcommand also accounts for fluctuating tickdelta as it isn't always perfect 50 ms by adding its value to another variable every tick and subtracting the time per tick from the variable until it is lower than it and counting how many times it subtracted it - the subtraction count is the return value
Please make an issue report if you find any undocumented unusual behaviour when changing the values, so I can document them.
评论 0
登录后参与评分
还没有评论,来抢沙发吧