diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlock.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlock.kt index 66db0ed..376a968 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlock.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlock.kt @@ -1,7 +1,5 @@ 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.BlockState import net.minecraft.block.Material @@ -12,15 +10,11 @@ import net.minecraft.state.StateManager import net.minecraft.state.property.Properties import net.minecraft.util.ActionResult 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.math.BlockPos import net.minecraft.util.math.Direction -import net.minecraft.world.BlockView import net.minecraft.world.World import net.minecraft.world.WorldAccess -import net.shadowfacts.phycon.PhysicalConnectivity import net.shadowfacts.phycon.api.NetworkComponentBlock import net.shadowfacts.phycon.block.DeviceBlock import java.util.EnumSet @@ -33,8 +27,7 @@ abstract class AbstractTerminalBlock : DeviceBl .strength(1.5f) .sounds(BlockSoundGroup.METAL) ), - NetworkComponentBlock, - AttributeProvider { + NetworkComponentBlock { companion object { val FACING = Properties.FACING @@ -75,8 +68,4 @@ abstract class AbstractTerminalBlock : DeviceBl super.onStateReplaced(state, world, pos, newState, moved) } } - - override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) { - to.offer(getBlockEntity(world, pos)) - } } diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt index 952ee2a..1a6993b 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt @@ -1,6 +1,5 @@ package net.shadowfacts.phycon.block.terminal -import alexiil.mc.lib.attributes.item.GroupedItemInvView import alexiil.mc.lib.attributes.item.ItemStackCollections import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant 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.component.* import net.shadowfacts.phycon.packet.* -import net.shadowfacts.phycon.util.Either import net.shadowfacts.phycon.util.NetworkUtil import net.shadowfacts.phycon.util.equalsIgnoringAmount import java.lang.ref.WeakReference @@ -47,7 +45,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP val REQUEST_INVENTORY_TIMEOUT: Long = 1 // ticks } - protected val inventoryCache = mutableMapOf, GroupedItemInvView>>() + protected val inventoryCache = mutableMapOf>() val internalBuffer = TerminalBufferInventory(18) protected val pendingRequests = LinkedList() @@ -82,7 +80,6 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP override fun handle(packet: Packet) { when (packet) { - is ReadGroupedInventoryPacket -> handleReadInventory(packet) is ReadItemStoragePacket -> handleReadItemStorage(packet) is DeviceRemovedPacket -> handleDeviceRemoved(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) { - inventoryCache[packet.source] = Either.Left(packet.inventory) + inventoryCache[packet.source] = packet.inventory updateAndSync() } @@ -147,22 +139,12 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP private fun updateNetItems() { cachedNetItems.clear() for (inventory in inventoryCache.values) { - when (inventory) { - is Either.Left -> { - val transaction = Transaction.openOuter() - for (view in inventory.left.iterator(transaction)) { - val amount = view.amount.toInt() - cachedNetItems.mergeInt(view.resource.toStack(), amount, IntBinaryOperator { a, b -> a + b }) - } - 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 }) - } - } + val transaction = Transaction.openOuter() + for (view in inventory.iterator(transaction)) { + val amount = view.amount.toInt() + cachedNetItems.mergeInt(view.resource.toStack(), amount, IntBinaryOperator { a, b -> a + b }) } + transaction.close() } } diff --git a/src/main/kotlin/net/shadowfacts/phycon/packet/ReadGroupedInventoryPacket.kt b/src/main/kotlin/net/shadowfacts/phycon/packet/ReadGroupedInventoryPacket.kt deleted file mode 100644 index 9e1a056..0000000 --- a/src/main/kotlin/net/shadowfacts/phycon/packet/ReadGroupedInventoryPacket.kt +++ /dev/null @@ -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)