Skip to content

Commit

Permalink
port to kutil 1.26
Browse files Browse the repository at this point in the history
  • Loading branch information
Bixilon committed Feb 2, 2024
1 parent a6fe96f commit 3b61973
Show file tree
Hide file tree
Showing 34 changed files with 92 additions and 182 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Minosoft
# Copyright (C) 2020-2023 Moritz Zwerger
# Copyright (C) 2020-2024 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.
#
Expand All @@ -17,5 +17,5 @@ lwjgl.version=3.3.3
ikonli.version=12.3.1
netty.version=4.1.101.Final
jackson.version=2.16.0
kutil.version=1.25.0
kutil.version=1.26.0
glm.version=0.9.9.1-12
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -18,7 +18,7 @@ import de.bixilon.kutil.primitive.DoubleUtil
import de.bixilon.kutil.primitive.DoubleUtil.matches
import de.bixilon.kutil.primitive.FloatUtil
import de.bixilon.kutil.primitive.FloatUtil.matches
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.reflection.ReflectionUtil.field
import de.bixilon.kutil.reflection.ReflectionUtil.jvmField
import de.bixilon.minosoft.camera.ConnectionCamera
import de.bixilon.minosoft.data.entities.StatusEffectInstance
Expand All @@ -42,17 +42,17 @@ object PhysicsTestUtil {
const val MATCH_EXACTLY = true
val VALUE_MARGIN = if (MATCH_EXACTLY) 0.0 else DoubleUtil.DEFAULT_MARGIN

private val PLAYER_ATTRIBUTES = LocalPlayerEntity::attributes.jvmField
private val CONNECTION_PLAYER = PlayConnection::player.jvmField
private val CONNECTION_CAMERA = PlayConnection::camera.jvmField
private val PLAYER_ATTRIBUTES = LocalPlayerEntity::attributes.jvmField.field
private val CONNECTION_PLAYER = PlayConnection::player.jvmField.field
private val CONNECTION_CAMERA = PlayConnection::camera.jvmField.field


fun createPlayer(connection: PlayConnection = createConnection(light = false)): LocalPlayerEntity {
val player = LocalPlayerEntity(connection.account, connection, SignatureKeyManagement(connection, connection.account))
PLAYER_ATTRIBUTES.forceSet(player, EntityAttributes(player.type.attributes))
PLAYER_ATTRIBUTES.set(player, EntityAttributes(player.type.attributes))
player.startInit()
CONNECTION_PLAYER.forceSet(connection, player)
CONNECTION_CAMERA.forceSet(connection, ConnectionCamera(connection))
CONNECTION_PLAYER.set(connection, player)
CONNECTION_CAMERA.set(connection, ConnectionCamera(connection))
connection.camera.init()
connection.world.entities.remove(0)
connection.world.entities.add(0, null, player)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -14,8 +14,8 @@
package de.bixilon.minosoft.data.physics.parkour

import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kutil.stream.InputStreamUtil.readAsString
import de.bixilon.kutil.string.WhitespaceUtil.trimWhitespaces
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAsString
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
import de.bixilon.minosoft.commands.parser.brigadier._float.FloatParser.Companion.readFloat
import de.bixilon.minosoft.commands.util.StringReader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -13,11 +13,11 @@

package de.bixilon.minosoft.data.registries.registries.registry

import de.bixilon.kutil.collections.spliterator.SpliteratorUtil.collect
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import org.testng.Assert.*
import org.testng.annotations.Test
import java.util.*

@Test(groups = ["registry"])
class RegistryTest {
Expand Down Expand Up @@ -114,14 +114,6 @@ class RegistryTest {
assertEquals(secondList.toSet(), setOf(c, d))
}


@Deprecated("kutil 1.25")
fun <T> Spliterator<T>.collect(): List<T> {
val list: MutableList<T> = mutableListOf()
forEachRemaining { list += it }

return list
}
// TODO: codec, spliterating

private class Entry(override val identifier: ResourceLocation) : RegistryItem() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -15,14 +15,14 @@ package de.bixilon.minosoft.gui.rendering.font.types.unicode.unihex

import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.buffer.ByteBufferUtil.toByteArray
import de.bixilon.kutil.buffer.ByteBufferUtil.readRemaining
import de.bixilon.kutil.reflection.ReflectionUtil.getFieldOrNull
import de.bixilon.kutil.unsafe.UnsafeUtil.setUnsafeAccessible
import de.bixilon.minosoft.gui.rendering.font.types.unicode.UnicodeCodeRenderer
import de.bixilon.minosoft.gui.rendering.font.types.unicode.unihex.UnihexFontType.Companion.fromHex
import de.bixilon.minosoft.test.IT.OBJENESIS
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import org.testng.Assert.*
import org.testng.Assert.assertEquals
import org.testng.Assert.assertTrue
import org.testng.annotations.Test
import java.io.ByteArrayInputStream
import java.io.InputStream
Expand All @@ -33,19 +33,6 @@ class UnihexFontTypeTest {
private val textureRemaining = UnifontTexture::class.java.getFieldOrNull("remaining")!!
val readUnihex = UnihexFontType::class.companionObject!!.java.getDeclaredMethod("readUnihex", InputStream::class.java, Int2ObjectOpenHashMap::class.java).apply { setUnsafeAccessible() }

fun `from hex`() {
assertEquals('0'.code.fromHex(), 0x00)
assertEquals('9'.code.fromHex(), 0x09)

assertEquals('a'.code.fromHex(), 0x0A)
assertEquals('A'.code.fromHex(), 0x0A)

assertEquals('f'.code.fromHex(), 0x0F)
assertEquals('F'.code.fromHex(), 0x0F)

assertThrows { 'z'.code.fromHex() }
}

fun `read unihex`() {
val data = "0E01DB:555580000001A2382241A238140588380001B31808A1913020A9BB100001AAAA\n298B:0000000E0808080808080808080E000E"

Expand Down Expand Up @@ -112,7 +99,7 @@ class UnihexFontTypeTest {
assertEquals(code.uvEnd, Vec2(0.18749f, 1.0f))

assertEquals(remaining, intArrayOf(13))
val data = texture.data.buffer.data.toByteArray()
val data = texture.data.buffer.data.readRemaining()


for (index in 0 until 48) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package de.bixilon.minosoft.gui.rendering.models.baked

import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.assets.MemoryAssetsManager
import de.bixilon.minosoft.assets.TestAssetsManager.box
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.gui.rendering.Rendering
import de.bixilon.minosoft.gui.rendering.models.block.element.face.ModelFace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.latch.SimpleLatch
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.reflection.ReflectionUtil.getFieldOrNull
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.assets.MemoryAssetsManager
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package de.bixilon.minosoft.gui.rendering.system.base.texture.skin

import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.kutil.unsafe.UnsafeUtil.setUnsafeAccessible
import de.bixilon.kutil.url.URLUtil.toURL
import de.bixilon.minosoft.assets.MemoryAssetsManager
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
import de.bixilon.minosoft.data.entities.entities.player.additional.PlayerAdditional
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package de.bixilon.minosoft.gui.rendering.textures

import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.kutil.unsafe.UnsafeUtil.setUnsafeAccessible
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.buffer.RGB8Buffer
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.buffer.RGBA8Buffer
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.buffer.TextureBuffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package de.bixilon.minosoft.gui.rendering.tint.tints.grass

import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.assets.MemoryAssetsManager
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import org.testng.Assert.assertEquals
import org.testng.annotations.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package de.bixilon.minosoft.protocol.network.connection.play

import de.bixilon.kotlinglm.pow
import de.bixilon.kutil.observer.DataObserver
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.reflection.ReflectionUtil.field
import de.bixilon.kutil.reflection.ReflectionUtil.jvmField
import de.bixilon.minosoft.assets.connection.ConnectionAssetsManager
import de.bixilon.minosoft.assets.minecraft.MinecraftPackFormat.packFormat
Expand Down Expand Up @@ -51,47 +51,47 @@ object ConnectionTestUtil {
reference()
}

private val LANGUAGE = PlayConnection::language.jvmField
private val SEQUENCE = PlayConnection::sequence.jvmField
private val ACCOUNT = PlayConnection::account.jvmField
private val VERSION = PlayConnection::version.jvmField
private val REGISTRIES = PlayConnection::registries.jvmField
private val WORLD = PlayConnection::world.jvmField
private val PLAYER = PlayConnection::player.jvmField
private val NETWORK = PlayConnection::network.jvmField
private val EVENTS = PlayConnection::events.jvmField
private val PROFILES = PlayConnection::profiles.jvmField
private val ASSETS_MANAGER = PlayConnection::assetsManager.jvmField
private val STATE = PlayConnection::state.jvmField
private val TAGS = PlayConnection::tags.jvmField
private val LEGACY_TAGS = PlayConnection::legacyTags.jvmField
private val CAMERA = PlayConnection::camera.jvmField
private val LANGUAGE = PlayConnection::language.jvmField.field
private val SEQUENCE = PlayConnection::sequence.jvmField.field
private val ACCOUNT = PlayConnection::account.jvmField.field
private val VERSION = PlayConnection::version.jvmField.field
private val REGISTRIES = PlayConnection::registries.jvmField.field
private val WORLD = PlayConnection::world.jvmField.field
private val PLAYER = PlayConnection::player.jvmField.field
private val NETWORK = PlayConnection::network.jvmField.field
private val EVENTS = PlayConnection::events.jvmField.field
private val PROFILES = PlayConnection::profiles.jvmField.field
private val ASSETS_MANAGER = PlayConnection::assetsManager.jvmField.field
private val STATE = PlayConnection::state.jvmField.field
private val TAGS = PlayConnection::tags.jvmField.field
private val LEGACY_TAGS = PlayConnection::legacyTags.jvmField.field
private val CAMERA = PlayConnection::camera.jvmField.field

private val language = LanguageManager()
private val signature = OBJENESIS.newInstance(SignatureKeyManagement::class.java)


fun createConnection(worldSize: Int = 0, light: Boolean = false, version: String? = null): PlayConnection {
val connection = OBJENESIS.newInstance(PlayConnection::class.java)
LANGUAGE.forceSet(connection, language)
LANGUAGE.set(connection, language)
val version = if (version == null) IT.VERSION else Versions[version] ?: throw IllegalArgumentException("Can not find version: $version")
SEQUENCE.forceSet(connection, AtomicInteger(1))
ACCOUNT.forceSet(connection, TestAccount)
VERSION.forceSet(connection, version)
REGISTRIES.forceSet(connection, Registries())
SEQUENCE.set(connection, AtomicInteger(1))
ACCOUNT.set(connection, TestAccount)
VERSION.set(connection, version)
REGISTRIES.set(connection, Registries())
connection.registries.updateFlattened(version.flattened)
connection.registries.parent = if (version == IT.VERSION) IT.REGISTRIES else ITUtil.loadRegistries(version)
WORLD.forceSet(connection, createWorld(connection, light, (worldSize * 2 + 1).pow(2)))
PLAYER.forceSet(connection, LocalPlayerEntity(connection.account, connection, signature))
WORLD.set(connection, createWorld(connection, light, (worldSize * 2 + 1).pow(2)))
PLAYER.set(connection, LocalPlayerEntity(connection.account, connection, signature))
connection.player.startInit()
NETWORK.forceSet(connection, TestNetwork(connection))
EVENTS.forceSet(connection, EventMaster())
PROFILES.forceSet(connection, profiles)
ASSETS_MANAGER.forceSet(connection, ConnectionAssetsManager(AssetsManagerProperties(PackProperties(version.packFormat))))
STATE.forceSet(connection, DataObserver(PlayConnectionStates.PLAYING))
TAGS.forceSet(connection, TagManager())
LEGACY_TAGS.forceSet(connection, FALLBACK_TAGS)
CAMERA.forceSet(connection, ConnectionCamera(connection))
NETWORK.set(connection, TestNetwork(connection))
EVENTS.set(connection, EventMaster())
PROFILES.set(connection, profiles)
ASSETS_MANAGER.set(connection, ConnectionAssetsManager(AssetsManagerProperties(PackProperties(version.packFormat))))
STATE.set(connection, DataObserver(PlayConnectionStates.PLAYING))
TAGS.set(connection, TagManager())
LEGACY_TAGS.set(connection, FALLBACK_TAGS)
CAMERA.set(connection, ConnectionCamera(connection))
connection.camera.init()
if (worldSize > 0) {
connection.world.initialize(worldSize) { DummyBiomeSource(null) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package de.bixilon.minosoft.protocol.packets.s2c.play

import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.S2CPacket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.observer.DataObserver
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.mbf.MBFBinaryReader
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.building.stone.StoneBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package de.bixilon.minosoft.protocol.packets.s2c.play.chunk

import de.bixilon.kutil.observer.DataObserver
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
import de.bixilon.minosoft.data.world.positions.ChunkPosition
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -13,7 +13,7 @@

package de.bixilon.minosoft.modding.dummy

import de.bixilon.minosoft.assets.util.InputStreamUtil.readAsString
import de.bixilon.kutil.stream.InputStreamUtil.readAsString
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.modding.loader.mod.ModMain

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
package de.bixilon.minosoft.assets.directory

import de.bixilon.kutil.latch.AbstractLatch
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.assets.AssetsManager
import de.bixilon.minosoft.assets.properties.manager.AssetsManagerProperties
import de.bixilon.minosoft.assets.util.FileAssetsUtil.normalizePath
import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
import de.bixilon.minosoft.assets.util.FileUtil
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJson
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
package de.bixilon.minosoft.assets.file

import de.bixilon.kutil.latch.AbstractLatch
import de.bixilon.kutil.stream.InputStreamUtil.readAll
import de.bixilon.minosoft.assets.AssetsManager
import de.bixilon.minosoft.assets.util.FileAssetsUtil.normalizePath
import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
import de.bixilon.minosoft.assets.util.InputStreamUtil.readAll
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJson
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import java.io.File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import com.github.luben.zstd.ZstdInputStream
import com.github.luben.zstd.ZstdOutputStream
import de.bixilon.kutil.array.ByteArrayUtil.toHex
import de.bixilon.kutil.file.FileUtil.createParent
import de.bixilon.kutil.stream.InputStreamUtil.copy
import de.bixilon.minosoft.assets.AssetsManager
import de.bixilon.minosoft.assets.util.HashTypes.Companion.hashType
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.util.KUtil.copy
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
Expand Down
Loading

0 comments on commit 3b61973

Please sign in to comment.