Search in sources :

Example 1 with SlotContext

use of top.theillusivec4.curios.api.SlotContext in project MiniUtilities by OneLemonyBoi.

the class AngelRing method initCapabilities.

@Override
public ICapabilityProvider initCapabilities(final ItemStack stack, CompoundNBT unused) {
    ICurio curio = new ICurio() {

        @Override
        public boolean canEquipFromUse(SlotContext slotContext) {
            return true;
        }

        @Override
        public void onEquip(SlotContext slotContext, ItemStack prevStack) {
            if (slotContext.getWearer() instanceof PlayerEntity) {
                startFlying((PlayerEntity) slotContext.getWearer());
            }
        }

        @Override
        public void onUnequip(SlotContext slotContext, ItemStack prevStack) {
            if (slotContext.getWearer() instanceof PlayerEntity) {
                stopFlying((PlayerEntity) slotContext.getWearer());
            }
        }

        private void startFlying(PlayerEntity player) {
            if (!player.isCreative() && !player.isSpectator()) {
                player.abilities.allowFlying = true;
                player.sendPlayerAbilities();
            }
        }

        private void stopFlying(PlayerEntity player) {
            if (!player.isCreative() && !player.isSpectator()) {
                player.abilities.isFlying = false;
                player.abilities.allowFlying = false;
                player.sendPlayerAbilities();
            }
        }

        @Override
        public void curioTick(String identifier, int index, LivingEntity livingEntity) {
            if (livingEntity instanceof PlayerEntity) {
                PlayerEntity player = ((PlayerEntity) livingEntity);
                if (!player.abilities.allowFlying) {
                    startFlying(player);
                }
            }
        }

        @Override
        public boolean canEquip(String identifier, LivingEntity entityLivingBase) {
            return !CuriosApi.getCuriosHelper().findEquippedCurio(ItemList.BaseAngelRing.get(), entityLivingBase).isPresent() && !CuriosApi.getCuriosHelper().findEquippedCurio(ItemList.BatAngelRing.get(), entityLivingBase).isPresent() && !CuriosApi.getCuriosHelper().findEquippedCurio(ItemList.GoldAngelRing.get(), entityLivingBase).isPresent() && !CuriosApi.getCuriosHelper().findEquippedCurio(ItemList.PeacockAngelRing.get(), entityLivingBase).isPresent() && !CuriosApi.getCuriosHelper().findEquippedCurio(ItemList.EnderDragonAngelRing.get(), entityLivingBase).isPresent() && !CuriosApi.getCuriosHelper().findEquippedCurio(ItemList.FeatherAngelRing.get(), entityLivingBase).isPresent();
        }
    };
    return new ICapabilityProvider() {

        private final LazyOptional<ICurio> curioOpt = LazyOptional.of(() -> curio);

        @Nonnull
        @Override
        public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
            return CuriosCapability.ITEM.orEmpty(cap, curioOpt);
        }
    };
}
Also used : Capability(net.minecraftforge.common.capabilities.Capability) CuriosCapability(top.theillusivec4.curios.api.CuriosCapability) ICurio(top.theillusivec4.curios.api.type.capability.ICurio) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) Nonnull(javax.annotation.Nonnull) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SlotContext(top.theillusivec4.curios.api.SlotContext) CompoundNBT(net.minecraft.nbt.CompoundNBT) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 2 with SlotContext

use of top.theillusivec4.curios.api.SlotContext in project relics by SSKirillSS.

the class RelicItem method getAttributeModifiers.

@Override
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(SlotContext slotContext, UUID uuid, ItemStack stack) {
    Multimap<Attribute, AttributeModifier> modifiers = LinkedHashMultimap.create();
    if (DurabilityUtils.isBroken(stack))
        return modifiers;
    RelicAttributeModifier attributes = getAttributeModifiers(stack);
    RelicSlotModifier slots = getSlotModifiers(stack);
    if (attributes != null)
        attributes.getAttributes().forEach(attribute -> modifiers.put(attribute.getAttribute(), new AttributeModifier(uuid, stack.getItem().getRegistryName().getPath() + "_" + attribute.getAttribute().getRegistryName().getPath(), attribute.getMultiplier(), attribute.getOperation())));
    if (slots != null)
        slots.getModifiers().forEach(slot -> CuriosApi.getCuriosHelper().addSlotModifier(modifiers, slot.getLeft(), uuid, slot.getRight(), AttributeModifier.Operation.ADDITION));
    return modifiers;
}
Also used : Setter(lombok.Setter) Enchantment(net.minecraft.enchantment.Enchantment) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) CuriosApi(top.theillusivec4.curios.api.CuriosApi) IRepairableItem(it.hurts.sskirillss.relics.api.durability.IRepairableItem) Item(net.minecraft.item.Item) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) Multimap(com.google.common.collect.Multimap) ITextComponent(net.minecraft.util.text.ITextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ICurioItem(top.theillusivec4.curios.api.type.capability.ICurioItem) Reference(it.hurts.sskirillss.relics.utils.Reference) ICurio(top.theillusivec4.curios.api.type.capability.ICurio) Enchantments(net.minecraft.enchantment.Enchantments) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) RelicSlotModifier(it.hurts.sskirillss.relics.items.relics.base.data.RelicSlotModifier) SlotContext(top.theillusivec4.curios.api.SlotContext) RelicTooltip(it.hurts.sskirillss.relics.client.tooltip.base.RelicTooltip) RelicData(it.hurts.sskirillss.relics.items.relics.base.data.RelicData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) CircleTintData(it.hurts.sskirillss.relics.client.particles.circle.CircleTintData) RenderType(net.minecraft.client.renderer.RenderType) MathUtils(it.hurts.sskirillss.relics.utils.MathUtils) UUID(java.util.UUID) RelicConfigData(it.hurts.sskirillss.relics.configs.data.relics.RelicConfigData) java.awt(java.awt) RelicLevelingData(it.hurts.sskirillss.relics.configs.data.relics.RelicLevelingData) Attribute(net.minecraft.entity.ai.attributes.Attribute) Vector3d(net.minecraft.util.math.vector.Vector3d) List(java.util.List) RelicStats(it.hurts.sskirillss.relics.items.relics.base.data.RelicStats) BipedModel(net.minecraft.client.renderer.entity.model.BipedModel) ResourceLocation(net.minecraft.util.ResourceLocation) RelicAttributeModifier(it.hurts.sskirillss.relics.items.relics.base.data.RelicAttributeModifier) ItemEntity(net.minecraft.entity.item.ItemEntity) OverlayTexture(net.minecraft.client.renderer.texture.OverlayTexture) DurabilityUtils(it.hurts.sskirillss.relics.utils.DurabilityUtils) RelicAttributeModifier(it.hurts.sskirillss.relics.items.relics.base.data.RelicAttributeModifier) Attribute(net.minecraft.entity.ai.attributes.Attribute) RelicSlotModifier(it.hurts.sskirillss.relics.items.relics.base.data.RelicSlotModifier) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) RelicAttributeModifier(it.hurts.sskirillss.relics.items.relics.base.data.RelicAttributeModifier)

Example 3 with SlotContext

use of top.theillusivec4.curios.api.SlotContext 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)

Aggregations

LivingEntity (net.minecraft.entity.LivingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 SlotContext (top.theillusivec4.curios.api.SlotContext)2 ICurio (top.theillusivec4.curios.api.type.capability.ICurio)2 CapeItem (com.gildedgames.aether.common.item.accessories.cape.CapeItem)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 IRepairableItem (it.hurts.sskirillss.relics.api.durability.IRepairableItem)1 CircleTintData (it.hurts.sskirillss.relics.client.particles.circle.CircleTintData)1 RelicTooltip (it.hurts.sskirillss.relics.client.tooltip.base.RelicTooltip)1 RelicConfigData (it.hurts.sskirillss.relics.configs.data.relics.RelicConfigData)1 RelicLevelingData (it.hurts.sskirillss.relics.configs.data.relics.RelicLevelingData)1 RelicAttributeModifier (it.hurts.sskirillss.relics.items.relics.base.data.RelicAttributeModifier)1 RelicData (it.hurts.sskirillss.relics.items.relics.base.data.RelicData)1 RelicSlotModifier (it.hurts.sskirillss.relics.items.relics.base.data.RelicSlotModifier)1 RelicStats (it.hurts.sskirillss.relics.items.relics.base.data.RelicStats)1 DurabilityUtils (it.hurts.sskirillss.relics.utils.DurabilityUtils)1 MathUtils (it.hurts.sskirillss.relics.utils.MathUtils)1