diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt index 3a4708335..b658152fe 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt @@ -19,35 +19,21 @@ import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.tagNotNull -sealed class ItemEnergyStorageImpl( - final override val energyFlow: FlowDirection, - protected val itemStack: ItemStack, - maxBatteryLevel: Decimal, - maxInput: Decimal?, - maxOutput: Decimal?, - val initialBatteryLevel: Decimal = Decimal.ZERO -) : IMatteryEnergyStorage, ICapabilityProvider, IEnergyStorageImpl { - final override var maxInput: Decimal? = maxInput - protected set - - final override var maxOutput: Decimal? = maxOutput - protected set - +abstract class ItemEnergyStorageImpl(val itemStack: ItemStack) : IMatteryEnergyStorage, ICapabilityProvider, IEnergyStorageImpl { private val resolver = LazyOptional.of { this } private val resolverMekanism = if (isMekanismLoaded) LazyOptional.of { Mattery2MekanismEnergyWrapper(this) } else null override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - if (cap == ForgeCapabilities.ENERGY || cap == MatteryCapability.ENERGY) { + if (cap === ForgeCapabilities.ENERGY || cap === MatteryCapability.ENERGY) { return resolver.cast() - } else if (cap == MatteryCapability.MEKANISM_ENERGY) { + } else if (cap === MatteryCapability.MEKANISM_ENERGY) { return resolverMekanism?.cast() ?: LazyOptional.empty() } return LazyOptional.empty() } - override var maxBatteryLevel: Decimal = maxBatteryLevel - protected set + abstract val initialBatteryLevel: Decimal override var batteryLevel: Decimal get() = itemStack.tag?.map(ENERGY_KEY, Decimal.Companion::deserializeNBT) ?: initialBatteryLevel @@ -128,13 +114,31 @@ sealed class ItemEnergyStorageImpl( } } +abstract class SimpleEnergyItem( + override val energyFlow: FlowDirection, + stack: ItemStack, + maxBatteryLevel: Decimal, + maxInput: Decimal?, + maxOutput: Decimal?, + override val initialBatteryLevel: Decimal +) : ItemEnergyStorageImpl(stack) { + override var maxInput: Decimal? = maxInput + protected set + + override var maxOutput: Decimal? = maxOutput + protected set + + override var maxBatteryLevel: Decimal = maxBatteryLevel + protected set +} + open class EnergyConsumerItem( stack: ItemStack, maxBatteryLevel: Decimal, maxInput: Decimal? = null, maxOutput: Decimal? = maxInput, initialBatteryLevel: Decimal = Decimal.ZERO -) : ItemEnergyStorageImpl(FlowDirection.INPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel) +) : SimpleEnergyItem(FlowDirection.INPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel) open class EnergyProducerItem( stack: ItemStack, @@ -142,7 +146,7 @@ open class EnergyProducerItem( maxInput: Decimal? = null, maxOutput: Decimal? = maxInput, initialBatteryLevel: Decimal = Decimal.ZERO -) : ItemEnergyStorageImpl(FlowDirection.OUTPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel) +) : SimpleEnergyItem(FlowDirection.OUTPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel) open class EnergyCapacitorItem( stack: ItemStack, @@ -150,4 +154,5 @@ open class EnergyCapacitorItem( maxInput: Decimal? = null, maxOutput: Decimal? = maxInput, initialBatteryLevel: Decimal = Decimal.ZERO -) : ItemEnergyStorageImpl(FlowDirection.BI_DIRECTIONAL, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel) +) : SimpleEnergyItem(FlowDirection.BI_DIRECTIONAL, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel) + diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt index 19710415f..f983a909b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt @@ -168,9 +168,7 @@ class CrudeBatteryItem : BatteryItem(ItemsConfig.Batteries.CRUDE) { ) { super.appendHoverText(stack, p_41422_, p_41423_, p_41424_) - val isAndroid = runIfClient(false) { - return@runIfClient minecraft.player?.matteryPlayer?.isAndroid ?: false - } + val isAndroid = runIfClient(false) { minecraft.player?.matteryPlayer?.isAndroid ?: false } if (isAndroid) { p_41423_.add(TranslatableComponent("otm.gui.crude_battery.replace_in_world").withStyle(ChatFormatting.GRAY)) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/exopack/ProceduralExoPackSlotUpgradeItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/exopack/ProceduralExoPackSlotUpgradeItem.kt index b66a98e7c..c4b7d8915 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/exopack/ProceduralExoPackSlotUpgradeItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/exopack/ProceduralExoPackSlotUpgradeItem.kt @@ -14,9 +14,7 @@ import ru.dbotthepony.mc.otm.core.tagNotNull import ru.dbotthepony.mc.otm.data.loot.IRandomizableItem import java.util.* -@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") // .tab(null) is a legal statement because tab field itself is nullable -class ProceduralExoPackSlotUpgradeItem : AbstractExoPackSlotUpgradeItem(defaultProperties()), - IRandomizableItem { +class ProceduralExoPackSlotUpgradeItem : AbstractExoPackSlotUpgradeItem(defaultProperties()), IRandomizableItem { override fun getRarity(itemStack: ItemStack): Rarity { return when (slotCount(itemStack)) { in 0 .. 9 -> Rarity.COMMON