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