Code of Copper 扩展
此数据包为 Code of Copper 提供了一些额外的功能,旨在满足那些希望在创造模式下或作为管理员使用本语言的玩家的需求。
尽管该数据包由 Code of Copper 的一名开发者制作,但它属于非官方性质。虽然其中部分功能未来可能会合并到主项目(上游),但大部分功能不会。
要求
提供的函数
Exec
Exec 会执行以字符串形式给出的任何命令。它由机器人执行,位置位于机器人所在位置。
允许在同一函数中使用多个字符串。
exec("time set day") # 将时间设置为白天
exec("weather clear", "gamemode adventure @p") # 将天气设置为晴朗,并将最近的玩家 (@p) 设置为冒险模式
Tp
将选定的实体传送到指定的坐标。
坐标可以是整数,也可以是字符串。
如果未设置,默认为 "@s"。波浪号 ~ 相对于机器人位置。
tp(0, 64, 0) # 将机器人 (@s) 传送到 0, 64, 0
tp(0, 64, 0, "@a") # 将所有玩家 (@a) 传送到 0, 64, 0
tp("~", "~8", "~", "@p") # 将最近的玩家传送到机器人上方 8 格处
tp("~", 100, "~", "@p") # 将最近的玩家传送到 Y 轴 100 的高度,位于机器人上方
Setblock
place() 的替代方案,不需要物品栏中有方块。
坐标可以是整数,也可以是字符串。波浪号 ~ 相对于机器人位置。
setblock(:stone, 0, 64, 0) # 在 0, 64, 0 处放置 minecraft:stone 方块
setblock(:grass_block, "~", "~8", "~") # 在机器人上方 8 格处放置 minecraft:grass_block 方块
Score
返回选定实体的分数,结果为整数。如果未设置,默认为 "@p"。
score("myscoreboard") # 返回 @p 在记分板 myscoreboard 上的分数
score("myotherscoreboard", "Moxvallix") # 返回 Moxvallix 在记分板 myotherscoreboard 上的分数
Scoreset
将选定实体的分数设置为给定的整数值。如果未设置,默认为 "@p"。
返回设置的分数值。
scoreset("myscoreboard", 8) # 将 @p 在记分板 myscoreboard 上的分数设置为 8
scoreset("myotherscoreboard", 123, "Gears_YT") # 将 Gears_YT 在记分板 myotherscoreboard 上的分数设置为 123
Rule
返回指定游戏规则的整数值。
如果提供了第二个参数,则将该游戏规则设置为相应值。
第二个参数接受字符串、整数或布尔值。
rule("keepInventory") # 返回游戏规则 keepInventory 的值(假为 0,真为 1)
rule("doFireTick", false) # 将游戏规则 doFireTick 设置为 false,返回 0
rule("randomTickSpeed", 5) # 将游戏规则 randomTickSpeed 设置为 5,返回 5
Run
运行以资源形式给出的函数,并返回该函数的返回值。
run(:foo) # 运行函数 minecraft:foo,并返回其返回值
run(code:bar) # 运行函数 code:bar,并返回其返回值
Code of Copper Extensions
This pack provides a couple additional functions to Code of Copper, aimed at providing functionality for those who would
prefer to use the language in creative mode, or as an operator.
Whilst made by one of the developers of Code of Copper, this pack is unofficial. While some functionality
provided by this pack may one day make it upstream, much of it will not.
Requirements
- This datapack will only work in versions 1.20.2 and higher
- This datapack will not work without Code of Copper
Provided Functions
Exec
Exec will run any command given to it, in a string. It runs as the bot, positioned at the bot.
It allows multiple strings in the same function.
exec("time set day") # Set time to day
exec("weather clear", "gamemode adventure @p") # Set weather to clear, and @p to adventure mode
Tp
Teleports the selected entity to the given coordinates.
Coordinates can be an integer, or a string.
Defaults to "@s" if unset. Tilde ~ is relative to the bot.
tp(0, 64, 0) # Teleport bot (@s) to 0, 64, 0
tp(0, 64, 0, "@a") # Teleport all players (@a) to 0, 64, 0
tp("~", "~8", "~", "@p") # Teleport nearest player 8 blocks above the bot
tp("~", 100, "~", "@p") # Teleport nearest player to Y 100, above the bot
Setblock
Alternative to place(), doesn't require blocks in inventory.
Coordinates can be an integer, or a string. Tilde ~ is relative to the bot.
setblock(:stone, 0, 64, 0) # Sets the block minecraft:stone at 0, 64, 0
setblock(:grass_block, "~", "~8", "~") # Sets the block minecraft:grass_block 8 blocks above the bot
Score
Returns the score of the selected entity, as an integer. Defaults to "@p" if unset.
score("myscoreboard") # Returns the score of @p, fo scoreboard myscoreboard
score("myotherscoreboard", "Moxvallix") # Returns the score of Moxvallix, for scoreboard myotherscoreboard
Scoreset
Sets the score of the selected entity, from a given integer. Defaults to "@p" if unset.
Returns the score set.
scoreset("myscoreboard", 8) # Sets @p to a score of 8 on scoreboard myscoreboard
scoreset("myotherscoreboard", 123, "Gears_YT") # Sets Gears_YT to a score of 123 on scoreboard myotherscoreboard
Rule
Returns the value of the given gamerule as an integer.
If a value is given as a second argument, it sets the gamerule as such.
Accepts either a string, integer or boolean as second value.
rule("keepInventory") # Returns the value of gamerule keepInventory (0 if false, 1 if true)
rule("doFireTick", false) # Sets the gamerule doFireTick to false, returns 0
rule("randomTickSpeed", 5) # Sets the gamerule randomTickSpeed to 5, returns 5
Run
Runs a function given as a resource, and returns the value the function returns.
run(:foo) # Runs function minecraft:foo, returning what the function returns
run(code:bar) # Runs function code:bar, returning what the function returns
评论 0
登录后参与评分
还没有评论,来抢沙发吧