allItemsStream, update quantum battery ticker
This commit is contained in:
parent
a1e6d28aff
commit
89c7adad8b
@ -15,9 +15,9 @@ import ru.dbotthepony.mc.otm.compat.mekanism.getMekanismEnergySided
|
|||||||
import ru.dbotthepony.mc.otm.compat.mekanism.mekanismEnergy
|
import ru.dbotthepony.mc.otm.compat.mekanism.mekanismEnergy
|
||||||
import ru.dbotthepony.mc.otm.container.iterator
|
import ru.dbotthepony.mc.otm.container.iterator
|
||||||
import ru.dbotthepony.mc.otm.container.stream
|
import ru.dbotthepony.mc.otm.container.stream
|
||||||
import ru.dbotthepony.mc.otm.core.iterator
|
|
||||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||||
import ru.dbotthepony.mc.otm.core.orNull
|
import ru.dbotthepony.mc.otm.core.orNull
|
||||||
|
import java.util.IdentityHashMap
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
|
|
||||||
val ICapabilityProvider.matteryPlayer: MatteryPlayerCapability? get() = getCapability(MatteryCapability.MATTERY_PLAYER).orNull()
|
val ICapabilityProvider.matteryPlayer: MatteryPlayerCapability? get() = getCapability(MatteryCapability.MATTERY_PLAYER).orNull()
|
||||||
@ -152,8 +152,10 @@ fun ICapabilityProvider.getMatteryEnergySided(side: Direction? = null): LazyOpti
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DO NOT modify returned ItemStacks!
|
* DO NOT modify returned ItemStacks!
|
||||||
|
*
|
||||||
|
* Contains all items that player might carry
|
||||||
*/
|
*/
|
||||||
fun Player.itemStream(): Stream<out ItemStack> {
|
fun Player.itemsStream(): Stream<out ItemStack> {
|
||||||
val streams = ArrayList<Stream<out ItemStack>>()
|
val streams = ArrayList<Stream<out ItemStack>>()
|
||||||
streams.add(inventory.stream())
|
streams.add(inventory.stream())
|
||||||
|
|
||||||
@ -170,6 +172,27 @@ fun Player.itemStream(): Stream<out ItemStack> {
|
|||||||
return Streams.concat(*streams.toTypedArray())
|
return Streams.concat(*streams.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DO NOT modify returned ItemStacks!
|
||||||
|
*
|
||||||
|
* Contains all items that player might see/access ([itemsStream] + open container's items)
|
||||||
|
*/
|
||||||
|
fun Player.allItemsStream(): Stream<out ItemStack> {
|
||||||
|
if (containerMenu == inventoryMenu) {
|
||||||
|
return itemsStream()
|
||||||
|
}
|
||||||
|
|
||||||
|
val seen = IdentityHashMap<ItemStack, Unit>(containerMenu.slots.size)
|
||||||
|
|
||||||
|
for (slot in containerMenu.slots) {
|
||||||
|
seen[slot.item] = Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
return Streams.concat(
|
||||||
|
itemsStream().filter { it.isEmpty || it !in seen },
|
||||||
|
containerMenu.slots.stream().map { it.item })
|
||||||
|
}
|
||||||
|
|
||||||
fun Player.extendedItemIterator(): MutableIterator<ItemStack> {
|
fun Player.extendedItemIterator(): MutableIterator<ItemStack> {
|
||||||
return object : MutableIterator<ItemStack> {
|
return object : MutableIterator<ItemStack> {
|
||||||
private val regular = this@extendedItemIterator.inventory.iterator()
|
private val regular = this@extendedItemIterator.inventory.iterator()
|
||||||
|
@ -14,7 +14,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
|||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType
|
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType
|
||||||
import net.minecraftforge.registries.ForgeRegistries
|
import net.minecraftforge.registries.ForgeRegistries
|
||||||
import ru.dbotthepony.mc.otm.capability.itemStream
|
import ru.dbotthepony.mc.otm.capability.itemsStream
|
||||||
import ru.dbotthepony.mc.otm.core.registryName
|
import ru.dbotthepony.mc.otm.core.registryName
|
||||||
import ru.dbotthepony.mc.otm.core.set
|
import ru.dbotthepony.mc.otm.core.set
|
||||||
import ru.dbotthepony.mc.otm.registry.MLootItemConditions
|
import ru.dbotthepony.mc.otm.registry.MLootItemConditions
|
||||||
@ -25,7 +25,7 @@ class ItemInInventoryCondition(
|
|||||||
val matchNBT: Boolean = false
|
val matchNBT: Boolean = false
|
||||||
) : LootItemCondition, LootItemCondition.Builder {
|
) : LootItemCondition, LootItemCondition.Builder {
|
||||||
override fun test(t: LootContext): Boolean {
|
override fun test(t: LootContext): Boolean {
|
||||||
val matches = t[LootContextParams.LAST_DAMAGE_PLAYER]?.itemStream()?.filter {
|
val matches = t[LootContextParams.LAST_DAMAGE_PLAYER]?.itemsStream()?.filter {
|
||||||
if (it.isEmpty) {
|
if (it.isEmpty) {
|
||||||
return@filter false
|
return@filter false
|
||||||
}
|
}
|
||||||
|
@ -380,8 +380,7 @@ class QuantumBatteryItem : Item {
|
|||||||
for (ply in event.server.playerList.players) {
|
for (ply in event.server.playerList.players) {
|
||||||
val networkedChannels = IntAVLTreeSet()
|
val networkedChannels = IntAVLTreeSet()
|
||||||
|
|
||||||
for (item in ply.containerMenu.itemStackIterator().nonEmpty()) {
|
for (item in ply.allItemsStream().filter { !it.isEmpty && it.item is QuantumBatteryItem }) {
|
||||||
if (item.item is QuantumBatteryItem) {
|
|
||||||
val power = item.getCapability(MatteryCapability.ENERGY).orThrow() as Power
|
val power = item.getCapability(MatteryCapability.ENERGY).orThrow() as Power
|
||||||
|
|
||||||
power.determineQuantumLinkWeak()
|
power.determineQuantumLinkWeak()
|
||||||
@ -397,7 +396,6 @@ class QuantumBatteryItem : Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadValue(parent: SavedCountingMap<Data>, tag: Tag, index: Int): Data {
|
private fun loadValue(parent: SavedCountingMap<Data>, tag: Tag, index: Int): Data {
|
||||||
if (tag is ByteArrayTag) {
|
if (tag is ByteArrayTag) {
|
||||||
|
Loading…
Reference in New Issue
Block a user