Declare batteryLevel and matterLevel as vars instead of vals
This commit is contained in:
parent
be2dcc6bae
commit
adad99a6bf
@ -42,11 +42,25 @@ interface IMatteryEnergyStorage : IEnergyStorage {
|
|||||||
*/
|
*/
|
||||||
fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal
|
fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
|
|
||||||
val batteryLevel: Decimal
|
var batteryLevel: Decimal
|
||||||
val maxBatteryLevel: Decimal
|
val maxBatteryLevel: Decimal
|
||||||
val missingPower: Decimal
|
val missingPower: Decimal
|
||||||
get() = (maxBatteryLevel - batteryLevel).moreThanZero()
|
get() = (maxBatteryLevel - batteryLevel).moreThanZero()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empties power of this energy storage
|
||||||
|
*/
|
||||||
|
fun emptyBattery() {
|
||||||
|
batteryLevel = Decimal.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully fills power in this energy storage
|
||||||
|
*/
|
||||||
|
fun fillBattery() {
|
||||||
|
batteryLevel = maxBatteryLevel
|
||||||
|
}
|
||||||
|
|
||||||
override fun receiveEnergy(maxReceive: Int, simulate: Boolean): Int {
|
override fun receiveEnergy(maxReceive: Int, simulate: Boolean): Int {
|
||||||
val received = receiveEnergyOuter(maxReceive, true).toInt()
|
val received = receiveEnergyOuter(maxReceive, true).toInt()
|
||||||
|
|
||||||
|
@ -8,9 +8,23 @@ import ru.dbotthepony.mc.otm.core.orNull
|
|||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
interface IMatterHandler {
|
interface IMatterHandler {
|
||||||
val storedMatter: Decimal
|
var storedMatter: Decimal
|
||||||
val maxStoredMatter: Decimal
|
val maxStoredMatter: Decimal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empties matter stored of this matter storage
|
||||||
|
*/
|
||||||
|
fun emptyMatter() {
|
||||||
|
storedMatter = Decimal.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully fills matter stored in this matter storage
|
||||||
|
*/
|
||||||
|
fun fillMatter() {
|
||||||
|
storedMatter = maxStoredMatter
|
||||||
|
}
|
||||||
|
|
||||||
fun receiveMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
fun receiveMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal
|
fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
fun extractMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
fun extractMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
|
@ -145,20 +145,6 @@ open class BatteryItem : Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fillItemCategory(p_41391_: CreativeModeTab, p_41392_: NonNullList<ItemStack>) {
|
|
||||||
super.fillItemCategory(p_41391_, p_41392_)
|
|
||||||
|
|
||||||
if (!isCreative && allowedIn(p_41391_)) {
|
|
||||||
p_41392_.add(ItemStack(this).also {
|
|
||||||
it.matteryEnergy?.let {
|
|
||||||
if (it is Power) {
|
|
||||||
it.maxPower()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||||
return Power(stack)
|
return Power(stack)
|
||||||
}
|
}
|
||||||
|
@ -193,16 +193,6 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
|
|||||||
return EnergyConsumerItem(stack, MAX_ENERGY)
|
return EnergyConsumerItem(stack, MAX_ENERGY)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fillItemCategory(p_41391_: CreativeModeTab, p_41392_: NonNullList<ItemStack>) {
|
|
||||||
super.fillItemCategory(p_41391_, p_41392_)
|
|
||||||
|
|
||||||
if (allowedIn(p_41391_)) {
|
|
||||||
p_41392_.add(ItemStack(this).also {
|
|
||||||
it.matteryEnergy?.receiveEnergyInner(MAX_ENERGY, false)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAttributeModifiers(
|
override fun getAttributeModifiers(
|
||||||
slot: EquipmentSlot,
|
slot: EquipmentSlot,
|
||||||
itemStack: ItemStack
|
itemStack: ItemStack
|
||||||
|
@ -109,20 +109,6 @@ class MatterCapacitorItem : Item {
|
|||||||
_capacity = { Decimal.LONG_MAX_VALUE }
|
_capacity = { Decimal.LONG_MAX_VALUE }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fillItemCategory(p_41391_: CreativeModeTab, p_41392_: NonNullList<ItemStack>) {
|
|
||||||
super.fillItemCategory(p_41391_, p_41392_)
|
|
||||||
|
|
||||||
if (!isCreative && allowedIn(p_41391_)) {
|
|
||||||
p_41392_.add(ItemStack(this).also {
|
|
||||||
it.getCapability(MatteryCapability.MATTER).ifPresentK {
|
|
||||||
if (it is Matter) {
|
|
||||||
it.storedMatter = it.maxStoredMatter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||||
if (isCreative)
|
if (isCreative)
|
||||||
return false
|
return false
|
||||||
|
@ -15,7 +15,7 @@ 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
|
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") // .tab(null) is a legal statement because tab field itself is nullable
|
||||||
class ProceduralExoPackSlotUpgradeItem : AbstractExoPackSlotUpgradeItem(defaultProperties().tab(null)),
|
class ProceduralExoPackSlotUpgradeItem : AbstractExoPackSlotUpgradeItem(defaultProperties()),
|
||||||
IRandomizableItem {
|
IRandomizableItem {
|
||||||
override fun getRarity(itemStack: ItemStack): Rarity {
|
override fun getRarity(itemStack: ItemStack): Rarity {
|
||||||
return when (slotCount(itemStack)) {
|
return when (slotCount(itemStack)) {
|
||||||
|
@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.capability.ItemEnergyStorageImpl
|
|||||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||||
import ru.dbotthepony.mc.otm.container.iterator
|
import ru.dbotthepony.mc.otm.container.iterator
|
||||||
import ru.dbotthepony.mc.otm.container.stream
|
import ru.dbotthepony.mc.otm.container.stream
|
||||||
|
import ru.dbotthepony.mc.otm.core.filterNotNull
|
||||||
import ru.dbotthepony.mc.otm.core.set
|
import ru.dbotthepony.mc.otm.core.set
|
||||||
import ru.dbotthepony.mc.otm.core.tagNotNull
|
import ru.dbotthepony.mc.otm.core.tagNotNull
|
||||||
|
|
||||||
@ -37,11 +38,11 @@ class EnergyContainerRecipe(
|
|||||||
val battery = container.stream()
|
val battery = container.stream()
|
||||||
.filter { !it.isEmpty }
|
.filter { !it.isEmpty }
|
||||||
.map { it.matteryEnergy }
|
.map { it.matteryEnergy }
|
||||||
.filter { it != null }
|
.filterNotNull()
|
||||||
.findAny().orElse(null)
|
.findAny().orElse(null)
|
||||||
|
|
||||||
if (battery != null) {
|
if (battery != null) {
|
||||||
itemStack.tagNotNull[ItemEnergyStorageImpl.ENERGY_KEY] = battery.batteryLevel.serializeNBT()
|
itemStack.matteryEnergy?.batteryLevel = battery.batteryLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemStack.isEnchantable) {
|
if (itemStack.isEnchantable) {
|
||||||
|
@ -3,6 +3,10 @@ package ru.dbotthepony.mc.otm.registry
|
|||||||
import net.minecraft.world.item.CreativeModeTab
|
import net.minecraft.world.item.CreativeModeTab
|
||||||
import net.minecraft.world.item.DyeColor
|
import net.minecraft.world.item.DyeColor
|
||||||
import net.minecraft.world.item.Item
|
import net.minecraft.world.item.Item
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import ru.dbotthepony.mc.otm.capability.matter.matter
|
||||||
|
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||||
|
import ru.dbotthepony.mc.otm.core.registryName
|
||||||
|
|
||||||
private fun CreativeModeTab.Output.accept(values: Collection<Item>) {
|
private fun CreativeModeTab.Output.accept(values: Collection<Item>) {
|
||||||
for (item in values) {
|
for (item in values) {
|
||||||
@ -58,6 +62,37 @@ private fun CreativeModeTab.Output.all(values: Map<DyeColor?, Item>) {
|
|||||||
colored(values)
|
colored(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun CreativeModeTab.Output.energized(value: Item) {
|
||||||
|
accept(value)
|
||||||
|
|
||||||
|
val stack = ItemStack(value, 1)
|
||||||
|
val energy = stack.matteryEnergy ?: throw IllegalArgumentException("${value.registryName} does not implement mattery energy capability")
|
||||||
|
energy.fillBattery()
|
||||||
|
accept(stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CreativeModeTab.Output.energized(values: Iterable<Item>) {
|
||||||
|
for (value in values) {
|
||||||
|
energized(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CreativeModeTab.Output.mattery(value: Item) {
|
||||||
|
accept(value)
|
||||||
|
|
||||||
|
val stack = ItemStack(value, 1)
|
||||||
|
val matter = stack.matter ?: throw IllegalArgumentException("${value.registryName} does not implement matter capability")
|
||||||
|
|
||||||
|
matter.fillMatter()
|
||||||
|
accept(stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CreativeModeTab.Output.mattery(values: Iterable<Item>) {
|
||||||
|
for (value in values) {
|
||||||
|
mattery(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal fun addMainCreativeTabItems(consumer: CreativeModeTab.Output) {
|
internal fun addMainCreativeTabItems(consumer: CreativeModeTab.Output) {
|
||||||
with(consumer) {
|
with(consumer) {
|
||||||
accept(MItems.MACHINES)
|
accept(MItems.MACHINES)
|
||||||
@ -77,8 +112,8 @@ internal fun addMainCreativeTabItems(consumer: CreativeModeTab.Output) {
|
|||||||
accept(MItems.TRITANIUM_TOOLS)
|
accept(MItems.TRITANIUM_TOOLS)
|
||||||
accept(MItems.TRITANIUM_ARMOR)
|
accept(MItems.TRITANIUM_ARMOR)
|
||||||
|
|
||||||
accept(MItems.ENERGY_SWORD)
|
energized(MItems.ENERGY_SWORD)
|
||||||
accept(MItems.PLASMA_RIFLE)
|
energized(MItems.PLASMA_RIFLE)
|
||||||
|
|
||||||
accept(MItems.BLACK_HOLE_SCANNER)
|
accept(MItems.BLACK_HOLE_SCANNER)
|
||||||
accept(MItems.GRAVITATION_FIELD_LIMITER)
|
accept(MItems.GRAVITATION_FIELD_LIMITER)
|
||||||
@ -87,8 +122,8 @@ internal fun addMainCreativeTabItems(consumer: CreativeModeTab.Output) {
|
|||||||
accept(MItems.BLACK_HOLE)
|
accept(MItems.BLACK_HOLE)
|
||||||
accept(MItems.GRAVITATIONAL_DISRUPTOR)
|
accept(MItems.GRAVITATIONAL_DISRUPTOR)
|
||||||
|
|
||||||
accept(MItems.ALL_BATTERIES)
|
energized(MItems.ALL_BATTERIES)
|
||||||
accept(MItems.MATTER_CAPACITORS)
|
mattery(MItems.MATTER_CAPACITORS)
|
||||||
|
|
||||||
base(MItems.CARGO_CRATE_MINECARTS)
|
base(MItems.CARGO_CRATE_MINECARTS)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user