Search in sources :

Example 1 with ActivatedAbility

use of com.lying.variousoddities.species.abilities.ActivatedAbility in project VariousOddities by Lyinginbedmon.

the class GuiHandler method drawFavouritedAbilities.

private static void drawFavouritedAbilities(MatrixStack matrix, MainWindow window, float partialTicks, EnumCorner corner) {
    profiler.startSection("abilities");
    Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
    Abilities abilities = LivingData.forEntity(player).getAbilities();
    float posXStart = 5F;
    float posYStart = 5F;
    float posXInc = 3F;
    float posYInc = 11F;
    switch(corner) {
        case TOP_LEFT:
            posXStart = (Abilities.FAVOURITE_SLOTS * 3F);
            break;
        case BOTTOM_LEFT:
            posXInc = -3F;
            posYStart = (float) (window.getScaledHeight() - (Abilities.FAVOURITE_SLOTS * posYInc) - 5F);
            break;
        case BOTTOM_RIGHT:
            posXStart = (float) (window.getScaledWidth() - (Abilities.FAVOURITE_SLOTS * 3F));
            posYStart = (float) (window.getScaledHeight() - (Abilities.FAVOURITE_SLOTS * posYInc) - 5F);
            break;
        case TOP_RIGHT:
            posXStart = (float) (window.getScaledWidth() - (Abilities.FAVOURITE_SLOTS * 3F) - ICON_SIZE);
            posXInc = -3F;
            break;
    }
    matrix.push();
    float posX = posXStart;
    float posY = posYStart;
    int maxFav = 0;
    for (int i = 0; i < Abilities.FAVOURITE_SLOTS; i++) {
        ResourceLocation mapName = abilities.getFavourite(i);
        if (mapName != null) {
            maxFav = Math.max(maxFav, i);
            ActivatedAbility ability = (ActivatedAbility) abilityMap.get(mapName);
            if (ability != null)
                drawAbility(ability, abilities.getCooldown(mapName), posX, posY, matrix, corner.textSide);
        }
        posX -= posXInc;
        posY += posYInc;
    }
    List<Ability> activatedAbilities = Lists.newArrayList();
    activatedAbilities.addAll(abilityMap.values());
    activatedAbilities.removeIf(new Predicate<Ability>() {

        public boolean apply(Ability input) {
            return input.passive();
        }
    });
    if (!activatedAbilities.isEmpty()) {
        // Draw either as many slots as you can fill OR up to the highest index of slots in use
        int slots = Math.max(maxFav, activatedAbilities.size());
        posX = posXStart;
        posY = posYStart;
        for (int i = 0; i < Math.min(Abilities.FAVOURITE_SLOTS, slots); i++) {
            drawAbilitySlot(matrix, posX, posY);
            posX -= posXInc;
            posY += posYInc;
        }
    }
    matrix.pop();
    profiler.endSection();
}
Also used : ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) Ability(com.lying.variousoddities.species.abilities.Ability) Abilities(com.lying.variousoddities.capabilities.Abilities) ResourceLocation(net.minecraft.util.ResourceLocation) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility)

Example 2 with ActivatedAbility

use of com.lying.variousoddities.species.abilities.ActivatedAbility in project VariousOddities by Lyinginbedmon.

the class KeyBindings method handleAbilityKey.

private static void handleAbilityKey(int index) {
    LivingData data = LivingData.forEntity(Minecraft.getInstance().player);
    ResourceLocation mapName = data.getAbilities().getFavourite(index);
    if (mapName != null) {
        ActivatedAbility ability = (ActivatedAbility) AbilityRegistry.getAbilityByName(Minecraft.getInstance().player, mapName);
        if (ability != null && ability.canTrigger(Minecraft.getInstance().player)) {
            ability.trigger(Minecraft.getInstance().player, Dist.CLIENT);
            PacketHandler.sendToServer(new PacketAbilityActivate(mapName));
        }
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) LivingData(com.lying.variousoddities.capabilities.LivingData) PacketAbilityActivate(com.lying.variousoddities.network.PacketAbilityActivate)

Example 3 with ActivatedAbility

use of com.lying.variousoddities.species.abilities.ActivatedAbility in project VariousOddities by Lyinginbedmon.

the class PacketAbilityActivate method handle.

public static void handle(PacketAbilityActivate msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (context.getDirection().getReceptionSide().isServer()) {
        PlayerEntity sender = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
        if (sender != null) {
            Ability ability = AbilityRegistry.getAbilityByName(sender, msg.abilityName);
            if (ability != null && !ability.passive()) {
                ActivatedAbility activatedAbility = (ActivatedAbility) ability;
                if (activatedAbility.canTrigger(sender))
                    activatedAbility.trigger(sender, Dist.DEDICATED_SERVER);
            } else
                VariousOddities.log.warn(sender.getName().getUnformattedComponentText() + " does not have the ability they tried to activate (" + msg.abilityName.toString() + ")");
        }
    }
    context.setPacketHandled(true);
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with ActivatedAbility

use of com.lying.variousoddities.species.abilities.ActivatedAbility in project VariousOddities by Lyinginbedmon.

the class ScreenAbilityMenu method drawAbilityNames.

public void drawAbilityNames(MatrixStack matrixStack) {
    matrixStack.push();
    matrixStack.translate(this.width * 0.5D, this.height * 0.5D, 0);
    matrixStack.push();
    float angleInc = 360F / (abilitySet.size() + 1);
    for (int index = 0; index < abilitySet.size(); index++) {
        ActivatedAbility ability = abilitySet.get(index);
        matrixStack.push();
        float angle = angleInc * (index + 1);
        matrixStack.rotate(Vector3f.ZP.rotationDegrees(angleInc * (index + 1)));
        matrixStack.translate(0, 60, 0);
        matrixStack.push();
        if (angle % 90 == 0)
            matrixStack.rotate(Vector3f.ZP.rotationDegrees(-angle));
        else {
            matrixStack.rotate(Vector3f.ZP.rotationDegrees(-90F));
            if (angle > 180)
                matrixStack.rotate(Vector3f.ZP.rotationDegrees(-180F));
        }
        List<ITextProperties> messageLines = VOHelper.getWrappedText(ability.getDisplayName(), font, 90);
        int textX = 0;
        for (ITextProperties line : messageLines) {
            int length = font.getStringWidth(line.getString());
            if (length > 80)
                textX = Math.min(textX, length - 80);
        }
        int textCol = ability.isActive() ? TextFormatting.GOLD.getColor() : -1;
        int textY = (int) (messageLines.size() * font.FONT_HEIGHT * -0.5D);
        for (ITextProperties line : messageLines) {
            drawCenteredString(matrixStack, font, line.getString(), textX, textY, textCol);
            textY += font.FONT_HEIGHT;
        }
        matrixStack.pop();
        matrixStack.pop();
    }
    matrixStack.pop();
    matrixStack.pop();
}
Also used : ITextProperties(net.minecraft.util.text.ITextProperties) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility)

Example 5 with ActivatedAbility

use of com.lying.variousoddities.species.abilities.ActivatedAbility in project VariousOddities by Lyinginbedmon.

the class ScreenAbilityMenu method render.

public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
    int maxRadius = (int) (this.height * 0.375D);
    int currentRadius = isLoaded() ? maxRadius : (maxRadius / 2) + (int) ((maxRadius / 2) * ((double) openTicks + partialTicks) / (double) startup);
    double angleInc = Math.toRadians(360F / (abilitySet.size() + 1));
    Vector2f vec = rotateVector(new Vector2f(0F, currentRadius), angleInc);
    Vector2f vec2 = rotateVector(new Vector2f(0F, this.height * 0.375F), angleInc);
    float angle = (float) -angleInc * 0.5F;
    float midX = this.width * 0.5F;
    float midY = this.height * 0.5F;
    if (abilities.size() > 7) {
        drawCenteredString(matrixStack, font, new StringTextComponent("..."), (int) midX, (int) (midY + 50), -1);
        if (index > 0)
            drawCenteredString(matrixStack, font, new StringTextComponent("<"), (int) midX - 6, (int) (midY + 50 + font.FONT_HEIGHT * 0.25D), -1);
        if (indexEnd < abilities.size())
            drawCenteredString(matrixStack, font, new StringTextComponent(">"), (int) midX + 5, (int) (midY + 50 + font.FONT_HEIGHT * 0.25D), -1);
    }
    if (!abilitySet.isEmpty()) {
        boolean canFavourite = theData.getAbilities().hasEmptyFavourites();
        ActivatedAbility currentlySelected = getAbilitySlice(mouseX, mouseY);
        int index = 0;
        for (ActivatedAbility ability : abilitySet) {
            boolean isSelected = currentlySelected != null && ability.getMapName().equals(currentlySelected.getMapName());
            /*
				 * Colour slice
				 * 	black if the ability cannot be used right now
				 * 	white if currently selected
				 * 	alternating shades of cyan otherwise 
				 */
            int red = 0, green = 0, blue = 0;
            if (ability.canTrigger(thePlayer)) {
                if (isSelected)
                    red = green = blue = 255;
                else {
                    red = 200;
                    green = 230;
                    blue = 255;
                }
            }
            int alpha = isSelected ? 150 : (index % 2 == 0 ? 120 : 90);
            drawRadialSlice(matrixStack, midX, midY, angle, (float) angleInc, isSelected ? currentRadius * 1.05F : currentRadius, red, green, blue, alpha, partialTicks);
            boolean isFavourite = theData.getAbilities().isFavourite(ability.getMapName());
            if (isLoaded() && (canFavourite || isFavourite))
                drawFavouriteButtonAt(matrixStack, midX + vec2.x, midY + vec2.y, isFavourite);
            vec = rotateVector(vec, angleInc);
            vec2 = rotateVector(vec2, angleInc);
            angle -= angleInc;
            index++;
        }
        if (isLoaded())
            drawAbilityNames(matrixStack);
    } else {
        // Draw full circle
        drawRadialSlice(matrixStack, midX, midY, angle, (float) angleInc, currentRadius, 200, 230, 255, 90, partialTicks);
        drawCenteredString(matrixStack, font, new TranslationTextComponent("gui." + Reference.ModInfo.MOD_ID + ".abilities_menu.empty"), (int) midX, (int) (midY + 50), -1);
    }
    if (!passives.isEmpty()) {
        matrixStack.push();
        matrixStack.translate(midX + maxRadius * 1.25D, midY, 0D);
        matrixStack.push();
        float scale = 0.75F;
        matrixStack.scale(scale, scale, scale);
        int textY = (int) (-(passives.size() * (font.FONT_HEIGHT + 2) * 0.5F));
        int textInc = font.FONT_HEIGHT + 2;
        for (int i = 0; i < Math.min(passives.size(), 1 + openTicks); i++) {
            Ability passive = passives.get(i);
            drawString(matrixStack, font, passive.getDisplayName(), 0, textY, -1);
            textY += textInc;
        }
        matrixStack.pop();
        matrixStack.pop();
    }
    super.render(matrixStack, mouseX, mouseY, partialTicks);
}
Also used : ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) Ability(com.lying.variousoddities.species.abilities.Ability) Vector2f(net.minecraft.util.math.vector.Vector2f) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Aggregations

ActivatedAbility (com.lying.variousoddities.species.abilities.ActivatedAbility)5 Ability (com.lying.variousoddities.species.abilities.Ability)3 ResourceLocation (net.minecraft.util.ResourceLocation)2 Abilities (com.lying.variousoddities.capabilities.Abilities)1 LivingData (com.lying.variousoddities.capabilities.LivingData)1 PacketAbilityActivate (com.lying.variousoddities.network.PacketAbilityActivate)1 CommonProxy (com.lying.variousoddities.proxy.CommonProxy)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 Vector2f (net.minecraft.util.math.vector.Vector2f)1 ITextProperties (net.minecraft.util.text.ITextProperties)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)1