Make client net handling run on main thread
This commit is contained in:
1 parent
a50a0d7328
commit
059fda49a4
4 files changed
+34
-58
No files matched your search
@@ -7,6 +7,7 @@ import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -16,9 +17,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public abstract class ClientPacketListener_customPacketsMixin
|
||||
{
|
||||
@Shadow private Minecraft minecraft;
|
||||
@Final @Shadow private Minecraft minecraft;
|
||||
|
||||
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||
@Inject(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getIdentifier()Lnet/minecraft/resources/ResourceLocation;"), cancellable = true)
|
||||
private void onOnCustomPayload(ClientboundCustomPayloadPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(packet.getIdentifier()))
|
||||
@@ -39,5 +40,4 @@ public abstract class ClientPacketListener_customPacketsMixin
|
||||
{
|
||||
CarpetClient.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class CarpetClient
|
||||
{
|
||||
public static final Object sync = new Object();
|
||||
public static final int HI = 69;
|
||||
public static final int HELLO = 420;
|
||||
public static final int DATA = 1;
|
||||
@@ -25,14 +24,7 @@ public class CarpetClient
|
||||
|
||||
public static void gameJoined(LocalPlayer player)
|
||||
{
|
||||
synchronized (sync)
|
||||
{
|
||||
clientPlayer = player;
|
||||
// client didn't say hi back yet
|
||||
if (isServerCarpet)
|
||||
ClientNetworkHandler.respondHello();
|
||||
|
||||
}
|
||||
clientPlayer = player;
|
||||
}
|
||||
|
||||
public static void disconnect()
|
||||
|
||||
@@ -87,6 +87,7 @@ public class ClientNetworkHandler
|
||||
});
|
||||
};
|
||||
|
||||
// Ran on the Main Minecraft Thread
|
||||
public static void handleData(FriendlyByteBuf data, LocalPlayer player)
|
||||
{
|
||||
if (data != null)
|
||||
@@ -101,22 +102,19 @@ public class ClientNetworkHandler
|
||||
|
||||
private static void onHi(FriendlyByteBuf data)
|
||||
{
|
||||
synchronized (CarpetClient.sync)
|
||||
CarpetClient.setCarpet();
|
||||
CarpetClient.serverCarpetVersion = data.readUtf(64);
|
||||
if (CarpetSettings.carpetVersion.equals(CarpetClient.serverCarpetVersion))
|
||||
{
|
||||
CarpetClient.setCarpet();
|
||||
CarpetClient.serverCarpetVersion = data.readUtf(64);
|
||||
if (CarpetSettings.carpetVersion.equals(CarpetClient.serverCarpetVersion))
|
||||
{
|
||||
CarpetSettings.LOG.info("Joined carpet server with matching carpet version");
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetSettings.LOG.warn("Joined carpet server with another carpet version: "+CarpetClient.serverCarpetVersion);
|
||||
}
|
||||
if (CarpetClient.getPlayer() != null)
|
||||
respondHello();
|
||||
|
||||
CarpetSettings.LOG.info("Joined carpet server with matching carpet version");
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetSettings.LOG.warn("Joined carpet server with another carpet version: "+CarpetClient.serverCarpetVersion);
|
||||
}
|
||||
// We can ensure that this packet is
|
||||
// processed AFTER the player has joined
|
||||
respondHello();
|
||||
}
|
||||
|
||||
public static void respondHello()
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ShapesRenderer
|
||||
double cameraZ = camera.getPosition().z;
|
||||
boolean entityBoxes = client.getEntityRenderDispatcher().shouldRenderHitBoxes();
|
||||
|
||||
if (shapes.size() != 0) { synchronized (shapes) {
|
||||
if (shapes.size() != 0) {
|
||||
shapes.get(dimensionType).long2ObjectEntrySet().removeIf(
|
||||
entry -> entry.getValue().isExpired(currentTime)
|
||||
);
|
||||
@@ -136,16 +136,15 @@ public class ShapesRenderer
|
||||
matrixStack.popPose();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
|
||||
}}
|
||||
if (labels.size() != 0) { synchronized (labels)
|
||||
{
|
||||
}
|
||||
if (labels.size() != 0) {
|
||||
labels.get(dimensionType).long2ObjectEntrySet().removeIf(
|
||||
entry -> entry.getValue().isExpired(currentTime)
|
||||
);
|
||||
labels.get(dimensionType).values().forEach(s -> {
|
||||
if ( (!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
});
|
||||
}}
|
||||
}
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.enableBlend();
|
||||
@@ -181,43 +180,30 @@ public class ShapesRenderer
|
||||
long key = rshape.key();
|
||||
Map<ResourceKey<Level>, Long2ObjectOpenHashMap<RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> container =
|
||||
rshape.stageDeux()?labels:shapes;
|
||||
synchronized (container)
|
||||
{
|
||||
RenderedShape<?> existing = container.computeIfAbsent(dim, d -> new Long2ObjectOpenHashMap<>()).get(key);
|
||||
if (existing != null)
|
||||
{ // promoting previous shape
|
||||
existing.promoteWith(rshape);
|
||||
}
|
||||
else
|
||||
{
|
||||
container.get(dim).put(key, rshape);
|
||||
}
|
||||
RenderedShape<?> existing = container.computeIfAbsent(dim, d -> new Long2ObjectOpenHashMap<>()).get(key);
|
||||
if (existing != null)
|
||||
{ // promoting previous shape
|
||||
existing.promoteWith(rshape);
|
||||
}
|
||||
else
|
||||
{
|
||||
container.get(dim).put(key, rshape);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void reset()
|
||||
{
|
||||
synchronized (shapes)
|
||||
{
|
||||
shapes.values().forEach(Long2ObjectOpenHashMap::clear);
|
||||
}
|
||||
synchronized (labels)
|
||||
{
|
||||
labels.values().forEach(Long2ObjectOpenHashMap::clear);
|
||||
}
|
||||
shapes.values().forEach(Long2ObjectOpenHashMap::clear);
|
||||
labels.values().forEach(Long2ObjectOpenHashMap::clear);
|
||||
}
|
||||
|
||||
public void renewShapes()
|
||||
{
|
||||
CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
synchronized (shapes)
|
||||
{
|
||||
shapes.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
}
|
||||
synchronized (labels)
|
||||
{
|
||||
labels.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
}
|
||||
shapes.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
labels.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
|
||||
CarpetProfiler.end_current_section(token);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user