Compare commits
No commits in common. "master" and "1.21" have entirely different histories.
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
* text eol=lf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.jar binary
|
||||||
|
*.class binary
|
||||||
|
*.png binary
|
129
README.MD
129
README.MD
@ -1,58 +1,83 @@
|
|||||||
# EnchantmentDoNotConflict (附魔不冲突)
|
# EnchantmentDoNotConflict (附魔不冲突)
|
||||||
|
- 1.21 ++ 数据驱动模式的附魔
|
||||||
|
- 由于麻将大改附魔系统 现在变为了 数据包模式的 我是用内置数据类实现的不冲突 外置的是配置文件
|
||||||
|
|
||||||
<img width="512" src="title_full.png">
|
## 让我们看看这个版本之后的配置文件
|
||||||
|
- 用户定义配置就行 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"
|
||||||
|
```
|
||||||
|
- 其他模组加载器也是同理 我会保持API不变的
|
||||||
|
- Demo
|
||||||
|
```java
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment;
|
||||||
|
|
||||||
## 注意事项
|
import java.util.HashMap;
|
||||||
- 主分支 master 仅存储一些文档 阅读代码请切换分支
|
import java.util.List;
|
||||||
- 1.20.* 升级到 1.21 需要删除配置文件
|
import java.util.Map;
|
||||||
- 仅服务端模组 客户端安装无效
|
|
||||||
- 客户端安装仅适配其他附魔模组
|
|
||||||
- 单人游戏有效
|
|
||||||
|
|
||||||
## 仓库列表
|
import net.fabricmc.api.ModInitializer;
|
||||||
- 这个是仓库Fabirc版本的
|
|
||||||
- 仓库[NeoForge](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflictNeoForge)版本
|
|
||||||
- 仓库[Forge](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflictForge)版本
|
|
||||||
|
|
||||||
## 支持的版本 Fabric
|
public class Mod implements ModInitializer {
|
||||||
- 1.20 意外支持 (1.20.1)
|
@Override
|
||||||
- 1.20.2 意外支持 (1.20.3 1.20.4)
|
public void onInitialize() {
|
||||||
- 1.20.5 意外支持 (1.20.6)
|
Enchantment.registerAllowEnchantment(() -> {
|
||||||
- 1.21 意外支持(1.21.1 1.21.2 1.21.3 1.21.4 1.21.5 1.21.6 1.21.7)
|
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(); //这样也会同步到客户端
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 支持的版本 [Forge](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflictForge)
|
### 数据优先级
|
||||||
- 1.20 意外支持 (1.20.1)
|
- 最最最低 原版
|
||||||
- 1.20.2 意外支持 (1.20.3 1.20.4)
|
- 最最低 数据包
|
||||||
- 1.20.6 Forge 废弃 API FMLJavaModLoadingContext.get().getModEventBus();
|
- 最低 配置文件
|
||||||
- 1.21 意外支持 (1.21.1 1.21.3 1.21.4 1.21.5) Forge 你 API不是说废弃了吗 怎么这版本不废弃了?
|
- 最高 最后注册的 AllowEnchantment
|
||||||
- 1.21.6 意外支持 (1.21.7) 又改APi Forge 女娲
|
|
||||||
|
|
||||||
## 支持的版本 [NeoForge](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflictNeoForge)
|
|
||||||
- 1.20.5 意外支持 (1.20.6)
|
|
||||||
- 1.21 意外支持(1.21.1 1.21.2 1.21.3 1.21.4 1.21.5 1.21.6 1.21.7)
|
|
||||||
|
|
||||||
## 游戏版本日志
|
|
||||||
### 1.20.2 ++ PlayerManager::onPlayerConnect 签名修改
|
|
||||||
- 由于麻将改了签名
|
|
||||||
- net.minecraft.server.PlayerManager::onPlayerConnect(ClientConnection connection, ServerPlayerEntity player) Old
|
|
||||||
- net.minecraft.server.PlayerManager::onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData) New
|
|
||||||
- 主版本 1.20.1
|
|
||||||
- 发行 1.20.2 - 1.20.4
|
|
||||||
|
|
||||||
### 1.20.5 ++ 服务端客户端通信大改
|
|
||||||
- 主版本 1.20.5
|
|
||||||
- 发行 1.20.5 - 1.20.6
|
|
||||||
|
|
||||||
### 1.21 ++ 数据驱动模式的附魔
|
|
||||||
- 由于麻将大改附魔系统 现在变为了 数据包模式的 我是用内置类实现的不冲突
|
|
||||||
- 后续大家想要添加模组的附魔不冲突的话请看这 分支[1.21](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflict/src/branch/1.21)
|
|
||||||
|
|
||||||
## 下载
|
|
||||||
- [Fabric](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflict/releases)
|
|
||||||
- [NeoForge](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflictNeoForge/releases)
|
|
||||||
- [Forge](https://git.mingliqiye.com/MinecraftMod/EnchantmentDoNotConflictForge/releases)
|
|
||||||
|
|
||||||
## 适配其他模组
|
|
||||||
- 服务器和客户端 都安装 本模组 即可
|
|
||||||
- [Enchanting Infuser](https://modrinth.com/mod/enchanting-infuser)
|
|
||||||
- <img src="bc7a632b-e68a-4c23-85a6-2d6aa51b6254.png">
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
68
build.gradle
Normal file
68
build.gradle
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '1.10.5'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
version = "${project.minecraft_version}-${project.mod_version}"
|
||||||
|
group = project.maven_group
|
||||||
|
|
||||||
|
base {
|
||||||
|
archivesName = project.archives_base_name
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
mappings "net.fabricmc:yarn:${project.minecraft_version}+${project.yarn_mappings}:v2"
|
||||||
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}+${project.minecraft_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property "version", project.version
|
||||||
|
inputs.property "minecraft_version", project.minecraft_version
|
||||||
|
inputs.property "loader_version", project.loader_version
|
||||||
|
filteringCharset "UTF-8"
|
||||||
|
|
||||||
|
filesMatching("fabric.mod.json") {
|
||||||
|
expand "version": project.version,
|
||||||
|
"minecraft_version": project.minecraft_version,
|
||||||
|
"loader_version": project.loader_version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def targetJavaVersion = 21
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
it.options.encoding = "UTF-8"
|
||||||
|
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||||
|
it.options.release.set(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
|
if (JavaVersion.current() < javaVersion) {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
|
}
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from("LICENSE") {
|
||||||
|
rename { "${project.archivesBaseName}_${it}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create("mavenJava", MavenPublication) {
|
||||||
|
artifactId = project.archives_base_name
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name= "Disk"
|
||||||
|
url = uri("D:/git/maven-repository-raw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
gradle.properties
Normal file
7
gradle.properties
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
minecraft_version=1.21
|
||||||
|
yarn_mappings=build.9
|
||||||
|
loader_version=0.16.13
|
||||||
|
mod_version=1.5
|
||||||
|
maven_group=com.mingliqiye.minecraft.enchantment.conflict
|
||||||
|
archives_base_name=enchantmentdoesnotconflict
|
||||||
|
fabric_version=0.102.0
|
1
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
1
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
11
settings.gradle
Normal file
11
settings.gradle
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
}
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name= "${archives_base_name}-${minecraft_version}-${mod_version}"
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict;
|
||||||
|
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment;
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
public class Mod implements ModInitializer {
|
||||||
|
|
||||||
|
public static String MOD_ID = "enchantmentdoesnotconflict";
|
||||||
|
public static MinecraftServer server;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
ServerLifecycleEvents.SERVER_STARTED.register((s) -> {
|
||||||
|
server = s;
|
||||||
|
Enchantment.reload();
|
||||||
|
});
|
||||||
|
ConfigPayload.initializeServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinecraftServer getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.client;
|
||||||
|
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
|
||||||
|
public class ModClient implements ClientModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
ConfigPayload.initializeClient();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.config;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.mingliqiye.minecraft.enchantment.conflict.Mod.MOD_ID;
|
||||||
|
|
||||||
|
public class ModConfig {
|
||||||
|
private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve(MOD_ID + ".json");
|
||||||
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
|
||||||
|
public static final Type TYPE = new TypeToken<HashMap<String, ArrayList<String>>>() {
|
||||||
|
}.getType();
|
||||||
|
private static Map<String, List<String>> instance;
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
|
public ModConfig() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Map<String, List<String>> getInstance() {
|
||||||
|
return ModConfig.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setInstance(Map<String, List<String>> instance) {
|
||||||
|
ModConfig.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, List<String>> load() {
|
||||||
|
try {
|
||||||
|
if (Files.exists(CONFIG_PATH)) {
|
||||||
|
return GSON.fromJson(Files.newBufferedReader(CONFIG_PATH), TYPE);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Map<String, List<String>> modConfig = getDefData();
|
||||||
|
setInstance(modConfig);
|
||||||
|
save();
|
||||||
|
return modConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void save() {
|
||||||
|
try {
|
||||||
|
Files.writeString(CONFIG_PATH, GSON.toJson(instance));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, List<String>> getDefData() {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = ModConfig.class.getResourceAsStream(
|
||||||
|
"/assets/enchantmentdoesnotconflict" + "/EnchantmentDoNotConflict.json");
|
||||||
|
if (inputStream != null) {
|
||||||
|
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
|
||||||
|
return GSON.fromJson(reader, TYPE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("resources 文件内 没有 EnchantmentDoNotConflict.json?");
|
||||||
|
}
|
||||||
|
} catch (RuntimeException | IOException e) {
|
||||||
|
LOGGER.error(e.getMessage(), e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
setInstance(load());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface AddAllowEnchantmentFunInf {
|
||||||
|
Map<String,List<String>> call();
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||||
|
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.Mod;
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Enchantment {
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
private final String id;
|
||||||
|
private final String father;
|
||||||
|
private final static List<AddAllowEnchantmentFunInf> allowEnchantmentFunInfs = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void registerAllowEnchantment(AddAllowEnchantmentFunInf fun) {
|
||||||
|
allowEnchantmentFunInfs.add(fun);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
ModConfig.reload();
|
||||||
|
allowEnchantmentFunInfs.forEach(e -> {
|
||||||
|
Map<String, List<String>> conf = ModConfig.getInstance();
|
||||||
|
conf.putAll(e.call());
|
||||||
|
ModConfig.setInstance(conf);
|
||||||
|
});
|
||||||
|
MinecraftServer server = Mod.getServer();
|
||||||
|
if (server != null) {
|
||||||
|
server.getPlayerManager().getPlayerList().forEach(ConfigPayload::sendToPlayer);
|
||||||
|
}
|
||||||
|
LOGGER.info("reload {} Ok Entity: \n{}", Mod.MOD_ID, ModConfig.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Enchantment(String id, String father) {
|
||||||
|
this.id = id;
|
||||||
|
this.father = father;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Enchantment> ofId(String id, Map<String, List<String>> listMap) {
|
||||||
|
final List<Enchantment> enchantmentList = new ArrayList<>();
|
||||||
|
for (String i : listMap.keySet()) {
|
||||||
|
if (listMap.get(i).contains(id)) {
|
||||||
|
enchantmentList.add(new Enchantment(id, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return enchantmentList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean canBeCombined(String enchantmentA, String enchantmentB) {
|
||||||
|
if (enchantmentA.equals(enchantmentB)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<String>> config = ModConfig.getInstance();
|
||||||
|
List<Enchantment> groupsA = ofId(enchantmentA, config);
|
||||||
|
List<Enchantment> groupsB = ofId(enchantmentB, config);
|
||||||
|
|
||||||
|
if (groupsA.isEmpty() && groupsB.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Enchantment groupA : groupsA) {
|
||||||
|
for (Enchantment groupB : groupsB) {
|
||||||
|
if (groupA.getFather().equals(groupB.getFather())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFather() {
|
||||||
|
return father;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||||
|
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment;
|
||||||
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(net.minecraft.enchantment.Enchantment.class)
|
||||||
|
public abstract class EnchantmentMixin {
|
||||||
|
|
||||||
|
|
||||||
|
@Inject(method = "canBeCombined", at = @At("HEAD"), cancellable = true)
|
||||||
|
private static void canBeCombined(
|
||||||
|
RegistryEntry<net.minecraft.enchantment.Enchantment> first,
|
||||||
|
RegistryEntry<net.minecraft.enchantment.Enchantment> second, CallbackInfoReturnable<Boolean> cir
|
||||||
|
) {
|
||||||
|
Boolean cbc = Enchantment.canBeCombined(first.getIdAsString(), second.getIdAsString());
|
||||||
|
if (cbc == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cir.setReturnValue(cbc);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||||
|
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
|
||||||
|
import net.minecraft.network.ClientConnection;
|
||||||
|
import net.minecraft.server.PlayerManager;
|
||||||
|
import net.minecraft.server.network.ConnectedClientData;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(PlayerManager.class)
|
||||||
|
public abstract class PlayerManagerMixin {
|
||||||
|
|
||||||
|
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
|
||||||
|
private void onPlayerConnect(
|
||||||
|
ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData,
|
||||||
|
CallbackInfo ci
|
||||||
|
) {
|
||||||
|
ConfigPayload.sendToPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.mingliqiye.minecraft.enchantment.conflict.network;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.Mod;
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||||
|
import com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.mingliqiye.minecraft.enchantment.conflict.Mod.MOD_ID;
|
||||||
|
|
||||||
|
public record ConfigPayload(Map<String, List<String>> data) implements CustomPayload {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
public static final CustomPayload.Id<ConfigPayload> TYPE =
|
||||||
|
new CustomPayload.Id<>(Identifier.of(Mod.MOD_ID, "config_packet"));
|
||||||
|
|
||||||
|
private static final Gson GSON = new Gson();
|
||||||
|
|
||||||
|
|
||||||
|
public static final PacketCodec<PacketByteBuf, ConfigPayload> CODEC =
|
||||||
|
PacketCodec.of((payload, buf) -> buf.writeString(GSON.toJson(payload.data())),
|
||||||
|
buf -> new ConfigPayload(GSON.fromJson(buf.readString(), ModConfig.TYPE)));
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initializeClient() {
|
||||||
|
ClientPlayNetworking.registerGlobalReceiver(TYPE, (payload, ctx) -> {
|
||||||
|
ctx.client().execute(() -> {
|
||||||
|
ModConfig.setInstance(payload.data());
|
||||||
|
LOGGER.info("Load Server {} config {}", MOD_ID, payload.data());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initializeServer() {
|
||||||
|
PayloadTypeRegistry.playS2C().register(TYPE, CODEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendToPlayer(ServerPlayerEntity player) {
|
||||||
|
if (ServerPlayNetworking.canSend(player, TYPE)) {
|
||||||
|
ServerPlayNetworking.send(player, new ConfigPayload(ModConfig.getInstance()));
|
||||||
|
LOGGER.info("Send {} config to player({}) ok", Mod.MOD_ID, player.getName().getString());
|
||||||
|
} else {
|
||||||
|
LOGGER.error("Cannot send config to {}: channel not registered", player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"minecraft:damageEnchantment": [
|
||||||
|
"minecraft:sharpness",
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
16
src/main/resources/enchantmentdoesnotconflict.mixins.json
Normal file
16
src/main/resources/enchantmentdoesnotconflict.mixins.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "com.mingliqiye.minecraft.enchantment.conflict.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"mixins": [
|
||||||
|
"EnchantmentMixin",
|
||||||
|
"PlayerManagerMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
},
|
||||||
|
"overwrites": {
|
||||||
|
"requireAnnotations": true
|
||||||
|
}
|
||||||
|
}
|
28
src/main/resources/fabric.mod.json
Normal file
28
src/main/resources/fabric.mod.json
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "enchantmentdoesnotconflict",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "enchantmentDoesNotConflict",
|
||||||
|
"description": "移除一些附魔冲突",
|
||||||
|
"authors": [],
|
||||||
|
"contact": {},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"icon": "assets/enchantmentdoesnotconflict/icon.png",
|
||||||
|
"environment": "*",
|
||||||
|
"entrypoints": {
|
||||||
|
"client": [
|
||||||
|
"com.mingliqiye.minecraft.enchantment.conflict.client.ModClient"
|
||||||
|
],
|
||||||
|
"main": [
|
||||||
|
"com.mingliqiye.minecraft.enchantment.conflict.Mod"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"enchantmentdoesnotconflict.mixins.json"
|
||||||
|
],
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": "*",
|
||||||
|
"fabric": "*",
|
||||||
|
"minecraft": ">=1.21 <=1.21.7"
|
||||||
|
}
|
||||||
|
}
|
BIN
title_full.png
BIN
title_full.png
Binary file not shown.
Before Width: | Height: | Size: 218 KiB |
Loading…
x
Reference in New Issue
Block a user