一个用于在 PaperMC 上为 1.20+ 版本创建自定义方块和物品的 API
如何使用?
数据驱动的方块与物品
创建一个“包”
以这种方式创建自定义物品和方块时,你需要创建一个类似于数据包或资源包的“包”。其文件结构如下所示:
- <命名空间>
- blocks(方块)
- default_block(默认方块)
- transparent_block(透明方块)
- items(物品)
你的包的命名空间将在 give 命令中显示在物品 ID 之前,格式为 namespace:item_id。
添加物品
要添加一个物品,你只需创建一个 json 并将其放入 items 文件夹中。文件名将成为该物品的 ID。
添加方块
要添加一个方块,你需要创建一个 json。如果你希望它是一个透明方块,需要将其放入 transparent_block 文件夹中。建议将放置后的方块也设为透明,否则外观可能会很奇怪。如果你想要一个普通方块,请将 json 文件放入 default_block 文件夹中。文件名将成为方块的 ID,为了良好的实践,建议使这个 ID 与其对应物品的 ID 相同,但这并非必需。
使用“包”(Pack)
要使用一个“包”,你需要将其放入 packs 文件夹中。该文件夹位于 plugins 文件夹下的 custom_item_api 文件夹内。
- plugins
- Custom_Item_Api
- packs
通过插件添加方块和物品
自定义物品
你可以通过创建 new CustomItem(Material material, NamespacedKey key, Class actions) 来添加一个自定义物品。
如果不存在具有该 NamespacedKey 的自定义物品,这将创建一个新的自定义物品。actions 定义了点击该物品时应发生的行为,它是一个实现了 CustomItemActions 接口的类。
你可以更改纹理、标签等。
如果你想使用此物品放置自定义方块,可以通过 CustomItem#setCustomBlock(NamespacedKey) 添加相关设置。
示例:
NamespacedKey itemKey = new NamespacedKey(plugin, "example_item");
CustomItem customItem = new CustomItem(Material.FURNACE, itemKey, Class.forName("org.super_man2006.custom_item_api.utils.items.EmptyCustomItemAction"));
customItem.setCustomBlock(blockKey);
customItem.setName(Component.text("Example"));
自定义方块
你可以通过创建 new CustomBlock(Material material, NamespacedKey key, Class actions, Material placedBlock) 来添加一个自定义方块。
如果不存在具有该 NamespacedKey 的自定义方块,这将创建一个新的自定义方块。actions 定义了放置/破坏/右键点击该方块时应发生的行为,它是一个实现了 CustomBlockActions 接口的类。
你可以更改纹理、标签等。
该方块使用的是物品纹理,而非方块纹理。这意味着如果你设置了自定义模型数据(cmd),可以更改其纹理。
如果你想在此方块被破坏后掉落一个自定义物品,可以通过 CustomBlock#setDropItem(NamespacedKey) 进行设置。
示例:
NamespacedKey blockKey = new NamespacedKey(plugin, "example_block");
CustomBlock customBlock = new CustomBlock(Material.FURNACE, blockKey, Class.forName("org.super_man2006.custom_item_api.utils.blocks.EmptyCustomBlockAction"), Material.STONE);
customBlock.setRotation(CustomBlock.Rotation.AROUND_Y);
功能 / 错误报告
如果你发现了错误或希望添加新功能,请在 Discord 中提问,或在 GitHub 上创建一个 Issue。
An API for making custom blocks and items for 1.20+ on paperMC
How to use?
Data driven blocks and items
Create a 'pack'
To create custom items and blocks in this way, you will have to create a 'pack' similar to a datapack or a resource pack. The file structure of which looks like this:
- <namespace>
- blocks
- default_block
- transparent_block
- items
The namespace of your pack will be what shows before the item id in the give command namespace:item_id.
Add items
To add an item you just need to create a json and put it in the items folder. The name of the file will become the item id.
Add blocks
To add a block you need to create a json. If you want it to be a transparent block, you need to put it in the transparent_block folder. It is recommended to use a block that is transparent as the placed_block, otherwise it might look weird. If you want a normal block you put the json in the default_block folder. The name of the file will become the block id, for good practice you should make this id the same as the id of its item but it's not required.
Use a 'pack'
To use a 'pack' you need to put it in the packs folder, this can be found by going in the plugins folder and then the custom_item_api folder.
- plugins
- Custom_Item_Api
- packs
Add blocks and items with a plugin
Custom items
You can add a custom item by creating a new CustomItem(Material material, NamespacedKey key, Class actions).
This will create the custom item if there isn't a custom item with this NamespacedKey. The actions define what should happen when the item is clicked, it's a class that implements CustomItemActions.
You can change the texture,tags,...
If you want to place a custom block using this item you can add this with CustomItem#setCustomBlock(NamespacedKey)
example:
NamespacedKey itemKey = new NamespacedKey(plugin, "example_item");
CustomItem customItem = new CustomItem(Material.FURNACE, itemKey, Class.forName("org.super_man2006.custom_item_api.utils.items.EmptyCustomItemAction"));
customItem.setCustomBlock(blockKey);
customItem.setName(Component.text("Example"));
Custom blocks
You can add a custom item by creating a new CustomBlock(Material material, NamespacedKey key, Class actions, Material placedBlock).
This will create the custom item if there isn't a custom item with this NamespacedKey. The actions define what should happen when the block is placed/broken/clicked on, it's a class that implements CustomBlockActions.
You can change the texture,tags,...
The block uses an item texture, NOT a block texture. This means that if you set custom model data (cmd) you can change the texture.
If you want to drop a custom item after breaking this block you made with CustomBlock#setDropItem(NamespacedKey)
example:
NamespacedKey blockKey = new NamespacedKey(plugin, "example_block");
CustomBlock customBlock = new CustomBlock(Material.FURNACE, blockKey, Class.forName("org.super_man2006.custom_item_api.utils.blocks.EmptyCustomBlockAction"), Material.STONE);
customBlock.setRotation(CustomBlock.Rotation.AROUND_Y);
Features / Bugs
If you find bugs or want a feature to be added, ask in the discord or create an issue on github.
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
下载 Custom Item API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
已更新到 Minecraft 1.20.6 和 Java 1.21
完整更新日志:
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
插件
PacketEvents 是一款专为 Minecraft Java 版打造的协议库,旨在简化数据包的处理与传输。
插件
ExyliaPlugins 的库。
插件
自定义你的Minecraft头像!
插件
重新定义服务器上的生物运输方式。使用高度可定制的口袋道具,安全地捕获、存储和释放任何实体。
插件
为基于 Spigot/Paper/Folia 的服务器添加对 Vivecraft 的支持
插件
使床在所有维度中爆炸的模组
评论 0
登录后参与评分
还没有评论,来抢沙发吧