minecraft-src/net/minecraft/network/protocol/game/ClientboundPlaceGhostRecipePacket.java
2025-07-04 01:41:11 +03:00

54 lines
1.6 KiB
Java

package net.minecraft.network.protocol.game;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.RecipeHolder;
public class ClientboundPlaceGhostRecipePacket implements Packet<ClientGamePacketListener> {
public static final StreamCodec<FriendlyByteBuf, ClientboundPlaceGhostRecipePacket> STREAM_CODEC = Packet.codec(
ClientboundPlaceGhostRecipePacket::write, ClientboundPlaceGhostRecipePacket::new
);
private final int containerId;
private final ResourceLocation recipe;
public ClientboundPlaceGhostRecipePacket(int containerId, RecipeHolder<?> recipe) {
this.containerId = containerId;
this.recipe = recipe.id();
}
private ClientboundPlaceGhostRecipePacket(FriendlyByteBuf buffer) {
this.containerId = buffer.readByte();
this.recipe = buffer.readResourceLocation();
}
/**
* Writes the raw packet data to the data stream.
*/
private void write(FriendlyByteBuf byteBuf) {
byteBuf.writeByte(this.containerId);
byteBuf.writeResourceLocation(this.recipe);
}
@Override
public PacketType<ClientboundPlaceGhostRecipePacket> type() {
return GamePacketTypes.CLIENTBOUND_PLACE_GHOST_RECIPE;
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void handle(ClientGamePacketListener handler) {
handler.handlePlaceRecipe(this);
}
public ResourceLocation getRecipe() {
return this.recipe;
}
public int getContainerId() {
return this.containerId;
}
}