Skip to content

Commit

Permalink
Fix default holder implementations not saving data
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed May 15, 2024
1 parent b724971 commit bb21ebf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kotlinx-coroutines = "1.8.0"
ktor = "2.3.9"
paper = "1.20.4-R0.1-SNAPSHOT"
paperweight = "1.5.15"
xenondevs-commons = "1.11"
xenondevs-commons = "1.12"

[libraries]
awssdk-s3 = { group = "software.amazon.awssdk", name = "s3", version = "2.25.23" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import xyz.xenondevs.cbf.Compound
import xyz.xenondevs.cbf.provider.entry
import xyz.xenondevs.commons.collections.toEnumMap
import xyz.xenondevs.commons.provider.Provider
import xyz.xenondevs.commons.provider.mutable.defaultsToLazily
import xyz.xenondevs.commons.provider.mutable.orElse
import xyz.xenondevs.commons.provider.mutable.orElseLazily
import xyz.xenondevs.nova.tileentity.network.type.NetworkConnectionType
import xyz.xenondevs.nova.util.TickedLong
import kotlin.math.max
Expand All @@ -29,7 +29,7 @@ class DefaultEnergyHolder(

override val connectionConfig: MutableMap<BlockFace, NetworkConnectionType>
by compound.entry<MutableMap<BlockFace, NetworkConnectionType>>("connectionConfig")
.orElseLazily { defaultConnectionConfig().toEnumMap() }
.defaultsToLazily { defaultConnectionConfig().toEnumMap() }

/**
* The maximum amount of energy this [EnergyHolder] can store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private fun createFluidConfiguration(
return when (type) {
NetworkConnectionType.INSERT, NetworkConnectionType.EXTRACT -> DefaultFluidConfiguration(fluidHolder, faces, container, type)
NetworkConnectionType.BUFFER -> FluidBufferConfiguration(fluidHolder, faces, container)
else -> throw IllegalArgumentException()
else -> throw IllegalArgumentException("Illegal network connection type: $type")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import xyz.xenondevs.cbf.provider.entry
import xyz.xenondevs.commons.collections.enumMap
import xyz.xenondevs.commons.collections.toEnumMap
import xyz.xenondevs.commons.provider.Provider
import xyz.xenondevs.commons.provider.mutable.defaultsToLazily
import xyz.xenondevs.commons.provider.mutable.mapNonNull
import xyz.xenondevs.commons.provider.mutable.orElseLazily
import xyz.xenondevs.nova.tileentity.network.type.NetworkConnectionType
import xyz.xenondevs.nova.tileentity.network.type.fluid.container.NetworkedFluidContainer
import xyz.xenondevs.nova.util.CUBE_FACES
Expand Down Expand Up @@ -41,23 +41,23 @@ class DefaultFluidHolder(
.mapNonNull(
{ it.mapValuesTo(enumMap()) { (_, uuid) -> uuidToContainer[uuid]!! } },
{ it.mapValuesTo(enumMap()) { (_, container) -> container.uuid } }
).orElseLazily { defaultContainerConfig().toEnumMap() }
).defaultsToLazily { defaultContainerConfig().toEnumMap() }

override val connectionConfig: MutableMap<BlockFace, NetworkConnectionType> by
compound.entry<MutableMap<BlockFace, NetworkConnectionType>>("connectionConfig")
.orElseLazily { defaultConnectionConfig().toEnumMap() }
.defaultsToLazily { defaultConnectionConfig().toEnumMap() }

override val channels: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("channels")
.orElseLazily(DEFAULT_CHANNEL_CONFIG)
.defaultsToLazily(DEFAULT_CHANNEL_CONFIG)

override val insertPriorities: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("insertPriorities")
.orElseLazily(DEFAULT_PRIORITIES)
.defaultsToLazily(DEFAULT_PRIORITIES)

override val extractPriorities: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("extractPriorities")
.orElseLazily(DEFAULT_PRIORITIES)
.defaultsToLazily(DEFAULT_PRIORITIES)

internal companion object {
val DEFAULT_CONNECTION_CONFIG = { CUBE_FACES.associateWithTo(enumMap()) { NetworkConnectionType.NONE } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import xyz.xenondevs.cbf.provider.entry
import xyz.xenondevs.commons.collections.enumMap
import xyz.xenondevs.commons.collections.toEnumMap
import xyz.xenondevs.commons.provider.Provider
import xyz.xenondevs.commons.provider.mutable.defaultsToLazily
import xyz.xenondevs.commons.provider.mutable.mapNonNull
import xyz.xenondevs.commons.provider.mutable.orElseLazily
import xyz.xenondevs.invui.inventory.VirtualInventory
import xyz.xenondevs.nova.tileentity.network.type.NetworkConnectionType
import xyz.xenondevs.nova.tileentity.network.type.item.ItemFilter
Expand Down Expand Up @@ -51,34 +51,34 @@ class DefaultItemHolder(
.mapNonNull(
{ it.mapValuesTo(enumMap()) { (_, uuid) -> uuidToInv[uuid]!! } },
{ it.mapValuesTo(enumMap()) { (_, inv) -> inv.uuid } }
).orElseLazily { defaultInventoryConfig().toEnumMap() }
).defaultsToLazily { defaultInventoryConfig().toEnumMap() }

override val connectionConfig: MutableMap<BlockFace, NetworkConnectionType>
by compound.entry<MutableMap<BlockFace, NetworkConnectionType>>("connectionConfig")
.orElseLazily {
.defaultsToLazily {
defaultConnectionConfig?.invoke()?.toEnumMap()
?: containerConfig.mapValuesTo(enumMap()) { (_, inv) -> containers[inv] }
}

override val channels: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("channels")
.orElseLazily(DEFAULT_CHANNELS)
.defaultsToLazily(DEFAULT_CHANNELS)

override val insertFilters: MutableMap<BlockFace, ItemFilter>
by compound.entry<MutableMap<BlockFace, ItemFilter>>("insertFilters")
.orElseLazily(::enumMap)
.defaultsToLazily(::enumMap)

override val extractFilters: MutableMap<BlockFace, ItemFilter>
by compound.entry<MutableMap<BlockFace, ItemFilter>>("extractFilters")
.orElseLazily(::enumMap)
.defaultsToLazily(::enumMap)

override val insertPriorities: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("insertPriorities")
.orElseLazily(DEFAULT_PRIORITIES)
.defaultsToLazily(DEFAULT_PRIORITIES)

override val extractPriorities: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("extractPriorities")
.orElseLazily(DEFAULT_PRIORITIES)
.defaultsToLazily(DEFAULT_PRIORITIES)

fun getNetworkedInventory(inv: VirtualInventory): NetworkedInventory =
getNetworkedInventory(inv.uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import xyz.xenondevs.cbf.provider.entry
import xyz.xenondevs.commons.collections.enumMap
import xyz.xenondevs.commons.collections.enumSet
import xyz.xenondevs.commons.provider.Provider
import xyz.xenondevs.commons.provider.mutable.orElseLazily
import xyz.xenondevs.commons.provider.mutable.defaultsToLazily
import xyz.xenondevs.nova.tileentity.network.type.NetworkConnectionType
import xyz.xenondevs.nova.tileentity.network.type.item.ItemFilter
import xyz.xenondevs.nova.tileentity.network.type.item.holder.DefaultItemHolder.Companion.DEFAULT_CHANNELS
Expand All @@ -20,8 +20,8 @@ internal abstract class VanillaItemHolder(
override val mergedInventory: NetworkedInventory? = null

override val connectionConfig: MutableMap<BlockFace, NetworkConnectionType> by
compound.entry<MutableMap<BlockFace, NetworkConnectionType>>("connectionConfig")
.orElseLazily { CUBE_FACES.associateWithTo(enumMap()) { NetworkConnectionType.INSERT } }
compound.entry<MutableMap<BlockFace, NetworkConnectionType>>("connectionConfig")
.defaultsToLazily { CUBE_FACES.associateWithTo(enumMap()) { NetworkConnectionType.INSERT } }

override val allowedFaces: Set<BlockFace>
get() = connectionConfig.mapNotNullTo(enumSet()) { (face, type) ->
Expand All @@ -32,25 +32,25 @@ internal abstract class VanillaItemHolder(
containerConfig.entries.associate { (_, inv) -> inv to NetworkConnectionType.BUFFER }
}

override val insertFilters: MutableMap<BlockFace, ItemFilter> by
compound.entry<MutableMap<BlockFace, ItemFilter>>("insertFilters")
.orElseLazily(::enumMap)
override val insertFilters: MutableMap<BlockFace, ItemFilter>
by compound.entry<MutableMap<BlockFace, ItemFilter>>("insertFilters")
.defaultsToLazily(::enumMap)

override val extractFilters: MutableMap<BlockFace, ItemFilter> by
compound.entry<MutableMap<BlockFace, ItemFilter>>("extractFilters")
.orElseLazily(::enumMap)
override val extractFilters: MutableMap<BlockFace, ItemFilter>
by compound.entry<MutableMap<BlockFace, ItemFilter>>("extractFilters")
.defaultsToLazily(::enumMap)

override val insertPriorities: MutableMap<BlockFace, Int> by
compound.entry<MutableMap<BlockFace, Int>>("insertPriorities")
.orElseLazily(DefaultItemHolder.DEFAULT_PRIORITIES)
override val insertPriorities: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("insertPriorities")
.defaultsToLazily(DefaultItemHolder.DEFAULT_PRIORITIES)

override val extractPriorities: MutableMap<BlockFace, Int> by
compound.entry<MutableMap<BlockFace, Int>>("extractPriorities")
.orElseLazily(DefaultItemHolder.DEFAULT_PRIORITIES)
override val extractPriorities: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("extractPriorities")
.defaultsToLazily(DefaultItemHolder.DEFAULT_PRIORITIES)

override val channels: MutableMap<BlockFace, Int> by
compound.entry<MutableMap<BlockFace, Int>>("channels")
.orElseLazily(DEFAULT_CHANNELS)
override val channels: MutableMap<BlockFace, Int>
by compound.entry<MutableMap<BlockFace, Int>>("channels")
.defaultsToLazily(DEFAULT_CHANNELS)

}

Expand Down

0 comments on commit bb21ebf

Please sign in to comment.