Rename IMatterHandler to IMatterStorage
This commit is contained in:
parent
e4dc6f60e7
commit
75211f068c
@ -5,7 +5,7 @@ import net.minecraftforge.common.capabilities.*;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive;
|
import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive;
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage;
|
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage;
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler;
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage;
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IReplicationTaskProvider;
|
import ru.dbotthepony.mc.otm.capability.matter.IReplicationTaskProvider;
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage;
|
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage;
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode;
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode;
|
||||||
@ -26,7 +26,7 @@ public class MatteryCapability {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final Capability<IMatterHandler> MATTER = CapabilityManager.get(new CapabilityToken<>() {});
|
public static final Capability<IMatterStorage> MATTER = CapabilityManager.get(new CapabilityToken<>() {});
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -63,7 +63,7 @@ public class MatteryCapability {
|
|||||||
public static void register(RegisterCapabilitiesEvent event) {
|
public static void register(RegisterCapabilitiesEvent event) {
|
||||||
event.register(IMatteryEnergyStorage.class);
|
event.register(IMatteryEnergyStorage.class);
|
||||||
event.register(MatteryPlayerCapability.class);
|
event.register(MatteryPlayerCapability.class);
|
||||||
event.register(IMatterHandler.class);
|
event.register(IMatterStorage.class);
|
||||||
event.register(IMatterGraphNode.class);
|
event.register(IMatterGraphNode.class);
|
||||||
event.register(IPatternStorage.class);
|
event.register(IPatternStorage.class);
|
||||||
event.register(IReplicationTaskProvider.class);
|
event.register(IReplicationTaskProvider.class);
|
||||||
|
@ -26,8 +26,8 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|||||||
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
@ -114,7 +114,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val matter: MatterHandlerImpl = object : MatterHandlerImpl(this::setChangedLight, FlowDirection.BI_DIRECTIONAL, ::CAPACITY) {
|
val matter: MatterStorageImpl = object : MatterStorageImpl(this::setChangedLight, FlowDirection.BI_DIRECTIONAL, ::CAPACITY) {
|
||||||
override val matterDirection: FlowDirection get() {
|
override val matterDirection: FlowDirection get() {
|
||||||
return if (this@MatterBottlerBlockEntity.isBottling) FlowDirection.INPUT else FlowDirection.OUTPUT
|
return if (this@MatterBottlerBlockEntity.isBottling) FlowDirection.INPUT else FlowDirection.OUTPUT
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
private var initialCapacity: Decimal? = null
|
private var initialCapacity: Decimal? = null
|
||||||
private var lastWorkStack: ItemStack? = null
|
private var lastWorkStack: ItemStack? = null
|
||||||
|
|
||||||
override fun getMatterHandler(): IMatterHandler {
|
override fun getMatterHandler(): IMatterStorage {
|
||||||
return matter
|
return matter
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
var work_stack: ItemStack? = null
|
var work_stack: ItemStack? = null
|
||||||
var capability: IMatterHandler? = null
|
var capability: IMatterStorage? = null
|
||||||
val align = if (isBottling) 0 else 3
|
val align = if (isBottling) 0 else 3
|
||||||
var work_slot = -1
|
var work_slot = -1
|
||||||
val unexpectedDirection = if (isBottling) FlowDirection.OUTPUT else FlowDirection.INPUT
|
val unexpectedDirection = if (isBottling) FlowDirection.OUTPUT else FlowDirection.INPUT
|
||||||
|
@ -21,7 +21,7 @@ import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.core.Decimal
|
import ru.dbotthepony.mc.otm.core.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||||
@ -33,7 +33,7 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
|||||||
import ru.dbotthepony.mc.otm.core.map
|
import ru.dbotthepony.mc.otm.core.map
|
||||||
import ru.dbotthepony.mc.otm.core.set
|
import ru.dbotthepony.mc.otm.core.set
|
||||||
|
|
||||||
class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterGraphNode, IMatterHandler, IDroppableContainer {
|
class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterGraphNode, IMatterStorage, IDroppableContainer {
|
||||||
var gaugeLevel by synchronizer.float()
|
var gaugeLevel by synchronizer.float()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
|||||||
MatterNetworkGraph.discoverFull(this, matterNode)
|
MatterNetworkGraph.discoverFull(this, matterNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMatterHandler(): IMatterHandler {
|
override fun getMatterHandler(): IMatterStorage {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|||||||
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
@ -128,7 +128,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState)
|
|||||||
private var valid = true
|
private var valid = true
|
||||||
override val matterNode = Graph6Node<IMatterGraphNode>(this)
|
override val matterNode = Graph6Node<IMatterGraphNode>(this)
|
||||||
|
|
||||||
val matter = MatterHandlerImpl(this::setChangedLight, FlowDirection.OUTPUT, ::CAPACITY)
|
val matter = MatterStorageImpl(this::setChangedLight, FlowDirection.OUTPUT, ::CAPACITY)
|
||||||
|
|
||||||
private var resolverMatter = LazyOptional.of { matter }
|
private var resolverMatter = LazyOptional.of { matter }
|
||||||
private var resolverNode = LazyOptional.of { this }
|
private var resolverNode = LazyOptional.of { this }
|
||||||
@ -242,7 +242,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState)
|
|||||||
MatterNetworkGraph.discoverFull(this, matterNode)
|
MatterNetworkGraph.discoverFull(this, matterNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMatterHandler(): IMatterHandler {
|
override fun getMatterHandler(): IMatterStorage {
|
||||||
return matter
|
return matter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|||||||
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||||
import ru.dbotthepony.mc.otm.core.Decimal
|
import ru.dbotthepony.mc.otm.core.Decimal
|
||||||
@ -73,7 +73,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val matter = MatterHandlerImpl(
|
val matter = MatterStorageImpl(
|
||||||
this::matterLevelUpdated,
|
this::matterLevelUpdated,
|
||||||
FlowDirection.OUTPUT,
|
FlowDirection.OUTPUT,
|
||||||
::CAPACITY
|
::CAPACITY
|
||||||
@ -88,7 +88,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
private var valid = true
|
private var valid = true
|
||||||
override val energy = WorkerEnergyStorage(this::powerLevelUpdated, ENERGY_CONFIG)
|
override val energy = WorkerEnergyStorage(this::powerLevelUpdated, ENERGY_CONFIG)
|
||||||
|
|
||||||
override fun getMatterHandler(): IMatterHandler {
|
override fun getMatterHandler(): IMatterStorage {
|
||||||
return matter
|
return matter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
override val matterNode = Graph6Node<IMatterGraphNode>(this)
|
override val matterNode = Graph6Node<IMatterGraphNode>(this)
|
||||||
private val resolverNode = LazyOptional.of { this }
|
private val resolverNode = LazyOptional.of { this }
|
||||||
|
|
||||||
val matter = MatterHandlerImpl(
|
val matter = MatterStorageImpl(
|
||||||
this::matterLevelUpdated,
|
this::matterLevelUpdated,
|
||||||
FlowDirection.INPUT,
|
FlowDirection.INPUT,
|
||||||
::MATTER_CAPACITY
|
::MATTER_CAPACITY
|
||||||
|
@ -8,7 +8,10 @@ import ru.dbotthepony.mc.otm.core.RGBAColor
|
|||||||
import ru.dbotthepony.mc.otm.core.orNull
|
import ru.dbotthepony.mc.otm.core.orNull
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
interface IMatterHandler {
|
/**
|
||||||
|
* Matter interface in Overdrive That Matters
|
||||||
|
*/
|
||||||
|
interface IMatterStorage {
|
||||||
/**
|
/**
|
||||||
* If this is false, then [storedMatter] will throw [UnsupportedOperationException] when trying to set it
|
* If this is false, then [storedMatter] will throw [UnsupportedOperationException] when trying to set it
|
||||||
*/
|
*/
|
||||||
@ -81,17 +84,17 @@ interface IMatterHandler {
|
|||||||
val matterDirection: FlowDirection
|
val matterDirection: FlowDirection
|
||||||
}
|
}
|
||||||
|
|
||||||
inline val IMatterHandler.canExtractMatter: Boolean
|
inline val IMatterStorage.canExtractMatter: Boolean
|
||||||
get() = matterDirection.output
|
get() = matterDirection.output
|
||||||
inline val IMatterHandler.canReceiveMatter: Boolean
|
inline val IMatterStorage.canReceiveMatter: Boolean
|
||||||
get() = matterDirection.input
|
get() = matterDirection.input
|
||||||
|
|
||||||
fun IMatterHandler.getBarWidth(): Int {
|
fun IMatterStorage.getBarWidth(): Int {
|
||||||
return ((storedMatter / maxStoredMatter).toFloat().coerceAtLeast(0f).coerceAtMost(1f) * 13f).roundToInt()
|
return ((storedMatter / maxStoredMatter).toFloat().coerceAtLeast(0f).coerceAtMost(1f) * 13f).roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IMatterHandler.getBarColor(): Int {
|
fun IMatterStorage.getBarColor(): Int {
|
||||||
return RGBAColor.LOW_MATTER.linearInterpolation((storedMatter / maxStoredMatter).toFloat(), RGBAColor.FULL_MATTER).toInt()
|
return RGBAColor.LOW_MATTER.linearInterpolation((storedMatter / maxStoredMatter).toFloat(), RGBAColor.FULL_MATTER).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
val ICapabilityProvider.matter: IMatterHandler? get() = getCapability(MatteryCapability.MATTER).orNull()
|
val ICapabilityProvider.matter: IMatterStorage? get() = getCapability(MatteryCapability.MATTER).orNull()
|
@ -9,13 +9,13 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|||||||
import ru.dbotthepony.mc.otm.core.Decimal
|
import ru.dbotthepony.mc.otm.core.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.set
|
import ru.dbotthepony.mc.otm.core.set
|
||||||
|
|
||||||
open class MatterHandlerImpl @JvmOverloads constructor(
|
open class MatterStorageImpl @JvmOverloads constructor(
|
||||||
protected val listener: Runnable?,
|
protected val listener: Runnable?,
|
||||||
override val matterDirection: FlowDirection,
|
override val matterDirection: FlowDirection,
|
||||||
protected val maxStoredMatterSupplier: () -> Decimal,
|
protected val maxStoredMatterSupplier: () -> Decimal,
|
||||||
protected val maxReceiveSupplier: () -> Decimal? = { null },
|
protected val maxReceiveSupplier: () -> Decimal? = { null },
|
||||||
protected val maxExtractSupplier: () -> Decimal? = maxReceiveSupplier
|
protected val maxExtractSupplier: () -> Decimal? = maxReceiveSupplier
|
||||||
) : IMatterHandler, INBTSerializable<CompoundTag> {
|
) : IMatterStorage, INBTSerializable<CompoundTag> {
|
||||||
constructor(
|
constructor(
|
||||||
listener: Runnable?,
|
listener: Runnable?,
|
||||||
direction: FlowDirection,
|
direction: FlowDirection,
|
||||||
@ -44,7 +44,7 @@ open class MatterHandlerImpl @JvmOverloads constructor(
|
|||||||
|
|
||||||
override var storedMatter = Decimal.ZERO
|
override var storedMatter = Decimal.ZERO
|
||||||
|
|
||||||
private var handler = LazyOptional.of<IMatterHandler> { this }
|
private var handler = LazyOptional.of<IMatterStorage> { this }
|
||||||
|
|
||||||
fun invalidate() {
|
fun invalidate() {
|
||||||
handler.invalidate()
|
handler.invalidate()
|
||||||
@ -54,7 +54,7 @@ open class MatterHandlerImpl @JvmOverloads constructor(
|
|||||||
handler = LazyOptional.of { this }
|
handler = LazyOptional.of { this }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(): LazyOptional<IMatterHandler> {
|
fun get(): LazyOptional<IMatterStorage> {
|
||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ interface IMatterGraphListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IMatterGraphNode : IMatterGraphListener {
|
interface IMatterGraphNode : IMatterGraphListener {
|
||||||
fun getMatterHandler(): IMatterHandler? = null
|
fun getMatterHandler(): IMatterStorage? = null
|
||||||
fun getPatternHandler(): IPatternStorage? = null
|
fun getPatternHandler(): IPatternStorage? = null
|
||||||
fun getTaskHandler(): IReplicationTaskProvider? = null
|
fun getTaskHandler(): IReplicationTaskProvider? = null
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ import javax.annotation.ParametersAreNonnullByDefault
|
|||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
class MatterCapacitorItem : Item {
|
class MatterCapacitorItem : Item {
|
||||||
private inner class Matter(private val stack: ItemStack) : ICapabilityProvider, IMatterHandler {
|
private inner class Matter(private val stack: ItemStack) : ICapabilityProvider, IMatterStorage {
|
||||||
private val resolver = LazyOptional.of<IMatterHandler> { this }
|
private val resolver = LazyOptional.of<IMatterStorage> { this }
|
||||||
|
|
||||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||||
return if (cap === MatteryCapability.MATTER) resolver.cast() else LazyOptional.empty()
|
return if (cap === MatteryCapability.MATTER) resolver.cast() else LazyOptional.empty()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.menu.widget
|
package ru.dbotthepony.mc.otm.menu.widget
|
||||||
|
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage
|
||||||
import ru.dbotthepony.mc.otm.core.Decimal
|
import ru.dbotthepony.mc.otm.core.Decimal
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
@ -28,7 +28,7 @@ class LevelGaugeWidget(menu: MatteryMenu) : AbstractWidget(menu) {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
menu: MatteryMenu,
|
menu: MatteryMenu,
|
||||||
matter: IMatterHandler?
|
matter: IMatterStorage?
|
||||||
) : this(menu) {
|
) : this(menu) {
|
||||||
if (matter == null) return
|
if (matter == null) return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user