package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;

public class ServerboundRecipeBookUpdatePacket implements Packet<ServerGamePacketListener> {
    private Purpose purpose;
    private ResourceLocation recipe;
    private boolean guiOpen;
    private boolean filteringCraftable;
    private boolean furnaceGuiOpen;
    private boolean furnaceFilteringCraftable;
    private boolean blastFurnaceGuiOpen;
    private boolean blastFurnaceFilteringCraftable;
    private boolean smokerGuiOpen;
    private boolean smokerFilteringCraftable;
    
    public ServerboundRecipeBookUpdatePacket() {
    }
    
    public ServerboundRecipeBookUpdatePacket(final Recipe<?> bgw) {
        this.purpose = Purpose.SHOWN;
        this.recipe = bgw.getId();
    }
    
    public ServerboundRecipeBookUpdatePacket(final boolean boolean1, final boolean boolean2, final boolean boolean3, final boolean boolean4, final boolean boolean5, final boolean boolean6) {
        this.purpose = Purpose.SETTINGS;
        this.guiOpen = boolean1;
        this.filteringCraftable = boolean2;
        this.furnaceGuiOpen = boolean3;
        this.furnaceFilteringCraftable = boolean4;
        this.blastFurnaceGuiOpen = boolean5;
        this.blastFurnaceFilteringCraftable = boolean6;
        this.smokerGuiOpen = boolean5;
        this.smokerFilteringCraftable = boolean6;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.purpose = kv.<Purpose>readEnum(Purpose.class);
        if (this.purpose == Purpose.SHOWN) {
            this.recipe = kv.readResourceLocation();
        }
        else if (this.purpose == Purpose.SETTINGS) {
            this.guiOpen = kv.readBoolean();
            this.filteringCraftable = kv.readBoolean();
            this.furnaceGuiOpen = kv.readBoolean();
            this.furnaceFilteringCraftable = kv.readBoolean();
            this.blastFurnaceGuiOpen = kv.readBoolean();
            this.blastFurnaceFilteringCraftable = kv.readBoolean();
            this.smokerGuiOpen = kv.readBoolean();
            this.smokerFilteringCraftable = kv.readBoolean();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeEnum(this.purpose);
        if (this.purpose == Purpose.SHOWN) {
            kv.writeResourceLocation(this.recipe);
        }
        else if (this.purpose == Purpose.SETTINGS) {
            kv.writeBoolean(this.guiOpen);
            kv.writeBoolean(this.filteringCraftable);
            kv.writeBoolean(this.furnaceGuiOpen);
            kv.writeBoolean(this.furnaceFilteringCraftable);
            kv.writeBoolean(this.blastFurnaceGuiOpen);
            kv.writeBoolean(this.blastFurnaceFilteringCraftable);
            kv.writeBoolean(this.smokerGuiOpen);
            kv.writeBoolean(this.smokerFilteringCraftable);
        }
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handleRecipeBookUpdatePacket(this);
    }
    
    public Purpose getPurpose() {
        return this.purpose;
    }
    
    public ResourceLocation getRecipe() {
        return this.recipe;
    }
    
    public boolean isGuiOpen() {
        return this.guiOpen;
    }
    
    public boolean isFilteringCraftable() {
        return this.filteringCraftable;
    }
    
    public boolean isFurnaceGuiOpen() {
        return this.furnaceGuiOpen;
    }
    
    public boolean isFurnaceFilteringCraftable() {
        return this.furnaceFilteringCraftable;
    }
    
    public boolean isBlastFurnaceGuiOpen() {
        return this.blastFurnaceGuiOpen;
    }
    
    public boolean isBlastFurnaceFilteringCraftable() {
        return this.blastFurnaceFilteringCraftable;
    }
    
    public boolean isSmokerGuiOpen() {
        return this.smokerGuiOpen;
    }
    
    public boolean isSmokerFilteringCraftable() {
        return this.smokerFilteringCraftable;
    }
    
    public enum Purpose {
        SHOWN, 
        SETTINGS;
    }
}
