2025-07-14 21:21:22 +08:00

83 lines
2.6 KiB
Markdown

# EnchantmentDoNotConflict (附魔不冲突)
- 1.21 ++ 数据驱动模式的附魔
- 由于麻将大改附魔系统 现在变为了 数据包模式的 我是用内置数据类实现的不冲突 外置的是配置文件
## 让我们看看这个版本之后的配置文件
- 用户定义配置就行 ID 请前往 [zh.minecraft.wiki](https://zh.minecraft.wiki/w/Java%E7%89%88%E6%95%B0%E6%8D%AE%E5%80%BC#%E9%AD%94%E5%92%92)
- 配置文件位置 config/enchantmentdoesnotconflict.json
```json
{
"minecraft:damageEnchantment": [ //这个key是自定义的
"minecraft:sharpness", // 附魔ID 在一组的表示不冲突
"minecraft:smite",
"minecraft:bane_of_arthropods",
"minecraft:density",
"minecraft:breach"
],
"minecraft:infinityEnchantment": [
"minecraft:infinity",
"minecraft:mending"
],
"minecraft:piercingEnchantment": [
"minecraft:piercing",
"minecraft:multishot"
],
"minecraft:protectionEnchantment": [
"minecraft:protection",
"minecraft:fire_protection",
"minecraft:blast_protection",
"minecraft:projectile_protection"
]
}
```
### mod 开发者适配 Demo
- 仓库
```groovy
maven {
name "mingliqiye-maven-repo-gitee"
url "https://gitee.com/minglipro/maven-repository-raw/raw/master"
}
```
- 添加依赖
```groovy
modImplementation "com.mingliqiye.minecraft.enchantment.conflict:enchantmentdoesnotconflict:1.21-1.4"
```
- Demo
```java
import com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.fabricmc.api.ModInitializer;
public class Mod implements ModInitializer {
@Override
public void onInitialize() {
Enchantment.registerAllowEnchantment(() -> {
Map<String, List<String>> map = new HashMap<>();
map.put("modId:enchantmentGroup",
List.of("modId:enchantmentId", "modId:enchantmentId1",
"modId:enchantmentId2"));
return map;
});
// 无限与经验修补 示例
Enchantment.registerAllowEnchantment(() -> {
Map<String, List<String>> map = new HashMap<>();
map.put("minecraft:infinityEnchantment", List.of("minecraft:infinity", "minecraft:mending"));
return map;
});
// 如果是注册一次的话则不需要 它会在服务器运行后运行你的表达式
// 如果是动态加载的话 请重载一下 它会运行你的表达式
// Enchantment.reload(); //这样也会同步到客户端
}
}
```
### 数据优先级
- 最最最低 原版
- 最最低 数据包
- 最低 配置文件
- 最高 最后注册的 AllowEnchantment