add 1.20.2 1.20.3 1.20.4

This commit is contained in:
Armamem0t 2025-07-16 11:28:51 +08:00
parent 07f069965b
commit f6b511a8bf
Signed by: minglipro
GPG Key ID: 5F355A77B22AA93B
5 changed files with 37 additions and 23 deletions

View File

@ -2,7 +2,7 @@ plugins {
id 'eclipse' id 'eclipse'
id 'idea' id 'idea'
id 'maven-publish' id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'org.spongepowered.mixin' version '0.7.38' id 'org.spongepowered.mixin' version '0.7.38'
} }
@ -13,6 +13,7 @@ base {
archivesName = mod_id archivesName = mod_id
} }
java.toolchain.languageVersion = JavaLanguageVersion.of(17) java.toolchain.languageVersion = JavaLanguageVersion.of(17)
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'}"

View File

@ -1,10 +1,12 @@
minecraft_version=1.20 org.gradle.jvmargs=-Xmx4096m -Xms2048m -XX:MaxMetaspaceSize=1024m
minecraft_version_range=[1.20,1.20.2) systemProp.file.encoding=UTF-8
forge_version=46.0.14 minecraft_version=1.20.2
forge_version_range=[45,) minecraft_version_range=[1.20,2.20.5)
loader_version_range=[45,) forge_version=48.1.0
forge_version_range=[47,)
loader_version_range=[47,)
mapping_channel=official mapping_channel=official
mapping_version=1.20 mapping_version=1.20.2
mod_id=enchantmentdoesnotconflict mod_id=enchantmentdoesnotconflict
mod_name=EnchantmentDoNotConflictForge mod_name=EnchantmentDoNotConflictForge
mod_license=Apache License 2.0 mod_license=Apache License 2.0

View File

@ -78,5 +78,14 @@ public class ModConfig {
public void setAllowProtectionEnchantment(boolean allowProtectionEnchantment) { public void setAllowProtectionEnchantment(boolean allowProtectionEnchantment) {
this.allowProtectionEnchantment = allowProtectionEnchantment; this.allowProtectionEnchantment = allowProtectionEnchantment;
} }
public String toString() {
return this.getClass().getName() + "(" + "allowDamageEnchantment" +
"=" + allowDamageEnchantment + "," +
"allowInfinityEnchantment" + "=" + allowInfinityEnchantment +
"," + "allowPiercingEnchantment" + "=" +
allowPiercingEnchantment + "," +
"allowProtectionEnchantment" + "=" +
allowProtectionEnchantment + ")";
}
} }
} }

View File

@ -2,16 +2,19 @@ package com.mingliqiye.minecraft.enchantment.conflict.network;
import com.mingliqiye.minecraft.enchantment.conflict.EnchantmentDoNotConflictForge; import com.mingliqiye.minecraft.enchantment.conflict.EnchantmentDoNotConflictForge;
import com.mingliqiye.minecraft.enchantment.conflict.network.message.ConfigMessage; import com.mingliqiye.minecraft.enchantment.conflict.network.message.ConfigMessage;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.Channel;
import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.SimpleChannel;
public class ChannelHander { public class ChannelHander {
private static final String PROTOCOL_VERSION = "1.0"; public static final SimpleChannel CONFIG_CHANNEL_INSTANCE =
public static final SimpleChannel CONFIG_CHANNEL_INSTANCE = NetworkRegistry.newSimpleChannel( ChannelBuilder.named("%s:%s".formatted(EnchantmentDoNotConflictForge.MODID, "config_channel")).networkProtocolVersion(1).clientAcceptedVersions(
new ResourceLocation(EnchantmentDoNotConflictForge.MODID, "config_channel"), () -> PROTOCOL_VERSION, Channel.VersionTest.ACCEPT_MISSING // 允许客户端没有该频道
PROTOCOL_VERSION::equals,(v)->true); .or(Channel.VersionTest.exact(1)))
.serverAcceptedVersions(
Channel.VersionTest.exact(1))
.simpleChannel();
public static final int CONFIG_SYNC = 0; public static final int CONFIG_SYNC = 0;
public static void sendConfig(ServerPlayer player) { public static void sendConfig(ServerPlayer player) {

View File

@ -6,12 +6,11 @@ import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import com.mojang.logging.LogUtils; import com.mojang.logging.LogUtils;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.function.Supplier;
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;
@ -21,8 +20,8 @@ public record ConfigMessage(ModConfig.ConfigItem data) {
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
public static void register() { public static void register() {
CONFIG_CHANNEL_INSTANCE.registerMessage(CONFIG_SYNC, ConfigMessage.class, ConfigMessage::encode, CONFIG_CHANNEL_INSTANCE.messageBuilder(ConfigMessage.class, CONFIG_SYNC, NetworkDirection.PLAY_TO_CLIENT)
ConfigMessage::decode, ConfigMessage::handle); .decoder(ConfigMessage::decode).encoder(ConfigMessage::encode).consumerMainThread(ConfigMessage::handle).add();
} }
public static void encode(ConfigMessage configMessage, FriendlyByteBuf byteBuf) { public static void encode(ConfigMessage configMessage, FriendlyByteBuf byteBuf) {
@ -35,16 +34,16 @@ public record ConfigMessage(ModConfig.ConfigItem data) {
public static void send(ServerPlayer player) { public static void send(ServerPlayer player) {
ModConfig.ConfigItem configItem = ModConfig.getInstance(); ModConfig.ConfigItem configItem = ModConfig.getInstance();
CONFIG_CHANNEL_INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new ConfigMessage(configItem)); 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.getName().getString(), configItem); player.getName().getString(), configItem);
} }
public static void handle(ConfigMessage configMessage, Supplier<NetworkEvent.Context> ctx) { public static void handle(ConfigMessage configMessage, CustomPayloadEvent.Context ctx) {
ctx.get().enqueueWork(() -> { ctx.enqueueWork(() -> {
ModConfig.setInstance(configMessage.data()); ModConfig.setInstance(configMessage.data());
LOGGER.info("Load Server Config {} data={}", EnchantmentDoNotConflictForge.MODID, configMessage.data()); LOGGER.info("Load Server Config {} data={}", EnchantmentDoNotConflictForge.MODID, configMessage.data());
}); });
ctx.get().setPacketHandled(true); ctx.setPacketHandled(true);
} }
} }