Compare commits
3 Commits
a88eda357c
...
870785f6f2
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 870785f6f2 | |
Shadowfacts | 9d16a7e5cd | |
Shadowfacts | c9fe6400f0 |
|
@ -50,7 +50,6 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL),
|
||||||
private val inventoryCache = mutableMapOf<IPAddress, GroupedItemInvView>()
|
private val inventoryCache = mutableMapOf<IPAddress, GroupedItemInvView>()
|
||||||
val internalBuffer = TerminalBufferInventory(18)
|
val internalBuffer = TerminalBufferInventory(18)
|
||||||
|
|
||||||
private val locateRequestQueue = LinkedList<StackLocateRequest>()
|
|
||||||
private val pendingRequests = LinkedList<StackLocateRequest>()
|
private val pendingRequests = LinkedList<StackLocateRequest>()
|
||||||
override val pendingInsertions = mutableListOf<PendingInsertion>()
|
override val pendingInsertions = mutableListOf<PendingInsertion>()
|
||||||
override val dispatchStackTimeout = INSERTION_TIMEOUT
|
override val dispatchStackTimeout = INSERTION_TIMEOUT
|
||||||
|
@ -103,7 +102,7 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL),
|
||||||
}
|
}
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
request.results.add(packet.amount to packet.stackProvider)
|
request.results.add(packet.amount to packet.stackProvider)
|
||||||
if (request.totalResultAmount >= request.amount || counter - request.timestamp >= LOCATE_REQUEST_TIMEOUT || request.results.size >= inventoryCache.size) {
|
if (request.isFinishable(counter)) {
|
||||||
stackLocateRequestCompleted(request)
|
stackLocateRequestCompleted(request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,16 +148,6 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendEnqueuedLocateRequests() {
|
|
||||||
if (world!!.isClient) return
|
|
||||||
|
|
||||||
for (request in locateRequestQueue) {
|
|
||||||
pendingRequests.add(request)
|
|
||||||
sendPacket(LocateStackPacket(request.stack, ipAddress))
|
|
||||||
}
|
|
||||||
locateRequestQueue.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun finishPendingRequests() {
|
private fun finishPendingRequests() {
|
||||||
if (world!!.isClient) return
|
if (world!!.isClient) return
|
||||||
if (pendingRequests.isEmpty()) return
|
if (pendingRequests.isEmpty()) return
|
||||||
|
@ -181,7 +170,6 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL),
|
||||||
|
|
||||||
if (counter % 20 == 0L) {
|
if (counter % 20 == 0L) {
|
||||||
if (!world!!.isClient) {
|
if (!world!!.isClient) {
|
||||||
sendEnqueuedLocateRequests()
|
|
||||||
finishPendingRequests()
|
finishPendingRequests()
|
||||||
beginInsertions()
|
beginInsertions()
|
||||||
finishTimedOutPendingInsertions()
|
finishTimedOutPendingInsertions()
|
||||||
|
@ -222,7 +210,11 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL),
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestItem(stack: ItemStack, amount: Int = stack.count) {
|
fun requestItem(stack: ItemStack, amount: Int = stack.count) {
|
||||||
locateRequestQueue.add(StackLocateRequest(stack, amount, counter))
|
val request = StackLocateRequest(stack, amount, counter)
|
||||||
|
pendingRequests.add(request)
|
||||||
|
// locate packets are sent immediately instead of being added to a queue
|
||||||
|
// otherwise the terminal UI feels sluggish and unresponsive
|
||||||
|
sendPacket(LocateStackPacket(stack, ipAddress))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stackLocateRequestCompleted(request: StackLocateRequest) {
|
private fun stackLocateRequestCompleted(request: StackLocateRequest) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.client.gui.widget.TextFieldWidget
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.screen.slot.Slot
|
import net.minecraft.screen.slot.Slot
|
||||||
|
import net.minecraft.screen.slot.SlotActionType
|
||||||
import net.minecraft.text.LiteralText
|
import net.minecraft.text.LiteralText
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
|
@ -89,6 +90,13 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
|
||||||
DrawableHelper.fill(matrixStack, slot.x, slot.y, slot.x + 16, slot.y + 16, color.toInt())
|
DrawableHelper.fill(matrixStack, slot.x, slot.y, slot.x + 16, slot.y + 16, color.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMouseClick(slot: Slot?, i: Int, j: Int, slotActionType: SlotActionType?) {
|
||||||
|
super.onMouseClick(slot, i, j, slotActionType)
|
||||||
|
|
||||||
|
// don't unfocus the search box on mouse click
|
||||||
|
searchBox.setSelected(true)
|
||||||
|
}
|
||||||
|
|
||||||
override fun charTyped(c: Char, i: Int): Boolean {
|
override fun charTyped(c: Char, i: Int): Boolean {
|
||||||
val oldText = searchBox.text
|
val oldText = searchBox.text
|
||||||
if (searchBox.charTyped(c, i)) {
|
if (searchBox.charTyped(c, i)) {
|
||||||
|
|
|
@ -26,7 +26,14 @@ object C2STerminalRequestItem: ServerReceiver {
|
||||||
val buf = PacketByteBufs.create()
|
val buf = PacketByteBufs.create()
|
||||||
buf.writeIdentifier(terminal.world!!.registryKey.value)
|
buf.writeIdentifier(terminal.world!!.registryKey.value)
|
||||||
buf.writeBlockPos(terminal.pos)
|
buf.writeBlockPos(terminal.pos)
|
||||||
buf.writeItemStack(stack)
|
|
||||||
|
// Force the count of the stack to be 1 before serializing for the network because
|
||||||
|
// PacketByteBuf serializes the stack count as a byte. Otherwise counts > 127 will result in
|
||||||
|
// an overflow and be negative on the receiving side.
|
||||||
|
val stackCopy = stack.copy()
|
||||||
|
stackCopy.count = 1
|
||||||
|
buf.writeItemStack(stackCopy)
|
||||||
|
|
||||||
buf.writeVarInt(amount)
|
buf.writeVarInt(amount)
|
||||||
return ClientPlayNetworking.createC2SPacket(CHANNEL, buf)
|
return ClientPlayNetworking.createC2SPacket(CHANNEL, buf)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue