package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.util.Iterator;
import java.io.IOException;
import com.google.common.collect.Lists;
import net.minecraft.network.FriendlyByteBuf;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import net.minecraft.resources.ResourceLocation;
import java.util.List;
import net.minecraft.network.protocol.Packet;

public class ClientboundRecipePacket implements Packet<ClientGamePacketListener> {
    private State state;
    private List<ResourceLocation> recipes;
    private List<ResourceLocation> toHighlight;
    private boolean guiOpen;
    private boolean filteringCraftable;
    private boolean furnaceGuiOpen;
    private boolean furnaceFilteringCraftable;
    
    public ClientboundRecipePacket() {
    }
    
    public ClientboundRecipePacket(final State a, final Collection<ResourceLocation> collection2, final Collection<ResourceLocation> collection3, final boolean boolean4, final boolean boolean5, final boolean boolean6, final boolean boolean7) {
        this.state = a;
        this.recipes = ImmutableList.copyOf(collection2);
        this.toHighlight = ImmutableList.copyOf(collection3);
        this.guiOpen = boolean4;
        this.filteringCraftable = boolean5;
        this.furnaceGuiOpen = boolean6;
        this.furnaceFilteringCraftable = boolean7;
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleAddOrRemoveRecipes(this);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.state = kv.<State>readEnum(State.class);
        this.guiOpen = kv.readBoolean();
        this.filteringCraftable = kv.readBoolean();
        this.furnaceGuiOpen = kv.readBoolean();
        this.furnaceFilteringCraftable = kv.readBoolean();
        int integer3 = kv.readVarInt();
        this.recipes = Lists.newArrayList();
        for (int integer4 = 0; integer4 < integer3; ++integer4) {
            this.recipes.add(kv.readResourceLocation());
        }
        if (this.state == State.INIT) {
            integer3 = kv.readVarInt();
            this.toHighlight = Lists.newArrayList();
            for (int integer4 = 0; integer4 < integer3; ++integer4) {
                this.toHighlight.add(kv.readResourceLocation());
            }
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeEnum(this.state);
        kv.writeBoolean(this.guiOpen);
        kv.writeBoolean(this.filteringCraftable);
        kv.writeBoolean(this.furnaceGuiOpen);
        kv.writeBoolean(this.furnaceFilteringCraftable);
        kv.writeVarInt(this.recipes.size());
        for (final ResourceLocation sm4 : this.recipes) {
            kv.writeResourceLocation(sm4);
        }
        if (this.state == State.INIT) {
            kv.writeVarInt(this.toHighlight.size());
            for (final ResourceLocation sm4 : this.toHighlight) {
                kv.writeResourceLocation(sm4);
            }
        }
    }
    
    public List<ResourceLocation> getRecipes() {
        return this.recipes;
    }
    
    public List<ResourceLocation> getHighlights() {
        return this.toHighlight;
    }
    
    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 State getState() {
        return this.state;
    }
    
    public enum State {
        INIT, 
        ADD, 
        REMOVE;
    }
}
