Update curios compat

This commit is contained in:
DBotThePony 2024-08-10 18:42:30 +07:00
parent dcd92f58a5
commit 73ce6e8e45
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -4,9 +4,9 @@ import com.google.common.collect.Streams
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.Slot import net.minecraft.world.inventory.Slot
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraftforge.fml.ModList import net.neoforged.fml.ModList
import net.minecraftforge.fml.loading.FMLEnvironment import net.neoforged.fml.loading.FMLEnvironment
import net.minecraftforge.network.PacketDistributor import net.neoforged.neoforge.network.PacketDistributor
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.matteryPlayer import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.container.util.awareStream import ru.dbotthepony.mc.otm.container.util.awareStream
@ -14,13 +14,12 @@ import ru.dbotthepony.mc.otm.container.util.iterator
import ru.dbotthepony.mc.otm.core.collect.AwareItemStack import ru.dbotthepony.mc.otm.core.collect.AwareItemStack
import ru.dbotthepony.mc.otm.core.collect.concatIterators import ru.dbotthepony.mc.otm.core.collect.concatIterators
import ru.dbotthepony.mc.otm.core.collect.emptyIterator import ru.dbotthepony.mc.otm.core.collect.emptyIterator
import ru.dbotthepony.mc.otm.core.orNull
import ru.dbotthepony.mc.otm.menu.PlayerSlot import ru.dbotthepony.mc.otm.menu.PlayerSlot
import top.theillusivec4.curios.api.CuriosApi import top.theillusivec4.curios.api.CuriosApi
import top.theillusivec4.curios.api.CuriosCapability
import top.theillusivec4.curios.api.event.SlotModifiersUpdatedEvent import top.theillusivec4.curios.api.event.SlotModifiersUpdatedEvent
import top.theillusivec4.curios.common.inventory.CosmeticCurioSlot import top.theillusivec4.curios.common.inventory.CosmeticCurioSlot
import top.theillusivec4.curios.common.inventory.CurioSlot import top.theillusivec4.curios.common.inventory.CurioSlot
import top.theillusivec4.curios.common.network.NetworkHandler
import top.theillusivec4.curios.common.network.client.CPacketOpenCurios import top.theillusivec4.curios.common.network.client.CPacketOpenCurios
import java.util.stream.Stream import java.util.stream.Stream
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -35,11 +34,11 @@ fun onCuriosSlotModifiersUpdated(event: SlotModifiersUpdatedEvent) {
} }
fun openCuriosScreen(carriedStack: ItemStack = ItemStack.EMPTY) { fun openCuriosScreen(carriedStack: ItemStack = ItemStack.EMPTY) {
if (FMLEnvironment.dist.isClient) NetworkHandler.INSTANCE.send(CPacketOpenCurios(carriedStack), PacketDistributor.SERVER.noArg()) if (FMLEnvironment.dist.isClient) PacketDistributor.sendToServer(CPacketOpenCurios(carriedStack))
} }
private fun Player.getCuriosSlotsImpl(): List<PlayerSlot<Slot, Slot>> { private fun Player.getCuriosSlotsImpl(): List<PlayerSlot<Slot, Slot>> {
val handler = getCapability(MatteryCapability.CURIOS_INVENTORY).orNull() ?: return listOf() val handler = getCapability(CuriosCapability.INVENTORY) ?: return listOf()
val result = ArrayList<PlayerSlot<Slot, Slot>>() val result = ArrayList<PlayerSlot<Slot, Slot>>()
@ -77,8 +76,6 @@ private fun Player.getCuriosSlotsImpl(): List<PlayerSlot<Slot, Slot>> {
* [Pair]<Regular, Cosmetic> * [Pair]<Regular, Cosmetic>
*/ */
val Player.curiosSlots: List<PlayerSlot<Slot, Slot>> get() { val Player.curiosSlots: List<PlayerSlot<Slot, Slot>> get() {
return listOf()
if (!isCuriosLoaded) { if (!isCuriosLoaded) {
return listOf() return listOf()
} }
@ -87,7 +84,7 @@ val Player.curiosSlots: List<PlayerSlot<Slot, Slot>> get() {
} }
private fun Player.curiosStreamImpl(includeCosmetics: Boolean): Iterator<ItemStack> { private fun Player.curiosStreamImpl(includeCosmetics: Boolean): Iterator<ItemStack> {
val handler = getCapability(MatteryCapability.CURIOS_INVENTORY).orNull() ?: return emptyIterator() val handler = getCapability(CuriosCapability.INVENTORY) ?: return emptyIterator()
val result = ArrayList<Iterator<ItemStack>>() val result = ArrayList<Iterator<ItemStack>>()
@ -103,8 +100,6 @@ private fun Player.curiosStreamImpl(includeCosmetics: Boolean): Iterator<ItemSta
} }
fun Player.curiosStream(includeCosmetics: Boolean = true): Iterator<ItemStack> { fun Player.curiosStream(includeCosmetics: Boolean = true): Iterator<ItemStack> {
return emptyIterator()
if (!isCuriosLoaded) { if (!isCuriosLoaded) {
return emptyIterator() return emptyIterator()
} }
@ -113,7 +108,7 @@ fun Player.curiosStream(includeCosmetics: Boolean = true): Iterator<ItemStack> {
} }
private fun Player.curiosAwareStreamImpl(includeCosmetics: Boolean): Stream<out AwareItemStack> { private fun Player.curiosAwareStreamImpl(includeCosmetics: Boolean): Stream<out AwareItemStack> {
val handler = getCapability(MatteryCapability.CURIOS_INVENTORY).orNull() ?: return Stream.empty() val handler = getCapability(CuriosCapability.INVENTORY) ?: return Stream.empty()
val result = ArrayList<Stream<out AwareItemStack>>() val result = ArrayList<Stream<out AwareItemStack>>()
@ -129,8 +124,6 @@ private fun Player.curiosAwareStreamImpl(includeCosmetics: Boolean): Stream<out
} }
fun Player.curiosAwareStream(includeCosmetics: Boolean = true): Stream<out AwareItemStack> { fun Player.curiosAwareStream(includeCosmetics: Boolean = true): Stream<out AwareItemStack> {
return Stream.empty()
if (!isCuriosLoaded) { if (!isCuriosLoaded) {
return Stream.empty() return Stream.empty()
} }