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.nbt.set
|
||||||
import ru.dbotthepony.mc.otm.core.tagNotNull
|
import ru.dbotthepony.mc.otm.core.tagNotNull
|
||||||
|
|
||||||
sealed class ItemEnergyStorageImpl(
|
abstract class ItemEnergyStorageImpl(val itemStack: ItemStack) : IMatteryEnergyStorage, ICapabilityProvider, IEnergyStorageImpl {
|
||||||
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
|
|
||||||
|
|
||||||
private val resolver = LazyOptional.of { this }
|
private val resolver = LazyOptional.of { this }
|
||||||
private val resolverMekanism = if (isMekanismLoaded) LazyOptional.of { Mattery2MekanismEnergyWrapper(this) } else null
|
private val resolverMekanism = if (isMekanismLoaded) LazyOptional.of { Mattery2MekanismEnergyWrapper(this) } else null
|
||||||
|
|
||||||
override fun <T : Any> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
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()
|
return resolver.cast()
|
||||||
} else if (cap == MatteryCapability.MEKANISM_ENERGY) {
|
} else if (cap === MatteryCapability.MEKANISM_ENERGY) {
|
||||||
return resolverMekanism?.cast() ?: LazyOptional.empty()
|
return resolverMekanism?.cast() ?: LazyOptional.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
return LazyOptional.empty()
|
return LazyOptional.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
override var maxBatteryLevel: Decimal = maxBatteryLevel
|
abstract val initialBatteryLevel: Decimal
|
||||||
protected set
|
|
||||||
|
|
||||||
override var batteryLevel: Decimal
|
override var batteryLevel: Decimal
|
||||||
get() = itemStack.tag?.map(ENERGY_KEY, Decimal.Companion::deserializeNBT) ?: initialBatteryLevel
|
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(
|
open class EnergyConsumerItem(
|
||||||
stack: ItemStack,
|
stack: ItemStack,
|
||||||
maxBatteryLevel: Decimal,
|
maxBatteryLevel: Decimal,
|
||||||
maxInput: Decimal? = null,
|
maxInput: Decimal? = null,
|
||||||
maxOutput: Decimal? = maxInput,
|
maxOutput: Decimal? = maxInput,
|
||||||
initialBatteryLevel: Decimal = Decimal.ZERO
|
initialBatteryLevel: Decimal = Decimal.ZERO
|
||||||
) : ItemEnergyStorageImpl(FlowDirection.INPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel)
|
) : SimpleEnergyItem(FlowDirection.INPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel)
|
||||||
|
|
||||||
open class EnergyProducerItem(
|
open class EnergyProducerItem(
|
||||||
stack: ItemStack,
|
stack: ItemStack,
|
||||||
@ -142,7 +146,7 @@ open class EnergyProducerItem(
|
|||||||
maxInput: Decimal? = null,
|
maxInput: Decimal? = null,
|
||||||
maxOutput: Decimal? = maxInput,
|
maxOutput: Decimal? = maxInput,
|
||||||
initialBatteryLevel: Decimal = Decimal.ZERO
|
initialBatteryLevel: Decimal = Decimal.ZERO
|
||||||
) : ItemEnergyStorageImpl(FlowDirection.OUTPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel)
|
) : SimpleEnergyItem(FlowDirection.OUTPUT, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel)
|
||||||
|
|
||||||
open class EnergyCapacitorItem(
|
open class EnergyCapacitorItem(
|
||||||
stack: ItemStack,
|
stack: ItemStack,
|
||||||
@ -150,4 +154,5 @@ open class EnergyCapacitorItem(
|
|||||||
maxInput: Decimal? = null,
|
maxInput: Decimal? = null,
|
||||||
maxOutput: Decimal? = maxInput,
|
maxOutput: Decimal? = maxInput,
|
||||||
initialBatteryLevel: Decimal = Decimal.ZERO
|
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_)
|
super.appendHoverText(stack, p_41422_, p_41423_, p_41424_)
|
||||||
|
|
||||||
val isAndroid = runIfClient(false) {
|
val isAndroid = runIfClient(false) { minecraft.player?.matteryPlayer?.isAndroid ?: false }
|
||||||
return@runIfClient minecraft.player?.matteryPlayer?.isAndroid ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
p_41423_.add(TranslatableComponent("otm.gui.crude_battery.replace_in_world").withStyle(ChatFormatting.GRAY))
|
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 ru.dbotthepony.mc.otm.data.loot.IRandomizableItem
|
||||||
import java.util.*
|
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 {
|
override fun getRarity(itemStack: ItemStack): Rarity {
|
||||||
return when (slotCount(itemStack)) {
|
return when (slotCount(itemStack)) {
|
||||||
in 0 .. 9 -> Rarity.COMMON
|
in 0 .. 9 -> Rarity.COMMON
|
||||||
|
Loading…
Reference in New Issue
Block a user