bunch of cards

This commit is contained in:
2026-04-19 21:22:12 +02:00
parent b025159791
commit 0416ddd4a5
69 changed files with 668 additions and 27 deletions

View File

@@ -9,8 +9,11 @@ import org.neoflock.neocomputers.network.Networking
import org.neoflock.neocomputers.utils.Formatting
import java.util.UUID
fun getEEPROMProperties(): Item.Properties = Item.Properties().component(
DataComponents.EEPROM_CODE, "").component(DataComponents.EEPROM_DATA, "").component(DataComponents.LABEL, "")
fun getEEPROMProperties(): Item.Properties = Item.Properties()
.component(DataComponents.EEPROM_CODE, "")
.component(DataComponents.EEPROM_DATA, "")
.component(DataComponents.LABEL, "")
.component(DataComponents.READONLY, false)
open class EEPROMItem(val tier: Int, val codeCapacity: Int, val dataCapacity: Int): Item(getEEPROMProperties()), ComponentItem {
override fun getComponentRoles(itemStack: ItemStack): Set<String> = setOf(ComponentRoles.FIRMWARE)
@@ -22,13 +25,10 @@ open class EEPROMItem(val tier: Int, val codeCapacity: Int, val dataCapacity: In
override fun getComponentCapacity(itemStack: ItemStack): Int = 0
override fun whenComponentPlaced(itemStack: ItemStack, newRole: String) {
if(!itemStack.has(DataComponents.ADDRESS)) {
itemStack.set(DataComponents.ADDRESS, UUID.randomUUID().toString())
}
ensureHasAddress(itemStack)
super.whenComponentPlaced(itemStack, newRole)
}
override fun whenComponentTaken(itemStack: ItemStack, previousRole: String) {}
override fun toComponentNode(itemStack: ItemStack): Networking.Node? = null
override fun appendHoverText(
@@ -41,6 +41,7 @@ open class EEPROMItem(val tier: Int, val codeCapacity: Int, val dataCapacity: In
val code = itemStack.get(DataComponents.EEPROM_CODE) ?: ""
val data = itemStack.get(DataComponents.EEPROM_DATA) ?: ""
val addr = itemStack.get(DataComponents.ADDRESS)
val readonly = itemStack.get(DataComponents.READONLY) ?: false
val codeSize = code.encodeToByteArray().size
val dataSize = data.encodeToByteArray().size
val addrComp = if(addr == null) Component.translatable("neocomputers.noaddr") else Component.literal(addr)
@@ -49,6 +50,7 @@ open class EEPROMItem(val tier: Int, val codeCapacity: Int, val dataCapacity: In
Formatting.formatMemory(codeCapacity.toLong())))
list.addLast(Component.translatable("neocomputers.eeprom.dataused", Formatting.formatMemory(dataSize.toLong()),
Formatting.formatMemory(dataCapacity.toLong())))
list.addLast(Component.translatable(if(readonly) "neocomputers.readonly" else "neocomputers.readwrite"))
}
super.appendHoverText(itemStack, tooltipContext, list, tooltipFlag)
}