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);
}
};
}
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;
}
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;
}
Aggregations