add init
This commit is contained in:
parent
8eaba32265
commit
c7e60c6eb4
@ -1,3 +0,0 @@
|
|||||||
- 这个版本不推出了 Forge 搞心态的玩意
|
|
||||||
- 映射出点问题 我还不会修
|
|
||||||
- 详情请见 [EnchantmentDoNotConflictForge](src%2Fmain%2Fjava%2Fcom%2Fmingliqiye%2Fminecraft%2Fenchantment%2Fconflict%2FEnchantmentDoNotConflictForge.java)
|
|
@ -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'}"
|
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
|
||||||
minecraft {
|
minecraft {
|
||||||
mappings channel: mapping_channel, version: mapping_version
|
mappings channel: mapping_channel, version: mapping_version
|
||||||
|
reobf = false
|
||||||
copyIdeResources = true
|
copyIdeResources = true
|
||||||
runs {
|
runs {
|
||||||
client {
|
client {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
org.gradle.jvmargs=-Xmx4096m -Xms2048m -XX:MaxMetaspaceSize=1024m
|
org.gradle.jvmargs=-Xmx4096m -Xms2048m -XX:MaxMetaspaceSize=1024m
|
||||||
systemProp.file.encoding=UTF-8
|
systemProp.file.encoding=UTF-8
|
||||||
minecraft_version=1.20.6
|
minecraft_version=1.21
|
||||||
minecraft_version_range=[1.20.6]
|
minecraft_version_range=[1.21,1.22)
|
||||||
forge_version=50.2.0
|
forge_version=51.0.0
|
||||||
forge_version_range=[50,)
|
forge_version_range=[51,)
|
||||||
loader_version_range=[50,)
|
loader_version_range=[51,)
|
||||||
mapping_channel=official
|
mapping_channel=official
|
||||||
mapping_version=1.20.6
|
mapping_version=1.21
|
||||||
mod_id=enchantmentdoesnotconflict
|
mod_id=enchantmentdoesnotconflict
|
||||||
mod_name=EnchantmentDoNotConflictForge
|
mod_name=EnchantmentDoNotConflictForge
|
||||||
mod_license=Apache License 2.0
|
mod_license=Apache License 2.0
|
||||||
|
@ -2,42 +2,24 @@ package com.mingliqiye.minecraft.enchantment.conflict;
|
|||||||
|
|
||||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||||
import com.mingliqiye.minecraft.enchantment.conflict.network.ChannelHander;
|
import com.mingliqiye.minecraft.enchantment.conflict.network.ChannelHander;
|
||||||
import com.mingliqiye.minecraft.enchantment.conflict.network.message.ConfigMessage;
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.ModContainer;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
/**
|
|
||||||
* 有没有大佬能够修复该版本的问题<br/>
|
|
||||||
* 开发环境可以运行 生产环境报错映射出错 FriendlyByteBuf::writeUtf(String s,int i)
|
|
||||||
* @see ConfigMessage
|
|
||||||
* @see FriendlyByteBuf
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Mod(EnchantmentDoNotConflictForge.MODID)
|
@Mod(EnchantmentDoNotConflictForge.MODID)
|
||||||
public class EnchantmentDoNotConflictForge {
|
public class EnchantmentDoNotConflictForge {
|
||||||
public static final String MODID = "enchantmentdoesnotconflict";
|
public static final String MODID = "enchantmentdoesnotconflict";
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
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) {
|
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) {
|
public void commonSetup(FMLCommonSetupEvent event) {
|
||||||
|
@ -1,91 +1,85 @@
|
|||||||
package com.mingliqiye.minecraft.enchantment.conflict.config;
|
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 {
|
public class ModConfig {
|
||||||
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
private final static Path CONFIG_PATH = FMLPaths.CONFIGDIR.get().resolve(EnchantmentDoNotConflictForge.MODID +
|
||||||
public static final ForgeConfigSpec.BooleanValue AllowDamageEnchantment =
|
".json");
|
||||||
BUILDER.define("AllowDamageEnchantment", true);
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
|
||||||
public static final ForgeConfigSpec.BooleanValue AllowInfinityEnchantment =
|
public static final Type TYPE = new TypeToken<HashMap<String, ArrayList<String>>>() {
|
||||||
BUILDER.define("AllowInfinityEnchantment", true);
|
}.getType();
|
||||||
public static final ForgeConfigSpec.BooleanValue AllowPiercingEnchantment =
|
private static Map<String, List<String>> instance;
|
||||||
BUILDER.define("AllowPiercingEnchantment", true);
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
public static final ForgeConfigSpec.BooleanValue AllowProtectionEnchantment =
|
|
||||||
BUILDER.define("AllowProtectionEnchantment", true);
|
|
||||||
public static final ForgeConfigSpec SPEC = BUILDER.build();
|
|
||||||
|
|
||||||
private static ConfigItem instance;
|
public ModConfig() {
|
||||||
|
|
||||||
public static ConfigItem getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setInstance(ConfigItem ins) {
|
|
||||||
instance = ins;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void load() {
|
public static Map<String, List<String>> getInstance() {
|
||||||
instance = new ConfigItem(AllowDamageEnchantment.get(), AllowInfinityEnchantment.get(),
|
return ModConfig.instance;
|
||||||
AllowPiercingEnchantment.get(), AllowProtectionEnchantment.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConfigItem {
|
public static void reload() {
|
||||||
private boolean allowDamageEnchantment;
|
load();
|
||||||
private boolean allowInfinityEnchantment;
|
}
|
||||||
private boolean allowPiercingEnchantment;
|
|
||||||
private boolean allowProtectionEnchantment;
|
|
||||||
|
|
||||||
ConfigItem() {
|
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) {
|
||||||
|
LOGGER.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
|
Map<String, List<String>> modConfig = getDefData();
|
||||||
|
setInstance(modConfig);
|
||||||
|
save();
|
||||||
|
return modConfig;
|
||||||
|
}
|
||||||
|
|
||||||
ConfigItem(boolean a, boolean b, boolean c, boolean d) {
|
public static void save() {
|
||||||
this.allowDamageEnchantment = a;
|
try {
|
||||||
this.allowInfinityEnchantment = b;
|
Files.writeString(CONFIG_PATH, GSON.toJson(instance));
|
||||||
this.allowPiercingEnchantment = c;
|
} catch (IOException e) {
|
||||||
this.allowProtectionEnchantment = d;
|
LOGGER.error(e.getMessage(),e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAllowDamageEnchantment() {
|
public static Map<String, List<String>> getDefData() {
|
||||||
return allowDamageEnchantment;
|
try {
|
||||||
}
|
InputStream inputStream = ModConfig.class.getResourceAsStream(
|
||||||
|
"/assets/enchantmentdoesnotconflict" + "/EnchantmentDoNotConflict.json");
|
||||||
public void setAllowDamageEnchantment(boolean allowDamageEnchantment) {
|
if (inputStream != null) {
|
||||||
this.allowDamageEnchantment = allowDamageEnchantment;
|
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
|
||||||
}
|
return GSON.fromJson(reader, TYPE);
|
||||||
|
}
|
||||||
public boolean isAllowInfinityEnchantment() {
|
} else {
|
||||||
return allowInfinityEnchantment;
|
throw new RuntimeException("resources 文件内 没有 EnchantmentDoNotConflict.json?");
|
||||||
}
|
}
|
||||||
|
} catch (RuntimeException | IOException e) {
|
||||||
public void setAllowInfinityEnchantment(boolean allowInfinityEnchantment) {
|
LOGGER.error(e.getMessage(), e);
|
||||||
this.allowInfinityEnchantment = allowInfinityEnchantment;
|
throw new RuntimeException(e);
|
||||||
}
|
|
||||||
|
|
||||||
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 + ")";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,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;
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,13 +9,15 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
import net.minecraftforge.event.network.CustomPayloadEvent;
|
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||||
import net.minecraftforge.network.NetworkDirection;
|
import net.minecraftforge.network.NetworkDirection;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.Logger;
|
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_CHANNEL_INSTANCE;
|
||||||
import static com.mingliqiye.minecraft.enchantment.conflict.network.ChannelHander.CONFIG_SYNC;
|
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 Logger LOGGER = LogUtils.getLogger();
|
||||||
private static final Gson GSON = new Gson();
|
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();
|
.decoder(ConfigMessage::decode).encoder(ConfigMessage::encode).consumerMainThread(ConfigMessage::handle).add();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public static void encode(ConfigMessage configMessage, FriendlyByteBuf byteBuf) {
|
public static void encode(ConfigMessage configMessage, FriendlyByteBuf byteBuf) {
|
||||||
byteBuf.writeUtf(GSON.toJson(configMessage.data),32767);
|
byteBuf.writeUtf(GSON.toJson(configMessage.data),32767);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigMessage decode(FriendlyByteBuf byteBuf) {
|
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) {
|
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));
|
CONFIG_CHANNEL_INSTANCE.send(new ConfigMessage(configItem),PacketDistributor.PLAYER.with(player));
|
||||||
LOGGER.info("Send Server Config {} to {} data={}", EnchantmentDoNotConflictForge.MODID,
|
LOGGER.info("Send Server Config {} to {} data={}", EnchantmentDoNotConflictForge.MODID,
|
||||||
player.getDisplayName().getString(), configItem);
|
player.getDisplayName().getString(), configItem);
|
||||||
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
@ -4,10 +4,7 @@
|
|||||||
"refmap": "enchantmentdoesnotconflict.mixins.refmap.json",
|
"refmap": "enchantmentdoesnotconflict.mixins.refmap.json",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"ArrowInfiniteEnchantmentMixin",
|
"EnchantmentMixin"
|
||||||
"ArrowPiercingEnchantmentMixin",
|
|
||||||
"DamageEnchantmentMixin",
|
|
||||||
"ProtectionEnchantmentMixin"
|
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user