Skip to content

Commit cb50e41

Browse files
committed
Merge branch 'refactor-containers'
2 parents b1270e7 + 777524c commit cb50e41

File tree

168 files changed

+2288
-2497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+2288
-2497
lines changed

doc/modding/Container.md

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/integration-test/kotlin/de/bixilon/minosoft/MinosoftSIT.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import de.bixilon.minosoft.gui.rendering.system.window.WindowFactory
3030
import de.bixilon.minosoft.gui.rendering.system.window.dummy.DummyWindow
3131
import de.bixilon.minosoft.main.BootTasks
3232
import de.bixilon.minosoft.main.MinosoftBoot
33+
import de.bixilon.minosoft.protocol.versions.Versions
3334
import de.bixilon.minosoft.terminal.RunConfiguration
3435
import de.bixilon.minosoft.test.IT
3536
import de.bixilon.minosoft.test.ITUtil
@@ -87,6 +88,7 @@ internal object MinosoftSIT {
8788
val (version, registries) = ITUtil.loadPixlyzerData(IT.TEST_VERSION_NAME)
8889
IT.VERSION = version
8990
IT.REGISTRIES = registries
91+
ITUtil.loadPreFlatteningData(Versions["1.12.2"]!!).let { IT.REGISTRIES_PRE_FLATTENING = it }
9092
IT.FALLBACK_TAGS = FallbackTags.map(registries)
9193

9294
IT::BLOCK_1.forceSet(registries.block[StoneBlock.Block]!!.states.default)

src/integration-test/kotlin/de/bixilon/minosoft/data/container/ContainerTestUtil.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@ object ContainerTestUtil {
4040
}
4141

4242
fun createContainer(session: PlaySession = createSession()): Container {
43-
val container = UnknownContainer(session, this.container)
43+
val container = UnknownContainer(session, this.container, id = 9)
4444
session.player.items.containers[9] = container
4545
return container
4646
}
4747

4848
fun createChest(session: PlaySession = createSession()): Generic9x3Container {
49-
val container = Generic9x3Container(session, this.chest, null)
49+
val container = Generic9x3Container(session, this.chest, null, id = 9)
5050
session.player.items.containers[9] = container
5151
return container
5252
}
5353

5454
fun createFurnace(session: PlaySession = createSession()): FurnaceContainer {
55-
val container = FurnaceContainer(session, this.furnace, null)
55+
val container = FurnaceContainer(session, this.furnace, null, id = 9)
5656
session.player.items.containers[9] = container
5757
return container
5858
}
5959

6060
private object GenericContainerFactory : ContainerFactory<Container> {
6161
override val identifier: ResourceLocation = minosoft("test")
6262

63-
override fun build(session: PlaySession, type: ContainerType, title: ChatComponent?, slots: Int): Container {
64-
return UnknownContainer(session, type, title)
63+
override fun build(session: PlaySession, type: ContainerType, title: ChatComponent?, slots: Int, id: Int): Container {
64+
return UnknownContainer(session, type, title, id)
6565
}
6666
}
6767
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Minosoft
3+
* Copyright (C) 2020-2025 Moritz Zwerger
4+
*
5+
* 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.
6+
*
7+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8+
*
9+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
10+
*
11+
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
12+
*/
13+
14+
package de.bixilon.minosoft.data.container
15+
16+
import org.testng.AssertJUnit.assertNull
17+
import org.testng.annotations.Test
18+
19+
@Test(groups = ["item_stack"], dependsOnGroups = ["item"])
20+
class ItemStackUtilTest {
21+
22+
fun `no count null`() {
23+
val item = ItemStackUtil.of(TestItem1, 0)
24+
assertNull(item)
25+
}
26+
27+
// TODO: dye color
28+
29+
30+
// TODO: HideFlags
31+
32+
33+
// TODO: hide, nbt, serialize
34+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Minosoft
3+
* Copyright (C) 2020-2025 Moritz Zwerger
4+
*
5+
* 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.
6+
*
7+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8+
*
9+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
10+
*
11+
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
12+
*/
13+
14+
package de.bixilon.minosoft.data.container
15+
16+
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
17+
import de.bixilon.minosoft.data.registries.item.items.DurableItem
18+
import de.bixilon.minosoft.data.registries.item.items.Item
19+
import de.bixilon.minosoft.data.registries.item.stack.StackableItem
20+
21+
object TestItem1 : Item(minosoft("test1"))
22+
object TestItem2 : Item(minosoft("test2"))
23+
object TestItem3 : Item(minosoft("test3"))
24+
25+
object StackableTest1 : Item(minosoft("stackable_test1")), StackableItem {
26+
override val maxStackSize get() = 64
27+
}
28+
29+
object StackableTest2 : Item(minosoft("stackable_test2")), StackableItem {
30+
override val maxStackSize get() = 64
31+
}
32+
33+
object StackableTest3 : Item(minosoft("stackable_test3")), StackableItem {
34+
override val maxStackSize get() = 16
35+
}
36+
37+
object DurableTestItem1 : Item(minosoft("durable_test1")), DurableItem {
38+
override val maxDurability get() = 100
39+
}
40+
41+
object DurableTestItem2 : Item(minosoft("durable_test2")), DurableItem {
42+
override val maxDurability get() = 100
43+
}
Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Minosoft
3-
* Copyright (C) 2020-2024 Moritz Zwerger
3+
* Copyright (C) 2020-2025 Moritz Zwerger
44
*
55
* 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.
66
*
@@ -15,10 +15,11 @@ package de.bixilon.minosoft.data.container.actions
1515

1616
import de.bixilon.minosoft.data.container.ContainerTestUtil.createContainer
1717
import de.bixilon.minosoft.data.container.ContainerUtil.slotsOf
18+
import de.bixilon.minosoft.data.container.StackableTest1
19+
import de.bixilon.minosoft.data.container.StackableTest2
20+
import de.bixilon.minosoft.data.container.StackableTest3
1821
import de.bixilon.minosoft.data.container.actions.types.CloneContainerAction
1922
import de.bixilon.minosoft.data.container.stack.ItemStack
20-
import de.bixilon.minosoft.data.registries.items.AppleTest0
21-
import de.bixilon.minosoft.data.registries.items.EggTest0
2223
import de.bixilon.minosoft.protocol.network.session.play.PacketTestUtil.assertNoPacket
2324
import de.bixilon.minosoft.protocol.network.session.play.PacketTestUtil.assertOnlyPacket
2425
import de.bixilon.minosoft.protocol.network.session.play.SessionTestUtil.createSession
@@ -33,70 +34,60 @@ class CloneContainerActionTest {
3334
fun testEmpty() {
3435
val session = createSession()
3536
val container = createContainer(session)
36-
container.actions.invoke(CloneContainerAction(0))
37-
assertNull(container.floatingItem)
37+
container.execute(CloneContainerAction(0))
38+
assertNull(container.floating)
3839
session.assertNoPacket()
3940
}
4041

4142
fun testAlready1() {
4243
val session = createSession()
4344
val container = createContainer(session)
44-
container.floatingItem = ItemStack(EggTest0.item, count = 7)
45-
container.actions.invoke(CloneContainerAction(6))
46-
assertEquals(container.floatingItem, ItemStack(EggTest0.item, count = 7))
47-
assertNull(container[6])
45+
container.floating = ItemStack(StackableTest1, count = 7)
46+
container.execute(CloneContainerAction(6))
47+
assertEquals(container.floating, ItemStack(StackableTest1, count = 7))
48+
assertNull(container.items[6])
4849
session.assertNoPacket()
4950
}
5051

5152
fun testAlready2() {
5253
val session = createSession()
5354
val container = createContainer(session)
54-
container[6] = ItemStack(AppleTest0.item, count = 7)
55-
container.floatingItem = ItemStack(EggTest0.item, count = 7)
56-
container.actions.invoke(CloneContainerAction(6))
57-
assertEquals(container.floatingItem, ItemStack(EggTest0.item, count = 7))
58-
assertEquals(container[6], ItemStack(AppleTest0.item, count = 7))
55+
container.items[6] = ItemStack(StackableTest2, count = 7)
56+
container.floating = ItemStack(StackableTest1, count = 7)
57+
container.execute(CloneContainerAction(6))
58+
assertEquals(container.floating, ItemStack(StackableTest1, count = 7))
59+
assertEquals(container.items[6], ItemStack(StackableTest2, count = 7))
5960
session.assertNoPacket()
6061
}
6162

6263
fun testTaking() {
6364
val session = createSession()
6465
val container = createContainer(session)
65-
container[1] = ItemStack(AppleTest0.item)
66-
container.actions.invoke(CloneContainerAction(1))
67-
assertEquals(container.floatingItem, ItemStack(AppleTest0.item, count = 64))
66+
container.items[1] = ItemStack(StackableTest1)
67+
container.execute(CloneContainerAction(1))
68+
assertEquals(container.floating, ItemStack(StackableTest1, count = 64))
6869
// TODO: Not sending any packet in 1.18.2?
69-
session.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 1, 3, 0, 0, slotsOf(), ItemStack(AppleTest0.item, count = 64)))
70+
session.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 1, 3, 0, 0, slotsOf(), ItemStack(StackableTest1, count = 64)))
7071
}
7172

7273
fun taskTalking2() {
7374
val session = createSession()
7475
val container = createContainer(session)
75-
container[3] = ItemStack(AppleTest0.item, count = 8)
76-
container.actions.invoke(CloneContainerAction(3))
77-
assertEquals(container.floatingItem, ItemStack(AppleTest0.item, count = 64))
76+
container.items[3] = ItemStack(StackableTest1, count = 8)
77+
container.execute(CloneContainerAction(3))
78+
assertEquals(container.floating, ItemStack(StackableTest1, count = 64))
7879
// TODO: Not sending any packet in 1.18.2?
79-
session.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 3, 3, 0, 0, slotsOf(), ItemStack(AppleTest0.item, count = 64)))
80+
session.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 3, 3, 0, 0, slotsOf(), ItemStack(StackableTest1, count = 64)))
8081
}
8182

8283
fun testStackLimit() {
8384
val session = createSession()
8485
val container = createContainer(session)
85-
container[8] = ItemStack(EggTest0.item, count = 9)
86-
container.actions.invoke(CloneContainerAction(8))
87-
assertEquals(container.floatingItem, ItemStack(EggTest0.item, count = 16))
86+
container.items[8] = ItemStack(StackableTest3, count = 9)
87+
container.execute(CloneContainerAction(8))
88+
assertEquals(container.floating, ItemStack(StackableTest3, count = 16))
8889
// TODO: Not sending any packet in 1.18.2?
89-
session.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 8, 3, 0, 0, slotsOf(), ItemStack(EggTest0.item, count = 16)))
90+
session.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 8, 3, 0, 0, slotsOf(), ItemStack(StackableTest3, count = 16)))
9091
}
9192

92-
fun testRevert() {
93-
val session = createSession()
94-
val container = createContainer(session)
95-
container[8] = ItemStack(EggTest0.item, count = 9)
96-
val action = CloneContainerAction(8)
97-
container.actions.invoke(action)
98-
assertEquals(container.floatingItem, ItemStack(EggTest0.item, count = 16))
99-
container.actions.revert(action)
100-
assertNull(container.floatingItem)
101-
}
10293
}

0 commit comments

Comments
 (0)