diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java b/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java index dc0966b1f..958ece5b3 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java @@ -5,7 +5,7 @@ import net.minecraftforge.common.capabilities.*; import org.jetbrains.annotations.NotNull; import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive; 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.IPatternStorage; import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode; @@ -26,7 +26,7 @@ public class MatteryCapability { @Nonnull @NotNull - public static final Capability MATTER = CapabilityManager.get(new CapabilityToken<>() {}); + public static final Capability MATTER = CapabilityManager.get(new CapabilityToken<>() {}); @Nonnull @NotNull @@ -63,7 +63,7 @@ public class MatteryCapability { public static void register(RegisterCapabilitiesEvent event) { event.register(IMatteryEnergyStorage.class); event.register(MatteryPlayerCapability.class); - event.register(IMatterHandler.class); + event.register(IMatterStorage.class); event.register(IMatterGraphNode.class); event.register(IPatternStorage.class); event.register(IReplicationTaskProvider.class); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt index d2cb29fd7..430890983 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt @@ -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.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage -import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler -import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl +import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage +import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainerHooks 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() { 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 lastWorkStack: ItemStack? = null - override fun getMatterHandler(): IMatterHandler { + override fun getMatterHandler(): IMatterStorage { return matter } @@ -230,7 +230,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } var work_stack: ItemStack? = null - var capability: IMatterHandler? = null + var capability: IMatterStorage? = null val align = if (isBottling) 0 else 3 var work_slot = -1 val unexpectedDirection = if (isBottling) FlowDirection.OUTPUT else FlowDirection.INPUT diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt index 9d2994ce9..0027a851f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt @@ -21,7 +21,7 @@ import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection 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.core.Decimal 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.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() private set @@ -211,7 +211,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) MatterNetworkGraph.discoverFull(this, matterNode) } - override fun getMatterHandler(): IMatterHandler { + override fun getMatterHandler(): IMatterStorage { return this } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt index d622b51bc..c0cd54136 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt @@ -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.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage -import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler -import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl +import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage +import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainerHooks import ru.dbotthepony.mc.otm.core.* @@ -128,7 +128,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) private var valid = true override val matterNode = Graph6Node(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 resolverNode = LazyOptional.of { this } @@ -242,7 +242,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) MatterNetworkGraph.discoverFull(this, matterNode) } - override fun getMatterHandler(): IMatterHandler { + override fun getMatterHandler(): IMatterStorage { return matter } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index a46221ec6..6d0f5bb13 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt @@ -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.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage -import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler -import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl +import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage +import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainerHooks 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, FlowDirection.OUTPUT, ::CAPACITY @@ -88,7 +88,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) private var valid = true override val energy = WorkerEnergyStorage(this::powerLevelUpdated, ENERGY_CONFIG) - override fun getMatterHandler(): IMatterHandler { + override fun getMatterHandler(): IMatterStorage { return matter } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index ec26eec2c..bd64d1820 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -103,7 +103,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override val matterNode = Graph6Node(this) private val resolverNode = LazyOptional.of { this } - val matter = MatterHandlerImpl( + val matter = MatterStorageImpl( this::matterLevelUpdated, FlowDirection.INPUT, ::MATTER_CAPACITY diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/IMatterHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/IMatterStorage.kt similarity index 89% rename from src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/IMatterHandler.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/IMatterStorage.kt index 6dd5334b5..ff4e0c345 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/IMatterHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/IMatterStorage.kt @@ -8,7 +8,10 @@ import ru.dbotthepony.mc.otm.core.RGBAColor import ru.dbotthepony.mc.otm.core.orNull 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 */ @@ -81,17 +84,17 @@ interface IMatterHandler { val matterDirection: FlowDirection } -inline val IMatterHandler.canExtractMatter: Boolean +inline val IMatterStorage.canExtractMatter: Boolean get() = matterDirection.output -inline val IMatterHandler.canReceiveMatter: Boolean +inline val IMatterStorage.canReceiveMatter: Boolean get() = matterDirection.input -fun IMatterHandler.getBarWidth(): Int { +fun IMatterStorage.getBarWidth(): Int { 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() } -val ICapabilityProvider.matter: IMatterHandler? get() = getCapability(MatteryCapability.MATTER).orNull() +val ICapabilityProvider.matter: IMatterStorage? get() = getCapability(MatteryCapability.MATTER).orNull() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterHandlerImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt similarity index 94% rename from src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterHandlerImpl.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt index f3baa9b2f..7bb3dcc36 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterHandlerImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt @@ -9,13 +9,13 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.core.Decimal import ru.dbotthepony.mc.otm.core.set -open class MatterHandlerImpl @JvmOverloads constructor( +open class MatterStorageImpl @JvmOverloads constructor( protected val listener: Runnable?, override val matterDirection: FlowDirection, protected val maxStoredMatterSupplier: () -> Decimal, protected val maxReceiveSupplier: () -> Decimal? = { null }, protected val maxExtractSupplier: () -> Decimal? = maxReceiveSupplier -) : IMatterHandler, INBTSerializable { +) : IMatterStorage, INBTSerializable { constructor( listener: Runnable?, direction: FlowDirection, @@ -44,7 +44,7 @@ open class MatterHandlerImpl @JvmOverloads constructor( override var storedMatter = Decimal.ZERO - private var handler = LazyOptional.of { this } + private var handler = LazyOptional.of { this } fun invalidate() { handler.invalidate() @@ -54,7 +54,7 @@ open class MatterHandlerImpl @JvmOverloads constructor( handler = LazyOptional.of { this } } - fun get(): LazyOptional { + fun get(): LazyOptional { return handler } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/IMatterGraphNode.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/IMatterGraphNode.kt index c1c995cfc..c64294c2c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/IMatterGraphNode.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/IMatterGraphNode.kt @@ -15,7 +15,7 @@ interface IMatterGraphListener { } interface IMatterGraphNode : IMatterGraphListener { - fun getMatterHandler(): IMatterHandler? = null + fun getMatterHandler(): IMatterStorage? = null fun getPatternHandler(): IPatternStorage? = null fun getTaskHandler(): IReplicationTaskProvider? = null diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/MatterCapacitorItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/MatterCapacitorItem.kt index a90a620df..4475dec6f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/MatterCapacitorItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/MatterCapacitorItem.kt @@ -26,8 +26,8 @@ import javax.annotation.ParametersAreNonnullByDefault @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault class MatterCapacitorItem : Item { - private inner class Matter(private val stack: ItemStack) : ICapabilityProvider, IMatterHandler { - private val resolver = LazyOptional.of { this } + private inner class Matter(private val stack: ItemStack) : ICapabilityProvider, IMatterStorage { + private val resolver = LazyOptional.of { this } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { return if (cap === MatteryCapability.MATTER) resolver.cast() else LazyOptional.empty() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/LevelGaugeWidget.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/LevelGaugeWidget.kt index e2bbb79e3..7c8b51a89 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/LevelGaugeWidget.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/LevelGaugeWidget.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.mc.otm.menu.widget 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.core.Decimal import ru.dbotthepony.mc.otm.menu.MatteryMenu @@ -28,7 +28,7 @@ class LevelGaugeWidget(menu: MatteryMenu) : AbstractWidget(menu) { constructor( menu: MatteryMenu, - matter: IMatterHandler? + matter: IMatterStorage? ) : this(menu) { if (matter == null) return