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<?> bmu) {
        this.purpose = Purpose.SHOWN;
        this.recipe = bmu.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 mg) throws IOException {
        this.purpose = mg.<Purpose>readEnum(Purpose.class);
        if (this.purpose == Purpose.SHOWN) {
            this.recipe = mg.readResourceLocation();
        }
        else if (this.purpose == Purpose.SETTINGS) {
            this.guiOpen = mg.readBoolean();
            this.filteringCraftable = mg.readBoolean();
            this.furnaceGuiOpen = mg.readBoolean();
            this.furnaceFilteringCraftable = mg.readBoolean();
            this.blastFurnaceGuiOpen = mg.readBoolean();
            this.blastFurnaceFilteringCraftable = mg.readBoolean();
            this.smokerGuiOpen = mg.readBoolean();
            this.smokerFilteringCraftable = mg.readBoolean();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeEnum(this.purpose);
        if (this.purpose == Purpose.SHOWN) {
            mg.writeResourceLocation(this.recipe);
        }
        else if (this.purpose == Purpose.SETTINGS) {
            mg.writeBoolean(this.guiOpen);
            mg.writeBoolean(this.filteringCraftable);
            mg.writeBoolean(this.furnaceGuiOpen);
            mg.writeBoolean(this.furnaceFilteringCraftable);
            mg.writeBoolean(this.blastFurnaceGuiOpen);
            mg.writeBoolean(this.blastFurnaceFilteringCraftable);
            mg.writeBoolean(this.smokerGuiOpen);
            mg.writeBoolean(this.smokerFilteringCraftable);
        }
    }
    
    @Override
    public void handle(final ServerGamePacketListener qz) {
        qz.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;
    }
}
