From 26aa16d684fbd3c841be4927fcb5da1d2da6b48b Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 28 Sep 2023 14:38:39 +0100 Subject: [PATCH] Fixed pony skin data not being reliably sent to servers --- .../minelittlepony/api/events/Channel.java | 19 +++++---- .../client/compat/hdskins/DummyPony.java | 8 +--- .../client/mixin/MixinClientPlayerEntity.java | 12 ++---- .../client/render/EquineRenderManager.java | 40 +++++++++++++++---- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/minelittlepony/api/events/Channel.java b/src/main/java/com/minelittlepony/api/events/Channel.java index e885ab4d..1e3d29a2 100644 --- a/src/main/java/com/minelittlepony/api/events/Channel.java +++ b/src/main/java/com/minelittlepony/api/events/Channel.java @@ -8,7 +8,6 @@ import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; @@ -29,7 +28,6 @@ public class Channel { public static void bootstrap() { ClientLoginConnectionEvents.INIT.register((handler, client) -> { registered = false; - LOGGER.info("Resetting registered flag"); }); ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { LOGGER.info("Sending consent packet to " + handler.getPlayer().getName().getString()); @@ -38,12 +36,14 @@ public class Channel { }); ClientPlayNetworking.registerGlobalReceiver(REQUEST_PONY_DATA, (client, handler, ignored, sender) -> { + registered = true; if (client.player != null) { Pony pony = Pony.getManager().getPony(client.player); - registered = true; LOGGER.info("Server has just consented"); sender.sendPacket(CLIENT_PONY_DATA, MsgPonyData.write(pony.metadata(), PacketByteBufs.create())); + } else { + LOGGER.info("Server has just consented but the client player was not set"); } }); ServerPlayNetworking.registerGlobalReceiver(CLIENT_PONY_DATA, (server, player, ignore, buffer, ignore2) -> { @@ -54,20 +54,19 @@ public class Channel { }); } - public static void broadcastPonyData(PonyData packet) { + public static boolean broadcastPonyData(PonyData packet) { if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) { throw new RuntimeException("Client packet send called by the server"); } if (!registered) { - if (MinecraftClient.getInstance().isInSingleplayer() || MinecraftClient.getInstance().isIntegratedServerRunning()) { - LOGGER.info("Sending pony skin data over as we are either in single-player or lan"); - } else { - LOGGER.info("Skipping network packet as the server has not consented"); - return; - } + LOGGER.info("Skipping network packet as the server has not consented"); + return false; + } else { + LOGGER.info("Sending pony data to server for player"); } ClientPlayNetworking.send(CLIENT_PONY_DATA, MsgPonyData.write(packet, PacketByteBufs.create())); + return true; } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/client/compat/hdskins/DummyPony.java b/src/main/java/com/minelittlepony/client/compat/hdskins/DummyPony.java index 87479a2f..059d8a40 100644 --- a/src/main/java/com/minelittlepony/client/compat/hdskins/DummyPony.java +++ b/src/main/java/com/minelittlepony/client/compat/hdskins/DummyPony.java @@ -4,7 +4,6 @@ import net.minecraft.client.world.ClientWorld; import com.minelittlepony.api.model.PreviewModel; import com.minelittlepony.api.pony.*; -import com.minelittlepony.client.render.EquineRenderManager; import com.minelittlepony.hdskins.client.gui.player.*; import com.minelittlepony.hdskins.client.gui.player.skins.PlayerSkins; @@ -13,18 +12,13 @@ import java.util.UUID; /** * Dummy model used for the skin uploading screen. */ -class DummyPony extends DummyPlayer implements PreviewModel, PonyManager.ForcedPony, EquineRenderManager.RegistrationHandler { +class DummyPony extends DummyPlayer implements PreviewModel, PonyManager.ForcedPony { public DummyPony(ClientWorld world, PlayerSkins textures) { super(world, textures); setUuid(UUID.randomUUID()); // uuid must be random so animations aren't linked between the two previews } - @Override - public boolean shouldUpdateRegistration(Pony pony) { - return false; - } - @Override public boolean forceSeapony() { return getTextures().getPosture().getActiveSkinType() == MineLPHDSkins.seaponySkinType; diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java index f16c7491..1926b1bd 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java @@ -9,7 +9,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; -import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,8 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implements EquineRenderManager.RegistrationHandler { public MixinClientPlayerEntity() { super(null, null); } - @Nullable - private Pony pony; + private final EquineRenderManager.SyncedPony syncedPony = new EquineRenderManager.SyncedPony(); @Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN")) private void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable info) { @@ -34,12 +32,8 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implem } @Override - public boolean shouldUpdateRegistration(Pony pony) { - if (this.pony != pony && (this.pony == null || this.pony.metadata().compareTo(pony.metadata()) != 0)) { - this.pony = pony.immutableCopy(); - return true; - } - return false; + public EquineRenderManager.SyncedPony getSyncedPony() { + return syncedPony; } @Override diff --git a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java index 307ffc50..734b6b70 100644 --- a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java +++ b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java @@ -22,6 +22,8 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import org.jetbrains.annotations.Nullable; + public class EquineRenderManager & PonyModel> { private ModelWrapper playerModel; @@ -120,16 +122,31 @@ public class EquineRenderManager