mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -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.JsonObject
|
||||||
import de.bixilon.kutil.json.MutableJsonObject
|
import de.bixilon.kutil.json.MutableJsonObject
|
||||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
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.inventory.stack.property.*
|
||||||
import de.bixilon.minosoft.data.registries.items.Item
|
import de.bixilon.minosoft.data.registries.items.Item
|
||||||
import de.bixilon.minosoft.data.text.ChatComponent
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
@ -85,24 +86,23 @@ class ItemStack {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
val rarity: Rarities
|
||||||
return Objects.hash(item, _display, _durability, _enchanting, _hide, _nbt)
|
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 {
|
return when (itemRarity) {
|
||||||
if (other !is ItemStack) {
|
Rarities.COMMON, Rarities.UNCOMMON -> Rarities.RARE
|
||||||
return false
|
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
|
val displayName: ChatComponent
|
||||||
get() {
|
get() {
|
||||||
@ -110,7 +110,7 @@ class ItemStack {
|
|||||||
item.item.translationKey?.let {
|
item.item.translationKey?.let {
|
||||||
val language = holder?.connection?.language ?: return@let
|
val language = holder?.connection?.language ?: return@let
|
||||||
val translated = language.translate(it)
|
val translated = language.translate(it)
|
||||||
_enchanting?.rarity?.color?.let { translated.applyDefaultColor(it) }
|
rarity.color.let { color -> translated.applyDefaultColor(color) }
|
||||||
return translated
|
return translated
|
||||||
}
|
}
|
||||||
return ChatComponent.of(toString())
|
return ChatComponent.of(toString())
|
||||||
@ -181,4 +181,23 @@ class ItemStack {
|
|||||||
revision++
|
revision++
|
||||||
holder?.container?.apply { revision++ } // increase revision after unlock to prevent deadlock
|
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(
|
class DurabilityProperty(
|
||||||
private val stack: ItemStack,
|
private val stack: ItemStack,
|
||||||
unbreakable: Boolean = false,
|
unbreakable: Boolean = false,
|
||||||
durability: Int = stack.item.item.maxDamage,
|
durability: Int = stack.item.item.maxDurability,
|
||||||
) : Property {
|
) : Property {
|
||||||
var _unbreakable = unbreakable
|
var _unbreakable = unbreakable
|
||||||
var unbreakable by InventoryDelegate(stack, this::_unbreakable)
|
var unbreakable by InventoryDelegate(stack, this::_unbreakable)
|
||||||
@ -32,7 +32,7 @@ class DurabilityProperty(
|
|||||||
get() {
|
get() {
|
||||||
try {
|
try {
|
||||||
stack.lock.acquire()
|
stack.lock.acquire()
|
||||||
return stack.item.item.maxDamage > 0 || !_unbreakable
|
return stack.item.item.maxDurability > 0 || !_unbreakable
|
||||||
} finally {
|
} finally {
|
||||||
stack.lock.release()
|
stack.lock.release()
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ class DurabilityProperty(
|
|||||||
if (_unbreakable) {
|
if (_unbreakable) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (stack.item.item.maxDamage <= 1) {
|
if (stack.item.item.maxDurability <= 1) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (_durability <= 0) { // ToDo
|
if (_durability <= 0) { // ToDo
|
||||||
|
@ -38,18 +38,19 @@ class EnchantingProperty(
|
|||||||
this::enchantments.observeMap(this) { stack.holder?.container?.let { it.revision++ } }
|
this::enchantments.observeMap(this) { stack.holder?.container?.let { it.revision++ } }
|
||||||
}
|
}
|
||||||
|
|
||||||
val rarity: Rarities
|
val enchantingRarity: Rarities
|
||||||
get() {
|
get() {
|
||||||
|
val itemRarity = stack.item.item.rarity
|
||||||
try {
|
try {
|
||||||
stack.lock.acquire()
|
stack.lock.acquire()
|
||||||
if (enchantments.isEmpty()) {
|
if (enchantments.isEmpty()) {
|
||||||
return stack.item.item.rarity
|
return itemRarity
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
stack.lock.release()
|
stack.lock.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (stack.item.item.rarity) {
|
return when (itemRarity) {
|
||||||
Rarities.COMMON, Rarities.UNCOMMON -> Rarities.RARE
|
Rarities.COMMON, Rarities.UNCOMMON -> Rarities.RARE
|
||||||
Rarities.RARE, Rarities.EPIC -> Rarities.EPIC
|
Rarities.RARE, Rarities.EPIC -> Rarities.EPIC
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ open class Item(
|
|||||||
) : RegistryItem(), Translatable {
|
) : RegistryItem(), Translatable {
|
||||||
val rarity: Rarities = data["rarity"]?.toInt()?.let { Rarities[it] } ?: Rarities.COMMON
|
val rarity: Rarities = data["rarity"]?.toInt()?.let { Rarities[it] } ?: Rarities.COMMON
|
||||||
val maxStackSize: Int = data["max_stack_size"]?.toInt() ?: 64
|
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
|
val isFireResistant: Boolean = data["is_fire_resistant"]?.toBoolean() ?: false
|
||||||
override val translationKey: ResourceLocation? = data["translation_key"]?.toResourceLocation()
|
override val translationKey: ResourceLocation? = data["translation_key"]?.toResourceLocation()
|
||||||
val creativeModeTab: CreativeModeTab? = data["category"]?.toInt()?.let { registries.creativeModeTabRegistry[it] }
|
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.inventory.stack.ItemStack
|
||||||
import de.bixilon.minosoft.data.text.BaseComponent
|
import de.bixilon.minosoft.data.text.BaseComponent
|
||||||
import de.bixilon.minosoft.data.text.ChatColors
|
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.data.text.TextComponent
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||||
@ -45,23 +46,39 @@ class ItemInfoPopper(
|
|||||||
override fun forceSilentApply() {
|
override fun forceSilentApply() {
|
||||||
val text = BaseComponent(
|
val text = BaseComponent(
|
||||||
stack.displayName,
|
stack.displayName,
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
TextComponent(stack.item.item.resourceLocation, color = ChatColors.DARK_GRAY),
|
|
||||||
)
|
)
|
||||||
stack._durability?.durability?.let {
|
stack._durability?.durability?.let {
|
||||||
if (it >= 0) {
|
val max = stack.item.item.maxDurability
|
||||||
text += "\n"
|
if (it in 0 until max) {
|
||||||
text += TextComponent("Durability: ${stack._durability?.durability}")
|
text += TextComponent(" (${it}/${max})", color = ChatColors.DARK_GRAY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack._display?.lore?.let {
|
stack._display?.lore?.let {
|
||||||
text += "\n"
|
if (it.isEmpty()) {
|
||||||
|
return@let
|
||||||
|
}
|
||||||
for (line in it) {
|
for (line in it) {
|
||||||
text += line
|
|
||||||
text += "\n"
|
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._chatComponent = text
|
||||||
textElement.forceSilentApply()
|
textElement.forceSilentApply()
|
||||||
recalculateSize()
|
recalculateSize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user