Make android research builder remember old feature levels
This commit is contained in:
parent
505ce8d08d
commit
f8965e583c
@ -3,13 +3,18 @@ package ru.dbotthepony.mc.otm.android
|
||||
import com.google.common.collect.ImmutableList
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.client.render.SkinElement
|
||||
import ru.dbotthepony.mc.otm.container.iterator
|
||||
import ru.dbotthepony.mc.otm.core.getCompoundList
|
||||
import ru.dbotthepony.mc.otm.core.map
|
||||
import ru.dbotthepony.mc.otm.core.nonEmpty
|
||||
import ru.dbotthepony.mc.otm.core.set
|
||||
import ru.dbotthepony.mc.otm.registry.MRegistry
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@ -239,6 +244,42 @@ class AndroidResearchBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeNBT(): CompoundTag {
|
||||
return super.serializeNBT().also {
|
||||
it["oldResearchLevel"] = ListTag().also {
|
||||
for ((k, v) in oldResearchLevel) {
|
||||
it.add(CompoundTag().also {
|
||||
it["key"] = k.registryName!!.toString()
|
||||
it["value"] = CompoundTag().also {
|
||||
it["isPresent"] = v.level != null
|
||||
|
||||
if (v.level != null) {
|
||||
it["value"] = v.level
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserializeNBT(nbt: CompoundTag) {
|
||||
super.deserializeNBT(nbt)
|
||||
|
||||
oldResearchLevel.clear()
|
||||
|
||||
for (tag in nbt.getCompoundList("oldResearchLevel")) {
|
||||
val key = tag.getString("key")
|
||||
val type = MRegistry.ANDROID_FEATURES.getValue(ResourceLocation(key)) ?: continue
|
||||
val value = tag.getCompound("value")
|
||||
|
||||
val isPresent = value.getBoolean("isPresent")
|
||||
val int = value.getInt("value")
|
||||
|
||||
oldResearchLevel[type] = RememberResearchLevel(if (isPresent) int else null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun consumeResearchCost(simulate: Boolean): Boolean {
|
||||
if (capability.ply.abilities.instabuild) {
|
||||
// creative
|
||||
|
Loading…
Reference in New Issue
Block a user