display i/o in jade for profiled storage (energy and matter)
closes #270
This commit is contained in:
parent
d4fb6d0b24
commit
28801252fa
@ -1,7 +1,10 @@
|
|||||||
package ru.dbotthepony.mc.otm.compat.jade.providers
|
package ru.dbotthepony.mc.otm.compat.jade.providers
|
||||||
|
|
||||||
|
import net.minecraft.ChatFormatting
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import ru.dbotthepony.mc.otm.capability.AbstractProfiledStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.compat.jade.JadeColors
|
import ru.dbotthepony.mc.otm.compat.jade.JadeColors
|
||||||
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
|
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
|
||||||
@ -30,6 +33,18 @@ object MatterStorageProvider : IBlockComponentProvider, IServerDataProvider<Bloc
|
|||||||
matterData.putDecimal("storedMatter", it.storedMatter)
|
matterData.putDecimal("storedMatter", it.storedMatter)
|
||||||
matterData.putDecimal("maxStoredMatter", it.maxStoredMatter)
|
matterData.putDecimal("maxStoredMatter", it.maxStoredMatter)
|
||||||
|
|
||||||
|
if (it is AbstractProfiledStorage<*>) {
|
||||||
|
val profiledData = CompoundTag()
|
||||||
|
|
||||||
|
// profiledData.putDecimal("lastTickReceive", it.lastTickReceive)
|
||||||
|
// profiledData.putDecimal("lastTickTransfer", it.lastTickTransfer)
|
||||||
|
|
||||||
|
profiledData.putDecimal("weightedReceive", it.weightedReceive)
|
||||||
|
profiledData.putDecimal("weightedTransfer", it.weightedTransfer)
|
||||||
|
|
||||||
|
matterData.put("profiledData", profiledData)
|
||||||
|
}
|
||||||
|
|
||||||
data.put(JadeTagKeys.MATTER_STORAGE_DATA, matterData)
|
data.put(JadeTagKeys.MATTER_STORAGE_DATA, matterData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,5 +75,33 @@ object MatterStorageProvider : IBlockComponentProvider, IServerDataProvider<Bloc
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (matterData.contains("profiledData")) {
|
||||||
|
val profiledData = matterData.getCompound("profiledData")
|
||||||
|
|
||||||
|
tooltip.add(
|
||||||
|
tooltip.elementHelper.text(
|
||||||
|
formatLevel(
|
||||||
|
profiledData.getDecimal("weightedReceive"),
|
||||||
|
profiledData.getDecimal("weightedTransfer")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatLevel(a: Decimal, b: Decimal): Component {
|
||||||
|
val diff = a - b
|
||||||
|
|
||||||
|
val fa = a.formatMatter().copy().withStyle(ChatFormatting.DARK_GREEN)
|
||||||
|
val fb = b.formatMatter().copy().withStyle(ChatFormatting.DARK_RED)
|
||||||
|
|
||||||
|
return if (diff.isZero) {
|
||||||
|
TranslatableComponent("otm.gui.diff", diff.formatMatter().copy().withStyle(ChatFormatting.GRAY), fa, fb)
|
||||||
|
} else if (diff.isPositive) {
|
||||||
|
TranslatableComponent("otm.gui.diff", diff.formatMatter().copy().withStyle(ChatFormatting.DARK_GREEN), fa, fb)
|
||||||
|
} else {
|
||||||
|
TranslatableComponent("otm.gui.diff", (-diff).formatMatter().copy().withStyle(ChatFormatting.DARK_RED), fa, fb)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package ru.dbotthepony.mc.otm.compat.jade.providers
|
package ru.dbotthepony.mc.otm.compat.jade.providers
|
||||||
|
|
||||||
|
import net.minecraft.ChatFormatting
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import ru.dbotthepony.mc.otm.capability.AbstractProfiledStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.compat.jade.JadeColors
|
import ru.dbotthepony.mc.otm.compat.jade.JadeColors
|
||||||
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
|
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
|
||||||
@ -12,6 +15,7 @@ import ru.dbotthepony.mc.otm.core.math.Decimal
|
|||||||
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.putDecimal
|
import ru.dbotthepony.mc.otm.core.math.putDecimal
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.formatMatter
|
||||||
import ru.dbotthepony.mc.otm.core.util.formatPower
|
import ru.dbotthepony.mc.otm.core.util.formatPower
|
||||||
import snownee.jade.api.*
|
import snownee.jade.api.*
|
||||||
import snownee.jade.api.config.IPluginConfig
|
import snownee.jade.api.config.IPluginConfig
|
||||||
@ -27,6 +31,18 @@ object MatteryEnergyProvider : IBlockComponentProvider, IServerDataProvider<Bloc
|
|||||||
energyData.putDecimal("batteryLevel", it.batteryLevel)
|
energyData.putDecimal("batteryLevel", it.batteryLevel)
|
||||||
energyData.putDecimal("maxBatteryLevel", it.maxBatteryLevel)
|
energyData.putDecimal("maxBatteryLevel", it.maxBatteryLevel)
|
||||||
|
|
||||||
|
if (it is AbstractProfiledStorage<*>) {
|
||||||
|
val profiledData = CompoundTag()
|
||||||
|
|
||||||
|
// profiledData.putDecimal("lastTickReceive", it.lastTickReceive)
|
||||||
|
// profiledData.putDecimal("lastTickTransfer", it.lastTickTransfer)
|
||||||
|
|
||||||
|
profiledData.putDecimal("weightedReceive", it.weightedReceive)
|
||||||
|
profiledData.putDecimal("weightedTransfer", it.weightedTransfer)
|
||||||
|
|
||||||
|
energyData.put("profiledData", profiledData)
|
||||||
|
}
|
||||||
|
|
||||||
data.put(JadeTagKeys.MATTERY_ENERGY_DATA, energyData)
|
data.put(JadeTagKeys.MATTERY_ENERGY_DATA, energyData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,5 +74,33 @@ object MatteryEnergyProvider : IBlockComponentProvider, IServerDataProvider<Bloc
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (energyData.contains("profiledData")) {
|
||||||
|
val profiledData = energyData.getCompound("profiledData")
|
||||||
|
|
||||||
|
tooltip.add(
|
||||||
|
tooltip.elementHelper.text(
|
||||||
|
formatLevel(
|
||||||
|
profiledData.getDecimal("weightedReceive"),
|
||||||
|
profiledData.getDecimal("weightedTransfer")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatLevel(a: Decimal, b: Decimal): Component {
|
||||||
|
val diff = a - b
|
||||||
|
|
||||||
|
val fa = a.formatPower().copy().withStyle(ChatFormatting.DARK_GREEN)
|
||||||
|
val fb = b.formatPower().copy().withStyle(ChatFormatting.DARK_RED)
|
||||||
|
|
||||||
|
return if (diff.isZero) {
|
||||||
|
TranslatableComponent("otm.gui.diff", diff.formatMatter().copy().withStyle(ChatFormatting.GRAY), fa, fb)
|
||||||
|
} else if (diff.isPositive) {
|
||||||
|
TranslatableComponent("otm.gui.diff", diff.formatMatter().copy().withStyle(ChatFormatting.DARK_GREEN), fa, fb)
|
||||||
|
} else {
|
||||||
|
TranslatableComponent("otm.gui.diff", (-diff).formatMatter().copy().withStyle(ChatFormatting.DARK_RED), fa, fb)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user