package moe.hazu.tinkeringabnormally.data;

import moe.hazu.tinkeringabnormally.TinkeringAbnormally;
import net.minecraft.data.DataGenerator;
import slimeknights.mantle.fluid.texture.AbstractFluidTextureProvider;
import slimeknights.mantle.fluid.texture.FluidTexture;
import slimeknights.mantle.registration.object.FluidObject;

import static moe.hazu.tinkeringabnormally.TinkeringAbnormally.getResource;

public class FluidTextureProvider extends AbstractFluidTextureProvider {
    public FluidTextureProvider(DataGenerator generator) {
        super(generator, TinkeringAbnormally.MODID);
    }

    @Override
    public void addTextures() {
        ore(TinkeringAbnormally.moltenSpinel);
        alloy(TinkeringAbnormally.moltenNecromium);
    }

    /** Creates a texture using the given fixed name in the fluid folder */
    private FluidTexture.Builder named(FluidObject<?> fluid, String name) {
        return texture(fluid).textures(getResource("fluid/"+name+"/"), false, false);
    }

    /** Length of the molten prefix */
    private static final int MOLTEN_LENGTH = "molten_".length();

    /** Removes the "molten_" prefix from the fluids ID */
    private static String withoutMolten(FluidObject<?> fluid) {
        return fluid.getId().getPath().substring(MOLTEN_LENGTH);
    }

    /** Creates a texture in given subfolder of molten, stripping molten from the name */
    private FluidTexture.Builder moltenFolder(FluidObject<?> fluid, String folder) {
        return named(fluid, "molten/"+folder+"/"+withoutMolten(fluid));
    }

    /** Creates a texture in the ore folder using the given name */
    private FluidTexture.Builder ore(FluidObject<?> fluid) {
        return moltenFolder(fluid, "ore");
    }

    /** Creates a texture in the alloy folder using the given name */
    private FluidTexture.Builder alloy(FluidObject<?> fluid) {
        return moltenFolder(fluid, "alloy");
    }

    @Override
    public String getName() {
        return "Tinkering Abnormally Fluid Texture Providers";
    }
}
