var DimensionalCoords = Java.type('com.fiskmods.heroes.common.DimensionalCoords');

function init(hero) {
    hero.setName("Super-Moustache-Man");
    hero.setVersion("JMemeCT");
    hero.setTier(9);
    hero.hide();
    
    hero.setHelmet("Moustache");
    
    hero.addPowers("jmctheroes:moustache_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 12.5, 0);
    hero.addAttribute("SPRINT_SPEED", 0.35, 1);
    hero.addAttribute("JUMP_HEIGHT", 1.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 3.0, 0);
    
    hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 1);
    hero.addKeyBind("SLOW_MOTION", "key.slowMotion", 2);
    hero.addKeyBind("HEAT_VISION", "Freeze Breath", 3);
    hero.addKeyBind("CHARGED_BEAM", "Moustache Charged Moustache Beam", 4);

    hero.addKeyBindFunc("func_TELEPORT", teleportOverrideKey, "Interstellar Travel", 5);

    hero.setHasProperty(hasProperty);
    hero.setKeyBindEnabled(isKeyBindEnabled);
}

function teleportOverrideKey(player, manager) {
    var x = player.posX();
    var y = player.posY();
    var z = player.posZ();
    var dim = player.world().getDimension();
    
    
    manager.setData(player, "fiskheroes:teleport_dest", new DimensionalCoords(x, y, z, dim + 1));
    manager.setData(player, "fiskheroes:teleport_delay", 6);
    return true;
}

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

function isKeyBindEnabled(entity, keyBind) {
    var height = entity.posY();
    switch (keyBind) {
    case "func_TELEPORT":
        return entity.getData("fiskheroes:gliding") && (height) >= 512;
    case "CHARGED_BEAM":
        return (height) < 512;
    default:
        return true;
    }
}