mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 05:48:00 +01:00
Fixed pony skin data not being reliably sent to servers
This commit is contained in:
parent
9f280f79eb
commit
26aa16d684
4 changed files with 45 additions and 34 deletions
|
@ -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;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
LOGGER.info("Sending pony data to server for player");
|
||||
}
|
||||
|
||||
ClientPlayNetworking.send(CLIENT_PONY_DATA, MsgPonyData.write(packet, PacketByteBufs.create()));
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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<Boolean> 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
|
||||
|
|
|
@ -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<T extends LivingEntity, M extends EntityModel<T> & PonyModel<T>> {
|
||||
|
||||
private ModelWrapper<T, M> playerModel;
|
||||
|
@ -120,16 +122,31 @@ public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T
|
|||
Pony pony = renderer.getEntityPony(entity);
|
||||
playerModel.applyMetadata(pony.metadata());
|
||||
|
||||
if (pony.hasMetadata() && entity instanceof RegistrationHandler && ((RegistrationHandler)entity).shouldUpdateRegistration(pony)) {
|
||||
entity.calculateDimensions();
|
||||
if (entity instanceof PlayerEntity player && entity instanceof RegistrationHandler handler) {
|
||||
SyncedPony synced = handler.getSyncedPony();
|
||||
boolean changed = pony.compareTo(synced.lastRenderedPony) != 0;
|
||||
|
||||
if (changed) {
|
||||
synced.lastRenderedPony = pony;
|
||||
player.calculateDimensions();
|
||||
}
|
||||
|
||||
if (!(player instanceof PreviewModel)) {
|
||||
@Nullable
|
||||
PlayerEntity clientPlayer = MinecraftClient.getInstance().player;
|
||||
if (clientPlayer != null) {
|
||||
if (Objects.equals(entity, clientPlayer) || Objects.equals(((PlayerEntity)entity).getGameProfile(), clientPlayer.getGameProfile())) {
|
||||
Channel.broadcastPonyData(pony.metadata());
|
||||
|
||||
if (pony.compareTo(synced.lastTransmittedPony) != 0) {
|
||||
if (clientPlayer != null && (Objects.equals(player, clientPlayer) || Objects.equals(player.getGameProfile(), clientPlayer.getGameProfile()))) {
|
||||
if (Channel.broadcastPonyData(pony.metadata())) {
|
||||
synced.lastTransmittedPony = pony;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
PonyDataCallback.EVENT.invoker().onPonyDataAvailable(player, pony.metadata(), EnvType.CLIENT);
|
||||
}
|
||||
}
|
||||
PonyDataCallback.EVENT.invoker().onPonyDataAvailable((PlayerEntity)entity, pony.metadata(), EnvType.CLIENT);
|
||||
}
|
||||
|
||||
getModel().updateLivingState(entity, pony, mode);
|
||||
|
@ -169,6 +186,13 @@ public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T
|
|||
}
|
||||
|
||||
public interface RegistrationHandler {
|
||||
boolean shouldUpdateRegistration(Pony pony);
|
||||
SyncedPony getSyncedPony();
|
||||
}
|
||||
|
||||
public static class SyncedPony {
|
||||
@Nullable
|
||||
private Pony lastRenderedPony;
|
||||
@Nullable
|
||||
private Pony lastTransmittedPony;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue