Created packet for updating recipes.
This commit is contained in:
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user