Display fill levels on items
This commit is contained in:
parent
0e10b47bb8
commit
8053ea69f9
@ -24,7 +24,6 @@ import net.minecraftforge.common.capabilities.Capability
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||
import ru.dbotthepony.mc.otm.container.forEachCapability
|
||||
import ru.dbotthepony.mc.otm.core.iterator
|
||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||
@ -44,21 +43,20 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
private val resolverPatterns = LazyOptional.of { this }
|
||||
private val resolverNode = LazyOptional.of { this }
|
||||
|
||||
@JvmField
|
||||
val patterns: MatteryContainer = object : MatteryContainer(this::setChanged, 8) {
|
||||
val patternContainer: MatteryContainer = object : MatteryContainer(this::setChanged, 8) {
|
||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||
val grid = matterNode.graph as MatterNetworkGraph?
|
||||
|
||||
if (grid != null && !ItemStack.isSameItemSameTags(new, old)) {
|
||||
if (!old.isEmpty) {
|
||||
old.getCapability(MatteryCapability.PATTERN).ifPresent { cap: IPatternStorage ->
|
||||
cap.storedPatterns.forEach { grid.onPatternRemoved(it) }
|
||||
cap.patterns.forEach { grid.onPatternRemoved(it) }
|
||||
}
|
||||
}
|
||||
|
||||
if (!new.isEmpty) {
|
||||
new.getCapability(MatteryCapability.PATTERN).ifPresent { cap: IPatternStorage ->
|
||||
cap.storedPatterns.forEach { grid.onPatternAdded(it) }
|
||||
cap.patterns.forEach { grid.onPatternAdded(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +79,7 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
for (i in 0..7) {
|
||||
state = state.setValue(
|
||||
PatternStorageBlock.PATTERN_STORAGE_DISKS_PROPS[i],
|
||||
patterns.getItem(i).getCapability(MatteryCapability.PATTERN).isPresent
|
||||
this.patternContainer.getItem(i).getCapability(MatteryCapability.PATTERN).isPresent
|
||||
)
|
||||
}
|
||||
|
||||
@ -91,18 +89,18 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
}
|
||||
|
||||
private val resolverItem =
|
||||
patterns.handler { slot: Int, stack: ItemStack -> stack.getCapability(MatteryCapability.PATTERN).isPresent }
|
||||
this.patternContainer.handler { slot: Int, stack: ItemStack -> stack.getCapability(MatteryCapability.PATTERN).isPresent }
|
||||
|
||||
override fun saveAdditional(nbt: CompoundTag) {
|
||||
super.saveAdditional(nbt)
|
||||
nbt["patterns"] = patterns.serializeNBT()
|
||||
nbt["patterns"] = this.patternContainer.serializeNBT()
|
||||
}
|
||||
|
||||
override fun load(nbt: CompoundTag) {
|
||||
super.load(nbt)
|
||||
|
||||
nbt.ifHas("patterns") {
|
||||
patterns.deserializeNBT(it)
|
||||
this.patternContainer.deserializeNBT(it)
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,30 +147,30 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
return PatternStorageMenu(containerID, inventory, this)
|
||||
}
|
||||
|
||||
override val storedPatterns: Stream<out IPatternState> get() {
|
||||
override val patterns: Stream<out IPatternState> get() {
|
||||
val streams = ArrayList<Stream<out IPatternState>>()
|
||||
|
||||
for (provider in patterns.iterator(MatteryCapability.PATTERN)) {
|
||||
streams.add(provider.second.storedPatterns)
|
||||
for (provider in this.patternContainer.iterator(MatteryCapability.PATTERN)) {
|
||||
streams.add(provider.second.patterns)
|
||||
}
|
||||
|
||||
return Streams.concat(*streams.toTypedArray())
|
||||
}
|
||||
|
||||
override val capacity: Int get() {
|
||||
override val patternCapacity: Int get() {
|
||||
var stored = 0L
|
||||
|
||||
for ((_, pattern) in patterns.iterator(MatteryCapability.PATTERN))
|
||||
stored += pattern.capacity.toLong()
|
||||
for ((_, pattern) in this.patternContainer.iterator(MatteryCapability.PATTERN))
|
||||
stored += pattern.patternCapacity.toLong()
|
||||
|
||||
return if (stored > Int.MAX_VALUE) Int.MAX_VALUE else stored.toInt()
|
||||
}
|
||||
|
||||
override val stored: Int get() {
|
||||
override val storedPatterns: Int get() {
|
||||
var stored = 0L
|
||||
|
||||
for ((_, pattern) in patterns.iterator(MatteryCapability.PATTERN))
|
||||
stored += pattern.stored.toLong()
|
||||
for ((_, pattern) in this.patternContainer.iterator(MatteryCapability.PATTERN))
|
||||
stored += pattern.storedPatterns.toLong()
|
||||
|
||||
return if (stored > Int.MAX_VALUE) Int.MAX_VALUE else stored.toInt()
|
||||
}
|
||||
@ -183,7 +181,7 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
}
|
||||
|
||||
override fun insertPattern(pattern: IPatternState, onlyUpdate: Boolean, simulate: Boolean): PatternInsertStatus {
|
||||
for (pair in patterns.iterator(MatteryCapability.PATTERN)) {
|
||||
for (pair in this.patternContainer.iterator(MatteryCapability.PATTERN)) {
|
||||
val status = pair.second.insertPattern(pattern, onlyUpdate, simulate)
|
||||
|
||||
if (!status.isFailed) {
|
||||
|
@ -1,8 +1,11 @@
|
||||
package ru.dbotthepony.mc.otm.capability
|
||||
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraftforge.energy.IEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.core.RGBAColor
|
||||
import java.math.BigInteger
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
// IEnergyStorage for direct compat with Forge Energy
|
||||
interface IMatteryEnergyStorage : IEnergyStorage {
|
||||
@ -241,3 +244,11 @@ fun IMatteryEnergyStorage.extractStepInnerBi(base: ImpreciseFraction, multiplier
|
||||
fun IMatteryEnergyStorage.extractStepOuterBi(base: ImpreciseFraction, multiplier: BigInteger, simulate: Boolean): BigInteger {
|
||||
return (extractEnergyOuter(base * multiplier, simulate) / base).whole
|
||||
}
|
||||
|
||||
fun IMatteryEnergyStorage.getBarWidth(): Int {
|
||||
return ((batteryLevel / maxBatteryLevel).toFloat().coerceAtLeast(0f).coerceAtMost(1f) * 13f).roundToInt()
|
||||
}
|
||||
|
||||
fun IMatteryEnergyStorage.getBarColor(): Int {
|
||||
return RGBAColor.LOW_POWER.linearInterpolation((batteryLevel / maxBatteryLevel).toFloat(), RGBAColor.FULL_POWER).toInt()
|
||||
}
|
||||
|
@ -1,132 +0,0 @@
|
||||
package ru.dbotthepony.mc.otm.capability.matter
|
||||
|
||||
import net.minecraft.world.item.Item
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import java.util.*
|
||||
import java.util.function.Predicate
|
||||
import java.util.stream.Collectors
|
||||
import java.util.stream.Stream
|
||||
|
||||
interface IMatterHandler {
|
||||
val storedMatter: ImpreciseFraction
|
||||
val maxStoredMatter: ImpreciseFraction
|
||||
|
||||
fun receiveMatterOuter(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
fun receiveMatterInner(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
fun extractMatterOuter(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
fun extractMatterInner(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
|
||||
val direction: MatterDirection
|
||||
val missingMatter: ImpreciseFraction
|
||||
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 }
|
||||
|
||||
interface IReplicationTaskProvider {
|
||||
/**
|
||||
* It must return new stream each time
|
||||
*/
|
||||
val replicationTasks: Stream<out IReplicationTask<*>>
|
||||
|
||||
/**
|
||||
* It must return new stream each time
|
||||
*/
|
||||
val allReplicationTasks: Stream<out IReplicationTask<*>>
|
||||
|
||||
/**
|
||||
* Allocates (marks as work-in-progress) a task
|
||||
* by incrementing it's [IReplicationTask.inProgress] by 1
|
||||
* and shrinking [IReplicationTask.required] by 1
|
||||
*
|
||||
* If [IReplicationTask.required] == 0, it should not be returned by this method
|
||||
* @param simulate whenever to change internal state
|
||||
* @return MatterTaskAllocation(task, pattern) that should be performed, or null if no work is available
|
||||
*/
|
||||
fun allocateTask(simulate: Boolean): ReplicationTaskAllocation?
|
||||
|
||||
/**
|
||||
* Notify about task completion. If this provider indeed contain this task, it should
|
||||
* shrink in_progress by 1
|
||||
* If in_progress == 0 and required == 0, it should discard the task
|
||||
* @param taskId task being completed. this method should ignore tasks that are not owned by it.
|
||||
* @return whenever task indeed belong to this provider and internal state was updated
|
||||
*/
|
||||
fun notifyTaskCompletion(taskId: UUID): Boolean
|
||||
|
||||
/**
|
||||
* @param id uuid of task
|
||||
* @return MatterTask that this capability holds with this id, or null
|
||||
*/
|
||||
fun getTask(id: UUID): IReplicationTask<*>? {
|
||||
return allReplicationTasks.filter { it.id == id }.findAny().orElse(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys all tasks this capability contains
|
||||
*/
|
||||
fun dropAllTasks()
|
||||
}
|
||||
|
||||
interface IPatternStorage {
|
||||
/**
|
||||
* It must return new stream each time
|
||||
*/
|
||||
val storedPatterns: Stream<out IPatternState>
|
||||
|
||||
fun findPatterns(item: Item): Collection<IPatternState> {
|
||||
return findPatterns { item == it.item }
|
||||
}
|
||||
|
||||
fun findPatterns(predicate: Predicate<IPatternState>): Collection<IPatternState> {
|
||||
return storedPatterns.filter(predicate).collect(Collectors.toList())
|
||||
}
|
||||
|
||||
fun findPattern(item: Item): IPatternState? {
|
||||
return storedPatterns.filter { it.item == item }.findAny().orElse(null)
|
||||
}
|
||||
|
||||
fun getPattern(id: UUID?): IPatternState? {
|
||||
return storedPatterns.filter { it.id == id }.findAny().orElse(null)
|
||||
}
|
||||
|
||||
fun hasPattern(item: Item): Boolean {
|
||||
return storedPatterns.filter { it.item == item }.findAny().isPresent
|
||||
}
|
||||
|
||||
fun hasPattern(state: IPatternState): Boolean {
|
||||
return hasPattern(state.id)
|
||||
}
|
||||
|
||||
fun hasPattern(id: UUID?): Boolean {
|
||||
return storedPatterns.filter { it.id == id }.findAny().isPresent
|
||||
}
|
||||
|
||||
val capacity: Int
|
||||
val stored: Int
|
||||
|
||||
/**
|
||||
* Prefer way to call it is to first call only_update = true
|
||||
* and if it fail, try only_update = false
|
||||
*
|
||||
* @param pattern pattern to be inserted or update value from
|
||||
* @param onlyUpdate do not insert new pattern if this pattern's UUID is not matched
|
||||
* @param simulate whenever to affect state
|
||||
* @return record of status of the operation (at status() FAIL, UPDATED, INSERTED) as well as new_state and old_state
|
||||
*/
|
||||
fun insertPattern(pattern: IPatternState, onlyUpdate: Boolean, simulate: Boolean): PatternInsertStatus
|
||||
|
||||
fun insertPattern(pattern: IPatternState, simulate: Boolean): PatternInsertStatus {
|
||||
return insertPattern(pattern, false, simulate)
|
||||
}
|
||||
|
||||
fun updatePattern(pattern: IPatternState, simulate: Boolean): PatternInsertStatus {
|
||||
return insertPattern(pattern, true, simulate)
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package ru.dbotthepony.mc.otm.capability.matter
|
||||
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.core.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.core.orNull
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
interface IMatterHandler {
|
||||
val storedMatter: ImpreciseFraction
|
||||
val maxStoredMatter: ImpreciseFraction
|
||||
|
||||
fun receiveMatterOuter(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
fun receiveMatterInner(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
fun extractMatterOuter(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
fun extractMatterInner(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction
|
||||
|
||||
val direction: MatterDirection
|
||||
val missingMatter: ImpreciseFraction
|
||||
get() = maxStoredMatter.minus(storedMatter).moreThanZero()
|
||||
|
||||
val allowsExtract: Boolean
|
||||
get() = direction != MatterDirection.RECEIVE
|
||||
|
||||
val allowsReceive: Boolean
|
||||
get() = direction != MatterDirection.EXTRACT
|
||||
}
|
||||
|
||||
fun IMatterHandler.getBarWidth(): Int {
|
||||
return ((storedMatter / maxStoredMatter).toFloat().coerceAtLeast(0f).coerceAtMost(1f) * 13f).roundToInt()
|
||||
}
|
||||
|
||||
fun IMatterHandler.getBarColor(): Int {
|
||||
return RGBAColor.LOW_MATTER.linearInterpolation((storedMatter / maxStoredMatter).toFloat(), RGBAColor.FULL_MATTER).toInt()
|
||||
}
|
||||
|
||||
val ICapabilityProvider.matter: IMatterHandler? get() = getCapability(MatteryCapability.MATTER).orNull()
|
@ -0,0 +1,80 @@
|
||||
package ru.dbotthepony.mc.otm.capability.matter
|
||||
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.core.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.core.orNull
|
||||
import java.util.*
|
||||
import java.util.function.Predicate
|
||||
import java.util.stream.Collectors
|
||||
import java.util.stream.Stream
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
interface IPatternStorage {
|
||||
/**
|
||||
* It must return new stream each time
|
||||
*/
|
||||
val patterns: Stream<out IPatternState>
|
||||
|
||||
fun findPatterns(item: Item): Collection<IPatternState> {
|
||||
return findPatterns { item == it.item }
|
||||
}
|
||||
|
||||
fun findPatterns(predicate: Predicate<IPatternState>): Collection<IPatternState> {
|
||||
return patterns.filter(predicate).collect(Collectors.toList())
|
||||
}
|
||||
|
||||
fun findPattern(item: Item): IPatternState? {
|
||||
return patterns.filter { it.item == item }.findAny().orElse(null)
|
||||
}
|
||||
|
||||
fun getPattern(id: UUID?): IPatternState? {
|
||||
return patterns.filter { it.id == id }.findAny().orElse(null)
|
||||
}
|
||||
|
||||
fun hasPattern(item: Item): Boolean {
|
||||
return patterns.filter { it.item == item }.findAny().isPresent
|
||||
}
|
||||
|
||||
fun hasPattern(state: IPatternState): Boolean {
|
||||
return hasPattern(state.id)
|
||||
}
|
||||
|
||||
fun hasPattern(id: UUID?): Boolean {
|
||||
return patterns.filter { it.id == id }.findAny().isPresent
|
||||
}
|
||||
|
||||
val patternCapacity: Int
|
||||
val storedPatterns: Int
|
||||
|
||||
/**
|
||||
* Prefer way to call it is to first call only_update = true
|
||||
* and if it fail, try only_update = false
|
||||
*
|
||||
* @param pattern pattern to be inserted or update value from
|
||||
* @param onlyUpdate do not insert new pattern if this pattern's UUID is not matched
|
||||
* @param simulate whenever to affect state
|
||||
* @return record of status of the operation (at status() FAIL, UPDATED, INSERTED) as well as new_state and old_state
|
||||
*/
|
||||
fun insertPattern(pattern: IPatternState, onlyUpdate: Boolean, simulate: Boolean): PatternInsertStatus
|
||||
|
||||
fun insertPattern(pattern: IPatternState, simulate: Boolean): PatternInsertStatus {
|
||||
return insertPattern(pattern, false, simulate)
|
||||
}
|
||||
|
||||
fun updatePattern(pattern: IPatternState, simulate: Boolean): PatternInsertStatus {
|
||||
return insertPattern(pattern, true, simulate)
|
||||
}
|
||||
}
|
||||
|
||||
fun IPatternStorage.getBarWidth(): Int {
|
||||
return ((storedPatterns.toFloat() / patternCapacity.toFloat()).coerceAtLeast(0f).coerceAtMost(1f) * 13f).roundToInt()
|
||||
}
|
||||
|
||||
fun IPatternStorage.getBarColor(): Int {
|
||||
return RGBAColor.LOW_PATTERNS.linearInterpolation((storedPatterns / patternCapacity).toFloat(), RGBAColor.FULL_PATTERNS).toInt()
|
||||
}
|
||||
|
||||
val ICapabilityProvider.patterns: IPatternStorage? get() = getCapability(MatteryCapability.PATTERN).orNull()
|
@ -0,0 +1,49 @@
|
||||
package ru.dbotthepony.mc.otm.capability.matter
|
||||
|
||||
import java.util.*
|
||||
import java.util.stream.Stream
|
||||
|
||||
interface IReplicationTaskProvider {
|
||||
/**
|
||||
* It must return new stream each time
|
||||
*/
|
||||
val replicationTasks: Stream<out IReplicationTask<*>>
|
||||
|
||||
/**
|
||||
* It must return new stream each time
|
||||
*/
|
||||
val allReplicationTasks: Stream<out IReplicationTask<*>>
|
||||
|
||||
/**
|
||||
* Allocates (marks as work-in-progress) a task
|
||||
* by incrementing it's [IReplicationTask.inProgress] by 1
|
||||
* and shrinking [IReplicationTask.required] by 1
|
||||
*
|
||||
* If [IReplicationTask.required] == 0, it should not be returned by this method
|
||||
* @param simulate whenever to change internal state
|
||||
* @return MatterTaskAllocation(task, pattern) that should be performed, or null if no work is available
|
||||
*/
|
||||
fun allocateTask(simulate: Boolean): ReplicationTaskAllocation?
|
||||
|
||||
/**
|
||||
* Notify about task completion. If this provider indeed contain this task, it should
|
||||
* shrink in_progress by 1
|
||||
* If in_progress == 0 and required == 0, it should discard the task
|
||||
* @param taskId task being completed. this method should ignore tasks that are not owned by it.
|
||||
* @return whenever task indeed belong to this provider and internal state was updated
|
||||
*/
|
||||
fun notifyTaskCompletion(taskId: UUID): Boolean
|
||||
|
||||
/**
|
||||
* @param id uuid of task
|
||||
* @return MatterTask that this capability holds with this id, or null
|
||||
*/
|
||||
fun getTask(id: UUID): IReplicationTask<*>? {
|
||||
return allReplicationTasks.filter { it.id == id }.findAny().orElse(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys all tasks this capability contains
|
||||
*/
|
||||
fun dropAllTasks()
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package ru.dbotthepony.mc.otm.capability.matter
|
||||
|
||||
enum class MatterDirection { RECEIVE, EXTRACT, BIDIRECTIONAL }
|
@ -305,7 +305,7 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
|
||||
|
||||
val bD = b.toDouble()
|
||||
|
||||
if (bD.isInfinite() || bD == 0.0 || bD == -0.0) {
|
||||
if (bD.isInfinite() || bD == 0.0) {
|
||||
return ImpreciseFraction(div[0].toBigInteger())
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,13 @@ data class RGBAColor(val red: Float, val green: Float, val blue: Float, val alph
|
||||
val LIGHT_PURPLE = rgb(ChatFormatting.LIGHT_PURPLE.color!!)
|
||||
val YELLOW = rgb(ChatFormatting.YELLOW.color!!)
|
||||
|
||||
val LOW_POWER = RGBAColor(173, 41, 41)
|
||||
val FULL_POWER = RGBAColor(255, 242, 40)
|
||||
val LOW_MATTER = RGBAColor(0, 24, 148)
|
||||
val FULL_MATTER = RGBAColor(72, 90, 255)
|
||||
val LOW_PATTERNS = RGBAColor(44, 104, 57)
|
||||
val FULL_PATTERNS = RGBAColor(65, 255, 87)
|
||||
|
||||
fun inv(color: Int): RGBAColor {
|
||||
val r = (color and -0x1000000 ushr 24) / 255f
|
||||
val g = (color and 0xFF0000 ushr 16) / 255f
|
||||
|
@ -25,7 +25,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
val patterns = node.value.getPatternHandler()
|
||||
|
||||
if (patterns != null) {
|
||||
for (pattern in patterns.storedPatterns) {
|
||||
for (pattern in patterns.patterns) {
|
||||
onPatternRemoved(pattern)
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
val patterns = node.value.getPatternHandler()
|
||||
|
||||
if (patterns != null) {
|
||||
for (pattern in patterns.storedPatterns) {
|
||||
for (pattern in patterns.patterns) {
|
||||
onPatternAdded(pattern)
|
||||
}
|
||||
}
|
||||
@ -205,7 +205,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
}
|
||||
|
||||
val patterns: Stream<out IPatternState> get() {
|
||||
return Streams.concat(*nodes.mapNotNull { it.value.getPatternHandler()?.storedPatterns }.toTypedArray())
|
||||
return Streams.concat(*nodes.mapNotNull { it.value.getPatternHandler()?.patterns }.toTypedArray())
|
||||
}
|
||||
|
||||
val patternCount: Long get() {
|
||||
@ -215,7 +215,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
val storage = node.value.getPatternHandler()
|
||||
|
||||
if (storage != null) {
|
||||
value += storage.stored
|
||||
value += storage.storedPatterns
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
val storage = node.value.getPatternHandler()
|
||||
|
||||
if (storage != null) {
|
||||
value += storage.capacity
|
||||
value += storage.patternCapacity
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
val storage = node.value.getPatternHandler()
|
||||
|
||||
if (storage != null) {
|
||||
val find = storage.storedPatterns.filter(predicate).findAny()
|
||||
val find = storage.patterns.filter(predicate).findAny()
|
||||
|
||||
if (find.isPresent) {
|
||||
return find.get()
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.item
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.Rarity
|
||||
@ -10,10 +11,9 @@ import net.minecraft.world.item.TooltipFlag
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.capability.EnergyCapacitorItem
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.*
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.formatPower
|
||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||
|
||||
@ -60,6 +60,27 @@ class BatteryItem : Item {
|
||||
extract = ImpreciseFraction.LONG_MAX_VALUE
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
if (isCreative)
|
||||
return false
|
||||
|
||||
return p_150899_.matteryEnergy != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 13
|
||||
|
||||
return p_150900_.matteryEnergy?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 0
|
||||
|
||||
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
override fun appendHoverText(
|
||||
stack: ItemStack,
|
||||
p_41422_: Level?,
|
||||
|
@ -76,6 +76,18 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
|
||||
return true
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
return p_150899_.matteryEnergy != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
return p_150900_.matteryEnergy?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
override fun appendHoverText(
|
||||
itemStack: ItemStack,
|
||||
p_41422_: Level?,
|
||||
|
@ -5,6 +5,7 @@ import net.minecraft.MethodsReturnNonnullByDefault
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.Rarity
|
||||
@ -16,8 +17,10 @@ import net.minecraftforge.common.util.LazyOptional
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterDirection
|
||||
import ru.dbotthepony.mc.otm.capability.getBarColor
|
||||
import ru.dbotthepony.mc.otm.capability.getBarWidth
|
||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.core.formatMatter
|
||||
import javax.annotation.ParametersAreNonnullByDefault
|
||||
@ -103,6 +106,27 @@ class MatterCapacitorItem : Item {
|
||||
storage = ImpreciseFraction.LONG_MAX_VALUE
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
if (isCreative)
|
||||
return false
|
||||
|
||||
return p_150899_.matter != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 13
|
||||
|
||||
return p_150900_.matter?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 0
|
||||
|
||||
return p_150901_.matter?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
override fun appendHoverText(
|
||||
stack: ItemStack,
|
||||
p_41422_: Level?,
|
||||
|
@ -11,6 +11,7 @@ import net.minecraftforge.common.util.LazyOptional
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
@ -46,11 +47,11 @@ class PatternStorageItem : Item {
|
||||
) {
|
||||
p_41421_.getCapability(MatteryCapability.PATTERN).ifPresent {
|
||||
if (isCreative)
|
||||
list.add(TranslatableComponent("otm.item.pattern.infinite.stored", it.stored).withStyle(ChatFormatting.GRAY))
|
||||
list.add(TranslatableComponent("otm.item.pattern.infinite.stored", it.storedPatterns).withStyle(ChatFormatting.GRAY))
|
||||
else
|
||||
list.add(TranslatableComponent("otm.item.pattern.stored", it.stored, it.capacity).withStyle(ChatFormatting.GRAY))
|
||||
list.add(TranslatableComponent("otm.item.pattern.stored", it.storedPatterns, it.patternCapacity).withStyle(ChatFormatting.GRAY))
|
||||
|
||||
for (state in it.storedPatterns) {
|
||||
for (state in it.patterns) {
|
||||
list.add(
|
||||
TranslatableComponent(
|
||||
"otm.item.pattern.line",
|
||||
@ -64,14 +65,35 @@ class PatternStorageItem : Item {
|
||||
super.appendHoverText(p_41421_, p_41422_, list, p_41424_)
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
if (isCreative)
|
||||
return false
|
||||
|
||||
return p_150899_.patterns != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 13
|
||||
|
||||
return p_150900_.patterns?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 0
|
||||
|
||||
return p_150901_.patterns?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
private inner class ItemPatternStorageCapability(val stack: ItemStack) : IPatternStorage, ICapabilityProvider {
|
||||
private val resolver = LazyOptional.of<IPatternStorage> { this }
|
||||
|
||||
override val capacity: Int get() {
|
||||
override val patternCapacity: Int get() {
|
||||
return this@PatternStorageItem.capacity
|
||||
}
|
||||
|
||||
override val stored: Int get() {
|
||||
override val storedPatterns: Int get() {
|
||||
stack.tag?.ifHas("otm_patterns", ListTag::class.java) {
|
||||
return it.size
|
||||
}
|
||||
@ -83,7 +105,7 @@ class PatternStorageItem : Item {
|
||||
return if (cap == MatteryCapability.PATTERN) resolver.cast() else LazyOptional.empty()
|
||||
}
|
||||
|
||||
override val storedPatterns: Stream<out IPatternState> get() {
|
||||
override val patterns: Stream<out IPatternState> get() {
|
||||
stack.tag?.ifHas("otm_patterns", ListTag::class.java) {
|
||||
return it.stream().map { PatternState.deserializeNBT(it) }.filter { it != null } as Stream<out IPatternState>
|
||||
}
|
||||
@ -104,7 +126,7 @@ class PatternStorageItem : Item {
|
||||
return PatternInsertFailure
|
||||
|
||||
if (simulate) {
|
||||
if (capacity > 0)
|
||||
if (patternCapacity > 0)
|
||||
return PatternInsertInserted(pattern.asImmutable())
|
||||
else
|
||||
return PatternInsertFailure
|
||||
@ -132,7 +154,7 @@ class PatternStorageItem : Item {
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyUpdate || capacity <= list.size - invalidCounter)
|
||||
if (onlyUpdate || patternCapacity <= list.size - invalidCounter)
|
||||
return PatternInsertFailure
|
||||
|
||||
if (invalidCounter > 0) {
|
||||
|
@ -9,6 +9,7 @@ import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.network.FriendlyByteBuf
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.*
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
@ -21,8 +22,7 @@ import net.minecraftforge.network.NetworkEvent
|
||||
import net.minecraftforge.registries.ForgeRegistries
|
||||
import net.minecraftforge.registries.ForgeRegistry
|
||||
import ru.dbotthepony.mc.otm.*
|
||||
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.*
|
||||
import ru.dbotthepony.mc.otm.core.itemStackIterator
|
||||
import ru.dbotthepony.mc.otm.core.nonEmpty
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
@ -297,6 +297,27 @@ class QuantumBatteryItem : Item {
|
||||
this.saveDataID = "otm_$saveDataID".intern()
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
if (isCreative)
|
||||
return false
|
||||
|
||||
return p_150899_.matteryEnergy != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 13
|
||||
|
||||
return p_150900_.matteryEnergy?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
if (isCreative)
|
||||
return 0
|
||||
|
||||
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||
return Power(stack)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.item
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.Rarity
|
||||
@ -10,8 +11,7 @@ import net.minecraft.world.item.TooltipFlag
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.capability.EnergyProducerItem
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.*
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
|
||||
open class SingleUseBatteryItem(
|
||||
@ -56,6 +56,18 @@ open class SingleUseBatteryItem(
|
||||
return Power(stack)
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
return p_150899_.matteryEnergy != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
return p_150900_.matteryEnergy?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SINGLE_USE = TranslatableComponent("otm.battery.single_use").withStyle(ChatFormatting.GRAY)
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import ru.dbotthepony.mc.otm.capability.extractEnergyInnerExact
|
||||
import ru.dbotthepony.mc.otm.capability.getBarColor
|
||||
import ru.dbotthepony.mc.otm.capability.getBarWidth
|
||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
import ru.dbotthepony.mc.otm.core.Vector
|
||||
import ru.dbotthepony.mc.otm.entity.PlasmaProjectile
|
||||
|
@ -211,6 +211,18 @@ abstract class PlasmaWeaponItem<D : PlasmaWeaponDataTable>(tables: KClass<D>, pr
|
||||
return true
|
||||
}
|
||||
|
||||
override fun isBarVisible(p_150899_: ItemStack): Boolean {
|
||||
return p_150899_.matteryEnergy != null
|
||||
}
|
||||
|
||||
override fun getBarWidth(p_150900_: ItemStack): Int {
|
||||
return p_150900_.matteryEnergy?.getBarWidth() ?: super.getBarWidth(p_150900_)
|
||||
}
|
||||
|
||||
override fun getBarColor(p_150901_: ItemStack): Int {
|
||||
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||
}
|
||||
|
||||
protected open fun coolWeaponDown(itemStack: ItemStack, player: Player, dt: D) {
|
||||
if (!canCooldown(itemStack, player, dt))
|
||||
return
|
||||
|
@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.core.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.PatternStorageBlockEntity
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
@ -34,7 +33,7 @@ class PatternStorageMenu @JvmOverloads constructor(
|
||||
})
|
||||
}
|
||||
|
||||
val patterns = tile?.patterns ?: SimpleContainer(2 * 4)
|
||||
val patterns = tile?.patternContainer ?: SimpleContainer(2 * 4)
|
||||
|
||||
storageSlots = ImmutableList(2 * 4) {
|
||||
PatternSlot(patterns, it)
|
||||
|
@ -42,8 +42,8 @@ class LevelGaugeWidget(menu: MatteryMenu) : AbstractWidget(menu) {
|
||||
) : this(menu) {
|
||||
if (patterns == null) return
|
||||
|
||||
this.levelProvider = {ImpreciseFraction(patterns.stored)}
|
||||
this.maxLevelProvider = {ImpreciseFraction(patterns.capacity)}
|
||||
this.levelProvider = {ImpreciseFraction(patterns.storedPatterns)}
|
||||
this.maxLevelProvider = {ImpreciseFraction(patterns.patternCapacity)}
|
||||
}
|
||||
|
||||
constructor(
|
||||
|
Loading…
Reference in New Issue
Block a user