From 0f173922a582a434469593333de076c59d31bff9 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 25 Sep 2022 21:14:24 +0700 Subject: [PATCH] cosmetic armor streams --- .../ru/dbotthepony/mc/otm/capability/Ext.kt | 15 ++++++- .../mc/otm/compat/cos/CosmeticArmorCompat.kt | 44 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Ext.kt index 0f6e26bc9..d1b847e73 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Ext.kt @@ -9,6 +9,9 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.energy.IEnergyStorage import net.minecraftforge.fml.ModList +import ru.dbotthepony.mc.otm.compat.cos.cosmeticArmorAwareStream +import ru.dbotthepony.mc.otm.compat.cos.cosmeticArmorStream +import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorLoaded import ru.dbotthepony.mc.otm.compat.curios.curiosAwareStream import ru.dbotthepony.mc.otm.compat.curios.curiosStream import ru.dbotthepony.mc.otm.compat.curios.isCuriosLoaded @@ -173,6 +176,10 @@ fun Player.itemsStream(includeCosmetics: Boolean = true): Stream streams.add(curiosStream(includeCosmetics)) } + if (includeCosmetics && isCosmeticArmorLoaded) { + streams.add(cosmeticArmorStream()) + } + return Streams.concat(*streams.toTypedArray()) } @@ -202,7 +209,7 @@ fun Player.allItemsStream(includeCosmetics: Boolean = true): Stream { +fun Player.awareItemsStream(includeCosmetics: Boolean = false): Stream { val streams = LinkedList>() streams.add(inventory.awareStream()) @@ -216,6 +223,10 @@ fun Player.awareItemsStream(includeCosmetics: Boolean = true): Stream { +fun Player.awareAllItemsStream(includeCosmetics: Boolean = false): Stream { if (containerMenu == inventoryMenu || containerMenu == matteryPlayer?.exoSuitMenu) { return awareItemsStream(includeCosmetics) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt index 834035f14..67e487169 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt @@ -25,7 +25,11 @@ import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.RectangleButtonPanel import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton.Companion.BUTTON_ACTIVE import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton.Companion.BUTTON_INACTIVE +import ru.dbotthepony.mc.otm.container.awareStream +import ru.dbotthepony.mc.otm.container.stream +import ru.dbotthepony.mc.otm.core.AwareItemStack import ru.dbotthepony.mc.otm.menu.MatterySlot +import java.util.stream.Stream val isCosmeticArmorLoaded by lazy { ModList.get().isLoaded("cosmeticarmorreworked") @@ -65,6 +69,46 @@ private class CosmeticSlot(container: Container, private val slot: EquipmentSlot } } +fun Player.cosmeticArmorStream(): Stream { + if (!isCosmeticArmorLoaded) { + return Stream.empty() + } + + return cosmeticArmorStreamImpl() +} + +private fun Player.cosmeticArmorStreamImpl(): Stream { + val manager = ModObjects.invMan ?: return Stream.empty() + + val container = if (this !is ServerPlayer) { + manager.getCosArmorInventoryClient(uuid) + } else { + manager.getCosArmorInventory(uuid) + } + + return (container as Container).stream() +} + +fun Player.cosmeticArmorAwareStream(): Stream { + if (!isCosmeticArmorLoaded) { + return Stream.empty() + } + + return cosmeticArmorAwareStreamImpl() +} + +private fun Player.cosmeticArmorAwareStreamImpl(): Stream { + val manager = ModObjects.invMan ?: return Stream.empty() + + val container = if (this !is ServerPlayer) { + manager.getCosArmorInventoryClient(uuid) + } else { + manager.getCosArmorInventory(uuid) + } + + return (container as Container).awareStream() +} + private val Player.cosmeticArmorSlotsImpl: Map? get() { val manager = ModObjects.invMan ?: return null