This commit is contained in:
Armamem0t 2025-07-16 21:45:37 +08:00
parent 8eaba32265
commit c7e60c6eb4
Signed by: minglipro
GPG Key ID: 5F355A77B22AA93B
15 changed files with 216 additions and 218 deletions

View File

@ -1,3 +0,0 @@
- 这个版本不推出了 Forge 搞心态的玩意
- 映射出点问题 我还不会修
- 详情请见 [EnchantmentDoNotConflictForge](src%2Fmain%2Fjava%2Fcom%2Fmingliqiye%2Fminecraft%2Fenchantment%2Fconflict%2FEnchantmentDoNotConflictForge.java)

View File

@ -19,7 +19,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(21)
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
mappings channel: mapping_channel, version: mapping_version
reobf = false
copyIdeResources = true
runs {
client {

View File

@ -1,12 +1,12 @@
org.gradle.jvmargs=-Xmx4096m -Xms2048m -XX:MaxMetaspaceSize=1024m
systemProp.file.encoding=UTF-8
minecraft_version=1.20.6
minecraft_version_range=[1.20.6]
forge_version=50.2.0
forge_version_range=[50,)
loader_version_range=[50,)
minecraft_version=1.21
minecraft_version_range=[1.21,1.22)
forge_version=51.0.0
forge_version_range=[51,)
loader_version_range=[51,)
mapping_channel=official
mapping_version=1.20.6
mapping_version=1.21
mod_id=enchantmentdoesnotconflict
mod_name=EnchantmentDoNotConflictForge
mod_license=Apache License 2.0

View File

@ -2,42 +2,24 @@ package com.mingliqiye.minecraft.enchantment.conflict;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import com.mingliqiye.minecraft.enchantment.conflict.network.ChannelHander;
import com.mingliqiye.minecraft.enchantment.conflict.network.message.ConfigMessage;
import com.mojang.logging.LogUtils;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger;
/**
* 有没有大佬能够修复该版本的问题<br/>
* 开发环境可以运行 生产环境报错映射出错 FriendlyByteBuf::writeUtf(String s,int i)
* @see ConfigMessage
* @see FriendlyByteBuf
* @deprecated
*/
@Mod(EnchantmentDoNotConflictForge.MODID)
public class EnchantmentDoNotConflictForge {
public static final String MODID = "enchantmentdoesnotconflict";
private static final Logger LOGGER = LogUtils.getLogger();
public EnchantmentDoNotConflictForge(IEventBus modEventBus, ModContainer container) {
container.addConfig(
new net.minecraftforge.fml.config.ModConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON,
ModConfig.SPEC, container));
modEventBus.addListener(this::commonSetup);
MinecraftForge.EVENT_BUS.addListener(this::onPlayerLogin);
}
public EnchantmentDoNotConflictForge(FMLJavaModLoadingContext context) {
this(context.getModEventBus(), context.getContainer());
context.getModEventBus().addListener(this::commonSetup);
MinecraftForge.EVENT_BUS.addListener(this::onPlayerLogin);
}
public void commonSetup(FMLCommonSetupEvent event) {

View File

@ -1,91 +1,85 @@
package com.mingliqiye.minecraft.enchantment.conflict.config;
import net.minecraftforge.common.ForgeConfigSpec;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.mingliqiye.minecraft.enchantment.conflict.EnchantmentDoNotConflictForge;
import com.mojang.logging.LogUtils;
import net.minecraftforge.fml.loading.FMLPaths;
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;
public class ModConfig {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec.BooleanValue AllowDamageEnchantment =
BUILDER.define("AllowDamageEnchantment", true);
public static final ForgeConfigSpec.BooleanValue AllowInfinityEnchantment =
BUILDER.define("AllowInfinityEnchantment", true);
public static final ForgeConfigSpec.BooleanValue AllowPiercingEnchantment =
BUILDER.define("AllowPiercingEnchantment", true);
public static final ForgeConfigSpec.BooleanValue AllowProtectionEnchantment =
BUILDER.define("AllowProtectionEnchantment", true);
public static final ForgeConfigSpec SPEC = BUILDER.build();
private final static Path CONFIG_PATH = FMLPaths.CONFIGDIR.get().resolve(EnchantmentDoNotConflictForge.MODID +
".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();
private static ConfigItem instance;
public static ConfigItem getInstance() {
return instance;
}
public static void setInstance(ConfigItem ins) {
instance = ins;
public ModConfig() {
}
public static void load() {
instance = new ConfigItem(AllowDamageEnchantment.get(), AllowInfinityEnchantment.get(),
AllowPiercingEnchantment.get(), AllowProtectionEnchantment.get());
public static Map<String, List<String>> getInstance() {
return ModConfig.instance;
}
public static class ConfigItem {
private boolean allowDamageEnchantment;
private boolean allowInfinityEnchantment;
private boolean allowPiercingEnchantment;
private boolean allowProtectionEnchantment;
ConfigItem() {
public static void reload() {
load();
}
ConfigItem(boolean a, boolean b, boolean c, boolean d) {
this.allowDamageEnchantment = a;
this.allowInfinityEnchantment = b;
this.allowPiercingEnchantment = c;
this.allowProtectionEnchantment = d;
public static void setInstance(Map<String, List<String>> instance) {
ModConfig.instance = instance;
}
public boolean isAllowDamageEnchantment() {
return allowDamageEnchantment;
public static Map<String, List<String>> load() {
try {
if (Files.exists(CONFIG_PATH)) {
return GSON.fromJson(Files.newBufferedReader(CONFIG_PATH), TYPE);
}
} catch (IOException e) {
LOGGER.error(e.getMessage(),e);
}
Map<String, List<String>> modConfig = getDefData();
setInstance(modConfig);
save();
return modConfig;
}
public void setAllowDamageEnchantment(boolean allowDamageEnchantment) {
this.allowDamageEnchantment = allowDamageEnchantment;
public static void save() {
try {
Files.writeString(CONFIG_PATH, GSON.toJson(instance));
} catch (IOException e) {
LOGGER.error(e.getMessage(),e);
}
}
public boolean isAllowInfinityEnchantment() {
return allowInfinityEnchantment;
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);
}
public void setAllowInfinityEnchantment(boolean allowInfinityEnchantment) {
this.allowInfinityEnchantment = allowInfinityEnchantment;
} else {
throw new RuntimeException("resources 文件内 没有 EnchantmentDoNotConflict.json?");
}
public boolean isAllowPiercingEnchantment() {
return allowPiercingEnchantment;
}
public void setAllowPiercingEnchantment(boolean allowPiercingEnchantment) {
this.allowPiercingEnchantment = allowPiercingEnchantment;
}
public boolean isAllowProtectionEnchantment() {
return allowProtectionEnchantment;
}
public void setAllowProtectionEnchantment(boolean allowProtectionEnchantment) {
this.allowProtectionEnchantment = allowProtectionEnchantment;
}
public String toString() {
return this.getClass().getName() + "(" + "allowDamageEnchantment" +
"=" + allowDamageEnchantment + "," +
"allowInfinityEnchantment" + "=" + allowInfinityEnchantment +
"," + "allowPiercingEnchantment" + "=" +
allowPiercingEnchantment + "," +
"allowProtectionEnchantment" + "=" +
allowProtectionEnchantment + ")";
} catch (RuntimeException | IOException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
}

View File

@ -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();
}

View File

@ -0,0 +1,76 @@
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
import com.mingliqiye.minecraft.enchantment.conflict.EnchantmentDoNotConflictForge;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import com.mojang.logging.LogUtils;
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);
});
//sendToAllPlayers();
LOGGER.info("reload {} Ok Entity: \n{}", EnchantmentDoNotConflictForge.MODID, 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;
}
}

View File

@ -1,26 +0,0 @@
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import net.minecraft.world.item.enchantment.ArrowInfiniteEnchantment;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.MendingEnchantment;
import org.jetbrains.annotations.NotNull;
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(ArrowInfiniteEnchantment.class)
public abstract class ArrowInfiniteEnchantmentMixin {
@Inject(method = "checkCompatibility", at = @At("HEAD"), cancellable = true)
private void canAccept(
@NotNull Enchantment enchantment,
@NotNull CallbackInfoReturnable<Boolean> cir
) {
if (enchantment instanceof MendingEnchantment) {
cir.setReturnValue(ModConfig.getInstance().isAllowInfinityEnchantment());
}
}
}

View File

@ -1,26 +0,0 @@
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import net.minecraft.world.item.enchantment.ArrowPiercingEnchantment;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;
import org.jetbrains.annotations.NotNull;
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(ArrowPiercingEnchantment.class)
public abstract class ArrowPiercingEnchantmentMixin {
@Inject(method = "checkCompatibility", at = @At("HEAD"), cancellable = true)
private void canAccept(
@NotNull Enchantment enchantment,
@NotNull CallbackInfoReturnable<Boolean> cir
) {
if (enchantment == Enchantments.MULTISHOT) {
cir.setReturnValue(ModConfig.getInstance().isAllowPiercingEnchantment());
}
}
}

View File

@ -1,26 +0,0 @@
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import net.minecraft.world.item.enchantment.DamageEnchantment;
import net.minecraft.world.item.enchantment.Enchantment;
import org.jetbrains.annotations.NotNull;
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(DamageEnchantment.class)
public abstract class DamageEnchantmentMixin {
@Inject(method = "checkCompatibility", at = @At("HEAD"), cancellable = true)
private void canAccept(
@NotNull Enchantment enchantment,
@NotNull CallbackInfoReturnable<Boolean> cir
) {
if (enchantment instanceof DamageEnchantment) {
cir.setReturnValue(ModConfig.getInstance().isAllowDamageEnchantment());
}
}
}

View File

@ -0,0 +1,25 @@
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
import com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment;
import net.minecraft.core.Holder;
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.world.item.enchantment.Enchantment.class)
public abstract class EnchantmentMixin {
@Inject(method = "areCompatible", at = @At("HEAD"), cancellable = true)
private static void canBeCombined(
Holder<net.minecraft.world.item.enchantment.Enchantment> first,
Holder<net.minecraft.world.item.enchantment.Enchantment> second, CallbackInfoReturnable<Boolean> cir
) {
Boolean cbc = Enchantment.canBeCombined(first.getRegisteredName(), second.getRegisteredName());
if (cbc == null) {
return;
}
cir.setReturnValue(cbc);
}
}

View File

@ -1,26 +0,0 @@
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
import org.jetbrains.annotations.NotNull;
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(ProtectionEnchantment.class)
public abstract class ProtectionEnchantmentMixin {
@Inject(method = "checkCompatibility", at = @At("HEAD"), cancellable = true)
private void onCheckCompatibility(
@NotNull Enchantment enchantment,
@NotNull CallbackInfoReturnable<Boolean> cir
) {
if (enchantment instanceof ProtectionEnchantment) {
cir.setReturnValue(ModConfig.getInstance().isAllowProtectionEnchantment());
}
}
}

View File

@ -9,13 +9,15 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import java.util.List;
import java.util.Map;
import static com.mingliqiye.minecraft.enchantment.conflict.network.ChannelHander.CONFIG_CHANNEL_INSTANCE;
import static com.mingliqiye.minecraft.enchantment.conflict.network.ChannelHander.CONFIG_SYNC;
public record ConfigMessage(ModConfig.ConfigItem data) {
public record ConfigMessage(Map<String, List<String>> data) {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Gson GSON = new Gson();
@ -25,19 +27,16 @@ public record ConfigMessage(ModConfig.ConfigItem data) {
.decoder(ConfigMessage::decode).encoder(ConfigMessage::encode).consumerMainThread(ConfigMessage::handle).add();
}
/**
* @deprecated
*/
public static void encode(ConfigMessage configMessage, FriendlyByteBuf byteBuf) {
byteBuf.writeUtf(GSON.toJson(configMessage.data),32767);
}
public static ConfigMessage decode(FriendlyByteBuf byteBuf) {
return new ConfigMessage(GSON.fromJson(byteBuf.readUtf(), ModConfig.ConfigItem.class));
return new ConfigMessage(GSON.fromJson(byteBuf.readUtf(), ModConfig.TYPE));
}
public static void send(ServerPlayer player) {
ModConfig.ConfigItem configItem = ModConfig.getInstance();
Map<String, List<String>> configItem = ModConfig.getInstance();
CONFIG_CHANNEL_INSTANCE.send(new ConfigMessage(configItem),PacketDistributor.PLAYER.with(player));
LOGGER.info("Send Server Config {} to {} data={}", EnchantmentDoNotConflictForge.MODID,
player.getDisplayName().getString(), configItem);

View File

@ -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"
]
}

View File

@ -4,10 +4,7 @@
"refmap": "enchantmentdoesnotconflict.mixins.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ArrowInfiniteEnchantmentMixin",
"ArrowPiercingEnchantmentMixin",
"DamageEnchantmentMixin",
"ProtectionEnchantmentMixin"
"EnchantmentMixin"
],
"injectors": {
"defaultRequire": 1