Small adjustments
This commit is contained in:
parent
232eeec9be
commit
d151ba46fb
@ -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 <T : Any> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
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)
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user