add 1.21.7
This commit is contained in:
parent
a512e6de59
commit
58dd14fa45
@ -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()) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
minecraft_version=1.20.1
|
||||
yarn_mappings=build.1
|
||||
loader_version=0.16.10
|
||||
minecraft_version=1.21.7
|
||||
yarn_mappings=build.7
|
||||
loader_version=0.16.13
|
||||
mod_version=1.0
|
||||
maven_group=com.mingliqiye.minecraft.enchantment.conflict
|
||||
archives_base_name=enchantmentdoesnotconflict
|
||||
fabric_version=0.92.6
|
||||
fabric_version=0.128.0
|
||||
|
@ -1,30 +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";
|
||||
public static final String PROTOCOL_VERSION = "1.0";
|
||||
private static MinecraftServer MINECRAFTSERVER;
|
||||
|
||||
public static MinecraftServer getMinecraftServer(){
|
||||
return MINECRAFTSERVER;
|
||||
}
|
||||
|
||||
public static boolean isClient(){
|
||||
return MINECRAFTSERVER.getOverworld().isClient();
|
||||
}
|
||||
public static boolean isServer(){
|
||||
return !MINECRAFTSERVER.getOverworld().isClient();
|
||||
}
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(
|
||||
(server) -> {
|
||||
MINECRAFTSERVER = server;
|
||||
});
|
||||
ConfigPayload.initializeServer();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.client;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.network.ClientNetworkHandler;
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class ModClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ClientNetworkHandler.registerReceivers();
|
||||
ConfigPayload.initializeClient();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class ModConfig {
|
||||
private boolean allowDamageEnchantment = true;
|
||||
private boolean allowInfinityEnchantment = true;
|
||||
private boolean allowPiercingEnchantment = true;
|
||||
private boolean allowProtectionEnchantmentMixin = true;
|
||||
private boolean allowProtectionEnchantment = true;
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
public ModConfig() {
|
||||
@ -89,15 +89,6 @@ public class ModConfig {
|
||||
this.allowPiercingEnchantment = allowPiercingEnchantment;
|
||||
}
|
||||
|
||||
public boolean isAllowProtectionEnchantmentMixin() {
|
||||
return allowProtectionEnchantmentMixin;
|
||||
}
|
||||
|
||||
public void setAllowProtectionEnchantmentMixin(
|
||||
boolean allowProtectionEnchantmentMixin
|
||||
) {
|
||||
this.allowProtectionEnchantmentMixin = allowProtectionEnchantmentMixin;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getName() + "(" + "allowDamageEnchantment" +
|
||||
@ -105,7 +96,15 @@ public class ModConfig {
|
||||
"allowInfinityEnchantment" + "=" + allowInfinityEnchantment +
|
||||
"," + "allowPiercingEnchantment" + "=" +
|
||||
allowPiercingEnchantment + "," +
|
||||
"allowProtectionEnchantmentMixin" + "=" +
|
||||
allowProtectionEnchantmentMixin + ")";
|
||||
"allowProtectionEnchantment" + "=" +
|
||||
allowProtectionEnchantment + ")";
|
||||
}
|
||||
|
||||
public boolean isAllowProtectionEnchantment() {
|
||||
return allowProtectionEnchantment;
|
||||
}
|
||||
|
||||
public void setAllowProtectionEnchantment(boolean allowProtectionEnchantment) {
|
||||
this.allowProtectionEnchantment = allowProtectionEnchantment;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DamageEnchantment extends Enchantment {
|
||||
|
||||
private final String id;
|
||||
|
||||
public DamageEnchantment(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private final static List<String> enchantmentIds =
|
||||
Arrays.asList("minecraft:sharpness", "minecraft:smite", "minecraft:bane_of_arthropods", "minecraft:density",
|
||||
"minecraft:breach");
|
||||
|
||||
public static DamageEnchantment ofId(String id) {
|
||||
if (enchantmentIds.contains(id)) {
|
||||
return new DamageEnchantment(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean canBeCombined(Enchantment enchantment) {
|
||||
if (enchantment instanceof DamageEnchantment) {
|
||||
return ModConfig.getInstance().isAllowDamageEnchantment();
|
||||
}
|
||||
return super.canBeCombined(enchantment);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||
|
||||
public abstract class Enchantment {
|
||||
public Boolean canBeCombined(Enchantment enchantment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract String getId();
|
||||
|
||||
public static Enchantment ofId(String id) {
|
||||
DamageEnchantment damageEnchantment = DamageEnchantment.ofId(id);
|
||||
if (damageEnchantment != null) {
|
||||
return damageEnchantment;
|
||||
}
|
||||
InfinityEnchantment infinityEnchantment = InfinityEnchantment.ofId(id);
|
||||
if (infinityEnchantment != null) {
|
||||
return infinityEnchantment;
|
||||
}
|
||||
PiercingEnchantment piercingEnchantment = PiercingEnchantment.ofId(id);
|
||||
if (piercingEnchantment != null) {
|
||||
return piercingEnchantment;
|
||||
}
|
||||
return ProtectionEnchantment.ofId(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class InfinityEnchantment extends Enchantment {
|
||||
private final String id;
|
||||
|
||||
private InfinityEnchantment(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private static final List<String> enchantmentIds =
|
||||
Arrays.asList("minecraft:infinity","minecraft:mending");
|
||||
|
||||
public static InfinityEnchantment ofId(String id) {
|
||||
if (enchantmentIds.contains(id)) {
|
||||
return new InfinityEnchantment(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canBeCombined(Enchantment enchantment) {
|
||||
if (enchantment instanceof InfinityEnchantment) {
|
||||
return ModConfig.getInstance().isAllowInfinityEnchantment();
|
||||
}
|
||||
return super.canBeCombined(enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PiercingEnchantment extends Enchantment {
|
||||
private final String id;
|
||||
|
||||
private PiercingEnchantment(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private static final List<String> enchantmentIds =
|
||||
Arrays.asList("minecraft:piercing","minecraft:multishot");
|
||||
|
||||
public static PiercingEnchantment ofId(String id) {
|
||||
if (enchantmentIds.contains(id)) {
|
||||
return new PiercingEnchantment(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canBeCombined(Enchantment enchantment) {
|
||||
if (enchantment instanceof PiercingEnchantment) {
|
||||
return ModConfig.getInstance().isAllowPiercingEnchantment();
|
||||
}
|
||||
return super.canBeCombined(enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.enchantment;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ProtectionEnchantment extends Enchantment {
|
||||
private final String id;
|
||||
|
||||
private ProtectionEnchantment(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private static final List<String> enchantmentIds =
|
||||
Arrays.asList(
|
||||
"minecraft:protection",
|
||||
"minecraft:fire_protection",
|
||||
"minecraft:blast_protection",
|
||||
"minecraft:projectile_protection"
|
||||
);
|
||||
|
||||
public static ProtectionEnchantment ofId(String id) {
|
||||
if (enchantmentIds.contains(id)) {
|
||||
return new ProtectionEnchantment(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canBeCombined(Enchantment enchantment) {
|
||||
if (enchantment instanceof ProtectionEnchantment) {
|
||||
return ModConfig.getInstance().isAllowProtectionEnchantment();
|
||||
}
|
||||
return super.canBeCombined(enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
import net.minecraft.enchantment.DamageEnchantment;
|
||||
import net.minecraft.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 = "canAccept", 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,33 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Enchantment.class)
|
||||
public abstract class EnchantmentMixin {
|
||||
@Unique
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
|
||||
@Inject(method = "canBeCombined", at = @At("HEAD"), cancellable = true)
|
||||
private static void canBeCombined(
|
||||
RegistryEntry<Enchantment> first, RegistryEntry<Enchantment> second,
|
||||
CallbackInfoReturnable<Boolean> cir
|
||||
) {
|
||||
com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment firste =
|
||||
com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment.ofId(first.getIdAsString());
|
||||
com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment seconde =
|
||||
com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment.ofId(second.getIdAsString());
|
||||
if (firste == null || seconde == null) {
|
||||
return;
|
||||
}
|
||||
cir.setReturnValue(firste.canBeCombined(seconde));
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.InfinityEnchantment;
|
||||
import net.minecraft.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(InfinityEnchantment.class)
|
||||
public abstract class InfinityEnchantmentMixin {
|
||||
|
||||
@Inject(method = "canAccept", 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.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.enchantment.PiercingEnchantment;
|
||||
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(PiercingEnchantment.class)
|
||||
public abstract class PiercingEnchantmentMixin {
|
||||
|
||||
@Inject(method = "canAccept", 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,9 +1,11 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.network.ServerNetWorkSender;
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.network.ConfigPayload;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
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;
|
||||
@ -13,11 +15,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(PlayerManager.class)
|
||||
public abstract class PlayerManagerMixin {
|
||||
|
||||
@Inject(method = "onPlayerConnect" ,at = @At("RETURN"))
|
||||
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
|
||||
private void onPlayerConnect(
|
||||
ClientConnection connection, ServerPlayerEntity player,
|
||||
ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData,
|
||||
CallbackInfo ci
|
||||
){
|
||||
ServerNetWorkSender.sendConfigToClient(player, ModConfig.getInstance());
|
||||
) {
|
||||
ConfigPayload.sendToPlayer(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.mixin;
|
||||
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
import net.minecraft.enchantment.ProtectionEnchantment;
|
||||
import net.minecraft.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(ProtectionEnchantment.class)
|
||||
public abstract class ProtectionEnchantmentMixin {
|
||||
|
||||
@Inject(method = "canAccept", at = @At("HEAD"), cancellable = true)
|
||||
|
||||
private void onCheckCompatibility(
|
||||
@NotNull Enchantment enchantment,
|
||||
@NotNull CallbackInfoReturnable<Boolean> cir
|
||||
) {
|
||||
if (enchantment instanceof ProtectionEnchantment) {
|
||||
cir.setReturnValue(ModConfig.getInstance().isAllowProtectionEnchantmentMixin());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ClientNetworkHandler {
|
||||
|
||||
public static void registerReceivers() {
|
||||
ClientPlayNetworking.registerGlobalReceiver(
|
||||
NetworkHandler.CONFIG_PACKET_ID,
|
||||
(client, handler, buf, responseSender) -> {
|
||||
JsonElement configData =
|
||||
JsonParser.parseString(buf.readString());
|
||||
client.execute(() -> handleConfigPacket(configData));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static void handleConfigPacket(JsonElement configData) {
|
||||
ModConfig config = new Gson().fromJson(configData, ModConfig.class);
|
||||
ModConfig.setInstance(config);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
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;
|
||||
|
||||
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.toLowerCase(), "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()));
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.network;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.Mod;
|
||||
|
||||
public class NetworkHandler {
|
||||
public static final Identifier
|
||||
CONFIG_PACKET_ID = new Identifier(Mod.MOD_ID, "config_packet");
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.mingliqiye.minecraft.enchantment.conflict.network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
@Environment(EnvType.SERVER)
|
||||
public class ServerNetWorkSender {
|
||||
public static void sendConfigToClient(ServerPlayerEntity player, ModConfig config) {
|
||||
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
|
||||
buf.writeString(new Gson().toJson(config));
|
||||
ServerPlayNetworking.send(player, NetworkHandler.CONFIG_PACKET_ID, buf);
|
||||
}
|
||||
}
|
@ -4,11 +4,8 @@
|
||||
"package": "com.mingliqiye.minecraft.enchantment.conflict.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"DamageEnchantmentMixin",
|
||||
"InfinityEnchantmentMixin",
|
||||
"PiercingEnchantmentMixin",
|
||||
"PlayerManagerMixin",
|
||||
"ProtectionEnchantmentMixin"
|
||||
"EnchantmentMixin",
|
||||
"PlayerManagerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user