Cleaner MenuMatterBottler code
This commit is contained in:
parent
1e49ec57ef
commit
02882509e5
@ -17,6 +17,12 @@ interface IMatterHandler {
|
|||||||
val direction: MatterDirection
|
val direction: MatterDirection
|
||||||
val missingMatter: ImpreciseFraction
|
val missingMatter: ImpreciseFraction
|
||||||
get() = maxStoredMatter.minus(storedMatter).moreThanZero()
|
get() = maxStoredMatter.minus(storedMatter).moreThanZero()
|
||||||
|
|
||||||
|
val allowsExtract: Boolean
|
||||||
|
get() = direction != MatterDirection.RECEIVE
|
||||||
|
|
||||||
|
val allowsReceive: Boolean
|
||||||
|
get() = direction != MatterDirection.EXTRACT
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class MatterDirection { RECEIVE, EXTRACT, BIDIRECTIONAL }
|
enum class MatterDirection { RECEIVE, EXTRACT, BIDIRECTIONAL }
|
||||||
|
@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.capability.matter.MatterDirection
|
|||||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||||
|
import ru.dbotthepony.mc.otm.orNull
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
|
|
||||||
class MenuMatterBottler @JvmOverloads constructor(
|
class MenuMatterBottler @JvmOverloads constructor(
|
||||||
@ -22,7 +23,7 @@ class MenuMatterBottler @JvmOverloads constructor(
|
|||||||
|
|
||||||
val progressWidget: ProgressGaugeWidget
|
val progressWidget: ProgressGaugeWidget
|
||||||
val matterWidget: LevelGaugeWidget
|
val matterWidget: LevelGaugeWidget
|
||||||
val container = arrayOfNulls<MatterySlot>(6)
|
val container: Array<MatterySlot>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val container = tile?.container ?: SimpleContainer(6)
|
val container = tile?.container ?: SimpleContainer(6)
|
||||||
@ -37,23 +38,21 @@ class MenuMatterBottler @JvmOverloads constructor(
|
|||||||
workFlow = BooleanPlayerInputWidget(this).withSupplier { tile.workFlow }.withClicker { tile.workFlow = it }
|
workFlow = BooleanPlayerInputWidget(this).withSupplier { tile.workFlow }.withClicker { tile.workFlow = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i in 0 until container.containerSize) {
|
this.container = Array(6) { index ->
|
||||||
this.container[i] = object : MatterySlot(container, i) {
|
object : MatterySlot(container, index) {
|
||||||
override fun mayPlace(p_40231_: ItemStack): Boolean {
|
override fun mayPlace(p_40231_: ItemStack): Boolean {
|
||||||
val cap = p_40231_.getCapability(MatteryCapability.MATTER).resolve()
|
val cap = p_40231_.getCapability(MatteryCapability.MATTER).orNull() ?: return false
|
||||||
if (!cap.isPresent) return false
|
|
||||||
|
|
||||||
if (workFlow.value) {
|
if (workFlow.value) {
|
||||||
return index < 3 && cap.get().direction != MatterDirection.EXTRACT
|
return index < 3 && cap.allowsReceive
|
||||||
} else {
|
} else {
|
||||||
return index >= 3 && cap.get().direction != MatterDirection.RECEIVE
|
return index >= 3 && cap.allowsExtract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSlot(this.container[i]!!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.container.forEach(this::addSlot)
|
||||||
addInventorySlots()
|
addInventorySlots()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user