重力枪
一个 Minecraft 插件,重现了《半条命2》中的重力枪工具。右键鼠标可以用来抓取生物或方块,也可以将其放下。左键鼠标可以用来推动生物,或者如果物体被捕获,则发射它。
| 命令 |
权限 |
描述 |
| help |
|
显示此帮助信息 |
| reload |
gravity-gun.reload |
重新加载插件配置 |
| give [target] |
gravity-gun.give |
给自己或其他玩家发放重力枪 |
| fix [target] |
gravity-gun.fix |
修复因不幸玩家抓取而导致的玩家重力和碰撞问题 |
| debug place_all_rotation_blocks |
gravity-gun.debug |
放置那些在旋转90°时 BlockData 会发生变化的方块类型的样本 |
| debug place_all_falling_visual_blocks |
gravity-gun.debug |
放置可能具有实体渲染或空掉落模型的方块,用于检查掉落视觉效果 |
配置
所有设置都位于 config.yml 中。缺失的选项会从捆绑的默认值中添加,同时用户的文件保留所有现有值;该文件会在启动时和 /gg reload 时更新。
version - 配置文件格式版本。
debug - 启用关于手持方块显示和恢复方块的额外日志记录。
language - 插件消息和工具提示的语言代码(en_us, en_gb, ru_ru, uk_ua)。
item.gravity-gun.name - 重力枪物品的自定义名称;空值将回退到语言文件中的默认名称。
机制:
mechanics.grab.range - 抓取方块或实体的最大距离。
mechanics.grab.cooldown - 两次抓取尝试之间的最小延迟。
mechanics.pull.range - 拉取的最大距离。
mechanics.pull.force - 拉力的强度。
mechanics.hold.max-time - 释放前可以保持抓取物体的最长时间;0 禁用此限制。
mechanics.hold.display-interpolation-duration - 手持显示对象的传送插值持续时间(以刻为单位);0 禁用插值(有效范围:0-59,默认值:2)。
mechanics.hold.display-items.enabled - 将掉落的物品作为物品显示持有,并保持投射物在其原生实体模型上。
mechanics.hold.distance.min / mechanics.hold.distance.max / mechanics.hold.distance.step - 手持物体与玩家眼睛之间距离的最小值、最大值和步长。
mechanics.launch.power - 当手持物体通过左键鼠标或释放时发射所应用的发射速度。
mechanics.release.momentum.enabled - 在释放和发射时继承玩家的移动和相机转动动量。
mechanics.release.momentum.multiplier - 继承动量的强度。
mechanics.release.momentum.max-speed - 每刻添加的最大动量(以方块为单位)。
效果:
effects.enabled - 切换重力枪和方块撞击粒子效果。
限制:
limits.entities.allow-grab - 是否允许抓取实体。
limits.entities.allow-grab-players - 是否允许抓取玩家。
limits.entities.list-mode - 适用于 limits.entities.list 的模式:BLACKLIST(黑名单)、WHITELIST(白名单)或 DISABLED(禁用)。
limits.entities.list - 应用实体抓取列表的实体类型名称。
limits.blocks.allow-grab - 是否允许抓取方块。
limits.blocks.list-mode - 适用于 limits.blocks.list 的模式:BLACKLIST(黑名单)、WHITELIST(白名单)或 DISABLED(禁用)。
limits.blocks.list - 应用方块抓取列表的方块名称。
效果和释放动量
config.yml 中的 effects.enabled 选项控制重力枪的粒子效果,包括方块撞击粒子。释放动量可以通过 mechanics.release.momentum.multiplier 和 mechanics.release.momentum.max-speed 进行调整。
mechanics.hold.display-items.enabled 选项默认启用。掉落的物品作为物品显示持有,而投射物保留并移动其原生实体模型。掉落的物品和箭矢在持有期间或释放后半秒内无法拾取;随后会恢复其原始拾取状态。投射物沿玩家视角瞄准,并在释放时赋予至少配置的发射速度。左键鼠标向前发射捕获的投射物;即使手持投射物位于准星下方也能工作,因为手臂摆动事件被用作后备方案。在启动和重新加载时,插件会填充用户配置中缺失的配置选项,同时保留现有值。
手持的方块显示跟随玩家的准星,并随相机平滑旋转;释放时,旋转会 snap 到最近的90°角度,然后再放置方块。方向性方块和多方块结构根据从拾取开始玩家水平相机转动的角度进行旋转。门和床一起携带和放置。双箱子故意拆分:被抓取的半边变成单个箱子,地面上的剩余半边也变成单个箱子,同时保持其各自的库存不变。床由单个显示表示,即使在掉落过程中也是如此,栅栏和玻璃板在放置后更新其连接。掉落块模型为空的方块在掉落时使用同步的物品显示,而掉落块本身继续处理物理和放置。同步显示使用短时间的传送插值来平滑其运动。
/gg debug place_all_falling_visual_blocks 命令创建一个基岩测试平台,包含可能的具有实体渲染或空掉落模型的方块,包括床、箱子、告示牌、旗帜、头颅、潜影盒、装饰花盆和其他常见的方块实体。这是一个实用的测试集,而不是穷尽的保证;资源包和 Minecraft 客户端渲染可能会引入其他情况。
方块实体
当方块拥有真实的三维方块模型时,使用方块实体的方块会采用 BlockDisplay(方块展示框)。因此,熔炉、箱子、蜂箱、营火、书架、宝库、投掷器、发射器等类似方块在手持时仍保持其正常的方块外观。而视觉效果仅存在于方块实体渲染器中或方块模型为空的方块,则会显示其物品模型:包括箱子(含铜箱和末影箱)、床、告示牌与悬挂告示牌、旗帜、头颅、潜影盒、装饰陶罐、引导座以及铜傀儡雕像。墙上的告示牌、旗帜、头颅和悬挂告示牌则以其站立状态的物品形式显示。
内容与元数据,如箱子的库存、告示牌文字、旗帜图案、头颅皮肤、陶罐碎片、铜傀儡姿态以及自定义名称,会随手持方块一起保存,并在放置时恢复。仅由方块实体渲染器呈现的细节在手持方块时不可见:例如书架和营火中的物品、宝库动画、刷怪笼的动画部分等。铃铛在手持及掉落时使用其方块模型而非平面的物品图标;其方块实体摆动动画未被还原。
重力枪仅拦截实际的左键和右键点击。物理交互(如在探测方块上行走)将被忽略,因此既不会取消也不会伴随抓取音效。在 config.yml 中设置 debug: true 可记录有关手持方块展示框和还原后的方块实体的额外详细信息。
针对资源包
对于资源包,可以通过以下方式将模型和纹理附加到弩上:
{
"model": {
"type": "select",
"property": "custom_model_data",
"fallback": {
"type": "model",
"model": "item/crossbow"
},
"cases": [
{
"when": "gravity-gun",
"model": {
"type": "model",
"model": "item/gravity_gun"
}
},
{
"when": "gravity-gun-blue",
"model": {
"type": "model",
"model": "item/gravity_gun_firework"
}
}
]
}
}
Gravity Gun
A Minecraft plugin that recreates the Gravity Gun tool from Half-Life 2. The right mouse button can be used to pick up a creature or block, or to drop it. The left mouse button can be used to push a creature or launch it if the object is captured.
| Command |
Permission |
Description |
| help |
|
Show this help |
| reload |
gravity-gun.reload |
Reload the plugin configuration |
| give [target] |
gravity-gun.give |
Give the gravity gun to yourself or another player |
| fix [target] |
gravity-gun.fix |
Fix gravity and collision player after unlucky player grabs it |
| debug place_all_rotation_blocks |
gravity-gun.debug |
Place samples of block types whose BlockData changes under a 90° rotation |
| debug place_all_falling_visual_blocks |
gravity-gun.debug |
Place likely block-entity/rendered blocks for checking falling visuals |
Configuration
All settings live in config.yml. Missing options are added from the bundled defaults while the user's file keeps all existing values; the file is updated on startup and on /gg reload.
version - config file format version.
debug - enables extra logging about held block displays and restored block entities.
language - language code for plugin messages and tooltips (en_us, en_gb, ru_ru, uk_ua).
item.gravity-gun.name - custom name of the gravity gun item; an empty value falls back to the default name from the language file.
Mechanics:
mechanics.grab.range - maximum distance to grab a block or entity.
mechanics.grab.cooldown - minimum delay between two grab attempts.
mechanics.pull.range - maximum distance for pull.
mechanics.pull.force - strength of the pull force.
mechanics.hold.max-time - maximum time the grabbed object may be held before it is released; 0 disables this limit.
mechanics.hold.display-interpolation-duration - teleport interpolation duration in ticks for held display objects; 0 disables interpolation (valid range: 0-59, default: 2).
mechanics.hold.display-items.enabled - holds dropped items as item displays and keeps projectiles on their native entity models.
mechanics.hold.distance.min / mechanics.hold.distance.max / mechanics.hold.distance.step - minimum, maximum and step of the distance between the held object and the player's eye.
mechanics.launch.power - launch speed that is applied when the held object is launched with the left mouse button or released.
mechanics.release.momentum.enabled - inherits player movement and camera-turn momentum on release and launch.
mechanics.release.momentum.multiplier - strength of the inherited momentum.
mechanics.release.momentum.max-speed - maximum added momentum in blocks per tick.
Effects:
effects.enabled - toggles gravity gun and block-impact particle effects.
Limits:
limits.entities.allow-grab - whether entities can be grabbed at all.
limits.entities.allow-grab-players - whether players can be grabbed.
limits.entities.list-mode - BLACKLIST, WHITELIST or DISABLED for limits.entities.list.
limits.entities.list - entity type names to apply the entity grab list to.
limits.blocks.allow-grab - whether blocks can be grabbed at all.
limits.blocks.list-mode - BLACKLIST, WHITELIST or DISABLED for limits.blocks.list.
limits.blocks.list - block names to apply the block grab list to.
Effects and release momentum
The effects.enabled option in config.yml controls the gravity gun's particle effects, including block-impact particles. Release momentum can be adjusted with mechanics.release.momentum.multiplier and mechanics.release.momentum.max-speed.
The mechanics.hold.display-items.enabled option is enabled by default. Dropped items are held as item displays, while projectiles retain and move their native entity models. Dropped items and arrows cannot be picked up while held or for half a second after release; their original pickup state is then restored. Projectiles are aimed along the player's view and given at least the configured launch speed when released. The left mouse button launches a captured projectile forward; it works even though the held projectile sits under the crosshair, because the arm swing event is used as a fallback. On startup and on reload the plugin fills in configuration options that are missing from the user's config while keeping existing values.
Held block displays follow the player's crosshair and rotate smoothly with the camera; on release, the rotation snaps to the nearest 90° before the blocks are placed. Directional blocks and multi-block structures rotate according to the player's horizontal camera turn since pickup. Doors and beds are carried and placed together. Double chests intentionally split: the grabbed half becomes a single chest, and the remaining half on the ground also becomes single while keeping its own inventory intact. Beds are shown by a single display, including while falling, and fences and panes update their connections after placement. Blocks whose falling-block model is empty use a synchronized item display while falling, while the falling block itself continues to handle physics and placement. Synchronized displays use short teleport interpolation to smooth their movement.
The /gg debug place_all_falling_visual_blocks command creates a bedrock test platform with likely block-entity-rendered or empty-falling-model blocks, including beds, chests, signs, banners, skulls, shulker boxes, decorated pots, and other common block entities. This is a practical test set rather than an exhaustive guarantee; resource packs and Minecraft client rendering can introduce additional cases.
Block entities
Block-entity blocks use a BlockDisplay whenever the block has a real 3D block model, so furnaces, barrels, beehives, campfires, shelves, vaults, droppers, dispensers, and similar blocks keep their normal block appearance while held. Blocks whose visuals only exist in a block-entity renderer or whose block model is empty are shown with their item model instead: chests (including copper and ender chests), beds, signs and hanging signs, banners, skulls, shulker boxes, decorated pots, conduits, and copper golem statues. Wall signs, wall banners, wall skulls, and wall hanging signs are displayed using their standing item form.
Contents and metadata such as chest inventories, sign text, banner patterns, skull profiles, pot sherds, copper golem poses, and custom names are stored with the held block and restored when it is placed. Details rendered only by a block-entity renderer are not visible while holding a block: shelf and campfire contents, vault animations, and the animated parts of spawners, for example. Bells use their block model while held and falling rather than the flat item icon; their block-entity swing animation is not reproduced.
The gravity gun only intercepts actual left and right clicks. Physical interactions such as walking on a sculk sensor are ignored, so they are neither cancelled nor accompanied by the grab sound. Setting debug: true in config.yml logs extra details about held block displays and restored block entities.
For resource packs
For resource packs, there is the option to attach a model and texture to a crossbow via:
{
"model": {
"type": "select",
"property": "custom_model_data",
"fallback": {
"type": "model",
"model": "item/crossbow"
},
"cases": [
{
"when": "gravity-gun",
"model": {
"type": "model",
"model": "item/gravity_gun"
}
},
{
"when": "gravity-gun-blue",
"model": {
"type": "model",
"model": "item/gravity_gun_firework"
}
}
]
}
}
评论 0
登录后参与评分
还没有评论,来抢沙发吧