Prepare for LibBlockAttributes removal
This commit is contained in:
parent
21d6a0a168
commit
4e32bfb510
|
@ -4,7 +4,6 @@ import alexiil.mc.lib.attributes.SearchOptions
|
||||||
import alexiil.mc.lib.attributes.Simulation
|
import alexiil.mc.lib.attributes.Simulation
|
||||||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||||
import alexiil.mc.lib.attributes.item.ItemInsertable
|
import alexiil.mc.lib.attributes.item.ItemInsertable
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.NbtCompound
|
||||||
|
@ -22,6 +21,7 @@ import net.shadowfacts.phycon.packet.*
|
||||||
import net.shadowfacts.phycon.util.ActivationMode
|
import net.shadowfacts.phycon.util.ActivationMode
|
||||||
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
||||||
import net.shadowfacts.phycon.util.GhostInv
|
import net.shadowfacts.phycon.util.GhostInv
|
||||||
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ class InserterBlockEntity(pos: BlockPos, state: BlockState) : DeviceBlockEntity(
|
||||||
|
|
||||||
private fun handleStackLocation(packet: StackLocationPacket) {
|
private fun handleStackLocation(packet: StackLocationPacket) {
|
||||||
val request = currentRequest
|
val request = currentRequest
|
||||||
if (request != null && ItemStackUtil.areEqualIgnoreAmounts(request.stack, packet.stack)) {
|
if (request != null && request.stack.equalsIgnoringAmount(packet.stack)) {
|
||||||
request.results.add(packet.amount to packet.stackProvider)
|
request.results.add(packet.amount to packet.stackProvider)
|
||||||
if (request.isFinishable(counter)) {
|
if (request.isFinishable(counter)) {
|
||||||
finishRequest()
|
finishRequest()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block.miner
|
package net.shadowfacts.phycon.block.miner
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import alexiil.mc.lib.attributes.item.filter.ItemFilter
|
import alexiil.mc.lib.attributes.item.filter.ItemFilter
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
|
@ -22,6 +21,7 @@ import net.shadowfacts.phycon.packet.*
|
||||||
import net.shadowfacts.phycon.util.ActivationMode
|
import net.shadowfacts.phycon.util.ActivationMode
|
||||||
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
||||||
import net.shadowfacts.phycon.util.copyWithCount
|
import net.shadowfacts.phycon.util.copyWithCount
|
||||||
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +89,7 @@ class MinerBlockEntity(pos: BlockPos, state: BlockState) : DeviceBlockEntity(Phy
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (!ItemStackUtil.areEqualIgnoreAmounts(droppedStack, packet.stack)) {
|
if (!droppedStack.equalsIgnoringAmount(packet.stack)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.shadowfacts.phycon.block.netinterface
|
package net.shadowfacts.phycon.block.netinterface
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.AttributeList
|
|
||||||
import alexiil.mc.lib.attributes.AttributeProvider
|
|
||||||
import net.minecraft.block.*
|
import net.minecraft.block.*
|
||||||
import net.minecraft.entity.LivingEntity
|
import net.minecraft.entity.LivingEntity
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
|
@ -23,8 +21,7 @@ class InterfaceBlock : FaceDeviceBlock<InterfaceBlockEntity>(
|
||||||
.strength(1.5f)
|
.strength(1.5f)
|
||||||
.sounds(BlockSoundGroup.METAL)
|
.sounds(BlockSoundGroup.METAL)
|
||||||
),
|
),
|
||||||
NetworkComponentBlock,
|
NetworkComponentBlock {
|
||||||
AttributeProvider {
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "network_interface")
|
val ID = Identifier(PhysicalConnectivity.MODID, "network_interface")
|
||||||
|
@ -61,8 +58,4 @@ class InterfaceBlock : FaceDeviceBlock<InterfaceBlockEntity>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
|
||||||
to.offer(getBlockEntity(world, pos))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.shadowfacts.phycon.block.netswitch
|
package net.shadowfacts.phycon.block.netswitch
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.AttributeList
|
|
||||||
import alexiil.mc.lib.attributes.AttributeProvider
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.Material
|
import net.minecraft.block.Material
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
|
@ -11,7 +9,6 @@ import net.minecraft.sound.BlockSoundGroup
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
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.PhysicalConnectivity
|
||||||
|
@ -28,8 +25,7 @@ class SwitchBlock : BlockWithEntity<SwitchBlockEntity>(
|
||||||
.strength(1.5f)
|
.strength(1.5f)
|
||||||
.sounds(BlockSoundGroup.METAL)
|
.sounds(BlockSoundGroup.METAL)
|
||||||
),
|
),
|
||||||
NetworkComponentBlock,
|
NetworkComponentBlock {
|
||||||
AttributeProvider {
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "switch")
|
val ID = Identifier(PhysicalConnectivity.MODID, "switch")
|
||||||
|
@ -63,8 +59,4 @@ class SwitchBlock : BlockWithEntity<SwitchBlockEntity>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
|
||||||
to.offer(getBlockEntity(world, pos))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
import net.minecraft.block.entity.BlockEntityType
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
|
@ -18,9 +17,9 @@ import net.shadowfacts.phycon.api.packet.Packet
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
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.frame.NetworkSplitFrame
|
|
||||||
import net.shadowfacts.phycon.packet.*
|
import net.shadowfacts.phycon.packet.*
|
||||||
import net.shadowfacts.phycon.util.NetworkUtil
|
import net.shadowfacts.phycon.util.NetworkUtil
|
||||||
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.function.IntBinaryOperator
|
import java.util.function.IntBinaryOperator
|
||||||
|
@ -98,7 +97,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
|
|
||||||
private fun handleStackLocation(packet: StackLocationPacket) {
|
private fun handleStackLocation(packet: StackLocationPacket) {
|
||||||
val request = pendingRequests.firstOrNull {
|
val request = pendingRequests.firstOrNull {
|
||||||
ItemStackUtil.areEqualIgnoreAmounts(it.stack, packet.stack)
|
it.stack.equalsIgnoringAmount(packet.stack)
|
||||||
}
|
}
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
request.results.add(packet.amount to packet.stackProvider)
|
request.results.add(packet.amount to packet.stackProvider)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
|
@ -17,7 +16,7 @@ import net.minecraft.util.math.BlockPos
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.packet.ItemStackPacket
|
import net.shadowfacts.phycon.packet.ItemStackPacket
|
||||||
import net.shadowfacts.phycon.packet.LocateStackPacket
|
import net.shadowfacts.phycon.packet.LocateStackPacket
|
||||||
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import net.shadowfacts.phycon.util.fromTag
|
import net.shadowfacts.phycon.util.fromTag
|
||||||
import net.shadowfacts.phycon.util.toTag
|
import net.shadowfacts.phycon.util.toTag
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
|
@ -82,14 +81,14 @@ class CraftingTerminalBlockEntity(pos: BlockPos, state: BlockState) :
|
||||||
|
|
||||||
override fun doHandleItemStack(packet: ItemStackPacket): ItemStack {
|
override fun doHandleItemStack(packet: ItemStackPacket): ItemStack {
|
||||||
val craftingReq =
|
val craftingReq =
|
||||||
completedCraftingStackRequests.find { ItemStackUtil.areEqualIgnoreAmounts(it.stack, packet.stack) }
|
completedCraftingStackRequests.find { it.stack.equalsIgnoringAmount(packet.stack) }
|
||||||
if (craftingReq != null) {
|
if (craftingReq != null) {
|
||||||
var remaining = packet.stack.copy()
|
var remaining = packet.stack.copy()
|
||||||
|
|
||||||
for (i in 0 until craftingInv.size()) {
|
for (i in 0 until craftingInv.size()) {
|
||||||
val currentStack = craftingInv.getStack(i)
|
val currentStack = craftingInv.getStack(i)
|
||||||
if (currentStack.count >= currentStack.maxCount) continue
|
if (currentStack.count >= currentStack.maxCount) continue
|
||||||
if (!ItemStackUtil.areEqualIgnoreAmounts(currentStack, remaining)) continue
|
if (!currentStack.equalsIgnoringAmount(remaining)) continue
|
||||||
|
|
||||||
val toInsert =
|
val toInsert =
|
||||||
minOf(remaining.count, currentStack.maxCount - currentStack.count, craftingReq.amountPerSlot[i])
|
minOf(remaining.count, currentStack.maxCount - currentStack.count, craftingReq.amountPerSlot[i])
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import net.minecraft.inventory.SimpleInventory
|
import net.minecraft.inventory.SimpleInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.NbtCompound
|
||||||
import net.minecraft.nbt.NbtIntArray
|
import net.minecraft.nbt.NbtIntArray
|
||||||
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import net.shadowfacts.phycon.util.fromTag
|
import net.shadowfacts.phycon.util.fromTag
|
||||||
import net.shadowfacts.phycon.util.toTag
|
import net.shadowfacts.phycon.util.toTag
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
@ -54,7 +54,7 @@ class TerminalBufferInventory(size: Int) : SimpleInventory(size) {
|
||||||
setStack(slot, stack)
|
setStack(slot, stack)
|
||||||
markSlot(slot, mode)
|
markSlot(slot, mode)
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
|
} else if (stack.equalsIgnoringAmount(current)) {
|
||||||
val toTransfer = min(current.maxCount - current.count, stack.count)
|
val toTransfer = min(current.maxCount - current.count, stack.count)
|
||||||
current.count += toTransfer
|
current.count += toTransfer
|
||||||
stack.count -= toTransfer
|
stack.count -= toTransfer
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.shadowfacts.phycon.component
|
package net.shadowfacts.phycon.component
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
|
@ -8,6 +7,7 @@ import net.shadowfacts.phycon.packet.CapacityPacket
|
||||||
import net.shadowfacts.phycon.packet.CheckCapacityPacket
|
import net.shadowfacts.phycon.packet.CheckCapacityPacket
|
||||||
import net.shadowfacts.phycon.packet.ItemStackPacket
|
import net.shadowfacts.phycon.packet.ItemStackPacket
|
||||||
import net.shadowfacts.phycon.util.copyWithCount
|
import net.shadowfacts.phycon.util.copyWithCount
|
||||||
|
import net.shadowfacts.phycon.util.equalsIgnoringAmount
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +31,7 @@ interface NetworkStackDispatcher<Insertion : NetworkStackDispatcher.PendingInser
|
||||||
|
|
||||||
fun handleCapacity(packet: CapacityPacket) {
|
fun handleCapacity(packet: CapacityPacket) {
|
||||||
pendingInsertions.firstOrNull { insertion ->
|
pendingInsertions.firstOrNull { insertion ->
|
||||||
ItemStackUtil.areEqualIgnoreAmounts(packet.stack, insertion.stack) &&
|
packet.stack.equalsIgnoringAmount(insertion.stack) &&
|
||||||
insertion.results.none { it.second.ipAddress == packet.source }
|
insertion.results.none { it.second.ipAddress == packet.source }
|
||||||
}?.also { insertion ->
|
}?.also { insertion ->
|
||||||
insertion.results.add(packet.capacity to packet.stackReceiver)
|
insertion.results.add(packet.capacity to packet.stackReceiver)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Use Fabric Transfer API")
|
||||||
class ReadGroupedInventoryPacket(
|
class ReadGroupedInventoryPacket(
|
||||||
val inventory: GroupedItemInvView,
|
val inventory: GroupedItemInvView,
|
||||||
source: IPAddress,
|
source: IPAddress,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.shadowfacts.phycon.util
|
package net.shadowfacts.phycon.util
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
|
||||||
import net.minecraft.inventory.SimpleInventory
|
import net.minecraft.inventory.SimpleInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.NbtCompound
|
||||||
|
@ -45,7 +44,7 @@ fun SimpleInventory.insert(stack: ItemStack, slot: Int): ItemStack {
|
||||||
if (current.isEmpty) {
|
if (current.isEmpty) {
|
||||||
setStack(slot, stack)
|
setStack(slot, stack)
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
|
} else if (stack.equalsIgnoringAmount(current)) {
|
||||||
val toTransfer = min(current.maxCount - current.count, stack.count)
|
val toTransfer = min(current.maxCount - current.count, stack.count)
|
||||||
current.count += toTransfer
|
current.count += toTransfer
|
||||||
stack.count -= toTransfer
|
stack.count -= toTransfer
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package net.shadowfacts.phycon.util
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author shadowfacts
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun ItemStack.equalsIgnoringAmount(other: ItemStack): Boolean {
|
||||||
|
if (this.isEmpty) return other.isEmpty
|
||||||
|
if (other.isEmpty) return false
|
||||||
|
return this.item === other.item && this.nbt == other.nbt;
|
||||||
|
}
|
Loading…
Reference in New Issue