add 1.20.5

This commit is contained in:
Armamem0t 2025-07-14 00:27:00 +08:00
parent 7dcdd78660
commit 9d8ee3f434
Signed by: minglipro
GPG Key ID: 5F355A77B22AA93B
10 changed files with 84 additions and 74 deletions

View File

@ -30,7 +30,7 @@ processResources {
}
}
def targetJavaVersion = 17
def targetJavaVersion = 21
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {

View File

@ -1,7 +1,7 @@
minecraft_version=1.20.1
minecraft_version=1.20.5
yarn_mappings=build.1
loader_version=0.16.10
mod_version=1.0
mod_version=1.1
maven_group=com.mingliqiye.minecraft.enchantment.conflict
archives_base_name=enchantmentdoesnotconflict
fabric_version=0.92.6
fabric_version=0.97.8

View File

@ -1,13 +1,13 @@
package com.mingliqiye.minecraft.enchantment.conflict;
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.server.MinecraftServer;
public class Mod implements ModInitializer {
public static String MOD_ID = "enchantmentdoesnotconflict";
@Override
public void onInitialize() {
ConfigPayload.initializeServer();
}
}

View File

@ -1,11 +1,11 @@
package com.mingliqiye.minecraft.enchantment.conflict.client;
import com.mingliqiye.minecraft.enchantment.conflict.network.NetworkHandler;
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
import net.fabricmc.api.ClientModInitializer;
public class ModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
NetworkHandler.registerReceivers();
ConfigPayload.initializeClient();
}
}

View File

@ -13,17 +13,15 @@ import java.nio.file.Path;
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();
private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve(MOD_ID + ".json");
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
private static ModConfig instance;
private boolean allowDamageEnchantment = true;
private boolean allowInfinityEnchantment = true;
private boolean allowPiercingEnchantment = true;
private boolean allowProtectionEnchantmentMixin = true;
private boolean allowProtectionEnchantment = true;
public ModConfig() {
}
@ -39,8 +37,7 @@ public class ModConfig {
public static ModConfig load() {
try {
if (Files.exists(CONFIG_PATH)) {
return GSON.fromJson(Files.newBufferedReader(CONFIG_PATH),
ModConfig.class);
return GSON.fromJson(Files.newBufferedReader(CONFIG_PATH), ModConfig.class);
}
} catch (IOException e) {
e.printStackTrace();
@ -87,23 +84,19 @@ public class ModConfig {
this.allowPiercingEnchantment = allowPiercingEnchantment;
}
public boolean isAllowProtectionEnchantmentMixin() {
return allowProtectionEnchantmentMixin;
public boolean isAllowProtectionEnchantment() {
return allowProtectionEnchantment;
}
public void setAllowProtectionEnchantmentMixin(
boolean allowProtectionEnchantmentMixin
public void setAllowProtectionEnchantment(
boolean allowProtectionEnchantment
) {
this.allowProtectionEnchantmentMixin = allowProtectionEnchantmentMixin;
this.allowProtectionEnchantment = allowProtectionEnchantment;
}
public String toString() {
return this.getClass().getName() + "(" + "allowDamageEnchantment" +
"=" + allowDamageEnchantment + "," +
"allowInfinityEnchantment" + "=" + allowInfinityEnchantment +
"," + "allowPiercingEnchantment" + "=" +
allowPiercingEnchantment + "," +
"allowProtectionEnchantmentMixin" + "=" +
allowProtectionEnchantmentMixin + ")";
return this.getClass().getName() + "(" + "allowDamageEnchantment" + "=" + allowDamageEnchantment + "," +
"allowInfinityEnchantment" + "=" + allowInfinityEnchantment + "," + "allowPiercingEnchantment" + "=" +
allowPiercingEnchantment + "," + "allowProtectionEnchantment" + "=" + allowProtectionEnchantment + ")";
}
}

View File

@ -1,9 +1,9 @@
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import com.mingliqiye.minecraft.enchantment.conflict.network.NetworkHandler;
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;
@ -15,9 +15,8 @@ public abstract class PlayerManagerMixin {
@Inject(method = "onPlayerConnect" ,at = @At("RETURN"))
private void onPlayerConnect(
ClientConnection connection, ServerPlayerEntity player,
CallbackInfo ci
ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci
){
NetworkHandler.sendConfigToClient(player);
ConfigPayload.sendToPlayer(player);
}
}

View File

@ -20,7 +20,7 @@ public abstract class ProtectionEnchantmentMixin {
@NotNull CallbackInfoReturnable<Boolean> cir
) {
if (enchantment instanceof ProtectionEnchantment) {
cir.setReturnValue(ModConfig.getInstance().isAllowProtectionEnchantmentMixin());
cir.setReturnValue(ModConfig.getInstance().isAllowProtectionEnchantment());
}
}
}

View File

@ -0,0 +1,58 @@
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.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 static com.mingliqiye.minecraft.enchantment.conflict.Mod.MOD_ID;
public record ConfigPayload(ModConfig 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.class)));
@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());
}
}
}

View File

@ -1,40 +0,0 @@
package com.mingliqiye.minecraft.enchantment.conflict.network;
import com.google.gson.Gson;
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import com.mojang.logging.LogUtils;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import com.mingliqiye.minecraft.enchantment.conflict.Mod;
import org.slf4j.Logger;
public class NetworkHandler {
public static final Identifier CONFIG_PACKET_ID = new Identifier(Mod.MOD_ID, "config_packet");
public static final Gson GSON = new Gson();
private static final Logger LOGGER = LogUtils.getLogger();
public static void sendConfigToClient(ServerPlayerEntity player) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeString(GSON.toJson(ModConfig.getInstance()));
ServerPlayNetworking.send(player, NetworkHandler.CONFIG_PACKET_ID, buf);
LOGGER.info("Send Player({}) Server {} config {}", player.getName().getString(), Mod.MOD_ID,
ModConfig.getInstance());
}
public static void registerReceivers() {
ClientPlayNetworking.registerGlobalReceiver(NetworkHandler.CONFIG_PACKET_ID,
(client, handler, buf, responseSender) -> {
ModConfig configData = GSON.fromJson(buf.readString(), ModConfig.class);
client.execute(() -> {
ModConfig.setInstance(configData);
LOGGER.info("Load Server {} config {}", Mod.MOD_ID, configData);
});
});
}
}

View File

@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "com.mingliqiye.minecraft.enchantment.conflict.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"DamageEnchantmentMixin",
"InfinityEnchantmentMixin",