function init(hero) {
    hero.setName("hero.fiskheroes.spider_man.name");
    hero.setVersion("Miles");
    hero.setTier(7);

    hero.setHelmet("item.superhero_armor.piece.mask");
    hero.setChestplate("item.superhero_armor.piece.chestpiece");
    hero.setLeggings("item.superhero_armor.piece.pants");
    hero.setBoots("item.superhero_armor.piece.boots");

    hero.addPowers("miles:spider_miles", "miles:web_shooters_miles");
    hero.addAttribute("FALL_RESISTANCE", 13.0, 0);
    hero.addAttribute("JUMP_HEIGHT", 2.0, 0);
    hero.addAttribute("PUNCH_DAMAGE", 7.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.45, 1);
    hero.addAttribute("STEP_HEIGHT", 0.5, 0);
    hero.addAttribute("IMPACT_DAMAGE", 0.5, 1);

    hero.addKeyBind("UTILITY_BELT", "key.webShooters", 1);
    hero.addKeyBind("CHARGE_ENERGY", "Venom Blast", 1);
    hero.addKeyBind("WEB_ZIP", "key.webZip", 2);
    hero.addKeyBindFunc("func_WEB_SWINGING", webSwingingKey, "key.webSwinging", 3);
    hero.addKeyBind("SLOW_MOTION", "Slow Motion", 4);
    hero.addKeyBind("TENTACLES", "Wall Crawl", 4);
    hero.addKeyBindFunc("STABLE", stable, "Wall Crawl Attach", 4);
    hero.addKeyBind("INVISIBILITY", "key.invisibility", 5);
    hero.addKeyBind("BLADE", "Venom Mode", 5)

    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setHasProperty(hasProperty);

    hero.addAttributeProfile("MELE", meleProfile);
    hero.setAttributeProfile(getProfile);
    hero.setDamageProfile(getProfile);
    hero.addDamageProfile("MELE", {
        "types": {
            "ENERGY": 1.0
        }
    });

}

function hasProperty(entity, property) {
    return property == "MASK_TOGGLE";
}

function stable(player, manager) {
    manager.setData(player, "fiskheroes:tentacle_lift", true)
    return true
}
function meleProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 15.0, 0);
}

function getProfile(entity) {
    return entity.getData("fiskheroes:blade") ? "MELE" : null;
}

function webSwingingKey(player, manager) {
    var flag = player.getData("fiskheroes:web_swinging");

    if (!flag) {
        manager.setDataWithNotify(player, "fiskheroes:prev_utility_belt_type", player.getData("fiskheroes:utility_belt_type"));
        manager.setDataWithNotify(player, "fiskheroes:utility_belt_type", -1);
    }

    manager.setDataWithNotify(player, "fiskheroes:web_swinging", !flag);
    return true;
}

function isModifierEnabled(entity, modifier) {
    switch (modifier.name()) {
    case "fiskheroes:tentacles":
        if (!entity.getData("fiskheroes:web_swinging") && entity.getHeldItem().isEmpty()) {
            if (entity.world().getBlock(entity.pos().add(0, 0, 0.5)) == 'minecraft:air'
                 && entity.world().getBlock(entity.pos().add(0, 0, -0.5)) == 'minecraft:air'
                 && entity.world().getBlock(entity.pos().add(0.5, 0, 0)) == 'minecraft:air'
                 && entity.world().getBlock(entity.pos().add(-0.5, 0, 0)) == 'minecraft:air' ||
                 entity.world().getBlock(entity.pos().add(0, 1, 0.5)) == 'minecraft:air'
                 && entity.world().getBlock(entity.pos().add(0, 1, -0.5)) == 'minecraft:air'
                 && entity.world().getBlock(entity.pos().add(0.5, 1, 0)) == 'minecraft:air'
                 && entity.world().getBlock(entity.pos().add(-0.5, 1, 0)) == 'minecraft:air' && entity.world().getBlock(entity.pos().add(0, -1, 0)) != 'minecraft:air'
                 || entity.isInWater()) {
                return (false)
            };
        }
        return true
    case "fiskheroes:web_swinging":
        return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:utility_belt_type") == -1 && entity.getData("fiskheroes:tentacles") == null && !entity.getData("fiskheroes:blade");
    case "fiskheroes:leaping":
        return modifier.id() == "springboard" == (entity.getData("fiskheroes:ticks_since_swinging") < 5);
    case "fiskheroes:equipment":
        return !entity.getData("fiskheroes:blade") && entity.getData("fiskheroes:tentacles") == null;
    case "fiskheroes:energy_manipulation":
        return entity.getData("fiskheroes:blade") && entity.getData("fiskheroes:tentacles") == null;
    case "fiskheroes:blade":
        return entity.getData("fiskheroes:tentacles") == null;
    default:
        return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    switch (keyBind) {
    case "func_WEB_SWINGING":
        return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:utility_belt_type") == -1 && entity.getData("fiskheroes:tentacles") == null && !entity.getData("fiskheroes:blade");
    case "WEB_ZIP":
        return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:utility_belt_type") == -1 && entity.getData("fiskheroes:tentacles") == null;
    case "INVISIBILITY":
        return entity.isSneaking() || !entity.getHeldItem().isEmpty() && !entity.getData("fiskheroes:blade") || entity.getData("fiskheroes:invisible");
    case "BLADE":
        return !entity.isSneaking() && entity.getHeldItem().isEmpty() && entity.getData("miles:dyn/mele") == 0 && entity.getData("fiskheroes:tentacles") == null && !entity.getData("fiskheroes:invisible") || entity.getData("fiskheroes:blade");
    case "TENTACLES":
        return !entity.getData("fiskheroes:web_swinging") && entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:tentacles") == null && entity.isOnGround() ;
    case "STABLE":
        if (!entity.getData("fiskheroes:web_swinging") && entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:tentacles") != null && !entity.getData("fiskheroes:tentacle_lift")) {
            if (entity.world().getBlock(entity.pos().add(0, 0.5, -0.5)) != "minecraft:air") {
                return true
            } else if (entity.world().getBlock(entity.pos().add(-0.5, 0.5, 0)) != "minecraft:air") {
                return true
            } else if (entity.world().getBlock(entity.pos().add(0.5, 0.5, 0)) != "minecraft:air") {
                return true
            } else if (entity.world().getBlock(entity.pos().add(0, 0.5, 0.5)) != "minecraft:air") {
                return true;
            }
        }
        return false;
    case "SLOW_MOTION":
        return entity.getData("fiskheroes:web_swinging");
    case "CHARGE_ENERGY":
        return entity.getData("fiskheroes:blade") && entity.getData("fiskheroes:tentacles") == null;
    case "UTILITY_BELT":
        return !entity.getData("fiskheroes:blade") && entity.getData("fiskheroes:tentacles") == null;
    default:
        return true;
    }
}
