mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
improve item popper
This commit is contained in:
parent
c02a300af0
commit
935a46f99b
@ -16,6 +16,7 @@ import de.bixilon.kutil.concurrent.lock.ParentLock
|
||||
import de.bixilon.kutil.json.JsonObject
|
||||
import de.bixilon.kutil.json.MutableJsonObject
|
||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
||||
import de.bixilon.minosoft.data.Rarities
|
||||
import de.bixilon.minosoft.data.inventory.stack.property.*
|
||||
import de.bixilon.minosoft.data.registries.items.Item
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
@ -85,24 +86,23 @@ class ItemStack {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(item, _display, _durability, _enchanting, _hide, _nbt)
|
||||
}
|
||||
val rarity: Rarities
|
||||
get() {
|
||||
lock.acquire()
|
||||
val itemRarity = item.item.rarity
|
||||
try {
|
||||
if (_enchanting?.enchantments?.isEmpty() != false) {
|
||||
return itemRarity
|
||||
}
|
||||
} finally {
|
||||
lock.release()
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ItemStack) {
|
||||
return false
|
||||
return when (itemRarity) {
|
||||
Rarities.COMMON, Rarities.UNCOMMON -> Rarities.RARE
|
||||
Rarities.RARE, Rarities.EPIC -> Rarities.EPIC
|
||||
}
|
||||
}
|
||||
if (other.hashCode() != this.hashCode()) {
|
||||
return false
|
||||
}
|
||||
return item == other.item && _display == other._display && _durability == other._durability && _enchanting == other._enchanting && _hide == other._hide && _nbt == other._nbt
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
// this should not get synchronized, otherwise your debugger won't work that good:)
|
||||
return "Item{type=${item.item}, count=${item._count}}"
|
||||
}
|
||||
|
||||
val displayName: ChatComponent
|
||||
get() {
|
||||
@ -110,7 +110,7 @@ class ItemStack {
|
||||
item.item.translationKey?.let {
|
||||
val language = holder?.connection?.language ?: return@let
|
||||
val translated = language.translate(it)
|
||||
_enchanting?.rarity?.color?.let { translated.applyDefaultColor(it) }
|
||||
rarity.color.let { color -> translated.applyDefaultColor(color) }
|
||||
return translated
|
||||
}
|
||||
return ChatComponent.of(toString())
|
||||
@ -181,4 +181,23 @@ class ItemStack {
|
||||
revision++
|
||||
holder?.container?.apply { revision++ } // increase revision after unlock to prevent deadlock
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(item, _display, _durability, _enchanting, _hide, _nbt)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ItemStack) {
|
||||
return false
|
||||
}
|
||||
if (other.hashCode() != this.hashCode()) {
|
||||
return false
|
||||
}
|
||||
return item == other.item && _display == other._display && _durability == other._durability && _enchanting == other._enchanting && _hide == other._hide && _nbt == other._nbt
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
// this should not get synchronized, otherwise your debugger won't work that good:)
|
||||
return "Item{type=${item.item}, count=${item._count}}"
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import de.bixilon.minosoft.data.inventory.stack.ItemStack
|
||||
class DurabilityProperty(
|
||||
private val stack: ItemStack,
|
||||
unbreakable: Boolean = false,
|
||||
durability: Int = stack.item.item.maxDamage,
|
||||
durability: Int = stack.item.item.maxDurability,
|
||||
) : Property {
|
||||
var _unbreakable = unbreakable
|
||||
var unbreakable by InventoryDelegate(stack, this::_unbreakable)
|
||||
@ -32,7 +32,7 @@ class DurabilityProperty(
|
||||
get() {
|
||||
try {
|
||||
stack.lock.acquire()
|
||||
return stack.item.item.maxDamage > 0 || !_unbreakable
|
||||
return stack.item.item.maxDurability > 0 || !_unbreakable
|
||||
} finally {
|
||||
stack.lock.release()
|
||||
}
|
||||
@ -43,7 +43,7 @@ class DurabilityProperty(
|
||||
if (_unbreakable) {
|
||||
return true
|
||||
}
|
||||
if (stack.item.item.maxDamage <= 1) {
|
||||
if (stack.item.item.maxDurability <= 1) {
|
||||
return true
|
||||
}
|
||||
if (_durability <= 0) { // ToDo
|
||||
|
@ -38,18 +38,19 @@ class EnchantingProperty(
|
||||
this::enchantments.observeMap(this) { stack.holder?.container?.let { it.revision++ } }
|
||||
}
|
||||
|
||||
val rarity: Rarities
|
||||
val enchantingRarity: Rarities
|
||||
get() {
|
||||
val itemRarity = stack.item.item.rarity
|
||||
try {
|
||||
stack.lock.acquire()
|
||||
if (enchantments.isEmpty()) {
|
||||
return stack.item.item.rarity
|
||||
return itemRarity
|
||||
}
|
||||
} finally {
|
||||
stack.lock.release()
|
||||
}
|
||||
|
||||
return when (stack.item.item.rarity) {
|
||||
return when (itemRarity) {
|
||||
Rarities.COMMON, Rarities.UNCOMMON -> Rarities.RARE
|
||||
Rarities.RARE, Rarities.EPIC -> Rarities.EPIC
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ open class Item(
|
||||
) : RegistryItem(), Translatable {
|
||||
val rarity: Rarities = data["rarity"]?.toInt()?.let { Rarities[it] } ?: Rarities.COMMON
|
||||
val maxStackSize: Int = data["max_stack_size"]?.toInt() ?: 64
|
||||
val maxDamage: Int = data["max_damage"]?.toInt() ?: 1
|
||||
val maxDurability: Int = data["max_damage"]?.toInt() ?: 1
|
||||
val isFireResistant: Boolean = data["is_fire_resistant"]?.toBoolean() ?: false
|
||||
override val translationKey: ResourceLocation? = data["translation_key"]?.toResourceLocation()
|
||||
val creativeModeTab: CreativeModeTab? = data["category"]?.toInt()?.let { registries.creativeModeTabRegistry[it] }
|
||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.gui.popper.item
|
||||
import de.bixilon.minosoft.data.inventory.stack.ItemStack
|
||||
import de.bixilon.minosoft.data.text.BaseComponent
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||
@ -45,23 +46,39 @@ class ItemInfoPopper(
|
||||
override fun forceSilentApply() {
|
||||
val text = BaseComponent(
|
||||
stack.displayName,
|
||||
"\n",
|
||||
"\n",
|
||||
TextComponent(stack.item.item.resourceLocation, color = ChatColors.DARK_GRAY),
|
||||
)
|
||||
stack._durability?.durability?.let {
|
||||
if (it >= 0) {
|
||||
text += "\n"
|
||||
text += TextComponent("Durability: ${stack._durability?.durability}")
|
||||
val max = stack.item.item.maxDurability
|
||||
if (it in 0 until max) {
|
||||
text += TextComponent(" (${it}/${max})", color = ChatColors.DARK_GRAY)
|
||||
}
|
||||
}
|
||||
stack._display?.lore?.let {
|
||||
text += "\n"
|
||||
if (it.isEmpty()) {
|
||||
return@let
|
||||
}
|
||||
for (line in it) {
|
||||
text += line
|
||||
text += "\n"
|
||||
text += line
|
||||
}
|
||||
}
|
||||
stack._enchanting?.enchantments?.let {
|
||||
if (it.isEmpty()) {
|
||||
return@let
|
||||
}
|
||||
text += "\n"
|
||||
val language = renderWindow.connection.language
|
||||
for ((enchantment, level) in it) {
|
||||
text += ChatComponent.of(enchantment, translator = language).apply { applyDefaultColor(ChatColors.BLUE) }
|
||||
text += TextComponent(" $level", color = ChatColors.BLUE)
|
||||
text += ", "
|
||||
}
|
||||
if (text.parts.lastOrNull()?.message == ", ") {
|
||||
text.parts.removeLast()
|
||||
}
|
||||
}
|
||||
text += "\n\n"
|
||||
text += TextComponent(stack.item.item.resourceLocation, color = ChatColors.DARK_GRAY)
|
||||
textElement._chatComponent = text
|
||||
textElement.forceSilentApply()
|
||||
recalculateSize()
|
||||
|
Loading…
x
Reference in New Issue
Block a user