use of top.theillusivec4.curios.api.type.capability.ICuriosItemHandler 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();
}
use of top.theillusivec4.curios.api.type.capability.ICuriosItemHandler 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;
}
use of top.theillusivec4.curios.api.type.capability.ICuriosItemHandler 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;
}
use of top.theillusivec4.curios.api.type.capability.ICuriosItemHandler 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();
}
use of top.theillusivec4.curios.api.type.capability.ICuriosItemHandler in project Backpacked by MrCrayfish.
the class Curios method getBackpackStack.
public static ItemStack getBackpackStack(Player player) {
AtomicReference<ItemStack> backpack = 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.getItem() instanceof BackpackItem) {
backpack.set(stack);
}
});
});
return backpack.get();
}
Aggregations