Skip to content

Commit

Permalink
optimized when will client send TISCM protocol handshake packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Nov 19, 2023
1 parent 1faf796 commit c49bac2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import carpettisaddition.network.TISCMClientPacketHandler;
import carpettisaddition.network.TISCMCustomPayload;
import carpettisaddition.network.TISCMNetworkUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.network.ClientPlayNetworkHandler;
Expand Down Expand Up @@ -105,15 +106,24 @@ public abstract class ClientPlayNetworkHandlerMixin
//#endif
}

@Inject(method = "onGameJoin", at = @At("RETURN"))
private void playerJoinClientHookOnGameJoin$TISCM(CallbackInfo ci)
{
TISCMClientPacketHandler.getInstance().onConnectedToNewServer();
}

@Inject(method = "onPlayerRespawn", at = @At("RETURN"))
private void playerJoinClientHookOnPlayerRespawn$TISCM(CallbackInfo ci)
@Inject(method = "onCustomPayload", at = @At("HEAD"))
private void sentTISCMHandshakeOnServerBrandPayload(
//#if MC >= 12002
//$$ CustomPayload payload,
//#else
CustomPayloadS2CPacket packet,
//#endif
CallbackInfo ci
)
{
TISCMClientPacketHandler.getInstance().onConnectedToNewServer();
//#if MC >= 12002
//$$ boolean flag = payload instanceof net.minecraft.network.packet.BrandCustomPayload;
//#else
boolean flag = ((CustomPayloadS2CPacketAccessor) packet).getChannel().equals(TISCMNetworkUtils.getServerBrandCustomPayloadId());
//#endif
if (flag)
{
TISCMClientPacketHandler.getInstance().onConnectedToNewServer();
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/carpettisaddition/network/TISCMNetworkUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.network;

import net.minecraft.util.Identifier;

//#if MC >= 12002
//$$ import net.minecraft.network.packet.BrandCustomPayload;
//#else
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
//#endif

public class TISCMNetworkUtils
{
public static Identifier getServerBrandCustomPayloadId()
{
//#if MC >= 12002
//$$ return BrandCustomPayload.ID;
//#else
return CustomPayloadS2CPacket.BRAND;
//#endif
}
}

0 comments on commit c49bac2

Please sign in to comment.