Revert "Hopefully more stable version of the original packet fix"
This reverts commit b21ee9a7e7.
This commit is contained in:
parent
f67fa07546
commit
0d4a12eafe
|
|
@ -11,13 +11,23 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
|
||||
@Mixin(ClientPacketListener.class)
|
||||
@ClientOnlyMixin
|
||||
public class ClientPlayNetHandlerMixin {
|
||||
public class ClientPlayNetHandlerMixin implements IClientNetHandler {
|
||||
private FriendlyByteBuf savedCopy = null;
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason allow the other function to track use of the buffer
|
||||
* @reason Release the packet buffer at the end. Needed in f
|
||||
*/
|
||||
@Redirect(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;"))
|
||||
private FriendlyByteBuf saveCopyForRelease(ClientboundCustomPayloadPacket instance) {
|
||||
return ((IClientNetHandler)instance).getCopiedCustomBuffer();
|
||||
FriendlyByteBuf copy = instance.getData();
|
||||
savedCopy = copy;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FriendlyByteBuf getCopiedCustomBuffer() {
|
||||
FriendlyByteBuf copy = savedCopy;
|
||||
savedCopy = null;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
@Mixin(ClientboundCustomPayloadPacket.class)
|
||||
@ClientOnlyMixin
|
||||
public abstract class SCustomPayloadPlayPacketMixin implements IClientNetHandler {
|
||||
public class SCustomPayloadPlayPacketMixin {
|
||||
@Shadow private FriendlyByteBuf data;
|
||||
|
||||
@Shadow public abstract FriendlyByteBuf getData();
|
||||
|
||||
private FriendlyByteBuf usedByteBuf = null;
|
||||
|
||||
private boolean needsRelease;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
|
||||
|
|
@ -34,25 +30,16 @@ public abstract class SCustomPayloadPlayPacketMixin implements IClientNetHandler
|
|||
this.needsRelease = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FriendlyByteBuf getCopiedCustomBuffer() {
|
||||
FriendlyByteBuf buf = this.getData();
|
||||
usedByteBuf = buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Redirect(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientGamePacketListener;handleCustomPayload(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V"))
|
||||
private void handleAndFree(ClientGamePacketListener instance, ClientboundCustomPayloadPacket sCustomPayloadPlayPacket) {
|
||||
usedByteBuf = null;
|
||||
try {
|
||||
instance.handleCustomPayload(sCustomPayloadPlayPacket);
|
||||
} finally {
|
||||
FriendlyByteBuf buf = usedByteBuf;
|
||||
if(buf != null && buf.refCnt() > 0) {
|
||||
buf.release();
|
||||
}
|
||||
FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer();
|
||||
if(copied != null)
|
||||
copied.release();
|
||||
}
|
||||
if(this.needsRelease && this.data.refCnt() > 0)
|
||||
if(this.needsRelease)
|
||||
this.data.release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user