get rid of rigid ModeState dependency
This commit is contained in:
parent
d8648d7088
commit
5f5af4ed06
@ -205,7 +205,6 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
}
|
||||
|
||||
private val caps = Reference2ObjectArrayMap<Capability<*>, Cap<*>>()
|
||||
private val modeStates = Object2ObjectArrayMap<String, ModeState>()
|
||||
private val data = Object2ObjectArrayMap<ResourceLocation, INBTSerializable<Tag>>()
|
||||
private val subscriptions = Reference2ObjectArrayMap<Capability<*>, SubRef<*>>()
|
||||
private val knownLOs = WeakHashSet<LazyOptional<*>>()
|
||||
@ -283,17 +282,14 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
}
|
||||
}
|
||||
|
||||
val isEmpty get() = caps.isEmpty() && modeStates.isEmpty()
|
||||
val isEmpty get() = caps.isEmpty() && data.isEmpty()
|
||||
|
||||
operator fun <T : Any> get(capability: Capability<T>): Cap<T>? {
|
||||
return caps[capability] as Cap<T>?
|
||||
}
|
||||
|
||||
operator fun get(index: String): ModeState? {
|
||||
return modeStates[index]
|
||||
}
|
||||
|
||||
fun addData(index: ResourceLocation, data: INBTSerializable<*>) {
|
||||
require(!this.data.containsKey(index)) { "Already has data with ID $index on $side!" }
|
||||
this.data[index] = data as INBTSerializable<Tag>
|
||||
}
|
||||
|
||||
@ -313,32 +309,25 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
|
||||
override fun serializeNBT(): CompoundTag {
|
||||
return CompoundTag().also {
|
||||
val modelist = CompoundTag()
|
||||
|
||||
for (cap in modeStates.values) {
|
||||
modelist[cap.name] = cap.serializeNBT()
|
||||
for ((k, v) in data) {
|
||||
it[k.toString()] = v.serializeNBT()
|
||||
}
|
||||
|
||||
it["Modes"] = modelist
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserializeNBT(nbt: CompoundTag) {
|
||||
if (nbt.contains("Modes")) {
|
||||
val caplist = nbt.getCompound("Modes")
|
||||
for ((k, v) in data) {
|
||||
val tag = nbt[k.toString()]
|
||||
|
||||
for (state in modeStates.values) {
|
||||
if (state.name in caplist) {
|
||||
state.deserializeNBT(caplist.getString(state.name))
|
||||
}
|
||||
if (tag != null) {
|
||||
v.deserializeNBT(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class ModeState(val name: String, val possibleValues: ImmutableSet<SideMode> = SideMode.BI_SET) : INBTSerializable<StringTag> {
|
||||
init {
|
||||
check(!modeStates.containsKey(name)) { "Already has config with name $name on side $side" }
|
||||
modeStates[name] = this
|
||||
addData(ResourceLocation(name), this)
|
||||
}
|
||||
|
||||
val side get() = this@Side.side
|
||||
|
Loading…
Reference in New Issue
Block a user