function init(hero) {
    hero.addKeyBindFunc("TENTACLES", StartClimb, "Wall Run", 3);
    hero.setName("Speedster");
    hero.setTier(1);

    hero.setChestplate("item.superhero_armor.piece.chestpiece");
    hero.addEquipment("fiskheroes:flash_ring");

    hero.addPowers("pkg:speed_force", "fiskheroes:energy_manipulation");
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("JUMP_HEIGHT", 3.0, 0);
    hero.addAttribute("PUNCH_DAMAGE", 3.8, 0);
    hero.addAttribute("SPRINT_SPEED", 0.15, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 4.0, 0);

    hero.addKeyBind("SUPER_SPEED", "Super speed", 1);
    hero.addKeyBind("SLOW_MOTION", "key.slowMotion", 2);
    hero.addKeyBind("INTANGIBILITY", "Phasing", 4);
    hero.addKeyBind("PHASE", "Phase (Sneak Or Sprint And Jump)", 4);
    hero.addKeyBind("PHASE_USING", "Phase (Hold Jump Unless Sneaking)", 4);
    hero.addKeyBind("INTANGIBILITY", "Phase (Hold Jump Unless Sneaking)", 4);
    hero.addKeyBind("CHARGE_ENERGY", "Lightning Throw", 5);

    hero.setHasProperty(hasProperty);

    hero.setModifierEnabled(isModifierEnabled);

    hero.setTickHandler((entity, manager) => { });

    hero.setKeyBindEnabled(isKeyBindEnabled);

    hero.setTickHandler((entity, manager) => {
        var data1 = entity.getData("pkg:dyn/phase_timer")
        var _data2 = "pkg:dyn/phase"
        var data2 = entity.getData(_data2)
        if (data1 == 1 && !data2) {
            manager.setData(entity, _data2, true)
        }
        if (entity.isOnGround() && data2) {
            manager.setData(entity, _data2, false)
        }
        var value = entity.getData("pkg:dyn/climb");
        if (entity.getData('fiskheroes:tentacle_lift')) {
            if (entity.motionY() > 0.05 || entity.isSneaking() && entity.world().getBlock(entity.pos().add(0, -1, 0)) == 'minecraft:air') {
                manager.setData(entity, "pkg:dyn/climb", value + 0.1);
            }
        } else if (!entity.getData('fiskheroes:tentacle_lift') && value != 0) {
            manager.setData(entity, "pkg:dyn/climb", 0);
            manager.setData(entity, "pkg:dyn/climb_bool", false);
        }
        if (entity.getData("fiskheroes:tentacles") == null && entity.getData('fiskheroes:tentacle_lift')) {
            manager.setData(entity, "fiskheroes:tentacle_lift", false);
        } else if (entity.getData("fiskheroes:tentacles") != null && !entity.getData('fiskheroes:tentacle_lift')) {
            manager.setData(entity, "fiskheroes:tentacle_lift", true);
        }

    });
}

function isModifierEnabled(entity, modifier) {
    var data1 = entity.getData("pkg:dyn/phase_timer");
    var data2 = (entity.getData("fiskheroes:speeding") || entity.isSprinting())
    var syaw = entity.getData("pkg:dyn/startedyaw");
    var yaw = entity.rotYaw();
    var pitch = entity.rotPitch();
    var Jump = entity.getData("pkg:dyn/jump");
    var YDif = Math.round(entity.posY()) - entity.posY();
    switch (modifier.name()) {

        case "fiskheroes:flight":
            return entity.getData("fiskheroes:intangible") && data1 > 0 && data1 < 0.15 && data2;
        case "fiskheroes:intangibility":
            return ((data1 > 0 && data1 < 1 || !entity.isOnGround()) && data2 || entity.isSneaking());
        case "fiskheroes:charged_beam":
            switch (modifier.id()) {
                case "speed_lightning":
                    return false;
            }
        case "fiskheroes:tentacles":
            if (entity.world().getBlock(entity.pos().add(0, YDif, 0.5)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(0, YDif, -0.5)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(0.5, YDif, 0)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(-0.5, YDif, 0)) == 'minecraft:air' ||

                Jump == true && entity.world().getBlock(entity.pos().add(0, YDif + 0, 1.5)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(0, YDif + 0, -2.0)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(2.0, YDif + 0, 0)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(-2.0, YDif + 0, 0)) == 'minecraft:air'

                || entity.isInWater() || pitch > 30 || yaw < syaw - 30 || yaw > syaw + 30 || !entity.getData("fiskheroes:speeding")) {
                return false
            };

    }

    return true;
}

function isKeyBindEnabled(entity, keyBind) {
    var data2 = (entity.getData("fiskheroes:speeding") || entity.isSprinting())
    var data3 = !entity.getData("pkg:dyn/phase")
    switch (keyBind) {
        case "PHASE":
            return !entity.getData("fiskheroes:intangible");
        case "PHASE_USING":
            return entity.getData("fiskheroes:intangible");
        case "INTANGIBILITY":
            return data3 && (!entity.isOnGround() && data2 || entity.isOnGround() && entity.isSneaking()) && !entity.getData("fiskheroes:intangible");
        case "CHARGE_ENERGY":
            return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:speeding");
        case "TENTACLES":
            return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:speeding");
        default:
            return true;
    }
}
function StartClimb(entity, manager) {
    manager.setData(entity, "pkg:dyn/startedclimb", true);
    manager.setData(entity, "pkg:dyn/startedyaw", entity.rotYaw());
    var syaw = entity.getData("pkg:dyn/startedyaw");
    return true;
}
function getDamageProfile(entity) {
    return entity.getData("fiskheroes:speeding") ? "SPEED_PUNCH" : null;
}

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