mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
backport to 1.20.3
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SkinShuffleHandshakePayload() implements CustomPacketPayload {
|
||||
|
||||
|
||||
public static final SkinShuffleHandshakePayload INSTANCE = new SkinShuffleHandshakePayload();
|
||||
|
||||
public static final CustomPacketPayload.Type<SkinShuffleHandshakePayload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("handshake"));
|
||||
public static final StreamCodec<FriendlyByteBuf, SkinShuffleHandshakePayload> PACKET_CODEC = StreamCodec.unit(INSTANCE);
|
||||
|
||||
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("handshake");
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomPacketPayload.@NotNull Type<? extends CustomPacketPayload> type() {
|
||||
public @NotNull ResourceLocation id() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,14 @@ package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SkinShuffleSkinRefreshV1Payload(
|
||||
Property textureProperty) implements CustomPacketPayload, SkinShuffleSkinRefreshPayload {
|
||||
|
||||
public static final CustomPacketPayload.Type<SkinShuffleSkinRefreshV1Payload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("refresh"));
|
||||
public static final StreamCodec<FriendlyByteBuf, SkinShuffleSkinRefreshV1Payload> PACKET_CODEC = StreamCodec.of(
|
||||
SkinShuffleSkinRefreshV1Payload::encode,
|
||||
SkinShuffleSkinRefreshV1Payload::decode
|
||||
);
|
||||
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("refresh");
|
||||
|
||||
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV1Payload value) {
|
||||
var textureProperty = value.textureProperty();
|
||||
@@ -22,13 +18,18 @@ public record SkinShuffleSkinRefreshV1Payload(
|
||||
buf.writeUtf(textureProperty.value());
|
||||
buf.writeNullable(textureProperty.signature(), FriendlyByteBuf::writeUtf);
|
||||
}
|
||||
|
||||
|
||||
public static SkinShuffleSkinRefreshV1Payload decode(FriendlyByteBuf buf) {
|
||||
return new SkinShuffleSkinRefreshV1Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readNullable(FriendlyByteBuf::readUtf)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
encode(buf, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResourceLocation id() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,14 @@ package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SkinShuffleSkinRefreshV2Payload(
|
||||
Property textureProperty) implements CustomPacketPayload, SkinShuffleSkinRefreshPayload {
|
||||
|
||||
public static final CustomPacketPayload.Type<SkinShuffleSkinRefreshV2Payload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("skin_refresh"));
|
||||
public static final StreamCodec<FriendlyByteBuf, SkinShuffleSkinRefreshV2Payload> PACKET_CODEC = StreamCodec.of(
|
||||
SkinShuffleSkinRefreshV2Payload::encode,
|
||||
SkinShuffleSkinRefreshV2Payload::decode
|
||||
);
|
||||
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("skin_refresh");
|
||||
|
||||
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV2Payload value) {
|
||||
var textureProperty = value.textureProperty();
|
||||
@@ -36,7 +32,12 @@ public record SkinShuffleSkinRefreshV2Payload(
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
encode(buf, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResourceLocation id() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package net.lionarius.skinrestorer.fabric.compat.skinshuffle;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshPayload;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV1Payload;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV2Payload;
|
||||
import net.lionarius.skinrestorer.fabric.SkinRestorerFabric;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
|
||||
public final class SkinShuffleCompatibility {
|
||||
|
||||
@@ -20,18 +23,24 @@ public final class SkinShuffleCompatibility {
|
||||
return;
|
||||
}
|
||||
|
||||
PayloadTypeRegistry.playS2C().register(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC);
|
||||
PayloadTypeRegistry.playC2S().register(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC);
|
||||
PayloadTypeRegistry.playC2S().register(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC);
|
||||
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.onPlayerJoin(handler.getPlayer()));
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshPacket);
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshV1Packet);
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshPacket);
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshV2Packet);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, ServerPlayNetworking.Context context) {
|
||||
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(context.player().getServer(), context.player(), payload);
|
||||
private static void handleSkinRefreshV1Packet(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl listener, FriendlyByteBuf buf, PacketSender sender) {
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.decode(buf);
|
||||
SkinShuffleCompatibility.handleSkinRefreshPacket(payload, server, player);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshV2Packet(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl listener, FriendlyByteBuf buf, PacketSender sender) {
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.decode(buf);
|
||||
SkinShuffleCompatibility.handleSkinRefreshPacket(payload, server, player);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, MinecraftServer server, ServerPlayer player) {
|
||||
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(server, player, payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.lionarius.skinrestorer.fabric.platform;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
|
||||
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public final class FabricCompatibilityHelper implements CompatibilityHelper {
|
||||
@Override
|
||||
public void skinShuffle_sendHandshake(ServerPlayer player) {
|
||||
ServerPlayNetworking.send(player, SkinShuffleHandshakePayload.INSTANCE);
|
||||
player.connection.send(new ServerboundCustomPayloadPacket(SkinShuffleHandshakePayload.INSTANCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,14 @@ mixin {
|
||||
|
||||
jarJar.enable()
|
||||
|
||||
tasks.named('jar') {
|
||||
archiveClassifier = 'thin'
|
||||
}
|
||||
|
||||
tasks.named('jarJar') {
|
||||
archiveClassifier = ''
|
||||
}
|
||||
|
||||
jar.finalizedBy('jarJar')
|
||||
|
||||
minecraft {
|
||||
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
|
||||
|
||||
|
||||
@@ -14,18 +14,18 @@ public class SkinShufflePacketHandler {
|
||||
}
|
||||
|
||||
private static final EventNetworkChannel HANDSHAKE_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleHandshakePayload.PACKET_ID.id())
|
||||
.named(SkinShuffleHandshakePayload.PACKET_ID)
|
||||
.optional()
|
||||
.eventNetworkChannel();
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID.id())
|
||||
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID)
|
||||
.optional()
|
||||
.eventNetworkChannel()
|
||||
.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID.id())
|
||||
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID)
|
||||
.optional()
|
||||
.eventNetworkChannel()
|
||||
.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
|
||||
@@ -39,12 +39,12 @@ public class SkinShufflePacketHandler {
|
||||
}
|
||||
|
||||
private static void skinRefreshV1Listener(CustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.PACKET_CODEC.decode(event.getPayload());
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void skinRefreshV2Listener(CustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.PACKET_CODEC.decode(event.getPayload());
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
|
||||
public final class SkinShuffleCompatibility {
|
||||
@@ -11,7 +9,6 @@ public final class SkinShuffleCompatibility {
|
||||
public static void initialize() {
|
||||
NeoForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||
|
||||
final var mod = ModList.get().getModContainerById(SkinRestorer.MOD_ID).get();
|
||||
mod.getEventBus().register(SkinShuffleModEventHandler.class);
|
||||
SkinShufflePacketHandler.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.neoforged.neoforge.network.registration.HandlerThread;
|
||||
|
||||
public final class SkinShuffleModEventHandler {
|
||||
private SkinShuffleModEventHandler() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterPayloadHandlers(RegisterPayloadHandlersEvent event) {
|
||||
final var registrar = event.registrar("1").optional().executesOn(HandlerThread.NETWORK);
|
||||
|
||||
registrar
|
||||
.playToClient(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC,
|
||||
(payload, context) -> {})
|
||||
.playToServer(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC,
|
||||
SkinShuffleModEventHandler::handleSkinRefreshPacket)
|
||||
.playToServer(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC,
|
||||
SkinShuffleModEventHandler::handleSkinRefreshPacket);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, IPayloadContext context) {
|
||||
var player = (ServerPlayer) context.player();
|
||||
SkinShuffleCompatibility.handleSkinRefresh(player.getServer(), player, payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||
import net.neoforged.neoforge.network.NetworkEvent;
|
||||
import net.neoforged.neoforge.network.NetworkRegistry;
|
||||
import net.neoforged.neoforge.network.event.EventNetworkChannel;
|
||||
|
||||
public final class SkinShufflePacketHandler {
|
||||
private SkinShufflePacketHandler() {
|
||||
}
|
||||
|
||||
// there is no need for handshake channel but register it to not allow other mods to use it
|
||||
private static final EventNetworkChannel HANDSHAKE_INSTANCE = NetworkRegistry.ChannelBuilder
|
||||
.named(SkinShuffleHandshakePayload.PACKET_ID)
|
||||
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.eventNetworkChannel();
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = NetworkRegistry.ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID)
|
||||
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.eventNetworkChannel();
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = NetworkRegistry.ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID)
|
||||
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.eventNetworkChannel();
|
||||
|
||||
static void initialize() {
|
||||
SKIN_REFRESH_V1_INSTANCE.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
|
||||
SKIN_REFRESH_V2_INSTANCE.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
|
||||
}
|
||||
|
||||
private static void skinRefreshV1Listener(NetworkEvent.ServerCustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void skinRefreshV2Listener(NetworkEvent.ServerCustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, NetworkEvent.Context context) {
|
||||
var player = context.getSender();
|
||||
SkinShuffleCompatibility.handleSkinRefresh(player.getServer(), player, payload);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,6 @@ public final class NeoForgeCompatibilityHelper implements CompatibilityHelper {
|
||||
@Override
|
||||
public void skinShuffle_sendHandshake(ServerPlayer player) {
|
||||
// we can't use the packet distributor here because neoforge doesn't support sending packets to non-neoforge players
|
||||
player.connection.getConnection().send(new ClientboundCustomPayloadPacket(SkinShuffleHandshakePayload.INSTANCE));
|
||||
player.connection.connection.send(new ClientboundCustomPayloadPacket(SkinShuffleHandshakePayload.INSTANCE));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user