Search in sources :

Example 1 with RelicItem

use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.

the class TooltipDescriptionHandler method renderState.

private static void renderState(ItemStack stack, List<ITextComponent> tooltip, PlayerEntity player) {
    if (player == null || stack == null)
        return;
    Item item = stack.getItem();
    if (item instanceof IRepairableItem) {
        if (DurabilityUtils.isBroken(stack))
            tooltip.add((new StringTextComponent("▶ ").withStyle(TextFormatting.GOLD)).append((new TranslationTextComponent("tooltip.relics.relic.broken")).withStyle(TextFormatting.YELLOW)));
        else if (stack.getDamageValue() >= stack.getMaxDamage() * 0.1F)
            tooltip.add((new StringTextComponent("▶ ").withStyle(TextFormatting.GOLD)).append((new TranslationTextComponent("tooltip.relics.relic.damaged")).withStyle(TextFormatting.YELLOW)));
    }
    for (String tag : CuriosApi.getCuriosHelper().getCurioTags(item)) {
        CuriosApi.getCuriosHelper().getCuriosHandler(player).ifPresent(handler -> {
            Map<String, ICurioStacksHandler> curios = handler.getCurios();
            if (curios.size() == 0)
                return;
            List<ITextComponent> list = new ArrayList<>();
            if (curios.get(tag) == null || curios.get(tag).getSlots() > 0)
                return;
            for (Item curio : ItemRegistry.getSlotModifiers()) {
                RelicItem<?> relic = (RelicItem<?>) curio;
                for (Pair<String, Integer> pair : relic.getSlotModifiers(stack).getModifiers()) {
                    String identifier = pair.getLeft();
                    int amount = pair.getRight();
                    if (identifier.equals(tag) && amount > 0)
                        list.add((new StringTextComponent("   ◆ ").withStyle(TextFormatting.YELLOW)).append(new StringTextComponent(new ItemStack(curio).getHoverName().getString()).withStyle(TextFormatting.GREEN)).append((new StringTextComponent(String.format(" [+%d]", amount)).withStyle(TextFormatting.WHITE))));
                }
            }
            StringTextComponent info = new StringTextComponent("");
            info.append((new StringTextComponent("▶ ").withStyle(TextFormatting.GOLD)).append((new TranslationTextComponent("tooltip.relics.relic.requires_slot")).withStyle(TextFormatting.YELLOW)).append(" ").append((new TranslationTextComponent("curios.identifier." + tag).withStyle(TextFormatting.GREEN))));
            if (!list.isEmpty())
                info.append(". ").withStyle(TextFormatting.YELLOW).append(new TranslationTextComponent("tooltip.relics.relic.allowed_modifiers").withStyle(TextFormatting.YELLOW));
            tooltip.add(info);
            if (!list.isEmpty())
                tooltip.addAll(list);
        });
    }
}
Also used : RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) ICurioStacksHandler(top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler) IRepairableItem(it.hurts.sskirillss.relics.api.durability.IRepairableItem) Item(net.minecraft.item.Item) ILeveledItem(it.hurts.sskirillss.relics.api.leveling.ILeveledItem) ICurioItem(top.theillusivec4.curios.api.type.capability.ICurioItem) RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) IRepairableItem(it.hurts.sskirillss.relics.api.durability.IRepairableItem) ItemStack(net.minecraft.item.ItemStack)

Example 2 with RelicItem

use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.

the class TooltipDescriptionHandler method getAbilitiesTooltip.

private static List<ITextComponent> getAbilitiesTooltip(ItemStack stack) {
    List<ITextComponent> tooltip = new ArrayList<>();
    if (!(stack.getItem() instanceof RelicItem))
        return tooltip;
    RelicItem<?> relic = (RelicItem<?>) stack.getItem();
    RelicTooltip data = relic.getTooltip(stack);
    if (data == null)
        return tooltip;
    List<AbilityTooltip> abilities = data.getAbilities();
    if (abilities.isEmpty())
        return tooltip;
    for (int i = 0; i < abilities.size(); i++) {
        AbilityTooltip ability = abilities.get(i);
        String path = "tooltip." + Reference.MODID + "." + Objects.requireNonNull(relic.getRegistryName()).getPath() + ".ability." + (i + 1) + ".";
        String key = ability.getKeybinding();
        tooltip.add((new StringTextComponent("   ◆ ").withStyle(ability.isNegative() ? TextFormatting.RED : TextFormatting.GREEN)).append((new TranslationTextComponent(path + "name")).withStyle(TextFormatting.YELLOW)).append((new StringTextComponent(key == null ? "" : String.format(" [%s]", key)).withStyle(TextFormatting.DARK_GRAY))).append((new StringTextComponent(" - ").withStyle(TextFormatting.WHITE))).append(new TranslationTextComponent(path + "description", ability.getArgs().toArray(new Object[0])).withStyle(TextFormatting.GRAY)));
    }
    return tooltip;
}
Also used : RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) RelicTooltip(it.hurts.sskirillss.relics.client.tooltip.base.RelicTooltip) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) AbilityTooltip(it.hurts.sskirillss.relics.client.tooltip.base.AbilityTooltip)

Example 3 with RelicItem

use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.

the class HUDEventHandler method onEntityUpdate.

@SubscribeEvent
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
    if (!(event.getEntityLiving() instanceof PlayerEntity))
        return;
    PlayerEntity player = (PlayerEntity) event.getEntityLiving();
    if (!player.getCommandSenderWorld().isClientSide() || player.tickCount % 10 != 0)
        return;
    CuriosApi.getCuriosHelper().getEquippedCurios(player).ifPresent(handler -> {
        relics.clear();
        for (int i = 0; i < handler.getSlots(); i++) {
            ItemStack stack = handler.getStackInSlot(i);
            if (!(stack.getItem() instanceof RelicItem))
                continue;
            RelicItem<?> relic = (RelicItem<?>) stack.getItem();
            if (DurabilityUtils.isBroken(stack) || !relic.getData().hasAbility())
                continue;
            relics.add(new ImmutablePair<>(stack, i));
        }
        offset = offset / slots * slots;
        if (offset == relics.size())
            offset = Math.max(0, offset - 1) / slots * slots;
    });
}
Also used : RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) ItemStack(net.minecraft.item.ItemStack) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with RelicItem

use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.

the class HUDEventHandler method onKeyPressed.

@SubscribeEvent
public static void onKeyPressed(InputEvent.KeyInputEvent event) {
    ClientPlayerEntity player = Minecraft.getInstance().player;
    if (player == null)
        return;
    if (relics.size() > slots) {
        if (HotkeyRegistry.HUD_UP.isDown()) {
            animation = 500;
            offset = offset - slots;
            if (offset < 0)
                offset = (relics.size() - 1) / slots * slots;
            player.getCommandSenderWorld().playSound(player, player.blockPosition(), SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 1.0F, 1.0F);
        } else if (HotkeyRegistry.HUD_DOWN.isDown()) {
            animation = 500;
            offset = offset + slots;
            if (offset >= relics.size())
                offset = 0;
            player.getCommandSenderWorld().playSound(player, player.blockPosition(), SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 1.0F, 1.0F);
        }
    }
    for (int i = 0; i < keyBindings.size(); i++) {
        KeyBinding key = keyBindings.get(i);
        if (!key.isDown())
            continue;
        animation = 500;
        int id = i + offset;
        if (id >= relics.size())
            continue;
        ImmutablePair<ItemStack, Integer> pair = relics.get(i + offset);
        ItemStack stack = pair.getLeft();
        if (!(stack.getItem() instanceof RelicItem))
            continue;
        RelicItem<?> relic = (RelicItem<?>) stack.getItem();
        if (!relic.getData().hasAbility())
            continue;
        NetworkHandler.sendToServer(new PacketRelicAbility(pair.getRight()));
        relic.castAbility(player, stack);
    }
}
Also used : RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) KeyBinding(net.minecraft.client.settings.KeyBinding) PacketRelicAbility(it.hurts.sskirillss.relics.network.PacketRelicAbility) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with RelicItem

use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.

the class PacketRelicAbility method handle.

public boolean handle(Supplier<NetworkEvent.Context> ctx) {
    ctx.get().enqueueWork(() -> {
        PlayerEntity player = ctx.get().getSender();
        if (player == null || !player.isAlive())
            return;
        CuriosApi.getCuriosHelper().getEquippedCurios(player).ifPresent(handler -> {
            ItemStack stack = handler.getStackInSlot(this.slot);
            if (stack.isEmpty() || !(stack.getItem() instanceof RelicItem))
                return;
            RelicItem relic = (RelicItem) stack.getItem();
            if (!relic.getData().hasAbility())
                return;
            relic.castAbility(player, stack);
        });
    });
    return true;
}
Also used : RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

RelicItem (it.hurts.sskirillss.relics.items.relics.base.RelicItem)11 ItemStack (net.minecraft.item.ItemStack)8 ArrayList (java.util.ArrayList)5 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)4 ITextComponent (net.minecraft.util.text.ITextComponent)3 RelicTooltip (it.hurts.sskirillss.relics.client.tooltip.base.RelicTooltip)2 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Item (net.minecraft.item.Item)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 IRepairableItem (it.hurts.sskirillss.relics.api.durability.IRepairableItem)1 ILeveledItem (it.hurts.sskirillss.relics.api.leveling.ILeveledItem)1 AbilityTooltip (it.hurts.sskirillss.relics.client.tooltip.base.AbilityTooltip)1 it.hurts.sskirillss.relics.items (it.hurts.sskirillss.relics.items)1 it.hurts.sskirillss.relics.items.relics (it.hurts.sskirillss.relics.items.relics)1 ArrowQuiverItem (it.hurts.sskirillss.relics.items.relics.back.ArrowQuiverItem)1 ElytraBoosterItem (it.hurts.sskirillss.relics.items.relics.back.ElytraBoosterItem)1 MidnightRobeItem (it.hurts.sskirillss.relics.items.relics.back.MidnightRobeItem)1 SquireBagItem (it.hurts.sskirillss.relics.items.relics.back.SquireBagItem)1