remove unneeded and deprecated resource location handling

This commit is contained in:
Bixilon 2023-10-01 21:48:09 +02:00
parent ad7354964d
commit a9069c7403
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 7 additions and 47 deletions

View File

@ -13,11 +13,10 @@
package de.bixilon.minosoft.data.entities.block
import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class JigsawBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
var joint: String = "rollable"
@ -33,11 +32,11 @@ class JigsawBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
override fun updateNBT(nbt: Map<String, Any>) {
nbt["joint"]?.nullCast<String>()?.let { joint = it }
nbt["name"]?.nullCast<String>()?.let { name = ResourceLocation.ofPath(it) }
nbt["pool"]?.nullCast<String>()?.let { pool = ResourceLocation.ofPath(it) }
nbt["finalState"]?.nullCast<String>()?.let { finalState = ResourceLocation.ofPath(it) }
nbt["target"]?.nullCast<String>()?.let { target = ResourceLocation.ofPath(it) }
nbt["joint"]?.let { joint = it.toString() }
nbt["name"]?.let { name = it.toResourceLocation() }
nbt["pool"]?.let { pool = it.toResourceLocation() }
nbt["finalState"]?.let { finalState = it.toResourceLocation() }
nbt["target"]?.let { target = it.toResourceLocation() }
}
companion object : BlockEntityFactory<JigsawBlockEntity> {

View File

@ -29,6 +29,7 @@ import de.bixilon.minosoft.data.registries.item.items.Item
class PlayerItemManager(private val player: LocalPlayerEntity) {
val inventory = PlayerInventory(this, player.connection)
@Deprecated("this is probably not needed anymore, container network packets are not async anymore")
val incomplete: SynchronizedMap<Int, IncompleteContainer> = synchronizedMapOf()
val containers: SynchronizedBiMap<Int, Container> = synchronizedBiMapOf(

View File

@ -13,7 +13,6 @@
package de.bixilon.minosoft.data.registries.identified
import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.data.registries.identified.ResourceLocation.Companion.ALLOWED_PATH_PATTERN
import java.util.*
/**
@ -82,7 +81,6 @@ open class ResourceLocation(
}
companion object {
val ALLOWED_PATH_PATTERN = Regex("(?!.*//)[a-z0-9_./\\-]+")
/**
* Creates a resource location from a string.
@ -98,21 +96,5 @@ open class ResourceLocation(
}
return ResourceLocation(split[0], split[1])
}
/**
* Creates a resource location from a string by splitting it at the first colon (:) or at the first slash (/) if there is no colon.
* If possible, use minecraft() or minosoft() instead.
*
* @param path The path to parse
* @return The parsed resource location
*/
@Deprecated("Don't know why this was a thing")
fun ofPath(path: String): ResourceLocation {
if (path.contains(':') || !path.contains('/')) {
return of(path)
}
val split = path.split('/', limit = 2)
return ResourceLocation(split[0], split[1])
}
}
}

View File

@ -95,26 +95,4 @@ class ResourceLocationTest {
assertThrows<IllegalArgumentException> { ResourceLocationUtil.validateNamespace("^minecraft") }
assertThrows<IllegalArgumentException> { ResourceLocationUtil.validateNamespace("mine/craft") }
}
/**
* @see [de.bixilon.minosoft.data.registries.identified.ResourceLocation]
*/
@Test
fun testAllowedResourceLocationPaths() {
// Should Pass
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("minecraft"), true)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("min1234567890craft"), true)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine-craft"), true)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine_craft"), true)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine.craft"), true)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine/craft"), true)
// Should Fail
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("MineCraft"), false)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine craft"), false)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("minecraft!"), false)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("^minecraft"), false)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine//craft"), false)
kotlin.test.assertEquals(ResourceLocation.ALLOWED_PATH_PATTERN.matches("mine///craft"), false)
}
}