Parse pony data on the client thread executor, and don't send unparsed pony data responses to a consenting server. Rather wait for the data to resolve and let the entity send it normally.

This commit is contained in:
Sollace 2023-10-27 22:09:55 +01:00
parent 9064272771
commit 8832beac32
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 8 additions and 15 deletions

View file

@ -13,7 +13,6 @@ import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.IPonyData; import com.minelittlepony.api.pony.IPonyData;
import com.minelittlepony.api.pony.network.MsgPonyData; import com.minelittlepony.api.pony.network.MsgPonyData;
import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.MineLittlePony;
@ -38,14 +37,7 @@ public class Channel {
ClientPlayNetworking.registerGlobalReceiver(REQUEST_PONY_DATA, (client, handler, ignored, sender) -> { ClientPlayNetworking.registerGlobalReceiver(REQUEST_PONY_DATA, (client, handler, ignored, sender) -> {
registered = true; registered = true;
if (client.player != null) { LOGGER.info("Server has just consented");
IPony pony = IPony.getManager().getPony(client.player);
LOGGER.info("Server has just consented");
sender.sendPacket(CLIENT_PONY_DATA, new MsgPonyData(pony.metadata(), pony.defaulted()).toBuffer(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) -> { ServerPlayNetworking.registerGlobalReceiver(CLIENT_PONY_DATA, (server, player, ignore, buffer, ignore2) -> {
MsgPonyData packet = new MsgPonyData(buffer); MsgPonyData packet = new MsgPonyData(buffer);

View file

@ -87,16 +87,17 @@ public class NativeUtil {
} }
public static void parseImage(Identifier resource, Consumer<NativeImage> consumer, Consumer<Exception> fail) { public static void parseImage(Identifier resource, Consumer<NativeImage> consumer, Consumer<Exception> fail) {
parseImage(resource, consumer, fail, 0); MinecraftClient.getInstance().execute(() -> {
}
private static void parseImage(Identifier resource, Consumer<NativeImage> consumer, Consumer<Exception> fail, int attempt) {
try {
if (!RenderSystem.isOnRenderThread()) { if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> parseImage(resource, consumer, fail, attempt)); RenderSystem.recordRenderCall(() -> _parseImage(resource, consumer, fail, 0));
return; return;
} }
_parseImage(resource, consumer, fail, 0);
});
}
private static void _parseImage(Identifier resource, Consumer<NativeImage> consumer, Consumer<Exception> fail, int attempt) {
try {
MinecraftClient mc = MinecraftClient.getInstance(); MinecraftClient mc = MinecraftClient.getInstance();
TextureManager textures = mc.getTextureManager(); TextureManager textures = mc.getTextureManager();