fix tests, noise biome test

This commit is contained in:
Bixilon 2022-11-15 15:03:44 +01:00
parent e417671473
commit cde3a965bc
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
17 changed files with 279 additions and 30 deletions

View File

@ -21,11 +21,11 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.a
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.*
import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull
import org.testng.annotations.Test
@Test(groups = ["container"])
@Deprecated("Verify with minecraft")
class CloneContainerActionTest {
fun testEmpty() {
@ -36,7 +36,7 @@ class CloneContainerActionTest {
connection.assertNoPacket()
}
fun testAlready() {
fun testAlready1() {
val connection = createConnection()
val container = createContainer(connection)
container.floatingItem = ItemStack(EggTestO.item, count = 7)
@ -46,12 +46,24 @@ class CloneContainerActionTest {
connection.assertNoPacket()
}
fun testAlready2() {
val connection = createConnection()
val container = createContainer(connection)
container[6] = ItemStack(AppleTestO.item, count = 7)
container.floatingItem = ItemStack(EggTestO.item, count = 7)
container.invokeAction(CloneContainerAction(6))
assertEquals(container.floatingItem, ItemStack(EggTestO.item, count = 7))
assertEquals(container[6], ItemStack(AppleTestO.item, count = 7))
connection.assertNoPacket()
}
fun testTaking() {
val connection = createConnection()
val container = createContainer(connection)
container[1] = ItemStack(AppleTestO.item)
container.invokeAction(CloneContainerAction(1))
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 64))
// TODO: Not sending any packet in 1.18.2?
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 1, 3, 0, 0, emptyMap(), ItemStack(AppleTestO.item, count = 64)))
}
@ -61,6 +73,7 @@ class CloneContainerActionTest {
container[3] = ItemStack(AppleTestO.item, count = 8)
container.invokeAction(CloneContainerAction(3))
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 64))
// TODO: Not sending any packet in 1.18.2?
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 3, 3, 0, 0, emptyMap(), ItemStack(AppleTestO.item, count = 64)))
}
@ -70,6 +83,7 @@ class CloneContainerActionTest {
container[8] = ItemStack(EggTestO.item, count = 9)
container.invokeAction(CloneContainerAction(8))
assertEquals(container.floatingItem, ItemStack(EggTestO.item, count = 16))
// TODO: Not sending any packet in 1.18.2?
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 8, 3, 0, 0, emptyMap(), ItemStack(EggTestO.item, count = 64)))
}

View File

@ -14,6 +14,8 @@
package de.bixilon.minosoft.data.container.click
import de.bixilon.minosoft.data.container.Container
import de.bixilon.minosoft.data.container.types.generic.Generic9x3Container
import de.bixilon.minosoft.data.container.types.processing.smelting.FurnaceContainer
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
@ -24,4 +26,12 @@ object ContainerTestUtil {
// TODO: set id to 9
TODO()
}
fun createChest(connection: PlayConnection = createConnection()): Generic9x3Container {
TODO()
}
fun createFurnace(connection: PlayConnection = createConnection()): FurnaceContainer {
TODO()
}
}

View File

@ -21,11 +21,11 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.a
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.*
import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull
import org.testng.annotations.Test
@Test(groups = ["container"])
@Deprecated("Verify with minecraft")
class DropContainerActionTest {
fun dropEmptySingle() {

View File

@ -0,0 +1,145 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.click
import de.bixilon.minosoft.data.container.click.ContainerTestUtil.createChest
import de.bixilon.minosoft.data.container.click.ContainerTestUtil.createFurnace
import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.registries.items.AppleTestO
import de.bixilon.minosoft.data.registries.items.CoalTest0
import de.bixilon.minosoft.data.registries.items.EggTestO
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.assertNoPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull
import org.testng.annotations.Test
@Test(groups = ["container"])
class FastMoveContainerActionTest {
fun empty() {
val connection = createConnection()
val container = createChest(connection)
container.invokeAction(FastMoveContainerAction(0))
assertNull(container.floatingItem)
assertEquals(container.slots.size, 0)
connection.assertNoPacket()
}
fun hotbarToChest() {
val connection = createConnection()
val container = createChest(connection)
container[54] = ItemStack(AppleTestO.item, 9)
container.invokeAction(FastMoveContainerAction(54))
assertNull(container.floatingItem)
assertNull(container[54])
assertEquals(container[0], ItemStack(AppleTestO.item, 9))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 53, 1, 0, 0, mapOf(54 to null, 0 to ItemStack(AppleTestO.item, count = 9)), null))
}
fun chestToHotbar() {
val connection = createConnection()
val container = createChest(connection)
container[0] = ItemStack(AppleTestO.item, 9)
container.invokeAction(FastMoveContainerAction(0))
assertNull(container.floatingItem)
assertNull(container[0])
assertEquals(container[62], ItemStack(AppleTestO.item, 9))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, mapOf(62 to null, 0 to ItemStack(AppleTestO.item, count = 9)), null))
}
fun fullHotbarChestToHotbar() {
val connection = createConnection()
val container = createChest(connection)
container[54] = ItemStack(EggTestO.item, 9)
container[55] = ItemStack(EggTestO.item, 9)
container[56] = ItemStack(EggTestO.item, 9)
container[57] = ItemStack(EggTestO.item, 9)
container[58] = ItemStack(EggTestO.item, 9)
container[59] = ItemStack(EggTestO.item, 9)
container[60] = ItemStack(EggTestO.item, 9)
container[61] = ItemStack(EggTestO.item, 9)
container[62] = ItemStack(EggTestO.item, 9)
container[0] = ItemStack(AppleTestO.item, 9)
container.invokeAction(FastMoveContainerAction(0))
assertNull(container.floatingItem)
assertNull(container[0])
assertEquals(container[53], ItemStack(AppleTestO.item, 9))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, mapOf(0 to null, 53 to ItemStack(AppleTestO.item, count = 9)), null))
}
fun mergeItems() {
val connection = createConnection()
val container = createChest(connection)
container[54] = ItemStack(CoalTest0.item, 60)
container[55] = ItemStack(AppleTestO.item, 61)
container[56] = ItemStack(CoalTest0.item, 60)
container[57] = ItemStack(CoalTest0.item, 56)
container[58] = ItemStack(CoalTest0.item, 21)
container[0] = ItemStack(CoalTest0.item, 63)
container.invokeAction(FastMoveContainerAction(0))
assertNull(container.floatingItem)
assertNull(container[0])
assertEquals(container[54], ItemStack(CoalTest0.item, 64))
assertEquals(container[55], ItemStack(AppleTestO.item, 61))
assertEquals(container[56], ItemStack(CoalTest0.item, 64))
assertEquals(container[57], ItemStack(CoalTest0.item, 64))
assertEquals(container[58], ItemStack(CoalTest0.item, 64))
assertEquals(container[62], ItemStack(CoalTest0.item, 4))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, mapOf(0 to null, 58 to ItemStack(AppleTestO.item, count = 64), 56 to ItemStack(AppleTestO.item, count = 64), 54 to ItemStack(AppleTestO.item, count = 64), 57 to ItemStack(AppleTestO.item, count = 64), 62 to ItemStack(AppleTestO.item, count = 4)), null)) // TODO: respect order of changes
}
fun fuelSlot1() {
val connection = createConnection()
val container = createFurnace(connection)
container[30] = ItemStack(EggTestO.item, 12)
container.invokeAction(FastMoveContainerAction(30))
assertNull(container.floatingItem)
assertNull(container[0])
assertNull(container[1])
assertNull(container[2])
assertNull(container[30])
assertEquals(container[3], ItemStack(EggTestO.item, 12))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, mapOf(30 to null, 3 to ItemStack(AppleTestO.item, count = 8)), null))
}
fun fuelSlot2() {
val connection = createConnection()
val container = createFurnace(connection)
container[30] = ItemStack(CoalTest0.item, 12)
container.invokeAction(FastMoveContainerAction(30))
assertNull(container.floatingItem)
assertNull(container[0])
assertEquals(container[1], ItemStack(CoalTest0.item, 12))
assertNull(container[2])
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, mapOf(30 to null, 1 to ItemStack(AppleTestO.item, count = 8)), null))
}
// TODO: revert, full container
}

View File

@ -21,11 +21,11 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.a
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.*
import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull
import org.testng.annotations.Test
@Test(groups = ["container"])
@Deprecated("Verify with minecraft")
class PickAllContainerActionTest {
fun testEmpty() {
@ -38,6 +38,7 @@ class PickAllContainerActionTest {
}
fun testAlready() {
// not invokable in minecraft
val connection = createConnection()
val container = createContainer(connection)
container.floatingItem = ItemStack(EggTestO.item, count = 7)
@ -48,16 +49,18 @@ class PickAllContainerActionTest {
}
fun testSingle() {
// theoretical test, not invokable
val connection = createConnection()
val container = createContainer(connection)
container[0] = ItemStack(AppleTestO.item, 1)
container.invokeAction(PickAllContainerAction(0))
assertNull(container[0])
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 1))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 0, 0, 0, mapOf(0 to null), ItemStack(AppleTestO.item, count = 1)))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 6, 0, 0, mapOf(0 to null), ItemStack(AppleTestO.item, count = 1)))
}
fun test2Single() {
// partly theoretical, one slot should be empty
val connection = createConnection()
val container = createContainer(connection)
container[0] = ItemStack(AppleTestO.item, 1)
@ -66,7 +69,7 @@ class PickAllContainerActionTest {
assertNull(container[0])
assertNull(container[1])
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 3))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 1, 0, 0, 0, mapOf(0 to null, 1 to null), ItemStack(AppleTestO.item, count = 3)))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 1, 6, 0, 0, mapOf(0 to null, 1 to null), ItemStack(AppleTestO.item, count = 3)))
}
fun testNotTaking() {
@ -80,10 +83,11 @@ class PickAllContainerActionTest {
assertEquals(container[1], ItemStack(EggTestO.item, 1))
assertNull(container[2])
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 3))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 2, 0, 0, 0, mapOf(0 to null, 2 to null), ItemStack(AppleTestO.item, count = 3)))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 2, 6, 0, 0, mapOf(0 to null, 2 to null), ItemStack(AppleTestO.item, count = 3)))
}
fun testStack() {
// theoretical, slot already empty
val connection = createConnection()
val container = createContainer(connection)
container[0] = ItemStack(AppleTestO.item, 64)
@ -92,7 +96,7 @@ class PickAllContainerActionTest {
assertNull(container[0])
assertEquals(container[5], ItemStack(AppleTestO.item, count = 2))
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 64))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 0, 0, 0, mapOf(0 to null), ItemStack(AppleTestO.item, count = 64)))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 6, 0, 0, mapOf(0 to null), ItemStack(AppleTestO.item, count = 64)))
}
fun testExceeds() {
@ -104,7 +108,7 @@ class PickAllContainerActionTest {
assertEquals(container[0], ItemStack(AppleTestO.item, count = 62))
assertNull(container[5])
assertEquals(container.floatingItem, ItemStack(AppleTestO.item, count = 64))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 5, 0, 0, 0, mapOf(0 to ItemStack(AppleTestO.item, count = 62), 5 to null), ItemStack(AppleTestO.item, count = 64)))
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 5, 6, 0, 0, mapOf(0 to ItemStack(AppleTestO.item, count = 2), 5 to null), ItemStack(AppleTestO.item, count = 64)))
}
fun testRevertSingle() {

View File

@ -25,8 +25,8 @@ class AppleTest : ItemTest<Item>() {
AppleTestO = this
}
fun getTorch() {
super.retrieveBlock(MinecraftItems.APPLE)
fun getApple() {
super.retrieveItem(MinecraftItems.APPLE)
}
}

View File

@ -25,8 +25,8 @@ class CoalTest : ItemTest<Item>() {
CoalTest0 = this
}
fun getTorch() {
super.retrieveBlock(MinecraftItems.COAL)
fun getCoal() {
super.retrieveItem(MinecraftItems.COAL)
}
}

View File

@ -25,8 +25,8 @@ class EggTest : ItemTest<Item>() {
EggTestO = this
}
fun getTorch() {
super.retrieveBlock(MinecraftItems.EGG)
fun getEgg() {
super.retrieveItem(MinecraftItems.EGG)
}
}

View File

@ -29,7 +29,7 @@ abstract class ItemTest<T : Item> {
reference()
}
fun retrieveBlock(name: ResourceLocation) {
fun retrieveItem(name: ResourceLocation) {
val item = IT.VERSION.registries!!.itemRegistry[name]
Assert.assertNotNull(item)
item!!

View File

@ -25,11 +25,11 @@ class LavaBucketTest : ItemTest<BucketItem>() {
init {
LavaBucketTest0 = this
assertTrue(item.fluid is LavaFluid)
}
fun getTorch() {
super.retrieveBlock(MinecraftItems.LAVA_BUCKET)
fun getLava() {
super.retrieveItem(MinecraftItems.LAVA_BUCKET)
assertTrue(item.fluid is LavaFluid)
}
}

View File

@ -25,11 +25,11 @@ class WaterBucketTest : ItemTest<BucketItem>() {
init {
WaterBucketTest0 = this
assertTrue(item.fluid is WaterFluid)
}
fun getTorch() {
super.retrieveBlock(MinecraftItems.WATER_BUCKET)
fun getWater() {
super.retrieveItem(MinecraftItems.WATER_BUCKET)
assertTrue(item.fluid is WaterFluid)
}
}

View File

@ -0,0 +1,63 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.world.biome.accessor
import de.bixilon.kotlinglm.vec3.Vec3i
import org.objenesis.ObjenesisStd
import org.testng.Assert.assertEquals
import org.testng.annotations.Test
class NoiseBiomeAccessorTest {
private val OBJENESIS = ObjenesisStd()
@Test
fun testBiomeNoise1() {
assertEquals(calculate(129, 3274, 91, 1823123L), Vec3i(32, 818, 22))
}
@Test
fun testBiomeNoise2() {
assertEquals(calculate(129, 3274, 91, -123213L), Vec3i(32, 818, 22))
}
@Test
fun testBiomeNoise3() {
assertEquals(calculate(-17, 3274, 91, -123213L), Vec3i(-5, 818, 22))
}
@Test
fun testBiomeNoise4() {
assertEquals(calculate(-1123, 3, 1, -18209371253621313), Vec3i(-281, 0, 0))
}
@Test
fun testBiomeNoise5() {
assertEquals(calculate(0, 3, 1, -33135639), Vec3i(0, 0, 0))
}
@Test
fun testBiomeNoise6() {
assertEquals(calculate(16, 15, -16, 561363374), Vec3i(4, 3, -4))
}
@Test
fun testBiomeNoise7() {
assertEquals(calculate(16, -15, -16, 79707367), Vec3i(4, -4, -5))
}
fun calculate(x: Int, y: Int, z: Int, seed: Long): Vec3i {
val accessor = OBJENESIS.newInstance(NoiseBiomeAccessor::class.java)
return accessor.getBiomePosition(seed, x, y, z)
}
}

View File

@ -29,6 +29,7 @@ class CloneContainerAction(
val itemStack = clicked.copy(count = clicked.item.item.maxStackSize)
this.copied = itemStack
// TODO (1.18.2): use creative inventory packet
connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, slot, 3, 0, container.createAction(this), emptyMap(), clicked))
container.floatingItem = itemStack

View File

@ -38,6 +38,8 @@ class DropContainerAction(
val actionId = container.createAction(this)
connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, slot, 4, if (stack) 1 else 0, actionId, mapOf(slot to item), null))
// TODO (1.18.2): use creative inventory packet
}
override fun revert(connection: PlayConnection, containerId: Int, container: Container) {

View File

@ -25,6 +25,7 @@ class FastMoveContainerAction(
// ToDo: Action reverting
override fun invoke(connection: PlayConnection, containerId: Int, container: Container) {
// ToDo: minecraft always sends a packet
val source = container.slots[slot] ?: return
val previous = source.copy()
container.lock.lock()

View File

@ -27,6 +27,7 @@ class PickAllContainerAction(
// ToDo: Action reverting
override fun invoke(connection: PlayConnection, containerId: Int, container: Container) {
// TODO (1.18.2) minecraft always sends a packet
container.lock.lock()
try {
val previous = container.slots[slot] ?: container.floatingItem?.copy() ?: return

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.data.world.biome.accessor
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.math.simple.DoubleMath.square
import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatch
import de.bixilon.minosoft.data.registries.biomes.Biome
@ -54,7 +55,7 @@ class NoiseBiomeAccessor(
}
private fun getBiome(seed: Long, x: Int, y: Int, z: Int, chunkPositionX: Int, chunkPositionZ: Int, chunk: Chunk, neighbours: Array<Chunk>?): Biome? {
fun getBiomePosition(seed: Long, x: Int, y: Int, z: Int): Vec3i {
val m = x - 2
val n = y - 2
val o = z - 2
@ -112,13 +113,18 @@ class NoiseBiomeAccessor(
if (s and 0x01 != 0) {
biomeZ++
}
return Vec3i(biomeX, biomeY, biomeZ)
}
private fun getBiome(seed: Long, x: Int, y: Int, z: Int, chunkPositionX: Int, chunkPositionZ: Int, chunk: Chunk, neighbours: Array<Chunk>?): Biome? {
val position = getBiomePosition(seed, x, y, z)
var biomeChunk: Chunk? = null
val biomeChunkX = biomeX shr 2
val biomeChunkZ = biomeZ shr 2
val biomeChunkX = position.x shr 2
val biomeChunkZ = position.z shr 2
if (neighbours == null) {
return world[Vec2i(biomeChunkX, biomeChunkZ)]?.biomeSource?.getBiome(biomeX, biomeY, biomeZ)
return world[Vec2i(biomeChunkX, biomeChunkZ)]?.biomeSource?.getBiome(position)
}
val deltaChunkX = biomeChunkX - chunkPositionX
@ -130,11 +136,13 @@ class NoiseBiomeAccessor(
-1 -> biomeChunk = neighbours[3]
1 -> biomeChunk = neighbours[4]
}
-1 -> when (deltaChunkZ) {
0 -> biomeChunk = neighbours[1]
-1 -> biomeChunk = neighbours[0]
1 -> biomeChunk = neighbours[2]
}
1 -> when (deltaChunkZ) {
0 -> biomeChunk = neighbours[6]
-1 -> biomeChunk = neighbours[5]
@ -142,7 +150,7 @@ class NoiseBiomeAccessor(
}
}
return biomeChunk?.biomeSource?.getBiome(biomeX, biomeY, biomeZ)
return biomeChunk?.biomeSource?.getBiome(position)
}
private fun calculateFiddle(seed: Long, x: Int, y: Int, z: Int, xFraction: Double, yFraction: Double, zFraction: Double): Double {