Remove last uses of LibBlockAttributes grouped inventories
This commit is contained in:
parent
03fd8ff699
commit
d782d43e1b
|
@ -1,7 +1,5 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.AttributeList
|
|
||||||
import alexiil.mc.lib.attributes.AttributeProvider
|
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.Material
|
import net.minecraft.block.Material
|
||||||
|
@ -12,15 +10,11 @@ import net.minecraft.state.StateManager
|
||||||
import net.minecraft.state.property.Properties
|
import net.minecraft.state.property.Properties
|
||||||
import net.minecraft.util.ActionResult
|
import net.minecraft.util.ActionResult
|
||||||
import net.minecraft.util.Hand
|
import net.minecraft.util.Hand
|
||||||
import net.minecraft.util.Identifier
|
|
||||||
import net.minecraft.util.ItemScatterer
|
|
||||||
import net.minecraft.util.hit.BlockHitResult
|
import net.minecraft.util.hit.BlockHitResult
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.math.BlockPos
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.minecraft.world.BlockView
|
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
import net.minecraft.world.WorldAccess
|
import net.minecraft.world.WorldAccess
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
||||||
import net.shadowfacts.phycon.api.NetworkComponentBlock
|
import net.shadowfacts.phycon.api.NetworkComponentBlock
|
||||||
import net.shadowfacts.phycon.block.DeviceBlock
|
import net.shadowfacts.phycon.block.DeviceBlock
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
|
@ -33,8 +27,7 @@ abstract class AbstractTerminalBlock<T : AbstractTerminalBlockEntity> : DeviceBl
|
||||||
.strength(1.5f)
|
.strength(1.5f)
|
||||||
.sounds(BlockSoundGroup.METAL)
|
.sounds(BlockSoundGroup.METAL)
|
||||||
),
|
),
|
||||||
NetworkComponentBlock,
|
NetworkComponentBlock {
|
||||||
AttributeProvider {
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val FACING = Properties.FACING
|
val FACING = Properties.FACING
|
||||||
|
@ -75,8 +68,4 @@ abstract class AbstractTerminalBlock<T : AbstractTerminalBlockEntity> : DeviceBl
|
||||||
super.onStateReplaced(state, world, pos, newState, moved)
|
super.onStateReplaced(state, world, pos, newState, moved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
|
||||||
to.offer(getBlockEntity(world, pos))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant
|
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant
|
||||||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage
|
import net.fabricmc.fabric.api.transfer.v1.storage.Storage
|
||||||
|
@ -21,7 +20,6 @@ import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||||
import net.shadowfacts.phycon.component.*
|
import net.shadowfacts.phycon.component.*
|
||||||
import net.shadowfacts.phycon.packet.*
|
import net.shadowfacts.phycon.packet.*
|
||||||
import net.shadowfacts.phycon.util.Either
|
|
||||||
import net.shadowfacts.phycon.util.NetworkUtil
|
import net.shadowfacts.phycon.util.NetworkUtil
|
||||||
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
@ -47,7 +45,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
val REQUEST_INVENTORY_TIMEOUT: Long = 1 // ticks
|
val REQUEST_INVENTORY_TIMEOUT: Long = 1 // ticks
|
||||||
}
|
}
|
||||||
|
|
||||||
protected val inventoryCache = mutableMapOf<IPAddress, Either<Storage<ItemVariant>, GroupedItemInvView>>()
|
protected val inventoryCache = mutableMapOf<IPAddress, Storage<ItemVariant>>()
|
||||||
val internalBuffer = TerminalBufferInventory(18)
|
val internalBuffer = TerminalBufferInventory(18)
|
||||||
|
|
||||||
protected val pendingRequests = LinkedList<StackLocateRequest>()
|
protected val pendingRequests = LinkedList<StackLocateRequest>()
|
||||||
|
@ -82,7 +80,6 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
|
|
||||||
override fun handle(packet: Packet) {
|
override fun handle(packet: Packet) {
|
||||||
when (packet) {
|
when (packet) {
|
||||||
is ReadGroupedInventoryPacket -> handleReadInventory(packet)
|
|
||||||
is ReadItemStoragePacket -> handleReadItemStorage(packet)
|
is ReadItemStoragePacket -> handleReadItemStorage(packet)
|
||||||
is DeviceRemovedPacket -> handleDeviceRemoved(packet)
|
is DeviceRemovedPacket -> handleDeviceRemoved(packet)
|
||||||
is StackLocationPacket -> handleStackLocation(packet)
|
is StackLocationPacket -> handleStackLocation(packet)
|
||||||
|
@ -91,13 +88,8 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReadInventory(packet: ReadGroupedInventoryPacket) {
|
|
||||||
inventoryCache[packet.source] = Either.Right(packet.inventory)
|
|
||||||
updateAndSync()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleReadItemStorage(packet: ReadItemStoragePacket) {
|
private fun handleReadItemStorage(packet: ReadItemStoragePacket) {
|
||||||
inventoryCache[packet.source] = Either.Left(packet.inventory)
|
inventoryCache[packet.source] = packet.inventory
|
||||||
updateAndSync()
|
updateAndSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,23 +139,13 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
private fun updateNetItems() {
|
private fun updateNetItems() {
|
||||||
cachedNetItems.clear()
|
cachedNetItems.clear()
|
||||||
for (inventory in inventoryCache.values) {
|
for (inventory in inventoryCache.values) {
|
||||||
when (inventory) {
|
|
||||||
is Either.Left -> {
|
|
||||||
val transaction = Transaction.openOuter()
|
val transaction = Transaction.openOuter()
|
||||||
for (view in inventory.left.iterator(transaction)) {
|
for (view in inventory.iterator(transaction)) {
|
||||||
val amount = view.amount.toInt()
|
val amount = view.amount.toInt()
|
||||||
cachedNetItems.mergeInt(view.resource.toStack(), amount, IntBinaryOperator { a, b -> a + b })
|
cachedNetItems.mergeInt(view.resource.toStack(), amount, IntBinaryOperator { a, b -> a + b })
|
||||||
}
|
}
|
||||||
transaction.close()
|
transaction.close()
|
||||||
}
|
}
|
||||||
is Either.Right -> {
|
|
||||||
for (stack in inventory.right.storedStacks) {
|
|
||||||
val amount = inventory.right.getAmount(stack)
|
|
||||||
cachedNetItems.mergeInt(stack, amount, IntBinaryOperator { a, b -> a + b })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun beginInsertions() {
|
private fun beginInsertions() {
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package net.shadowfacts.phycon.packet
|
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
@Deprecated("Use Fabric Transfer API")
|
|
||||||
class ReadGroupedInventoryPacket(
|
|
||||||
val inventory: GroupedItemInvView,
|
|
||||||
source: IPAddress,
|
|
||||||
destination: IPAddress
|
|
||||||
) : BasePacket(source, destination)
|
|
Loading…
Reference in New Issue