Skip to content

Commit

Permalink
Updated Fabric API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Nov 27, 2023
1 parent 7cb50c7 commit 77c3f1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ org.gradle.parallel=true

# Minecraft/Fabric
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.2
loader_version=0.14.23
fabric_api_version=0.90.0+1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.24
fabric_api_version=0.91.1+1.20.2

# Project Details
mod_version=2.9.9-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
import net.fabricmc.fabric.impl.networking.payload.ResolvablePayload;
import net.fabricmc.fabric.impl.networking.payload.UntypedPayload;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.network.listener.ServerPacketListener;
Expand All @@ -43,11 +44,15 @@
@Mixin(value = ClientCommonNetworkHandler.class, priority = 1 /* Has to be applied before Fabric's Networking API, so it doesn't cancel our custom-payload packets */)
public abstract class MixinClientCommonNetworkHandler {

@Shadow @Final protected MinecraftClient client;
@Shadow
@Final
protected MinecraftClient client;

@Shadow protected abstract void send(Packet<? extends ServerPacketListener> packet, BooleanSupplier sendCondition, Duration expiry);
@Shadow
protected abstract void send(Packet<? extends ServerPacketListener> packet, BooleanSupplier sendCondition, Duration expiry);

@Shadow public abstract void sendPacket(Packet<?> packet);
@Shadow
public abstract void sendPacket(Packet<?> packet);

@Inject(method = "onPing", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true)
private void onPing(CommonPingS2CPacket packet, CallbackInfo ci) {
Expand Down Expand Up @@ -78,8 +83,8 @@ public void forceSendKeepAlive(ClientCommonNetworkHandler instance, Packet<? ext

@Inject(method = "onCustomPayload(Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;)V", at = @At("HEAD"), cancellable = true)
public void handleSyncTask(CustomPayloadS2CPacket packet, CallbackInfo ci) {
if (packet.payload().id().toString().equals(ClientsideFixes.PACKET_SYNC_IDENTIFIER) && packet.payload() instanceof PacketByteBufPayload payload) {
ClientsideFixes.handleSyncTask(payload.data());
if (packet.payload().id().toString().equals(ClientsideFixes.PACKET_SYNC_IDENTIFIER) && packet.payload() instanceof ResolvablePayload payload) {
ClientsideFixes.handleSyncTask(((UntypedPayload) payload.resolve(null)).buffer());
ci.cancel(); // Cancel the packet, so it doesn't get processed by the client
}
}
Expand Down

0 comments on commit 77c3f1a

Please sign in to comment.