package me.km.items;

import me.km.blocks.ModBlocks;
import net.minecraft.item.Items;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.IItemTier;
import net.minecraft.item.Item;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.BedItem;
import net.minecraft.item.Food;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.HoeItem;
import net.minecraft.item.PotionItem;
import net.minecraft.item.ShovelItem;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ItemTier;
import net.minecraftforge.registries.IForgeRegistry;

public class ModItems {
    // nuggets and ingots
    public static Item copperIngot;
    public static Item copperNugget;

    public static Item tinIngot;
    public static Item tinNugget;

    public static Item bronzeIngot;
    public static Item bronzeNugget;

    public static Item silverIngot;
    public static Item silverNugget;

    // tools and swords
    public static Item copperSword;
    public static Item copperShovel;
    public static Item copperPickaxe;
    public static Item copperAxe;
    public static Item copperHoe;

    public static Item bronzeSword;
    public static Item bronzeShovel;
    public static Item bronzePickaxe;
    public static Item bronzeAxe;
    public static Item bronzeHoe;

    public static Item sling;

    // armor
    public static Item copperHelmet;
    public static Item copperChestplate;
    public static Item copperLeggings;
    public static Item copperBoots;

    public static Item bronzeHelmet;
    public static Item bronzeChestplate;
    public static Item bronzeLeggings;
    public static Item bronzeBoots;

    public static Item cylinder;
    public static Item suitChestplate;
    public static Item suitLeggings;
    public static Item suitBoots;

    public static Item strawHat;

    // sticks
    public static Item woodenStick;
    public static Item stoneStick;
    public static Item copperStick;
    public static Item bronzeStick;
    public static Item ironStick;
    public static Item goldStick;
    public static Item diamondStick;

    // scepters
    public static Item woodenScepter;
    public static Item stoneScepter;
    public static Item copperScepter;
    public static Item bronzeScepter;
    public static Item ironScepter;
    public static Item goldScepter;
    public static Item diamondScepter;

    // dagger
    public static Item woodenDagger;
    public static Item stoneDagger;
    public static Item copperDagger;
    public static Item bronzeDagger;
    public static Item ironDagger;
    public static Item goldDagger;
    public static Item diamondDagger;

    // hammer
    public static Item woodenHammer;
    public static Item stoneHammer;
    public static Item copperHammer;
    public static Item bronzeHammer;
    public static Item ironHammer;
    public static Item goldHammer;
    public static Item diamondHammer;

    // battle axe
    public static Item woodenBattleAxe;
    public static Item stoneBattleAxe;
    public static Item copperBattleAxe;
    public static Item bronzeBattleAxe;
    public static Item ironBattleAxe;
    public static Item goldBattleAxe;
    public static Item diamondBattleAxe;

    // key
    public static Item silverKey;
    public static Item copperKey;
    public static Item bronzeKey;
    public static Item ironKey;
    public static Item goldKey;

    // coins
    public static Item copperCoin;
    public static Item silverCoin;
    public static Item goldCoin;

    // misc
    public static Item realHayBed;
    public static Item hayBundle;
    public static Item batWing;
    public static Item wolfFur;
    public static Item bearBrownFur;
    public static Item bearBlackFur;
    public static Item bearPolarFur;
    public static Item cloth;
    public static Item coarseCloth;
    public static Item gemStone;
    public static Item rawGemStone;
    public static Item flawlessGemStone;
    public static Item scroll;
    public static Item soulStone;
    public static Item piercingStone;
    public static Item shell;

    // food
    public static Item coloredSoup;
    public static Item apricot;
    public static Item friedEgg;
    public static Item mushroomStickRaw;
    public static Item mushroomStickCooked;
    public static Item pear;
    public static Item plum;

    // icons
    public static Item arrowDown;
    public static Item arrowLeft;
    public static Item arrowRight;
    public static Item arrowUp;
    public static Item checkGreen;
    public static Item checkRed;
    public static Item crossGreen;
    public static Item crossRed;
    public static Item minusGreen;
    public static Item minusRed;
    public static Item plusGreen;
    public static Item plusRed;
    public static Item returnGreen;
    public static Item returnRed;
    public static Item gear;

    // herbs
    public static Item herbStrong;
    public static Item herbShadow;
    public static Item herbXp;
    public static Item herbSea;
    public static Item herbGold;
    public static Item herbBreathing;
    public static Item herbFire;
    
    // berry
    public static Item berryBeast;
    public static Item berryCloud;
    public static Item berryGold;
    public static Item berryMagma;
    public static Item berryWork;
    public static Item berryExperience;

    private static Item newSword(IItemTier tier) {
        return new SwordItem(tier, 3, -2.4f, (new Item.Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newShovel(IItemTier tier) {
        return new ShovelItem(tier, 1.5f, -3.0f, (new Item.Properties()).group(ItemGroup.TOOLS));
    }

    private static Item newPickaxe(IItemTier tier) {
        return new ModItemPickaxe(tier, 1, -2.8f, (new Item.Properties()).group(ItemGroup.TOOLS));
    }

    private static Item newAxe(IItemTier tier, int attackDamageIn, float attackSpeedIn) {
        return new ModItemAxe(tier, attackDamageIn, attackSpeedIn, (new Item.Properties()).group(ItemGroup.TOOLS));
    }

    private static Item newHoe(IItemTier tier, float speed) {
        return new HoeItem(tier, speed, (new Item.Properties()).group(ItemGroup.TOOLS));
    }

    private static Item newStick(IItemTier tier) {
        return new SwordItem(tier, 0, -2.3f, (new Item.Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newScepter(IItemTier tier) {
        return new SwordItem(tier, 1, -2.6f, (new Item.Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newHammer(IItemTier tier) {
        return new SwordItem(tier, 4, -3.0f, (new Item.Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newDagger(IItemTier tier) {
        return new SwordItem(tier, 1, -2.2f, (new Item.Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newBattleAxe(IItemTier tier) {
        return new SwordItem(tier, 5, -3.0f, (new Item.Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newArmor(IArmorMaterial am, EquipmentSlotType slot) {
        return new ArmorItem(am, slot, (new Properties()).group(ItemGroup.COMBAT));
    }

    private static Item newItem(ItemGroup group) {
        return new Item(new Properties().group(group));
    }

    private static Item newHerb() {
        return new Item(new Properties().group(ItemGroup.FOOD).food(
                new Food.Builder().hunger(2).saturation(0.1F).setAlwaysEdible().fastToEat().build()));
    }
    
    private static Item newBerry() {
        return new Item(new Properties().group(ItemGroup.FOOD).food(
                new Food.Builder().hunger(2).saturation(0.1F).setAlwaysEdible().fastToEat().build()));
    }

    private static Item newFood(int food, float saturation) {
        return new Item(new Properties().group(ItemGroup.FOOD).food(
                new Food.Builder().hunger(food).saturation(saturation).build()));
    }

    public static void init(IForgeRegistry<Item> r) {
        // nuggets and ingots
        copperIngot = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "copper_ingot");
        copperNugget = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "copper_nugget");

        tinIngot = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "tin_ingot");
        tinNugget = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "tin_nugget");

        bronzeIngot = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "bronze_ingot");
        bronzeNugget = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "bronze_nugget");

        silverIngot = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "silver_ingot");
        silverNugget = register(r, new Item(new Properties().group(ItemGroup.MATERIALS)), "silver_nugget");

        // tools and swords
        copperSword = register(r, newSword(ModItemTier.COPPER), "copper_sword");
        copperShovel = register(r, newShovel(ModItemTier.COPPER), "copper_shovel");
        copperPickaxe = register(r, newPickaxe(ModItemTier.COPPER), "copper_pickaxe");
        copperAxe = register(r, newAxe(ModItemTier.COPPER, 7, -3.1f), "copper_axe");
        copperHoe = register(r, newHoe(ModItemTier.COPPER, -2.0f), "copper_hoe");

        bronzeSword = register(r, newSword(ModItemTier.BRONZE), "bronze_sword");
        bronzeShovel = register(r, newShovel(ModItemTier.BRONZE), "bronze_shovel");
        bronzePickaxe = register(r, newPickaxe(ModItemTier.BRONZE), "bronze_pickaxe");
        bronzeAxe = register(r, newAxe(ModItemTier.BRONZE, 8, -3.0f), "bronze_axe");
        bronzeHoe = register(r, newHoe(ModItemTier.BRONZE, -1.0f), "bronze_hoe");

        sling = register(r, new ItemSling(192), "sling");

        // armor
        copperHelmet = register(r, newArmor(ModArmorMaterial.COPPER, EquipmentSlotType.HEAD), "copper_helmet");
        copperChestplate = register(r, newArmor(ModArmorMaterial.COPPER, EquipmentSlotType.CHEST), "copper_chestplate");
        copperLeggings = register(r, newArmor(ModArmorMaterial.COPPER, EquipmentSlotType.LEGS), "copper_leggings");
        copperBoots = register(r, newArmor(ModArmorMaterial.COPPER, EquipmentSlotType.FEET), "copper_boots");

        bronzeHelmet = register(r, newArmor(ModArmorMaterial.BRONZE, EquipmentSlotType.HEAD), "bronze_helmet");
        bronzeChestplate = register(r, newArmor(ModArmorMaterial.BRONZE, EquipmentSlotType.CHEST), "bronze_chestplate");
        bronzeLeggings = register(r, newArmor(ModArmorMaterial.BRONZE, EquipmentSlotType.LEGS), "bronze_leggings");
        bronzeBoots = register(r, newArmor(ModArmorMaterial.BRONZE, EquipmentSlotType.FEET), "bronze_boots");

        cylinder = register(r, new ItemCylinder(ModArmorMaterial.CYLINDER, new Properties()), "cylinder");
        suitChestplate = register(r, newArmor(ModArmorMaterial.SILK, EquipmentSlotType.CHEST), "suit_chestplate");
        suitLeggings = register(r, newArmor(ModArmorMaterial.SILK, EquipmentSlotType.LEGS), "suit_leggings");
        suitBoots = register(r, newArmor(ModArmorMaterial.SILK, EquipmentSlotType.FEET), "suit_boots");

        strawHat = register(r, new ItemHat(ModArmorMaterial.STRAW, new Properties()), "straw_hat");

        // sticks
        woodenStick = register(r, newStick(ItemTier.WOOD), "wooden_stick");
        stoneStick = register(r, newStick(ItemTier.STONE), "stone_stick");
        copperStick = register(r, newStick(ModItemTier.COPPER), "copper_stick");
        bronzeStick = register(r, newStick(ModItemTier.BRONZE), "bronze_stick");
        ironStick = register(r, newStick(ItemTier.IRON), "iron_stick");
        goldStick = register(r, newStick(ItemTier.GOLD), "golden_stick");
        diamondStick = register(r, newStick(ItemTier.DIAMOND), "diamond_stick");

        // scepter
        woodenScepter = register(r, newScepter(ItemTier.WOOD), "wooden_scepter");
        stoneScepter = register(r, newScepter(ItemTier.STONE), "stone_scepter");
        copperScepter = register(r, newScepter(ModItemTier.COPPER), "copper_scepter");
        bronzeScepter = register(r, newScepter(ModItemTier.BRONZE), "bronze_scepter");
        ironScepter = register(r, newScepter(ItemTier.IRON), "iron_scepter");
        goldScepter = register(r, newScepter(ItemTier.GOLD), "golden_scepter");
        diamondScepter = register(r, newScepter(ItemTier.DIAMOND), "diamond_scepter");

        // dagger
        woodenDagger = register(r, newDagger(ItemTier.WOOD), "wooden_dagger");
        stoneDagger = register(r, newDagger(ItemTier.STONE), "stone_dagger");
        copperDagger = register(r, newDagger(ModItemTier.COPPER), "copper_dagger");
        bronzeDagger = register(r, newDagger(ModItemTier.BRONZE), "bronze_dagger");
        ironDagger = register(r, newDagger(ItemTier.IRON), "iron_dagger");
        goldDagger = register(r, newDagger(ItemTier.GOLD), "golden_dagger");
        diamondDagger = register(r, newDagger(ItemTier.DIAMOND), "diamond_dagger");

        // hammer
        woodenHammer = register(r, newHammer(ItemTier.WOOD), "wooden_hammer");
        stoneHammer = register(r, newHammer(ItemTier.STONE), "stone_hammer");
        copperHammer = register(r, newHammer(ModItemTier.COPPER), "copper_hammer");
        bronzeHammer = register(r, newHammer(ModItemTier.BRONZE), "bronze_hammer");
        ironHammer = register(r, newHammer(ItemTier.IRON), "iron_hammer");
        goldHammer = register(r, newHammer(ItemTier.GOLD), "golden_hammer");
        diamondHammer = register(r, newHammer(ItemTier.DIAMOND), "diamond_hammer");

        // battle axe
        woodenBattleAxe = register(r, newBattleAxe(ItemTier.WOOD), "wooden_battleaxe");
        stoneBattleAxe = register(r, newBattleAxe(ItemTier.STONE), "stone_battleaxe");
        copperBattleAxe = register(r, newBattleAxe(ModItemTier.COPPER), "copper_battleaxe");
        bronzeBattleAxe = register(r, newBattleAxe(ModItemTier.BRONZE), "bronze_battleaxe");
        ironBattleAxe = register(r, newBattleAxe(ItemTier.IRON), "iron_battleaxe");
        goldBattleAxe = register(r, newBattleAxe(ItemTier.GOLD), "golden_battleaxe");
        diamondBattleAxe = register(r, newBattleAxe(ItemTier.DIAMOND), "diamond_battleaxe");

        // key
        silverKey = register(r, new ItemKey(ModItemTier.SILVER), "silver_key");
        copperKey = register(r, new ItemKey(ModItemTier.COPPER), "copper_key");
        bronzeKey = register(r, new ItemKey(ModItemTier.BRONZE), "bronze_key");
        ironKey = register(r, new ItemKey(ItemTier.IRON), "iron_key");
        goldKey = register(r, new ItemKey(ItemTier.GOLD), "golden_key");

        // coins
        copperCoin = register(r, newItem(ItemGroup.MISC), "coin_copper");
        silverCoin = register(r, newItem(ItemGroup.MISC), "coin_silver");
        goldCoin = register(r, newItem(ItemGroup.MISC), "coin_gold");

        // misc
        realHayBed = register(r, new BedItem(ModBlocks.realHayBed, (new Item.Properties()).maxStackSize(1).group(ItemGroup.DECORATIONS)), "real_hay_bed");
        hayBundle = register(r, newItem(ItemGroup.MATERIALS), "hay_bundle");
        batWing = register(r, newItem(ItemGroup.MATERIALS), "bat_wing");
        wolfFur = register(r, newItem(ItemGroup.MATERIALS), "wolf_fur");
        bearBrownFur = register(r, newItem(ItemGroup.MATERIALS), "bear_brown_fur");
        bearBlackFur = register(r, newItem(ItemGroup.MATERIALS), "bear_black_fur");
        bearPolarFur = register(r, newItem(ItemGroup.MATERIALS), "bear_polar_fur");
        cloth = register(r, newItem(ItemGroup.MATERIALS), "cloth");
        coarseCloth = register(r, newItem(ItemGroup.MATERIALS), "coarse_cloth");
        gemStone = register(r, new ItemGemStone(), "gem_stone");
        rawGemStone = register(r, new ItemGemStone(), "raw_gem_stone");
        flawlessGemStone = register(r, new ItemGemStone(), "flawless_gem_stone");
        scroll = register(r, newItem(ItemGroup.MISC), "scroll");
        soulStone = register(r, newItem(ItemGroup.MATERIALS), "soul_stone");
        piercingStone = register(r, newItem(ItemGroup.MATERIALS), "piercing_stone");
        shell = register(r, newItem(ItemGroup.MATERIALS), "shell");

        // food
        coloredSoup = register(r, new ItemColoredSoup(), "colored_soup");
        friedEgg = register(r, newFood(2, 0.3f), "fried_egg");
        mushroomStickRaw = register(r, newItem(ItemGroup.FOOD), "mushroom_stick_raw");
        mushroomStickCooked = register(r, newFood(9, 0.9f), "mushroom_stick_cooked");
        apricot = register(r, newFood(4, 0.3f), "apricot");
        pear = register(r, newFood(4, 0.3f), "pear");
        plum = register(r, newFood(4, 0.3f), "plum");

        // icons
        arrowDown = register(r, newItem(ItemGroup.MISC), "arrow_down");
        arrowLeft = register(r, newItem(ItemGroup.MISC), "arrow_left");
        arrowRight = register(r, newItem(ItemGroup.MISC), "arrow_right");
        arrowUp = register(r, newItem(ItemGroup.MISC), "arrow_up");
        checkGreen = register(r, newItem(ItemGroup.MISC), "check_green");
        checkRed = register(r, newItem(ItemGroup.MISC), "check_red");
        crossGreen = register(r, newItem(ItemGroup.MISC), "cross_green");
        crossRed = register(r, newItem(ItemGroup.MISC), "cross_red");
        minusGreen = register(r, newItem(ItemGroup.MISC), "minus_green");
        minusRed = register(r, newItem(ItemGroup.MISC), "minus_red");
        plusGreen = register(r, newItem(ItemGroup.MISC), "plus_green");
        plusRed = register(r, newItem(ItemGroup.MISC), "plus_red");
        returnGreen = register(r, newItem(ItemGroup.MISC), "return_green");
        returnRed = register(r, newItem(ItemGroup.MISC), "return_red");
        gear = register(r, newItem(ItemGroup.MISC), "gear");

        // herbs
        herbStrong = register(r, newHerb(), "herb_strong");
        herbShadow = register(r, newHerb(), "herb_shadow");
        herbXp = register(r, newHerb(), "herb_xp");
        herbSea = register(r, newHerb(), "herb_sea");
        herbGold = register(r, newHerb(), "herb_gold");
        herbBreathing = register(r, newHerb(), "herb_breathing");
        herbFire = register(r, newHerb(), "herb_fire");
        
        // berries
        berryBeast = register(r, newBerry(), "berry_beast");
        berryCloud = register(r, newBerry(), "berry_cloud");
        berryGold = register(r, newBerry(), "berry_gold");
        berryMagma = register(r, newBerry(), "berry_magma");
        berryWork = register(r, newBerry(), "berry_work");
        berryExperience = register(r, newBerry(), "berry_experience");

        // skill icons
        for(int i = 1; i <= 57; i++) {
            register(r, newItem(ItemGroup.MISC), "skill" + i);
        }

        // block overrides
        try {
            PotionItem potion = new ItemNoGlintPotion();
            register(r, Items.POTION, potion);

            PotionItem splashPotion = new ItemNoGlintSplashPotion();
            register(r, Items.SPLASH_POTION, splashPotion);

            PotionItem lingeringPotion = new ItemNoGlintLingeringPotion();
            register(r, Items.LINGERING_POTION, lingeringPotion);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }

    private static Item register(IForgeRegistry<Item> r, Item item, String registry) {
        item.setRegistryName(registry);
        r.register(item);
        return item;
    }

    private static void register(IForgeRegistry<Item> r, Item old, Item newItem) {
        newItem.setRegistryName(old.getRegistryName());
        r.register(newItem);
    }
}
