package net.minecraft.data.models.model;

import net.minecraft.core.Registry;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import java.util.Collection;
import java.util.stream.Stream;
import com.google.common.collect.Sets;
import com.google.common.collect.Maps;
import java.util.Set;
import net.minecraft.resources.ResourceLocation;
import java.util.Map;

public class TextureMapping {
    private final Map<TextureSlot, ResourceLocation> slots;
    private final Set<TextureSlot> forcedSlots;
    
    public TextureMapping() {
        this.slots = Maps.newHashMap();
        this.forcedSlots = Sets.newHashSet();
    }
    
    public TextureMapping put(final TextureSlot iz, final ResourceLocation uh) {
        this.slots.put(iz, uh);
        return this;
    }
    
    public Stream<TextureSlot> getForced() {
        return this.forcedSlots.stream();
    }
    
    public TextureMapping copyForced(final TextureSlot iz1, final TextureSlot iz2) {
        this.slots.put(iz2, this.slots.get(iz1));
        this.forcedSlots.add(iz2);
        return this;
    }
    
    public ResourceLocation get(final TextureSlot iz) {
        for (TextureSlot iz2 = iz; iz2 != null; iz2 = iz2.getParent()) {
            final ResourceLocation uh4 = this.slots.get(iz2);
            if (uh4 != null) {
                return uh4;
            }
        }
        throw new IllegalStateException("Can't find texture for slot " + iz);
    }
    
    public TextureMapping copyAndUpdate(final TextureSlot iz, final ResourceLocation uh) {
        final TextureMapping iy4 = new TextureMapping();
        iy4.slots.putAll(this.slots);
        iy4.forcedSlots.addAll(this.forcedSlots);
        iy4.put(iz, uh);
        return iy4;
    }
    
    public static TextureMapping cube(final Block bvr) {
        final ResourceLocation uh2 = getBlockTexture(bvr);
        return cube(uh2);
    }
    
    public static TextureMapping defaultTexture(final Block bvr) {
        final ResourceLocation uh2 = getBlockTexture(bvr);
        return defaultTexture(uh2);
    }
    
    public static TextureMapping defaultTexture(final ResourceLocation uh) {
        return new TextureMapping().put(TextureSlot.TEXTURE, uh);
    }
    
    public static TextureMapping cube(final ResourceLocation uh) {
        return new TextureMapping().put(TextureSlot.ALL, uh);
    }
    
    public static TextureMapping cross(final Block bvr) {
        return singleSlot(TextureSlot.CROSS, getBlockTexture(bvr));
    }
    
    public static TextureMapping cross(final ResourceLocation uh) {
        return singleSlot(TextureSlot.CROSS, uh);
    }
    
    public static TextureMapping plant(final Block bvr) {
        return singleSlot(TextureSlot.PLANT, getBlockTexture(bvr));
    }
    
    public static TextureMapping plant(final ResourceLocation uh) {
        return singleSlot(TextureSlot.PLANT, uh);
    }
    
    public static TextureMapping rail(final Block bvr) {
        return singleSlot(TextureSlot.RAIL, getBlockTexture(bvr));
    }
    
    public static TextureMapping rail(final ResourceLocation uh) {
        return singleSlot(TextureSlot.RAIL, uh);
    }
    
    public static TextureMapping wool(final Block bvr) {
        return singleSlot(TextureSlot.WOOL, getBlockTexture(bvr));
    }
    
    public static TextureMapping stem(final Block bvr) {
        return singleSlot(TextureSlot.STEM, getBlockTexture(bvr));
    }
    
    public static TextureMapping attachedStem(final Block bvr1, final Block bvr2) {
        return new TextureMapping().put(TextureSlot.STEM, getBlockTexture(bvr1)).put(TextureSlot.UPPER_STEM, getBlockTexture(bvr2));
    }
    
    public static TextureMapping pattern(final Block bvr) {
        return singleSlot(TextureSlot.PATTERN, getBlockTexture(bvr));
    }
    
    public static TextureMapping fan(final Block bvr) {
        return singleSlot(TextureSlot.FAN, getBlockTexture(bvr));
    }
    
    public static TextureMapping crop(final ResourceLocation uh) {
        return singleSlot(TextureSlot.CROP, uh);
    }
    
    public static TextureMapping pane(final Block bvr1, final Block bvr2) {
        return new TextureMapping().put(TextureSlot.PANE, getBlockTexture(bvr1)).put(TextureSlot.EDGE, getBlockTexture(bvr2, "_top"));
    }
    
    public static TextureMapping singleSlot(final TextureSlot iz, final ResourceLocation uh) {
        return new TextureMapping().put(iz, uh);
    }
    
    public static TextureMapping column(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.END, getBlockTexture(bvr, "_top"));
    }
    
    public static TextureMapping cubeTop(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.TOP, getBlockTexture(bvr, "_top"));
    }
    
    public static TextureMapping logColumn(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr)).put(TextureSlot.END, getBlockTexture(bvr, "_top"));
    }
    
    public static TextureMapping column(final ResourceLocation uh1, final ResourceLocation uh2) {
        return new TextureMapping().put(TextureSlot.SIDE, uh1).put(TextureSlot.END, uh2);
    }
    
    public static TextureMapping cubeBottomTop(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.TOP, getBlockTexture(bvr, "_top")).put(TextureSlot.BOTTOM, getBlockTexture(bvr, "_bottom"));
    }
    
    public static TextureMapping cubeBottomTopWithWall(final Block bvr) {
        final ResourceLocation uh2 = getBlockTexture(bvr);
        return new TextureMapping().put(TextureSlot.WALL, uh2).put(TextureSlot.SIDE, uh2).put(TextureSlot.TOP, getBlockTexture(bvr, "_top")).put(TextureSlot.BOTTOM, getBlockTexture(bvr, "_bottom"));
    }
    
    public static TextureMapping columnWithWall(final Block bvr) {
        final ResourceLocation uh2 = getBlockTexture(bvr);
        return new TextureMapping().put(TextureSlot.WALL, uh2).put(TextureSlot.SIDE, uh2).put(TextureSlot.END, getBlockTexture(bvr, "_top"));
    }
    
    public static TextureMapping door(final Block bvr) {
        return new TextureMapping().put(TextureSlot.TOP, getBlockTexture(bvr, "_top")).put(TextureSlot.BOTTOM, getBlockTexture(bvr, "_bottom"));
    }
    
    public static TextureMapping particle(final Block bvr) {
        return new TextureMapping().put(TextureSlot.PARTICLE, getBlockTexture(bvr));
    }
    
    public static TextureMapping particle(final ResourceLocation uh) {
        return new TextureMapping().put(TextureSlot.PARTICLE, uh);
    }
    
    public static TextureMapping fire0(final Block bvr) {
        return new TextureMapping().put(TextureSlot.FIRE, getBlockTexture(bvr, "_0"));
    }
    
    public static TextureMapping fire1(final Block bvr) {
        return new TextureMapping().put(TextureSlot.FIRE, getBlockTexture(bvr, "_1"));
    }
    
    public static TextureMapping lantern(final Block bvr) {
        return new TextureMapping().put(TextureSlot.LANTERN, getBlockTexture(bvr));
    }
    
    public static TextureMapping torch(final Block bvr) {
        return new TextureMapping().put(TextureSlot.TORCH, getBlockTexture(bvr));
    }
    
    public static TextureMapping torch(final ResourceLocation uh) {
        return new TextureMapping().put(TextureSlot.TORCH, uh);
    }
    
    public static TextureMapping particleFromItem(final Item bke) {
        return new TextureMapping().put(TextureSlot.PARTICLE, getItemTexture(bke));
    }
    
    public static TextureMapping commandBlock(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.FRONT, getBlockTexture(bvr, "_front")).put(TextureSlot.BACK, getBlockTexture(bvr, "_back"));
    }
    
    public static TextureMapping orientableCube(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.FRONT, getBlockTexture(bvr, "_front")).put(TextureSlot.TOP, getBlockTexture(bvr, "_top")).put(TextureSlot.BOTTOM, getBlockTexture(bvr, "_bottom"));
    }
    
    public static TextureMapping orientableCubeOnlyTop(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.FRONT, getBlockTexture(bvr, "_front")).put(TextureSlot.TOP, getBlockTexture(bvr, "_top"));
    }
    
    public static TextureMapping orientableCubeSameEnds(final Block bvr) {
        return new TextureMapping().put(TextureSlot.SIDE, getBlockTexture(bvr, "_side")).put(TextureSlot.FRONT, getBlockTexture(bvr, "_front")).put(TextureSlot.END, getBlockTexture(bvr, "_end"));
    }
    
    public static TextureMapping top(final Block bvr) {
        return new TextureMapping().put(TextureSlot.TOP, getBlockTexture(bvr, "_top"));
    }
    
    public static TextureMapping craftingTable(final Block bvr1, final Block bvr2) {
        return new TextureMapping().put(TextureSlot.PARTICLE, getBlockTexture(bvr1, "_front")).put(TextureSlot.DOWN, getBlockTexture(bvr2)).put(TextureSlot.UP, getBlockTexture(bvr1, "_top")).put(TextureSlot.NORTH, getBlockTexture(bvr1, "_front")).put(TextureSlot.EAST, getBlockTexture(bvr1, "_side")).put(TextureSlot.SOUTH, getBlockTexture(bvr1, "_side")).put(TextureSlot.WEST, getBlockTexture(bvr1, "_front"));
    }
    
    public static TextureMapping fletchingTable(final Block bvr1, final Block bvr2) {
        return new TextureMapping().put(TextureSlot.PARTICLE, getBlockTexture(bvr1, "_front")).put(TextureSlot.DOWN, getBlockTexture(bvr2)).put(TextureSlot.UP, getBlockTexture(bvr1, "_top")).put(TextureSlot.NORTH, getBlockTexture(bvr1, "_front")).put(TextureSlot.SOUTH, getBlockTexture(bvr1, "_front")).put(TextureSlot.EAST, getBlockTexture(bvr1, "_side")).put(TextureSlot.WEST, getBlockTexture(bvr1, "_side"));
    }
    
    public static TextureMapping campfire(final Block bvr) {
        return new TextureMapping().put(TextureSlot.LIT_LOG, getBlockTexture(bvr, "_log_lit")).put(TextureSlot.FIRE, getBlockTexture(bvr, "_fire"));
    }
    
    public static TextureMapping layer0(final Item bke) {
        return new TextureMapping().put(TextureSlot.LAYER0, getItemTexture(bke));
    }
    
    public static TextureMapping layer0(final Block bvr) {
        return new TextureMapping().put(TextureSlot.LAYER0, getBlockTexture(bvr));
    }
    
    public static TextureMapping layer0(final ResourceLocation uh) {
        return new TextureMapping().put(TextureSlot.LAYER0, uh);
    }
    
    public static ResourceLocation getBlockTexture(final Block bvr) {
        final ResourceLocation uh2 = Registry.BLOCK.getKey(bvr);
        return new ResourceLocation(uh2.getNamespace(), "block/" + uh2.getPath());
    }
    
    public static ResourceLocation getBlockTexture(final Block bvr, final String string) {
        final ResourceLocation uh3 = Registry.BLOCK.getKey(bvr);
        return new ResourceLocation(uh3.getNamespace(), "block/" + uh3.getPath() + string);
    }
    
    public static ResourceLocation getItemTexture(final Item bke) {
        final ResourceLocation uh2 = Registry.ITEM.getKey(bke);
        return new ResourceLocation(uh2.getNamespace(), "item/" + uh2.getPath());
    }
    
    public static ResourceLocation getItemTexture(final Item bke, final String string) {
        final ResourceLocation uh3 = Registry.ITEM.getKey(bke);
        return new ResourceLocation(uh3.getNamespace(), "item/" + uh3.getPath() + string);
    }
}
