mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix some container bugs + tests
This commit is contained in:
parent
c825d9434e
commit
c6f6453c73
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.data.container
|
||||
|
||||
import de.bixilon.minosoft.data.container.types.PlayerInventory
|
||||
import de.bixilon.minosoft.data.container.types.generic.Generic9x3Container
|
||||
import de.bixilon.minosoft.data.container.types.processing.smelting.FurnaceContainer
|
||||
import de.bixilon.minosoft.data.registries.containers.ContainerFactory
|
||||
@ -36,6 +37,12 @@ object ContainerTestUtil {
|
||||
reference()
|
||||
}
|
||||
|
||||
fun createInventory(connection: PlayConnection = createConnection()): Container {
|
||||
val inventory = PlayerInventory(connection)
|
||||
connection.player.containers[0] = inventory
|
||||
return inventory
|
||||
}
|
||||
|
||||
fun createContainer(connection: PlayConnection = createConnection()): Container {
|
||||
val container = Container(connection, this.container)
|
||||
connection.player.containers[9] = container
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.container.click
|
||||
|
||||
import de.bixilon.minosoft.data.container.ContainerTestUtil.createChest
|
||||
import de.bixilon.minosoft.data.container.ContainerTestUtil.createFurnace
|
||||
import de.bixilon.minosoft.data.container.ContainerTestUtil.createInventory
|
||||
import de.bixilon.minosoft.data.container.ContainerUtil.slotsOf
|
||||
import de.bixilon.minosoft.data.container.stack.ItemStack
|
||||
import de.bixilon.minosoft.data.registries.items.AppleTestO
|
||||
@ -139,5 +140,33 @@ class FastMoveContainerActionTest {
|
||||
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 30, 1, 0, 0, slotsOf(30 to null, 1 to ItemStack(CoalTest0.item, count = 12)), null))
|
||||
}
|
||||
|
||||
|
||||
fun playerPassiveToHotbar() {
|
||||
val connection = createConnection()
|
||||
val container = createInventory(connection)
|
||||
container[9] = ItemStack(AppleTestO.item)
|
||||
container.invokeAction(FastMoveContainerAction(9))
|
||||
assertNull(container.floatingItem)
|
||||
assertEquals(container.slots, slotsOf(36 to ItemStack(AppleTestO.item)))
|
||||
}
|
||||
|
||||
fun craftingToPassive() {
|
||||
val connection = createConnection()
|
||||
val container = createInventory(connection)
|
||||
container[1] = ItemStack(AppleTestO.item)
|
||||
container.invokeAction(FastMoveContainerAction(1))
|
||||
assertNull(container.floatingItem)
|
||||
assertEquals(container.slots, slotsOf(9 to ItemStack(AppleTestO.item)))
|
||||
}
|
||||
|
||||
fun hotbarToPassive() {
|
||||
val connection = createConnection()
|
||||
val container = createInventory(connection)
|
||||
container[36] = ItemStack(AppleTestO.item)
|
||||
container.invokeAction(FastMoveContainerAction(36))
|
||||
assertNull(container.floatingItem)
|
||||
assertEquals(container.slots, slotsOf(9 to ItemStack(AppleTestO.item)))
|
||||
}
|
||||
|
||||
// TODO: revert, full container
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.container.sections
|
||||
|
||||
import de.bixilon.minosoft.data.container.types.PlayerInventory
|
||||
|
||||
class HotbarSection(val offset: Int) : RangeSection(offset, PlayerInventory.HOTBAR_SLOTS) {
|
||||
override val fillReversed: Boolean get() = true
|
||||
class HotbarSection(val offset: Int, override val fillReversed: Boolean = true) : RangeSection(offset, PlayerInventory.HOTBAR_SLOTS) {
|
||||
override val count: Int get() = PlayerInventory.HOTBAR_SLOTS
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.container.sections
|
||||
|
||||
import de.bixilon.minosoft.data.container.types.PlayerInventory
|
||||
|
||||
class PassiveInventorySection(val offset: Int) : RangeSection(offset, PlayerInventory.PASSIVE_SLOTS) {
|
||||
class PassiveInventorySection(val offset: Int, override val fillReversed: Boolean = true) : RangeSection(offset, PlayerInventory.PASSIVE_SLOTS) {
|
||||
override val count: Int get() = PlayerInventory.PASSIVE_SLOTS
|
||||
override val fillReversed: Boolean get() = true
|
||||
}
|
||||
|
@ -115,16 +115,6 @@ class PlayerInventory(connection: PlayConnection) : Container(connection = conne
|
||||
return HOTBAR_OFFSET + slot.ordinal
|
||||
}
|
||||
|
||||
override fun getSection(slotId: Int): Int? {
|
||||
return when (slotId) {
|
||||
in 0..4 -> null // crafting
|
||||
in ARMOR_OFFSET..ARMOR_OFFSET + 4 -> 0 // armor
|
||||
in MAIN_SLOTS_START until HOTBAR_OFFSET -> 1 // inventory
|
||||
in HOTBAR_OFFSET..HOTBAR_OFFSET + HOTBAR_SLOTS -> 2 // hotbar
|
||||
else -> null // offhand, else
|
||||
}
|
||||
}
|
||||
|
||||
val EquipmentSlots.slot: Int
|
||||
get() = when (this) {
|
||||
EquipmentSlots.HEAD -> ARMOR_OFFSET + 0
|
||||
@ -169,8 +159,8 @@ class PlayerInventory(connection: PlayConnection) : Container(connection = conne
|
||||
|
||||
private val SECTIONS = arrayOf<ContainerSection>(
|
||||
RangeSection(ARMOR_OFFSET, 4),
|
||||
PassiveInventorySection(ARMOR_OFFSET + 5),
|
||||
HotbarSection(HOTBAR_OFFSET),
|
||||
PassiveInventorySection(MAIN_SLOTS_START, false),
|
||||
HotbarSection(HOTBAR_OFFSET, false),
|
||||
)
|
||||
|
||||
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): PlayerInventory {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -80,7 +80,8 @@ class ClientPacketHandler(
|
||||
|
||||
private fun handle(packet: S2CPacket) {
|
||||
val event = PacketReceiveEvent(connection, packet)
|
||||
if (connection.fire(event)) {
|
||||
Thread.sleep(100)
|
||||
if (connection.events.fire(event)) {
|
||||
return
|
||||
}
|
||||
when (packet) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.container
|
||||
|
||||
import de.bixilon.minosoft.data.container.types.PlayerInventory
|
||||
import de.bixilon.minosoft.modding.event.events.container.ContainerCloseEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||
@ -26,9 +27,13 @@ class CloseContainerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val containerId: Int = buffer.readUnsignedByte()
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
if (containerId == PlayerInventory.CONTAINER_ID) {
|
||||
// server can not close inventory
|
||||
return
|
||||
}
|
||||
val container = connection.player.containers[containerId] ?: return
|
||||
container.onClose()
|
||||
connection.fire(ContainerCloseEvent(connection, containerId, container))
|
||||
connection.events.fire(ContainerCloseEvent(connection, containerId, container))
|
||||
}
|
||||
|
||||
override fun log(reducedLog: Boolean) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user