Skip to content

Commit

Permalink
rename ResourceLocationCodec to IdentifierCodec
Browse files Browse the repository at this point in the history
Yes, its a resource location but functions as an identifier in that context
  • Loading branch information
Bixilon committed Nov 27, 2023
1 parent 4cc551d commit c18515f
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ package de.bixilon.minosoft.data.entities
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec

class EntityObjectType(
override val identifier: ResourceLocation,
) : RegistryItem() {

companion object : ResourceLocationCodec<EntityObjectType> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): EntityObjectType {
return EntityObjectType(resourceLocation)
companion object : IdentifierCodec<EntityObjectType> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): EntityObjectType {
return EntityObjectType(identifier)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec


class BlockDataDataType(
override val identifier: ResourceLocation,
) : RegistryItem() {

companion object : ResourceLocationCodec<BlockDataDataType> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): BlockDataDataType {
return BlockDataDataType(resourceLocation)
companion object : IdentifierCodec<BlockDataDataType> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): BlockDataDataType {
return BlockDataDataType(identifier)
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/de/bixilon/minosoft/data/registries/Motif.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec

data class Motif(
override val identifier: ResourceLocation,
Expand All @@ -28,12 +28,12 @@ data class Motif(
return identifier.toString()
}

companion object : ResourceLocationCodec<Motif> {
companion object : IdentifierCodec<Motif> {
const val DEFAULT_SIZE = 16

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Motif {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): Motif {
return Motif(
identifier = resourceLocation,
identifier = identifier,
width = data["width"]?.toInt() ?: DEFAULT_SIZE,
height = data["height"]?.toInt() ?: DEFAULT_SIZE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec

data class PluginChannel(
override val identifier: ResourceLocation,
Expand All @@ -28,10 +28,10 @@ data class PluginChannel(
return identifier.toString()
}

companion object : ResourceLocationCodec<PluginChannel> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): PluginChannel {
companion object : IdentifierCodec<PluginChannel> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): PluginChannel {
return PluginChannel(
identifier = resourceLocation,
identifier = identifier,
name = ResourceLocation.of(data["name"].unsafeCast())
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import de.bixilon.kutil.primitive.FloatUtil.toFloat
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.gui.rendering.tint.TintManager.Companion.jsonTint
Expand Down Expand Up @@ -48,22 +48,21 @@ data class Biome(
return identifier.toString()
}

companion object : ResourceLocationCodec<Biome> {
companion object : IdentifierCodec<Biome> {

private fun getColorMapCoordinate(value: Float): Int {
return ((1.0 - value.clamp(0.0f, 1.0f)) * RenderConstants.COLORMAP_SIZE).toInt()
}

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Biome {
check(registries != null) { "Registries is null!" }
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): Biome {
val effects = data["effects"].toJsonObject() // nbt data
val skyColor = (data["sky_color"] ?: effects?.get("sky_color"))?.jsonTint()
val fogColor = (data["fog_color"] ?: effects?.get("fog_color"))?.jsonTint()
val waterColor = (data["water_color"] ?: effects?.get("water_color"))?.jsonTint()
val waterFogColor = (data["water_fog_color"] ?: effects?.get("water_fog_color"))?.jsonTint()

return Biome(
identifier = resourceLocation,
identifier = identifier,
temperature = data["temperature"]?.toFloat() ?: 0.0f,
downfall = data["downfall"]?.toFloat() ?: 0.0f,
skyColor = skyColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection

data class BlockEntityType<T : BlockEntity>(
Expand All @@ -34,11 +34,11 @@ data class BlockEntityType<T : BlockEntity>(
return factory.build(connection)
}

companion object : ResourceLocationCodec<BlockEntityType<*>> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): BlockEntityType<*>? {
companion object : IdentifierCodec<BlockEntityType<*>> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): BlockEntityType<*>? {
// ToDo: Fix resource location
check(registries != null)
val factory = DefaultBlockDataFactory[resourceLocation] ?: return null // ToDo
val factory = DefaultBlockDataFactory[identifier] ?: return null // ToDo

val blocks: MutableSet<Block> = mutableSetOf()

Expand All @@ -47,7 +47,7 @@ data class BlockEntityType<T : BlockEntity>(
}

return BlockEntityType(
identifier = resourceLocation,
identifier = identifier,
blocks = blocks,
factory = factory,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import de.bixilon.minosoft.data.registries.item.items.Item
import de.bixilon.minosoft.data.registries.item.items.tool.properties.requirement.ToolRequirement
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec
import de.bixilon.minosoft.data.world.positions.BlockPosition
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
import de.bixilon.minosoft.gui.rendering.tint.TintedBlock
Expand Down Expand Up @@ -116,19 +116,19 @@ open class PixLyzerBlock(
}


companion object : ResourceLocationCodec<Block>, PixLyzerBlockFactory<Block>, MultiClassFactory<Block> {
companion object : IdentifierCodec<Block>, PixLyzerBlockFactory<Block>, MultiClassFactory<Block> {
private val NULL_OFFSET_XYZ = Vec3i(0, 0, 0).getWorldOffset(RandomOffsetTypes.XYZ)
private val NULL_OFFSET_XZ = Vec3i(0, 0, 0).getWorldOffset(RandomOffsetTypes.XZ)
private val ITEM_FIELD = PixLyzerBlock::item.jvmField
override val ALIASES: Set<String> = setOf("Block")

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Block {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): Block {
check(registries != null) { "Registries is null!" }

val className = data["class"].toString()
val factory = PixLyzerBlockFactories[className] ?: PixLyzerBlock

return factory.build(resourceLocation, registries, data)
return factory.build(identifier, registries, data)
}

override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): PixLyzerBlock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import de.bixilon.minosoft.data.chat.ChatTextPositions
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec
import de.bixilon.minosoft.data.text.formatting.color.ChatColors

class ChatMessageType(
Expand All @@ -33,12 +33,12 @@ class ChatMessageType(
return identifier.toString()
}

companion object : ResourceLocationCodec<ChatMessageType> {
companion object : IdentifierCodec<ChatMessageType> {
private val DEFAULT_PROPERTIES = TypeProperties("[%s] %s", listOf(ChatParameter.SENDER, ChatParameter.SENDER), mapOf("color" to ChatColors.GRAY))

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: JsonObject): ChatMessageType {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: JsonObject): ChatMessageType {
return ChatMessageType(
identifier = resourceLocation,
identifier = identifier,
chat = data["chat"]?.asJsonObject()?.let { TypeProperties.deserialize(it) } ?: DEFAULT_PROPERTIES,
narration = data["narration"]?.asJsonObject()?.let { TypeProperties.deserialize(it) },
position = data["position"]?.let { ChatTextPositions[it] } ?: ChatTextPositions.CHAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import de.bixilon.minosoft.data.container.types.UnknownContainer
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec

data class ContainerType(
override val identifier: ResourceLocation,
Expand All @@ -28,11 +28,11 @@ data class ContainerType(
return identifier.toString()
}

companion object : ResourceLocationCodec<ContainerType> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): ContainerType {
companion object : IdentifierCodec<ContainerType> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): ContainerType {
return ContainerType(
identifier = resourceLocation,
factory = DefaultContainerFactories[resourceLocation] ?: UnknownContainer,
identifier = identifier,
factory = DefaultContainerFactories[identifier] ?: UnknownContainer,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.registries.dimension
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec

data class Dimension(
override val identifier: ResourceLocation,
Expand All @@ -26,11 +26,11 @@ data class Dimension(
return identifier.toString()
}

companion object : ResourceLocationCodec<Dimension> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Dimension {
companion object : IdentifierCodec<Dimension> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): Dimension {
return Dimension(
identifier = resourceLocation,
properties = DimensionProperties.deserialize(resourceLocation, data)
identifier = identifier,
properties = DimensionProperties.deserialize(identifier, data)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import de.bixilon.minosoft.data.registries.effects.properties.categories.Categor
import de.bixilon.minosoft.data.registries.effects.properties.categories.StatusEffectCategories
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.data.text.formatting.color.Colored
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
Expand All @@ -34,12 +34,12 @@ class PixlyzerStatusEffectType(
return identifier.toString()
}

companion object : ResourceLocationCodec<StatusEffectType> {
companion object : IdentifierCodec<StatusEffectType> {

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): PixlyzerStatusEffectType {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): PixlyzerStatusEffectType {

return PixlyzerStatusEffectType(
identifier = resourceLocation,
identifier = identifier,
category = data["category"]?.unsafeCast<String>()?.let { return@let StatusEffectCategories[it] } ?: StatusEffectCategories.NEUTRAL,
color = data["color"]?.toInt()?.asRGBColor() ?: ChatColors.WHITE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ package de.bixilon.minosoft.data.registries.enchantment

import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierCodec

class PixLyzerEnchantment(
override val identifier: ResourceLocation,
) : Enchantment() {
override val injectable: Boolean get() = true

companion object : ResourceLocationCodec<Enchantment> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Enchantment {
return PixLyzerEnchantment(resourceLocation)
companion object : IdentifierCodec<Enchantment> {
override fun deserialize(registries: Registries?, identifier: ResourceLocation, data: Map<String, Any>): Enchantment {
return PixLyzerEnchantment(identifier)
}
}
}
Loading

0 comments on commit c18515f

Please sign in to comment.