Formatting without SI prefix while holding shift
This commit is contained in:
parent
2d519356fa
commit
e28867e913
@ -4,6 +4,7 @@ import net.minecraft.ChatFormatting
|
|||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraftforge.energy.IEnergyStorage
|
import net.minecraftforge.energy.IEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.core.util.formatPower
|
import ru.dbotthepony.mc.otm.core.util.formatPower
|
||||||
@ -17,8 +18,8 @@ internal fun batteryLevel(it: IEnergyStorage, tooltips: MutableList<Component>)
|
|||||||
tooltips.add(
|
tooltips.add(
|
||||||
TranslatableComponent(
|
TranslatableComponent(
|
||||||
"otm.item.power.storage",
|
"otm.item.power.storage",
|
||||||
it.energyStored.formatPower(),
|
it.energyStored.formatPower(formatAsReadable = ShiftPressedCond),
|
||||||
it.maxEnergyStored.formatPower()
|
it.maxEnergyStored.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,8 +27,8 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
|
|||||||
tooltips.add(
|
tooltips.add(
|
||||||
TranslatableComponent(
|
TranslatableComponent(
|
||||||
"otm.item.power.storage",
|
"otm.item.power.storage",
|
||||||
it.batteryLevel.formatPower(),
|
it.batteryLevel.formatPower(formatAsReadable = ShiftPressedCond),
|
||||||
it.maxBatteryLevel.formatPower()
|
it.maxBatteryLevel.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
|
|
||||||
if (it is IEnergyStorageImpl) {
|
if (it is IEnergyStorageImpl) {
|
||||||
@ -35,7 +36,7 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
|
|||||||
FlowDirection.INPUT -> {
|
FlowDirection.INPUT -> {
|
||||||
if (it.maxInput != null) {
|
if (it.maxInput != null) {
|
||||||
tooltips.add(
|
tooltips.add(
|
||||||
TranslatableComponent("otm.item.power.throughput_mono", it.maxInput!!.formatPower()).withStyle(
|
TranslatableComponent("otm.item.power.throughput_mono", it.maxInput!!.formatPower(formatAsReadable = ShiftPressedCond)).withStyle(
|
||||||
ChatFormatting.GRAY
|
ChatFormatting.GRAY
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
@ -50,7 +51,7 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
|
|||||||
FlowDirection.OUTPUT -> {
|
FlowDirection.OUTPUT -> {
|
||||||
if (it.maxOutput != null) {
|
if (it.maxOutput != null) {
|
||||||
tooltips.add(
|
tooltips.add(
|
||||||
TranslatableComponent("otm.item.power.throughput_mono", it.maxOutput!!.formatPower()).withStyle(
|
TranslatableComponent("otm.item.power.throughput_mono", it.maxOutput!!.formatPower(formatAsReadable = ShiftPressedCond)).withStyle(
|
||||||
ChatFormatting.GRAY
|
ChatFormatting.GRAY
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
@ -70,14 +71,14 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
|
|||||||
tooltips.add(
|
tooltips.add(
|
||||||
TranslatableComponent(
|
TranslatableComponent(
|
||||||
"otm.item.power.throughput",
|
"otm.item.power.throughput",
|
||||||
maxInput.formatPower(),
|
maxInput.formatPower(formatAsReadable = ShiftPressedCond),
|
||||||
maxOutput.formatPower()
|
maxOutput.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
} else if (maxInput != null) {
|
} else if (maxInput != null) {
|
||||||
tooltips.add(
|
tooltips.add(
|
||||||
TranslatableComponent(
|
TranslatableComponent(
|
||||||
"otm.item.power.throughput",
|
"otm.item.power.throughput",
|
||||||
maxInput.formatPower(),
|
maxInput.formatPower(formatAsReadable = ShiftPressedCond),
|
||||||
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY)
|
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY)
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
} else if (maxOutput != null) {
|
} else if (maxOutput != null) {
|
||||||
@ -85,7 +86,7 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
|
|||||||
TranslatableComponent(
|
TranslatableComponent(
|
||||||
"otm.item.power.throughput",
|
"otm.item.power.throughput",
|
||||||
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
|
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
|
||||||
maxOutput.formatPower(),
|
maxOutput.formatPower(formatAsReadable = ShiftPressedCond),
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
} else {
|
} else {
|
||||||
tooltips.add(
|
tooltips.add(
|
||||||
|
@ -8,9 +8,11 @@ import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
|||||||
import net.minecraft.sounds.SoundEvents
|
import net.minecraft.sounds.SoundEvents
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
import org.lwjgl.glfw.GLFW.GLFW_CURSOR
|
import org.lwjgl.glfw.GLFW.GLFW_CURSOR
|
||||||
|
import ru.dbotthepony.mc.otm.isClient
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.nio.ByteOrder
|
import java.nio.ByteOrder
|
||||||
import java.nio.DoubleBuffer
|
import java.nio.DoubleBuffer
|
||||||
|
import java.util.function.BooleanSupplier
|
||||||
|
|
||||||
inline val minecraft: Minecraft get() = Minecraft.getInstance()
|
inline val minecraft: Minecraft get() = Minecraft.getInstance()
|
||||||
inline val font: Font get() = minecraft.font
|
inline val font: Font get() = minecraft.font
|
||||||
@ -20,6 +22,25 @@ fun Window.isKeyDown(key: Int) = InputConstants.isKeyDown(window, key)
|
|||||||
val Window.isShiftDown get() = isKeyDown(InputConstants.KEY_LSHIFT) || isKeyDown(InputConstants.KEY_RSHIFT)
|
val Window.isShiftDown get() = isKeyDown(InputConstants.KEY_LSHIFT) || isKeyDown(InputConstants.KEY_RSHIFT)
|
||||||
val Window.isCtrlDown get() = isKeyDown(InputConstants.KEY_RCONTROL) || isKeyDown(InputConstants.KEY_LCONTROL)
|
val Window.isCtrlDown get() = isKeyDown(InputConstants.KEY_RCONTROL) || isKeyDown(InputConstants.KEY_LCONTROL)
|
||||||
|
|
||||||
|
object ShiftPressedCond : BooleanSupplier {
|
||||||
|
override fun getAsBoolean(): Boolean {
|
||||||
|
if (isClient) {
|
||||||
|
return impl()
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun impl(): Boolean {
|
||||||
|
return minecraft.window.isShiftDown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object ShiftDepressedCond : BooleanSupplier {
|
||||||
|
override fun getAsBoolean(): Boolean {
|
||||||
|
return !ShiftPressedCond.asBoolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun playGuiClickSound() {
|
fun playGuiClickSound() {
|
||||||
minecraft.soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0f))
|
minecraft.soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0f))
|
||||||
|
@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.render.*
|
import ru.dbotthepony.mc.otm.client.render.*
|
||||||
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
||||||
@ -180,7 +181,7 @@ class BlackHoleRenderer(private val context: BlockEntityRendererProvider.Context
|
|||||||
poseStack.scale(scale, scale, scale)
|
poseStack.scale(scale, scale, scale)
|
||||||
|
|
||||||
val font = Minecraft.getInstance().font
|
val font = Minecraft.getInstance().font
|
||||||
val text1 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", tile.mass.formatMatter())
|
val text1 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", tile.mass.formatMatter(formatAsReadable = ShiftPressedCond))
|
||||||
val text2 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(tile.gravitationStrength))
|
val text2 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(tile.gravitationStrength))
|
||||||
|
|
||||||
val sorse = DynamicBufferSource.WORLD
|
val sorse = DynamicBufferSource.WORLD
|
||||||
|
@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.block.entity.WorkerState
|
import ru.dbotthepony.mc.otm.block.entity.WorkerState
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.render.*
|
import ru.dbotthepony.mc.otm.client.render.*
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
@ -156,11 +157,11 @@ class GravitationStabilizerRenderer(private val context: BlockEntityRendererProv
|
|||||||
|
|
||||||
val sorse = DynamicBufferSource.WORLD
|
val sorse = DynamicBufferSource.WORLD
|
||||||
val font = minecraft.font
|
val font = minecraft.font
|
||||||
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", bhTile.mass.formatMatter()), TextAlign.TOP_CENTER, 1f, -font.lineHeight.toFloat() / 2f + 1f, 0)
|
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", bhTile.mass.formatMatter(formatAsReadable = ShiftPressedCond)), TextAlign.TOP_CENTER, 1f, -font.lineHeight.toFloat() / 2f + 1f, 0)
|
||||||
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(bhTile.gravitationStrength)), TextAlign.TOP_CENTER, 1f, font.lineHeight.toFloat() / 2f + 1f, 0)
|
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(bhTile.gravitationStrength)), TextAlign.TOP_CENTER, 1f, font.lineHeight.toFloat() / 2f + 1f, 0)
|
||||||
|
|
||||||
poseStack.translate(0.2f, 0f, -0.5f)
|
poseStack.translate(0.2f, 0f, -0.5f)
|
||||||
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", bhTile.mass.formatMatter()), TextAlign.TOP_CENTER, 0f, -font.lineHeight.toFloat() / 2f, 0xFFFFFF)
|
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", bhTile.mass.formatMatter(formatAsReadable = ShiftPressedCond)), TextAlign.TOP_CENTER, 0f, -font.lineHeight.toFloat() / 2f, 0xFFFFFF)
|
||||||
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(bhTile.gravitationStrength)), TextAlign.TOP_CENTER, 0f, font.lineHeight.toFloat() / 2f, 0xFFFFFF)
|
font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(bhTile.gravitationStrength)), TextAlign.TOP_CENTER, 0f, font.lineHeight.toFloat() / 2f, 0xFFFFFF)
|
||||||
|
|
||||||
poseStack.popPose()
|
poseStack.popPose()
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.client.screen.tech
|
|||||||
|
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
@ -12,7 +13,7 @@ import ru.dbotthepony.mc.otm.core.util.formatPower
|
|||||||
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
|
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
|
||||||
|
|
||||||
class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title: Component) : MatteryScreen<EnergyCounterMenu>(menu, inventory, title) {
|
class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title: Component) : MatteryScreen<EnergyCounterMenu>(menu, inventory, title) {
|
||||||
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
|
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
||||||
val frame = super.makeMainFrame()!!
|
val frame = super.makeMainFrame()!!
|
||||||
|
|
||||||
var label: Label<EnergyCounterScreen> = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
|
var label: Label<EnergyCounterScreen> = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
|
||||||
@ -20,7 +21,7 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
|||||||
super.tick()
|
super.tick()
|
||||||
text = TranslatableComponent(
|
text = TranslatableComponent(
|
||||||
"otm.item.power.passed",
|
"otm.item.power.passed",
|
||||||
menu.passed.formatPower()
|
menu.passed.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +34,7 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
|||||||
super.tick()
|
super.tick()
|
||||||
text = TranslatableComponent(
|
text = TranslatableComponent(
|
||||||
"otm.item.power.average",
|
"otm.item.power.average",
|
||||||
menu.average.formatPower()
|
menu.average.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +47,7 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
|||||||
super.tick()
|
super.tick()
|
||||||
text = TranslatableComponent(
|
text = TranslatableComponent(
|
||||||
"otm.item.power.last_20_ticks",
|
"otm.item.power.last_20_ticks",
|
||||||
menu.last20Ticks.formatPower()
|
menu.last20Ticks.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
|||||||
super.tick()
|
super.tick()
|
||||||
text = TranslatableComponent(
|
text = TranslatableComponent(
|
||||||
"otm.item.power.last_tick",
|
"otm.item.power.last_tick",
|
||||||
menu.lastTick.formatPower()
|
menu.lastTick.formatPower(formatAsReadable = ShiftPressedCond)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import net.minecraft.client.renderer.GameRenderer
|
import net.minecraft.client.renderer.GameRenderer
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||||
import ru.dbotthepony.mc.otm.client.render.tesselator
|
import ru.dbotthepony.mc.otm.client.render.tesselator
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
@ -44,7 +45,7 @@ open class MatterGaugePanel<S : Screen> @JvmOverloads constructor(
|
|||||||
"otm.gui.matter.percentage_level",
|
"otm.gui.matter.percentage_level",
|
||||||
String.format("%.2f", widget.percentage() * 100.0)
|
String.format("%.2f", widget.percentage() * 100.0)
|
||||||
),
|
),
|
||||||
formatMatterLevel(widget.level(), widget.maxLevel())
|
formatMatterLevel(widget.level(), widget.maxLevel(), formatAsReadable = ShiftPressedCond)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client.screen.widget
|
|||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.render.*
|
import ru.dbotthepony.mc.otm.client.render.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
@ -25,7 +26,7 @@ open class PowerGaugePanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
protected open fun makeTooltip(): MutableList<Component> {
|
protected open fun makeTooltip(): MutableList<Component> {
|
||||||
return mutableListOf(
|
return mutableListOf(
|
||||||
TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", widget.percentage() * 100.0)),
|
TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", widget.percentage() * 100.0)),
|
||||||
formatPowerLevel(widget.level(), widget.maxLevel())
|
formatPowerLevel(widget.level(), widget.maxLevel(), formatAsReadable = ShiftPressedCond)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.core.util
|
package ru.dbotthepony.mc.otm.core.util
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.chars.CharArrayList
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import ru.dbotthepony.mc.otm.core.TextComponent
|
import ru.dbotthepony.mc.otm.core.TextComponent
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
@ -8,7 +9,9 @@ import ru.dbotthepony.mc.otm.core.math.isNegative
|
|||||||
import ru.dbotthepony.mc.otm.core.math.isZero
|
import ru.dbotthepony.mc.otm.core.math.isZero
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
|
import java.util.function.BooleanSupplier
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private fun concat(numbers: String, suffix: Any): Component {
|
private fun concat(numbers: String, suffix: Any): Component {
|
||||||
if (suffix == "")
|
if (suffix == "")
|
||||||
@ -75,7 +78,7 @@ fun BigInteger.determineSiPrefix(): SiPrefix? {
|
|||||||
return SiPrefix.MULTIPLIES.lastOrNull { it.integer!! <= num }
|
return SiPrefix.MULTIPLIES.lastOrNull { it.integer!! <= num }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BigInteger.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component {
|
fun BigInteger.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never): Component {
|
||||||
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
||||||
val prefix = determineSiPrefix() ?: return concat(toString(decimalPlaces), suffix)
|
val prefix = determineSiPrefix() ?: return concat(toString(decimalPlaces), suffix)
|
||||||
val isNegative = isNegative
|
val isNegative = isNegative
|
||||||
@ -148,41 +151,74 @@ fun Double.determineSiPrefix(): SiPrefix? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Decimal.formatSi(decimalPlaces: Int = 2): String {
|
private val never = BooleanSupplier { false }
|
||||||
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
|
||||||
val prefix = determineSiPrefix() ?: return toString(decimalPlaces)
|
private fun reformat(numbers: String): String {
|
||||||
return (this / prefix.impreciseFraction).toString(decimalPlaces) + prefix.symbol
|
if (numbers.length <= 4)
|
||||||
|
return numbers
|
||||||
|
|
||||||
|
val result = CharArrayList((numbers.length * 1.6).roundToInt())
|
||||||
|
|
||||||
|
var dot = numbers.lastIndexOf('.')
|
||||||
|
|
||||||
|
if (dot != -1) {
|
||||||
|
for (i in numbers.length - 1 downTo dot) {
|
||||||
|
result.add(numbers[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
dot--
|
||||||
|
} else {
|
||||||
|
dot = numbers.length - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
var c = 0
|
||||||
|
|
||||||
|
for (i in dot downTo 0) {
|
||||||
|
if (++c == 4) {
|
||||||
|
c = 1
|
||||||
|
result.add(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
result.add(numbers[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(CharArray(result.size) {
|
||||||
|
result.getChar(result.size - it - 1)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component {
|
fun Int.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never): Component {
|
||||||
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
||||||
|
if (formatAsReadable.asBoolean) return concat(reformat(toString()), suffix)
|
||||||
val prefix = determineSiPrefix() ?: return concat(toString(), suffix)
|
val prefix = determineSiPrefix() ?: return concat(toString(), suffix)
|
||||||
return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this.toFloat() / prefix.int!!.toFloat()), suffix)
|
return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this.toFloat() / prefix.int!!.toFloat()), suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component {
|
fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never): Component {
|
||||||
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
||||||
|
if (formatAsReadable.asBoolean) return concat(reformat("%.${decimalPlaces}f".format(this)), suffix)
|
||||||
val prefix = determineSiPrefix() ?: return concat("%.${decimalPlaces}f".format(this), suffix)
|
val prefix = determineSiPrefix() ?: return concat("%.${decimalPlaces}f".format(this), suffix)
|
||||||
return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this / prefix.double), suffix)
|
return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this / prefix.double), suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component {
|
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never): Component {
|
||||||
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
||||||
|
if (formatAsReadable.asBoolean) return concat(reformat(toString(decimalPlaces)), suffix)
|
||||||
val prefix = determineSiPrefix() ?: return concat(toString(decimalPlaces), suffix)
|
val prefix = determineSiPrefix() ?: return concat(toString(decimalPlaces), suffix)
|
||||||
return TranslatableComponent(prefix.formatLocaleKey, (this / prefix.impreciseFraction).toString(decimalPlaces), suffix)
|
return TranslatableComponent(prefix.formatLocaleKey, (this / prefix.impreciseFraction).toString(decimalPlaces), suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.formatPower(decimalPlaces: Int = 2) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces)
|
fun Int.formatPower(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces, formatAsReadable = formatAsReadable)
|
||||||
fun Decimal.formatPower(decimalPlaces: Int = 2) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces)
|
fun Decimal.formatPower(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces, formatAsReadable = formatAsReadable)
|
||||||
fun Decimal.formatMatter(decimalPlaces: Int = 2) = formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces)
|
fun Decimal.formatMatter(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces, formatAsReadable = formatAsReadable)
|
||||||
fun Decimal.formatMatterFull(decimalPlaces: Int = 2) = TranslatableComponent("otm.gui.matter.format", formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces))
|
fun Decimal.formatMatterFull(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = TranslatableComponent("otm.gui.matter.format", formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces, formatAsReadable = formatAsReadable))
|
||||||
|
|
||||||
fun BigInteger.formatPower(decimalPlaces: Int = 2) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces)
|
fun BigInteger.formatPower(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces, formatAsReadable = formatAsReadable)
|
||||||
fun BigInteger.formatMatter(decimalPlaces: Int = 2) = formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces)
|
fun BigInteger.formatMatter(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces, formatAsReadable = formatAsReadable)
|
||||||
fun BigInteger.formatMatterFull(decimalPlaces: Int = 2) = TranslatableComponent("otm.gui.matter.format", formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces))
|
fun BigInteger.formatMatterFull(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = TranslatableComponent("otm.gui.matter.format", formatSiComponent(TranslatableComponent("otm.gui.matter.name"), decimalPlaces, formatAsReadable = formatAsReadable))
|
||||||
|
|
||||||
fun formatPowerLevel(a: Decimal, b: Decimal, decimalPlaces: Int = 2) = TranslatableComponent("otm.gui.level", a.formatPower(decimalPlaces), b.formatPower(decimalPlaces))
|
fun formatPowerLevel(a: Decimal, b: Decimal, decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = TranslatableComponent("otm.gui.level", a.formatPower(decimalPlaces, formatAsReadable = formatAsReadable), b.formatPower(decimalPlaces, formatAsReadable = formatAsReadable))
|
||||||
fun formatMatterLevel(a: Decimal, b: Decimal, decimalPlaces: Int = 2) = TranslatableComponent("otm.gui.level", a.formatMatter(decimalPlaces), b.formatMatter(decimalPlaces))
|
fun formatMatterLevel(a: Decimal, b: Decimal, decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = TranslatableComponent("otm.gui.level", a.formatMatter(decimalPlaces, formatAsReadable = formatAsReadable), b.formatMatter(decimalPlaces, formatAsReadable = formatAsReadable))
|
||||||
|
|
||||||
private fun padded(num: Int): String {
|
private fun padded(num: Int): String {
|
||||||
if (num in 0 .. 9) {
|
if (num in 0 .. 9) {
|
||||||
|
@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||||
|
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.util.formatMatter
|
import ru.dbotthepony.mc.otm.core.util.formatMatter
|
||||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||||
@ -136,8 +137,8 @@ class MatterCapacitorItem : Item {
|
|||||||
p_41423_.add(
|
p_41423_.add(
|
||||||
TranslatableComponent(
|
TranslatableComponent(
|
||||||
"otm.item.matter.normal",
|
"otm.item.matter.normal",
|
||||||
it.storedMatter.formatMatter(),
|
it.storedMatter.formatMatter(formatAsReadable = ShiftPressedCond),
|
||||||
capacity.formatMatter()
|
capacity.formatMatter(formatAsReadable = ShiftPressedCond)
|
||||||
).withStyle(ChatFormatting.GRAY)
|
).withStyle(ChatFormatting.GRAY)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
|
|||||||
import ru.dbotthepony.mc.otm.SystemTime
|
import ru.dbotthepony.mc.otm.SystemTime
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive
|
import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive
|
||||||
|
import ru.dbotthepony.mc.otm.client.isShiftDown
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.container.stream
|
import ru.dbotthepony.mc.otm.container.stream
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
@ -1085,9 +1086,7 @@ object MatterManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tooltipEvent(event: ItemTooltipEvent) {
|
fun tooltipEvent(event: ItemTooltipEvent) {
|
||||||
val window = minecraft.window.window
|
if (minecraft.window.isShiftDown) {
|
||||||
|
|
||||||
if (InputConstants.isKeyDown(window, GLFW.GLFW_KEY_LEFT_SHIFT) || InputConstants.isKeyDown(window, GLFW.GLFW_KEY_RIGHT_SHIFT)) {
|
|
||||||
val matter = get(event.itemStack, accountForStackSize = false)
|
val matter = get(event.itemStack, accountForStackSize = false)
|
||||||
|
|
||||||
if (matter.hasMatterValue) {
|
if (matter.hasMatterValue) {
|
||||||
|
Loading…
Reference in New Issue
Block a user