port some test util

This commit is contained in:
Bixilon 2022-11-22 13:49:51 +01:00
parent 83cc5992c7
commit 77874c38ce
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
13 changed files with 163 additions and 80 deletions

View File

@ -15,8 +15,10 @@ package de.bixilon.minosoft
import de.bixilon.kutil.cast.CastUtil.unsafeNull import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.minosoft.data.registries.versions.Version import de.bixilon.minosoft.data.registries.versions.Version
import org.objenesis.ObjenesisStd
object IT { object IT {
val OBJENESIS = ObjenesisStd()
const val VERSION_NAME = "1.18.2" const val VERSION_NAME = "1.18.2"
var VERSION: Version = unsafeNull() var VERSION: Version = unsafeNull()

View File

@ -21,8 +21,8 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.other.containers.ContainerFactory import de.bixilon.minosoft.data.registries.other.containers.ContainerFactory
import de.bixilon.minosoft.data.registries.other.containers.ContainerType import de.bixilon.minosoft.data.registries.other.containers.ContainerType
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.util.KUtil.minosoft import de.bixilon.minosoft.util.KUtil.minosoft

View File

@ -18,9 +18,9 @@ import de.bixilon.minosoft.data.container.ContainerUtil.slotsOf
import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.registries.items.AppleTestO import de.bixilon.minosoft.data.registries.items.AppleTestO
import de.bixilon.minosoft.data.registries.items.EggTestO import de.bixilon.minosoft.data.registries.items.EggTestO
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull import org.testng.Assert.assertNull

View File

@ -18,9 +18,9 @@ import de.bixilon.minosoft.data.container.ContainerUtil.slotsOf
import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.registries.items.AppleTestO import de.bixilon.minosoft.data.registries.items.AppleTestO
import de.bixilon.minosoft.data.registries.items.EggTestO import de.bixilon.minosoft.data.registries.items.EggTestO
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull import org.testng.Assert.assertNull

View File

@ -20,9 +20,9 @@ import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.registries.items.AppleTestO import de.bixilon.minosoft.data.registries.items.AppleTestO
import de.bixilon.minosoft.data.registries.items.CoalTest0 import de.bixilon.minosoft.data.registries.items.CoalTest0
import de.bixilon.minosoft.data.registries.items.EggTestO import de.bixilon.minosoft.data.registries.items.EggTestO
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull import org.testng.Assert.assertNull

View File

@ -18,9 +18,9 @@ import de.bixilon.minosoft.data.container.ContainerUtil.slotsOf
import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.registries.items.AppleTestO import de.bixilon.minosoft.data.registries.items.AppleTestO
import de.bixilon.minosoft.data.registries.items.EggTestO import de.bixilon.minosoft.data.registries.items.EggTestO
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull import org.testng.Assert.assertNull

View File

@ -18,9 +18,9 @@ import de.bixilon.minosoft.data.container.ContainerUtil.slotsOf
import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.registries.items.AppleTestO import de.bixilon.minosoft.data.registries.items.AppleTestO
import de.bixilon.minosoft.data.registries.items.EggTestO import de.bixilon.minosoft.data.registries.items.EggTestO
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertNoPacket
import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket import de.bixilon.minosoft.protocol.network.connection.play.PacketTestUtil.assertOnlyPacket
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionUtil.createConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.Assert.assertNull import org.testng.Assert.assertNull

View File

@ -0,0 +1,66 @@
/*
* 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
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.collections.CollectionUtil
import de.bixilon.kutil.watcher.DataWatcher
import de.bixilon.minosoft.IT
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
import de.bixilon.minosoft.data.world.border.WorldBorder
import de.bixilon.minosoft.data.world.chunk.ChunkData
import de.bixilon.minosoft.data.world.positions.ChunkPosition
import de.bixilon.minosoft.data.world.view.TEST_WORLD_VIEW
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.forceSet
object WorldTestUtil {
fun createWorld(connection: PlayConnection): World {
val world = IT.OBJENESIS.newInstance(World::class.java)
world::chunks.forceSet(CollectionUtil.lockMapOf())
world::border.forceSet(WorldBorder())
world::dimension.forceSet(DataWatcher.watched(DimensionProperties()))
world::connection.forceSet(connection)
world.chunkMin = Vec2i.EMPTY
world.chunkMax = Vec2i.EMPTY
world.chunkSize = Vec2i.EMPTY
world::view.forceSet(TEST_WORLD_VIEW)
return world
}
fun World.initialize(size: Int) {
for (x in -size..size) {
for (z in -size..size) {
val chunk = getOrCreateChunk(ChunkPosition(x, z))
chunk.setData(ChunkData(blocks = arrayOfNulls(16)))
}
}
}
fun World.fill(start: Vec3i, end: Vec3i, state: BlockState?) {
for (x in start.x..end.x) {
for (y in start.y..end.y) {
for (z in start.z..end.z) {
this[Vec3i(x, y, z)] = state
}
}
}
}
}

View File

@ -18,9 +18,10 @@ import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf
import de.bixilon.minosoft.data.registries.blocks.StoneTestO import de.bixilon.minosoft.data.registries.blocks.StoneTestO
import de.bixilon.minosoft.data.registries.blocks.TorchTest0 import de.bixilon.minosoft.data.registries.blocks.TorchTest0
import de.bixilon.minosoft.data.world.chunk.ChunkTestingUtil.createWorld import de.bixilon.minosoft.data.world.WorldTestUtil.fill
import de.bixilon.minosoft.modding.event.events.blocks.chunk.LightChangeEvent import de.bixilon.minosoft.modding.event.events.blocks.chunk.LightChangeEvent
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.annotations.Test import org.testng.annotations.Test
@ -29,14 +30,14 @@ import org.testng.annotations.Test
class BlockLightBreakIT { class BlockLightBreakIT {
fun inBlock() { fun inBlock() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(8, 10, 8)), 0xF0) assertEquals(world.getLight(Vec3i(8, 10, 8)), 0xF0)
} }
fun nextToBlock1() { fun nextToBlock1() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(8, 9, 8)), 0xF0) assertEquals(world.getLight(Vec3i(8, 9, 8)), 0xF0)
@ -44,126 +45,126 @@ class BlockLightBreakIT {
} }
fun nextToBlock2() { fun nextToBlock2() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(8, 11, 8)), 0xF0) assertEquals(world.getLight(Vec3i(8, 11, 8)), 0xF0)
} }
fun nextToBlock3() { fun nextToBlock3() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(7, 10, 8)), 0xF0) assertEquals(world.getLight(Vec3i(7, 10, 8)), 0xF0)
} }
fun nextToBlock4() { fun nextToBlock4() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(9, 10, 8)), 0xF0) assertEquals(world.getLight(Vec3i(9, 10, 8)), 0xF0)
} }
fun nextToBlock5() { fun nextToBlock5() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(8, 10, 7)), 0xF0) assertEquals(world.getLight(Vec3i(8, 10, 7)), 0xF0)
} }
fun nextToBlock6() { fun nextToBlock6() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
world[Vec3i(8, 10, 8)] = null world[Vec3i(8, 10, 8)] = null
assertEquals(world.getLight(Vec3i(8, 10, 9)), 0xF0) assertEquals(world.getLight(Vec3i(8, 10, 9)), 0xF0)
} }
fun nextNeighbour1() { fun nextNeighbour1() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = TorchTest0.state
world[Vec3i(16, 16, 16)] = null world[Vec3i(16, 16, 16)] = null
assertEquals(world.getLight(Vec3i(16, 17, 16)), 0xF0) assertEquals(world.getLight(Vec3i(16, 17, 16)), 0xF0)
} }
fun nextNeighbour2() { fun nextNeighbour2() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = TorchTest0.state
world[Vec3i(16, 16, 16)] = null world[Vec3i(16, 16, 16)] = null
assertEquals(world.getLight(Vec3i(17, 16, 16)), 0xF0) assertEquals(world.getLight(Vec3i(17, 16, 16)), 0xF0)
} }
fun nextNeighbour3() { fun nextNeighbour3() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = TorchTest0.state
world[Vec3i(16, 16, 16)] = null world[Vec3i(16, 16, 16)] = null
assertEquals(world.getLight(Vec3i(16, 16, 17)), 0xF0) assertEquals(world.getLight(Vec3i(16, 16, 17)), 0xF0)
} }
fun nextNeighbour4() { fun nextNeighbour4() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = TorchTest0.state
world[Vec3i(17, 17, 17)] = null world[Vec3i(17, 17, 17)] = null
assertEquals(world.getLight(Vec3i(17, 16, 17)), 0xF0) assertEquals(world.getLight(Vec3i(17, 16, 17)), 0xF0)
} }
fun nextNeighbour5() { fun nextNeighbour5() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = TorchTest0.state
world[Vec3i(17, 17, 17)] = null world[Vec3i(17, 17, 17)] = null
assertEquals(world.getLight(Vec3i(16, 17, 17)), 0xF0) assertEquals(world.getLight(Vec3i(16, 17, 17)), 0xF0)
} }
fun nextNeighbour6() { fun nextNeighbour6() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = TorchTest0.state
world[Vec3i(17, 17, 17)] = null world[Vec3i(17, 17, 17)] = null
assertEquals(world.getLight(Vec3i(17, 17, 16)), 0xF0) assertEquals(world.getLight(Vec3i(17, 17, 16)), 0xF0)
} }
fun totalPropagation1() { fun totalPropagation1() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
world[Vec3i(12, 20, 12)] = null world[Vec3i(12, 20, 12)] = null
assertEquals(world.getLight(Vec3i(12, 7, 12)), 0xF0) assertEquals(world.getLight(Vec3i(12, 7, 12)), 0xF0)
} }
fun totalPropagation2() { fun totalPropagation2() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
world[Vec3i(12, 20, 12)] = null world[Vec3i(12, 20, 12)] = null
assertEquals(world.getLight(Vec3i(12, 33, 12)), 0xF0) assertEquals(world.getLight(Vec3i(12, 33, 12)), 0xF0)
} }
fun totalPropagation3() { fun totalPropagation3() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
world[Vec3i(12, 20, 12)] = null world[Vec3i(12, 20, 12)] = null
assertEquals(world.getLight(Vec3i(-1, 33, 12)), 0xF0) assertEquals(world.getLight(Vec3i(-1, 33, 12)), 0xF0)
} }
fun totalPropagation4() { fun totalPropagation4() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
world[Vec3i(12, 20, 12)] = null world[Vec3i(12, 20, 12)] = null
assertEquals(world.getLight(Vec3i(25, 33, 12)), 0xF0) assertEquals(world.getLight(Vec3i(25, 33, 12)), 0xF0)
} }
fun totalPropagation5() { fun totalPropagation5() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
world[Vec3i(12, 20, 12)] = null world[Vec3i(12, 20, 12)] = null
assertEquals(world.getLight(Vec3i(12, 33, 25)), 0xF0) assertEquals(world.getLight(Vec3i(12, 33, 25)), 0xF0)
} }
fun totalPropagation6() { fun totalPropagation6() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
world[Vec3i(12, 20, 12)] = null world[Vec3i(12, 20, 12)] = null
assertEquals(world.getLight(Vec3i(12, 33, -1)), 0xF0) assertEquals(world.getLight(Vec3i(12, 33, -1)), 0xF0)
} }
fun lightUpdate() { fun lightUpdate() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 24, 8)] = TorchTest0.state world[Vec3i(8, 24, 8)] = TorchTest0.state
val events: MutableSet<Vec3i> = synchronizedSetOf() val events: MutableSet<Vec3i> = synchronizedSetOf()
world.connection.events.listen<LightChangeEvent> { world.connection.events.listen<LightChangeEvent> {
@ -186,7 +187,7 @@ class BlockLightBreakIT {
fun bottomLight() { fun bottomLight() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 0, 8)] = TorchTest0.state world[Vec3i(8, 0, 8)] = TorchTest0.state
world[Vec3i(8, 0, 8)] = null world[Vec3i(8, 0, 8)] = null
val chunk = world[Vec2i(0, 0)]!! val chunk = world[Vec2i(0, 0)]!!
@ -196,7 +197,7 @@ class BlockLightBreakIT {
fun topLight() { fun topLight() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 255, 8)] = TorchTest0.state world[Vec3i(8, 255, 8)] = TorchTest0.state
world[Vec3i(8, 255, 8)] = null world[Vec3i(8, 255, 8)] = null
val chunk = world[Vec2i(0, 0)]!! val chunk = world[Vec2i(0, 0)]!!
@ -205,7 +206,7 @@ class BlockLightBreakIT {
} }
fun bottomPropagation() { fun bottomPropagation() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(5).world
world.fill(Vec3i(-10, 0, -10), Vec3i(30, 1, 30), StoneTestO.state) world.fill(Vec3i(-10, 0, -10), Vec3i(30, 1, 30), StoneTestO.state)
world[Vec3i(8, 0, 8)] = TorchTest0.state world[Vec3i(8, 0, 8)] = TorchTest0.state
world[Vec3i(8, 0, 8)] = null world[Vec3i(8, 0, 8)] = null
@ -221,7 +222,7 @@ class BlockLightBreakIT {
} }
fun topPropagation() { fun topPropagation() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(5).world
world.fill(Vec3i(-10, 254, -10), Vec3i(30, 255, 30), StoneTestO.state) world.fill(Vec3i(-10, 254, -10), Vec3i(30, 255, 30), StoneTestO.state)
world[Vec3i(8, 255, 8)] = TorchTest0.state world[Vec3i(8, 255, 8)] = TorchTest0.state
world[Vec3i(8, 255, 8)] = null world[Vec3i(8, 255, 8)] = null

View File

@ -18,9 +18,10 @@ import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf
import de.bixilon.minosoft.data.registries.blocks.StoneTestO import de.bixilon.minosoft.data.registries.blocks.StoneTestO
import de.bixilon.minosoft.data.registries.blocks.TorchTest0 import de.bixilon.minosoft.data.registries.blocks.TorchTest0
import de.bixilon.minosoft.data.world.chunk.ChunkTestingUtil.createWorld import de.bixilon.minosoft.data.world.WorldTestUtil.fill
import de.bixilon.minosoft.modding.event.events.blocks.chunk.LightChangeEvent import de.bixilon.minosoft.modding.event.events.blocks.chunk.LightChangeEvent
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil
import org.testng.Assert.assertEquals import org.testng.Assert.assertEquals
import org.testng.annotations.Test import org.testng.annotations.Test
@ -29,122 +30,122 @@ import org.testng.annotations.Test
class BlockLightPlaceIT { class BlockLightPlaceIT {
fun inBlock() { fun inBlock() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(8, 10, 8)), 0xFD) assertEquals(world.getLight(Vec3i(8, 10, 8)), 0xFD)
} }
fun nextToBlock1() { fun nextToBlock1() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(8, 9, 8)), 0xFC) assertEquals(world.getLight(Vec3i(8, 9, 8)), 0xFC)
assertEquals(world.getLight(Vec3i(8, 0, 8)), 0xF4) assertEquals(world.getLight(Vec3i(8, 0, 8)), 0xF4)
} }
fun nextToBlock2() { fun nextToBlock2() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(8, 11, 8)), 0xFC) assertEquals(world.getLight(Vec3i(8, 11, 8)), 0xFC)
} }
fun nextToBlock3() { fun nextToBlock3() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(7, 10, 8)), 0xFC) assertEquals(world.getLight(Vec3i(7, 10, 8)), 0xFC)
} }
fun nextToBlock4() { fun nextToBlock4() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(9, 10, 8)), 0xFC) assertEquals(world.getLight(Vec3i(9, 10, 8)), 0xFC)
} }
fun nextToBlock5() { fun nextToBlock5() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(8, 10, 7)), 0xFC) assertEquals(world.getLight(Vec3i(8, 10, 7)), 0xFC)
} }
fun nextToBlock6() { fun nextToBlock6() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(8, 10, 9)), 0xFC) assertEquals(world.getLight(Vec3i(8, 10, 9)), 0xFC)
} }
fun nextNeighbour1() { fun nextNeighbour1() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(16, 17, 16)), 0xFC) assertEquals(world.getLight(Vec3i(16, 17, 16)), 0xFC)
} }
fun nextNeighbour2() { fun nextNeighbour2() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(17, 16, 16)), 0xFC) assertEquals(world.getLight(Vec3i(17, 16, 16)), 0xFC)
} }
fun nextNeighbour3() { fun nextNeighbour3() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(16, 16, 17)), 0xFC) assertEquals(world.getLight(Vec3i(16, 16, 17)), 0xFC)
} }
fun nextNeighbour4() { fun nextNeighbour4() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(17, 16, 17)), 0xFC) assertEquals(world.getLight(Vec3i(17, 16, 17)), 0xFC)
} }
fun nextNeighbour5() { fun nextNeighbour5() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(16, 17, 17)), 0xFC) assertEquals(world.getLight(Vec3i(16, 17, 17)), 0xFC)
} }
fun nextNeighbour6() { fun nextNeighbour6() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(17, 17, 16)), 0xFC) assertEquals(world.getLight(Vec3i(17, 17, 16)), 0xFC)
} }
fun totalPropagation1() { fun totalPropagation1() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(12, 7, 12)), 0xF1) assertEquals(world.getLight(Vec3i(12, 7, 12)), 0xF1)
} }
fun totalPropagation2() { fun totalPropagation2() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(12, 33, 12)), 0xF1) assertEquals(world.getLight(Vec3i(12, 33, 12)), 0xF1)
} }
fun totalPropagation3() { fun totalPropagation3() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(-1, 33, 12)), 0xF1) assertEquals(world.getLight(Vec3i(-1, 33, 12)), 0xF1)
} }
fun totalPropagation4() { fun totalPropagation4() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(25, 33, 12)), 0xF1) assertEquals(world.getLight(Vec3i(25, 33, 12)), 0xF1)
} }
fun totalPropagation5() { fun totalPropagation5() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(12, 33, 25)), 0xF1) assertEquals(world.getLight(Vec3i(12, 33, 25)), 0xF1)
} }
fun totalPropagation6() { fun totalPropagation6() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = TorchTest0.state
assertEquals(world.getLight(Vec3i(12, 33, -1)), 0xF1) assertEquals(world.getLight(Vec3i(12, 33, -1)), 0xF1)
} }
fun lightUpdate() { fun lightUpdate() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
val events: MutableSet<Vec3i> = synchronizedSetOf() val events: MutableSet<Vec3i> = synchronizedSetOf()
world.connection.events.listen<LightChangeEvent> { world.connection.events.listen<LightChangeEvent> {
events += Vec3i(it.chunkPosition.x, it.sectionHeight, it.chunkPosition.y) events += Vec3i(it.chunkPosition.x, it.sectionHeight, it.chunkPosition.y)
@ -166,7 +167,7 @@ class BlockLightPlaceIT {
fun bottomLight() { fun bottomLight() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 0, 8)] = TorchTest0.state world[Vec3i(8, 0, 8)] = TorchTest0.state
val chunk = world[Vec2i(0, 0)]!! val chunk = world[Vec2i(0, 0)]!!
assertEquals(chunk.light[Vec3i(8, -1, 8)], 0xFC) assertEquals(chunk.light[Vec3i(8, -1, 8)], 0xFC)
@ -175,7 +176,7 @@ class BlockLightPlaceIT {
fun topLight() { fun topLight() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(3).world
world[Vec3i(8, 255, 8)] = TorchTest0.state world[Vec3i(8, 255, 8)] = TorchTest0.state
val chunk = world[Vec2i(0, 0)]!! val chunk = world[Vec2i(0, 0)]!!
assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xFC) assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xFC)
@ -183,7 +184,7 @@ class BlockLightPlaceIT {
} }
fun bottomPropagation() { fun bottomPropagation() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(5).world
world.fill(Vec3i(-10, 0, -10), Vec3i(30, 1, 30), StoneTestO.state) world.fill(Vec3i(-10, 0, -10), Vec3i(30, 1, 30), StoneTestO.state)
world[Vec3i(8, 0, 8)] = TorchTest0.state world[Vec3i(8, 0, 8)] = TorchTest0.state
@ -198,7 +199,7 @@ class BlockLightPlaceIT {
} }
fun topPropagation() { fun topPropagation() {
val world = createWorld() val world = ConnectionTestUtil.createConnection(4).world
world.fill(Vec3i(-10, 254, -10), Vec3i(30, 255, 30), StoneTestO.state) world.fill(Vec3i(-10, 254, -10), Vec3i(30, 255, 30), StoneTestO.state)
world[Vec3i(8, 255, 8)] = TorchTest0.state world[Vec3i(8, 255, 8)] = TorchTest0.state

View File

@ -0,0 +1,24 @@
/*
* 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.view
import de.bixilon.kutil.cast.CastUtil
import de.bixilon.minosoft.IT
class TestWorldView : WorldView(CastUtil.unsafeNull()) {
override fun updateServerDistance() = Unit
}
val TEST_WORLD_VIEW = IT.OBJENESIS.newInstance(TestWorldView::class.java)

View File

@ -13,50 +13,39 @@
package de.bixilon.minosoft.protocol.network.connection.play package de.bixilon.minosoft.protocol.network.connection.play
import de.bixilon.kutil.collections.CollectionUtil.lockMapOf
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
import de.bixilon.minosoft.IT import de.bixilon.minosoft.IT
import de.bixilon.minosoft.IT.reference import de.bixilon.minosoft.IT.reference
import de.bixilon.minosoft.data.accounts.types.offline.OfflineAccount import de.bixilon.minosoft.data.accounts.types.offline.OfflineAccount
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.world.World import de.bixilon.minosoft.data.world.WorldTestUtil.createWorld
import de.bixilon.minosoft.data.world.border.WorldBorder import de.bixilon.minosoft.data.world.WorldTestUtil.initialize
import de.bixilon.minosoft.modding.event.master.EventMaster import de.bixilon.minosoft.modding.event.master.EventMaster
import de.bixilon.minosoft.protocol.network.network.client.test.TestNetwork import de.bixilon.minosoft.protocol.network.network.client.test.TestNetwork
import de.bixilon.minosoft.util.KUtil.forceSet import de.bixilon.minosoft.util.KUtil.forceSet
import org.objenesis.ObjenesisStd
object PlayConnectionUtil { object ConnectionTestUtil {
private val OBJENESIS = ObjenesisStd()
init { init {
reference() reference()
} }
fun createWorld(): World { fun createConnection(worldSize: Int = 0): PlayConnection {
val world = OBJENESIS.newInstance(World::class.java) val connection = IT.OBJENESIS.newInstance(PlayConnection::class.java)
world::chunks.forceSet(lockMapOf())
world::border.forceSet(WorldBorder())
world::dimension.forceSet(watched(DimensionProperties()))
return world
}
fun createConnection(): PlayConnection {
val connection = OBJENESIS.newInstance(PlayConnection::class.java)
connection::account.forceSet(OfflineAccount("dummy")) connection::account.forceSet(OfflineAccount("dummy"))
connection::version.forceSet(IT.VERSION) connection::version.forceSet(IT.VERSION)
connection::registries.forceSet(Registries()) connection::registries.forceSet(Registries())
connection.registries.parentRegistries = IT.VERSION.registries connection.registries.parentRegistries = IT.VERSION.registries
connection::world.forceSet(createWorld()) connection::world.forceSet(createWorld(connection))
connection::network.forceSet(TestNetwork())
connection::player.forceSet(LocalPlayerEntity(connection.account, connection, null)) connection::player.forceSet(LocalPlayerEntity(connection.account, connection, null))
connection::network.forceSet(TestNetwork())
connection::events.forceSet(EventMaster()) connection::events.forceSet(EventMaster())
if (worldSize > 0) {
connection.world.initialize(worldSize)
}
return connection return connection
} }
} }

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.data.world.view
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import kotlin.math.abs import kotlin.math.abs
class WorldView( open class WorldView(
private val connection: PlayConnection, private val connection: PlayConnection,
) { ) {
var serverViewDistance = Int.MAX_VALUE var serverViewDistance = Int.MAX_VALUE
@ -64,7 +64,7 @@ class WorldView(
} }
@Synchronized @Synchronized
fun updateServerDistance() { open fun updateServerDistance() {
val cameraPosition = connection.player.positionInfo.chunkPosition val cameraPosition = connection.player.positionInfo.chunkPosition
val max = connection.world.chunkMax - cameraPosition val max = connection.world.chunkMax - cameraPosition
val min = connection.world.chunkMin - cameraPosition val min = connection.world.chunkMin - cameraPosition