diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt index 7d2283702..f79bc621c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt @@ -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 } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt index 871f21e60..ef06105ad 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt @@ -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(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 get() = listOf() + + companion object { + private val NEWLINES = Regex("\r?\n") + } }