Created packet for updating recipes.

This commit is contained in:
2022-01-16 13:33:17 +00:00
parent 2667cdd658
commit 438d543283

View File

@ -0,0 +1,37 @@
package dev.micle.totemofreviving.network;
import dev.micle.totemofreviving.event.UpdateRecipesEventHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.network.NetworkEvent;
import java.util.function.Supplier;
public class UpdateRecipesPacket {
public UpdateRecipesPacket() {}
public static void encode(final UpdateRecipesPacket packet, final PacketBuffer buffer) {
Network.writeVersionInfo(buffer);
}
public static UpdateRecipesPacket decode(final PacketBuffer buffer) {
Network.checkVersion(buffer);
return new UpdateRecipesPacket();
}
public static void handle(final UpdateRecipesPacket packet, final Supplier<NetworkEvent.Context> contextSupplier) {
final NetworkEvent.Context context = contextSupplier.get();
context.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientPacketHandler.handle(packet, contextSupplier));
});
context.setPacketHandled(true);
}
private static class ClientPacketHandler {
private static void handle(UpdateRecipesPacket packet, Supplier<NetworkEvent.Context> contextSupplier) {
UpdateRecipesEventHandler.updateRecipeManager(Minecraft.getInstance().getConnection().getRecipeManager());
}
}
}