use of top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler 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.inventory.IDynamicStackHandler in project SkyblockBuilder by MelanX.
the class CuriosCompat method dropInventory.
public static void dropInventory(Player player) {
if (player.level.isClientSide) {
return;
}
CuriosApi.getCuriosHelper().getCuriosHandler(player).ifPresent(handler -> {
handler.getCurios().forEach((id, type) -> {
IDynamicStackHandler stacks = type.getStacks();
IDynamicStackHandler cosmeticStacks = type.getCosmeticStacks();
for (int i = 0; i < type.getSlots(); i++) {
ItemStack stack = stacks.getStackInSlot(i);
ItemStack stack1 = cosmeticStacks.getStackInSlot(i);
stacks.setStackInSlot(i, ItemStack.EMPTY);
cosmeticStacks.setStackInSlot(i, ItemStack.EMPTY);
player.drop(stack, true, false);
player.drop(stack1, true, false);
}
});
});
}
use of top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler in project artifacts by ochotonida.
the class ArmRenderHandler method onRenderArm.
public static void onRenderArm(RenderArmEvent event) {
if (!ModConfig.client.showFirstPersonGloves.get() || event.isCanceled()) {
return;
}
InteractionHand hand = event.getArm() == event.getPlayer().getMainArm() ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
CuriosApi.getCuriosHelper().getCuriosHandler(event.getPlayer()).ifPresent(handler -> {
ICurioStacksHandler stacksHandler = handler.getCurios().get(SlotTypePreset.HANDS.getIdentifier());
if (stacksHandler != null) {
IDynamicStackHandler stacks = stacksHandler.getStacks();
IDynamicStackHandler cosmeticStacks = stacksHandler.getCosmeticStacks();
for (int slot = hand == InteractionHand.MAIN_HAND ? 0 : 1; slot < stacks.getSlots(); slot += 2) {
ItemStack stack = cosmeticStacks.getStackInSlot(slot);
if (stack.isEmpty() && stacksHandler.getRenders().get(slot)) {
stack = stacks.getStackInSlot(slot);
}
GloveCurioRenderer renderer = GloveCurioRenderer.getGloveRenderer(stack);
if (renderer != null) {
renderer.renderFirstPersonArm(event.getPoseStack(), event.getMultiBufferSource(), event.getPackedLight(), event.getPlayer(), event.getArm(), stack.hasFoil());
}
}
}
});
}
use of top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler in project The-Aether by Gilded-Games.
the class ArmorAbilityListener method breakPhoenixGloves.
private static void breakPhoenixGloves(LivingEntity entity, SlotResult slotResult, ItemStack outcomeStack) {
if (entity.level.getGameTime() % 10 == 0) {
slotResult.stack().hurtAndBreak(1, entity, (p) -> p.broadcastBreakEvent(EquipmentSlot.MAINHAND));
if (CuriosApi.getCuriosHelper().findFirstCurio(entity, AetherItems.PHOENIX_GLOVES.get()).isEmpty()) {
EnchantmentHelper.setEnchantments(EnchantmentHelper.getEnchantments(slotResult.stack()), outcomeStack);
if (slotResult.stack().hasTag()) {
outcomeStack.setTag(slotResult.stack().getTag());
}
CuriosApi.getCuriosHelper().getCuriosHandler(entity).ifPresent(iCuriosItemHandler -> {
Map<String, ICurioStacksHandler> curios = iCuriosItemHandler.getCurios();
ICurioStacksHandler inv = curios.get(slotResult.slotContext().identifier());
if (inv != null) {
IDynamicStackHandler stackHandler = inv.getStacks();
stackHandler.setStackInSlot(slotResult.slotContext().index(), outcomeStack);
}
});
}
}
}
Aggregations