From 8004658a0a7778eed7327a1d0af1127ae309dfb2 Mon Sep 17 00:00:00 2001 From: ionut Date: Sat, 25 Apr 2026 20:58:13 +0000 Subject: [PATCH] get internationalized --- .../neocomputers/entity/CaseBlockEntity.kt | 13 +++++++------ .../neoflock/neocomputers/entity/MachineEntity.kt | 2 ++ .../neoflock/neocomputers/gui/screen/CaseScreen.kt | 14 ++++++++------ .../neoflock/neocomputers/item/DataComponents.kt | 3 +++ .../org/neoflock/neocomputers/item/EEPROMItem.kt | 4 ++++ .../kotlin/org/neoflock/neocomputers/item/Tabs.kt | 1 + .../resources/assets/neocomputers/lang/en_us.json | 11 +++++++++++ 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/CaseBlockEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/CaseBlockEntity.kt index c1484c8..6ce9ba5 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/CaseBlockEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/CaseBlockEntity.kt @@ -153,28 +153,29 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti val archs = getMachineArchitectures() // Beep patterns taken from https://github.com/MightyPirates/OpenComputers/blob/571482db88080d56329e8f8cf0db2a90825bf1d7/src/main/scala/li/cil/oc/server/machine/Machine.scala if(archs.isEmpty()) { - crash("no cpu") + crash("@neocomputers.errors.ENOCPU") beepAsync("-..") return false } if(getMachineComponentsUsed() > getMachineComponentsTotal()) { - crash("too many components") + crash("@neocomputers.errors.E2BIG") beepAsync("-..") return false } - if(node.energy < 100) { - crash("not enough energy") + // less than 20% energy is bad + if(node.energy < node.energyCapacity/5) { + crash("@neocomputers.errors.ENOENJ") // we add a beep for the special case where we do have a little bit of energy :P if(node.energy > 0) beepAsync("..") return false } if(getMachineMemoryTotal() == 0L) { - crash("no memory provided") + crash("@neocomputers.errors.ENOMEM") beepAsync("-.") return false } if(arch !in archs) { - // Just pick one! + // Just pick one! TODO: consult EEPROM first arch = archs.first() } beepAsync(".") diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/MachineEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/MachineEntity.kt index be226a6..9fbf922 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/MachineEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/MachineEntity.kt @@ -3,6 +3,7 @@ package org.neoflock.neocomputers.entity import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.world.level.Level +import net.minecraft.world.phys.Vec3 import org.neoflock.neocomputers.item.ComponentItem import org.neoflock.neocomputers.network.Networking import java.time.Duration @@ -18,6 +19,7 @@ data class MachineCrashEvent(override val machine: MachineEntity, val error: Str interface MachineEntity { // Block position of machine, for wireless tech fun getMachineBlockPosition(): BlockPos + fun getMachinePrecisePosition(): Vec3 = getMachineBlockPosition().center fun getMachineLevel(): Level // Pattern can have dots (.), dashes (-) and spaces ( ). diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt index c17a072..8d7ca0b 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt @@ -57,18 +57,20 @@ class CaseScreen : GenericContainerScreen { arch = buf.readUtf() } + fun getErrorComponent(err: String): Component = if(err.startsWith("@")) Component.translatable(err.substring(1)) else Component.literal(err) + fun computeButtonTooltip(): List { - val msgs = mutableListOf(Component.literal("Computer " + if(isOn) "ON" else "OFF").withStyle(if(isOn) ChatFormatting.GREEN else ChatFormatting.RED)) + val msgs = mutableListOf(Component.translatable(if(isOn) "neocomputers.computer.on" else "neocomputers.computer.off").withStyle(if(isOn) ChatFormatting.GREEN else ChatFormatting.RED)) if(lastError != null) { - msgs.addLast(Component.literal("Error: ").withStyle(ChatFormatting.RED).append(Component.literal(lastError!!))) + msgs.addLast(Component.translatable("neocomputers.computer.errorNoMsg").withStyle(ChatFormatting.RED).append(getErrorComponent(lastError!!))) } if(arch.isNotEmpty()) { - msgs.addLast(Component.literal("Architecture: $arch")) + msgs.addLast(Component.translatable("neocomputers.arch", arch)) } if(hasShiftDown()) { - msgs.addLast(Component.literal("Energy: $energy / $maxEnergy J").withStyle(if(energy < 100) ChatFormatting.RED else ChatFormatting.WHITE)) - msgs.addLast(Component.literal("Memory: ${Formatting.formatMemory(memory)} / ${Formatting.formatMemory(maxMemory)}")) - msgs.addLast(Component.literal("Components: $components / $maxComponents").withStyle(if(components <= maxComponents) ChatFormatting.WHITE else ChatFormatting.RED)) + msgs.addLast(Component.translatable("neocomputers.computer.energy", energy, maxEnergy).withStyle(if(energy < maxEnergy/5) ChatFormatting.RED else ChatFormatting.WHITE)) + msgs.addLast(Component.translatable("neocomputers.computer.memory", Formatting.formatMemory(memory), Formatting.formatMemory(maxMemory))) + msgs.addLast(Component.translatable("neocomputers.computer.components", components, maxEnergy).withStyle(if(components <= maxComponents) ChatFormatting.WHITE else ChatFormatting.RED)) } return msgs } diff --git a/src/main/kotlin/org/neoflock/neocomputers/item/DataComponents.kt b/src/main/kotlin/org/neoflock/neocomputers/item/DataComponents.kt index ff3ac77..7a0c4d2 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/item/DataComponents.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/item/DataComponents.kt @@ -15,6 +15,9 @@ object DataComponents { DataComponentType.builder().persistent(Codec.STRING).build()) val READONLY = Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "readonly"), DataComponentType.builder().persistent(Codec.BOOL).build()) + val ARCH = Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "architecture"), + DataComponentType.builder().persistent(Codec.STRING).build()) + val EEPROM_CODE = Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "eeprom_code"), DataComponentType.builder().persistent(Codec.BYTE_BUFFER).build()) val EEPROM_DATA = Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "eeprom_data"), diff --git a/src/main/kotlin/org/neoflock/neocomputers/item/EEPROMItem.kt b/src/main/kotlin/org/neoflock/neocomputers/item/EEPROMItem.kt index c5c7872..b73b15d 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/item/EEPROMItem.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/item/EEPROMItem.kt @@ -43,10 +43,14 @@ open class EEPROMItem(val tier: Int, val codeCapacity: Int, val dataCapacity: In if(tooltipFlag.isAdvanced) { val codeSize = itemStack.get(DataComponents.EEPROM_CODESIZE) ?: 0 val dataSize = itemStack.get(DataComponents.EEPROM_DATASIZE) ?: 0 + val arch = itemStack.get(DataComponents.ARCH) val addr = itemStack.get(DataComponents.ADDRESS) val readonly = itemStack.get(DataComponents.READONLY) ?: false val addrComp = if(addr == null) Component.translatable("neocomputers.noaddr") else Component.literal(addr) list.addLast(addrComp) + if(arch != null) { + list.addLast(Component.translatable("neocomputers.arch", arch)) + } list.addLast(Component.translatable("neocomputers.eeprom.codeused", Formatting.formatMemory(codeSize.toLong()), Formatting.formatMemory(codeCapacity.toLong()))) list.addLast(Component.translatable("neocomputers.eeprom.dataused", Formatting.formatMemory(dataSize.toLong()), diff --git a/src/main/kotlin/org/neoflock/neocomputers/item/Tabs.kt b/src/main/kotlin/org/neoflock/neocomputers/item/Tabs.kt index 16848a2..dc54ba8 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/item/Tabs.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/item/Tabs.kt @@ -71,6 +71,7 @@ object Tabs { val codeBuf = ByteBuffer.allocate(code.size) codeBuf.put(code) luaBios.set(DataComponents.LABEL, "Lua BIOS") + luaBios.set(DataComponents.ARCH, "Lua 5.2") luaBios.set(DataComponents.EEPROM_CODE, codeBuf) luaBios.set(DataComponents.EEPROM_CODESIZE, code.size) output.accept(luaBios) diff --git a/src/main/resources/assets/neocomputers/lang/en_us.json b/src/main/resources/assets/neocomputers/lang/en_us.json index 294c0ff..21d2dbd 100644 --- a/src/main/resources/assets/neocomputers/lang/en_us.json +++ b/src/main/resources/assets/neocomputers/lang/en_us.json @@ -38,6 +38,10 @@ "item.neocomputers.hdd0": "Hard Disk Drive (Tier 1)", "item.neocomputers.hdd1": "Hard Disk Drive (Tier 2)", "item.neocomputers.hdd2": "Hard Disk Drive (Tier 3)", + "neocomputers.errors.ENOCPU": "no CPU", + "neocomputers.errors.E2BIG": "too many components", + "neocomputers.errors.ENOENJ": "dangerously low energy", + "neocomputers.errors.ENOMEM": "missing memory", "neocomputers.wlan.range": "Range: %1$s blocks", "neocomputers.data.limit": "Memory: %1$s", "neocomputers.gpu.vram": "Video Memory: %1$spx", @@ -45,7 +49,14 @@ "neocomputers.readonly": "Read-Only", "neocomputers.readwrite": "Read-Write", "neocomputers.noaddr": "No address assigned", + "neocomputers.computer.on": "ON", + "neocomputers.computer.off": "OFF", + "neocomputers.computer.errorNoMsg": "Error: ", + "neocomputers.computer.energy": "Energy: %1$s / %2$s J", + "neocomputers.computer.memory": "Memory: %1$s / %2$s", + "neocomputers.computer.components": "Components: %1$s / %2$s", "neocomputers.memory.capacity": "Capacity: %1$s", + "neocomputers.arch": "Architecture: %1$s", "neocomputers.eeprom.codeused": "Code Storage: %1$s / %2$s", "neocomputers.eeprom.dataused": "Data Storage: %1$s / %2$s", "neocomputers.tunnel.channel": "Linked Channel: %1$s",