Search in sources :

Example 1 with ICurioStacksHandler

use of top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler in project Chargers by GoryMoon.

the class Curios method chargeItems.

public boolean chargeItems(Player player, WirelessChargerBlockEntity charger) {
    AtomicBoolean result = new AtomicBoolean(false);
    if (isLoaded()) {
        LazyOptional<ICuriosItemHandler> lazyOptional = CuriosApi.getCuriosHelper().getCuriosHandler(player);
        lazyOptional.ifPresent(handler -> {
            NonNullList<ItemStack> chargeList = NonNullList.create();
            chargeList.add(ItemStack.EMPTY);
            for (ICurioStacksHandler itemHandler : handler.getCurios().values()) {
                // Early exit if we are out of energy this tick
                if (charger.getAvailableEnergy() <= 0)
                    break;
                IDynamicStackHandler stacks = itemHandler.getStacks();
                for (int i = 0; i < itemHandler.getSlots(); i++) {
                    // Early exit if we are out of energy this tick
                    if (charger.getAvailableEnergy() <= 0)
                        break;
                    ItemStack stack = stacks.getStackInSlot(i);
                    if (!stack.isEmpty() && stack.getCount() == 1) {
                        chargeList.set(0, stack = stack.copy());
                        if (charger.chargeItems(chargeList)) {
                            stacks.setStackInSlot(i, stack);
                            // Successful charge of an item
                            result.set(true);
                        }
                    }
                }
            }
        });
    }
    return result.get();
}
Also used : ICurioStacksHandler(top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ICuriosItemHandler(top.theillusivec4.curios.api.type.capability.ICuriosItemHandler) IDynamicStackHandler(top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with ICurioStacksHandler

use of top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler in project CustomizableElytra by Hidoni.

the class CustomizableElytraLayer method getTextureWithCape.

private ResourceLocation getTextureWithCape(T entitylivingbaseIn, CompoundNBT customizationTag, boolean capeHidden) {
    ResourceLocation elytraTexture = null;
    boolean isTextureGrayscale = ElytraCustomizationUtil.getData(customizationTag).type != ElytraCustomizationData.CustomizationType.None;
    if (!capeHidden) {
        if (entitylivingbaseIn instanceof AbstractClientPlayerEntity) {
            AbstractClientPlayerEntity abstractclientplayerentity = (AbstractClientPlayerEntity) entitylivingbaseIn;
            if (abstractclientplayerentity.isPlayerInfoSet() && abstractclientplayerentity.getLocationElytra() != null) {
                elytraTexture = abstractclientplayerentity.getLocationElytra();
            } else if (abstractclientplayerentity.hasPlayerInfo() && abstractclientplayerentity.getLocationCape() != null && abstractclientplayerentity.isWearing(PlayerModelPart.CAPE)) {
                elytraTexture = abstractclientplayerentity.getLocationCape();
            }
        }
        if (elytraTexture == null && CustomizableElytra.aetherLoaded) {
            Optional<ImmutableTriple<String, Integer, ItemStack>> curiosHelper = CuriosApi.getCuriosHelper().findEquippedCurio((item) -> item.getItem() instanceof CapeItem, entitylivingbaseIn);
            Optional<ICuriosItemHandler> curiosHandler = CuriosApi.getCuriosHelper().getCuriosHandler(entitylivingbaseIn).resolve();
            if (curiosHelper.isPresent() && curiosHandler.isPresent()) {
                Optional<ICurioStacksHandler> stacksHandler = curiosHandler.get().getStacksHandler(curiosHelper.get().getLeft());
                if (stacksHandler.isPresent()) {
                    CapeItem cape = (CapeItem) curiosHelper.get().getRight().getItem();
                    if (cape.getCapeTexture() != null && stacksHandler.get().getRenders().get(curiosHelper.get().getMiddle())) {
                        elytraTexture = cape.getCapeTexture();
                    }
                }
            }
        }
    }
    if (elytraTexture == null) {
        elytraTexture = getElytraTexture(isTextureGrayscale);
    } else if (isTextureGrayscale) {
        elytraTexture = ElytraTextureUtil.getGrayscale(elytraTexture);
    }
    return elytraTexture;
}
Also used : ICurioStacksHandler(top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler) ICuriosItemHandler(top.theillusivec4.curios.api.type.capability.ICuriosItemHandler) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractClientPlayerEntity(net.minecraft.client.entity.player.AbstractClientPlayerEntity) CapeItem(com.gildedgames.aether.common.item.accessories.cape.CapeItem)

Example 3 with ICurioStacksHandler

use of top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler 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 4 with ICurioStacksHandler

use of top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler in project The-Aether by Gilded-Games.

the class AetherMixinHooks method elytraLayerMixin.

public static <T extends LivingEntity> ResourceLocation elytraLayerMixin(ItemStack stack, T entity) {
    Optional<SlotResult> slotResult = CuriosApi.getCuriosHelper().findFirstCurio(entity, (item) -> item.getItem() instanceof CapeItem);
    if (slotResult.isPresent()) {
        String identifier = slotResult.get().slotContext().identifier();
        int id = slotResult.get().slotContext().index();
        LazyOptional<ICuriosItemHandler> itemHandler = CuriosApi.getCuriosHelper().getCuriosHandler(entity);
        if (itemHandler.resolve().isPresent()) {
            Optional<ICurioStacksHandler> stacksHandler = itemHandler.resolve().get().getStacksHandler(identifier);
            CapeItem cape = (CapeItem) slotResult.get().stack().getItem();
            boolean isCapeVisible = stacksHandler.get().getRenders().get(id);
            if (cape.getCapeTexture() != null && isCapeVisible) {
                return cape.getCapeTexture();
            }
        }
    }
    return null;
}
Also used : ICurioStacksHandler(top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler) ICuriosItemHandler(top.theillusivec4.curios.api.type.capability.ICuriosItemHandler) CapeItem(com.gildedgames.aether.common.item.accessories.cape.CapeItem) SlotResult(top.theillusivec4.curios.api.SlotResult)

Example 5 with ICurioStacksHandler

use of top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler in project Backpacked by MrCrayfish.

the class Curios method getBackStack.

/**
 * Gets the stack in the back slot
 */
public static ItemStack getBackStack(Player player) {
    AtomicReference<ItemStack> back = new AtomicReference<>(ItemStack.EMPTY);
    LazyOptional<ICuriosItemHandler> optional = CuriosApi.getCuriosHelper().getCuriosHandler(player);
    optional.ifPresent(itemHandler -> {
        Optional<ICurioStacksHandler> stacksOptional = itemHandler.getStacksHandler(SlotTypePreset.BACK.getIdentifier());
        stacksOptional.ifPresent(stacksHandler -> {
            ItemStack stack = stacksHandler.getStacks().getStackInSlot(0);
            if (!stack.isEmpty()) {
                back.set(stack);
            }
        });
    });
    return back.get();
}
Also used : ICurioStacksHandler(top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler) ICuriosItemHandler(top.theillusivec4.curios.api.type.capability.ICuriosItemHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

ICurioStacksHandler (top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler)8 ICuriosItemHandler (top.theillusivec4.curios.api.type.capability.ICuriosItemHandler)5 ItemStack (net.minecraft.world.item.ItemStack)4 IDynamicStackHandler (top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler)3 CapeItem (com.gildedgames.aether.common.item.accessories.cape.CapeItem)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 BackpackItem (com.mrcrayfish.backpacked.item.BackpackItem)1 IRepairableItem (it.hurts.sskirillss.relics.api.durability.IRepairableItem)1 ILeveledItem (it.hurts.sskirillss.relics.api.leveling.ILeveledItem)1 RelicItem (it.hurts.sskirillss.relics.items.relics.base.RelicItem)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AbstractClientPlayerEntity (net.minecraft.client.entity.player.AbstractClientPlayerEntity)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1 InteractionHand (net.minecraft.world.InteractionHand)1