Fabric API

Fabric API

111M Downloads

[1.21.1] CustomIngredientPacketCodec always falls back.

MerchantPug opened this issue ยท 7 comments

commented

Fabric Loader: 0.16.9
Fabric API: 0.108.0+1.21.1

Hello, I've found a bit of an edge case with the class I mentioned in the title.

Whenever a custom ingredient is attempted to be synced, it will always fall back.

I think that this might be because of the current supported ingredients set being cleared unconditionally.

@Inject(
at = {
// Normal target after writing
@At(
value = "INVOKE",
target = "Lnet/minecraft/network/codec/PacketCodec;encode(Ljava/lang/Object;Ljava/lang/Object;)V",
shift = At.Shift.AFTER,
by = 1
),
// In the catch handler in case some exception was thrown
@At(
value = "INVOKE",
target = "net/minecraft/network/packet/Packet.isWritingErrorSkippable()Z"
)
},
method = "encode(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/packet/Packet;Lio/netty/buffer/ByteBuf;)V"
)
private void releasePacketEncoder(ChannelHandlerContext channelHandlerContext, Packet<?> packet, ByteBuf byteBuf, CallbackInfo ci) {
CustomIngredientSync.CURRENT_SUPPORTED_INGREDIENTS.set(null);
}

commented

If anybody is curious on how I found this. I was implementing an EMI plugin that required the custom ingredient data to be sent to the client, so that the remainder stack may be updated.

commented

The mixin is correct and the set is supposed to be cleared unconditionally. CustomIngredientSync.CURRENT_SUPPORTED_INGREDIENTS is set before PacketCodec#encode is called and cleared right after encode is called. If there is an issue with syncing, this mixin is likely not the cause.

commented

This may be because Ingredient.OPTIONAL_PACKET_CODEC is not patched at all by Fabric API, so if any mod uses it to sync an ingredient, custom ingredients will be ignored.