Limit text input in holo sign
This commit is contained in:
parent
64a54add95
commit
8de86dd087
@ -40,5 +40,7 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : Synchron
|
||||
|
||||
companion object {
|
||||
const val TEXT_KEY = "SignText"
|
||||
const val DEFAULT_MAX_NEWLINES = 8
|
||||
const val DEFAULT_MAX_LINE_LENGTH = 15
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.menu.decorative
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.input.TextInputPanel
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.input.NetworkedStringInput
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
@ -12,8 +13,28 @@ class HoloSignMenu @JvmOverloads constructor(
|
||||
inventory: Inventory,
|
||||
tile: HoloSignBlockEntity? = null
|
||||
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
|
||||
val text = if (tile != null) NetworkedStringInput(this, tile::text) else NetworkedStringInput(this)
|
||||
val text = if (tile != null)
|
||||
NetworkedStringInput(this).withConsumer {
|
||||
val lines = it.split(NEWLINES)
|
||||
val result = ArrayList<String>(lines.size.coerceAtMost(HoloSignBlockEntity.DEFAULT_MAX_NEWLINES))
|
||||
|
||||
for (i in 0 until lines.size.coerceAtMost(HoloSignBlockEntity.DEFAULT_MAX_NEWLINES)) {
|
||||
if (lines[i].length > HoloSignBlockEntity.DEFAULT_MAX_LINE_LENGTH) {
|
||||
result.add(lines[i].substring(0, HoloSignBlockEntity.DEFAULT_MAX_LINE_LENGTH))
|
||||
} else {
|
||||
result.add(lines[i])
|
||||
}
|
||||
}
|
||||
|
||||
tile.text = result.joinToString("\n")
|
||||
}.withSupplier(tile::text)
|
||||
else
|
||||
NetworkedStringInput(this)
|
||||
|
||||
override val storageSlots: Collection<Slot>
|
||||
get() = listOf()
|
||||
|
||||
companion object {
|
||||
private val NEWLINES = Regex("\r?\n")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user