Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 3a6c978

Browse files
committed
improve item extensions
1 parent e94d155 commit 3a6c978

File tree

1 file changed

+18
-46
lines changed
  • src/main/kotlin/dev/nyon/skylper/extensions

1 file changed

+18
-46
lines changed
Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,33 @@
1-
package dev.nyon.skylper.extensions/*? if >1.20.5 {*/
1+
package dev.nyon.skylper.extensions
2+
23
import dev.nyon.skylper.minecraft
3-
import net.minecraft.core.component.DataComponents
44
import net.minecraft.nbt.CompoundTag
55
import net.minecraft.network.chat.Component
6-
import net.minecraft.world.item.Item
76
import net.minecraft.world.item.ItemStack
87
import net.minecraft.world.item.TooltipFlag
98

9+
/*? if >=1.20.6 {*/
10+
import net.minecraft.core.component.DataComponents
11+
import net.minecraft.world.item.Item
12+
/*?}*/
13+
1014
val ItemStack.nameAsString: String
1115
get() {
1216
return displayName.string.replace("[", "").replace("]", "")
1317
}
1418

15-
val ItemStack.extraAttributes: CompoundTag?
16-
get() {
17-
val tag = get(DataComponents.CUSTOM_DATA)?.copyTag() ?: return null
18-
val key = "ExtraAttributes"
19-
if (!tag.contains(key)) return null
20-
return tag.getCompound(key)
21-
}
22-
23-
val ItemStack.internalName: String?
24-
get() {
25-
val attributes = extraAttributes ?: return null
26-
val key = "id"
27-
if (!attributes.contains(key)) return null
28-
return attributes.getString(key)
29-
}
30-
31-
val ItemStack.display: CompoundTag?
19+
val ItemStack.compoundTag: CompoundTag?
3220
get() {
33-
val tag = get(DataComponents.CUSTOM_DATA)?.copyTag() ?: return null
34-
val key = "display"
35-
if (!tag.contains(key)) return null
36-
return tag.getCompound(key)
37-
}
21+
//? if >=1.20.6
22+
return get(DataComponents.CUSTOM_DATA)?.copyTag() ?: return null
3823

39-
val ItemStack.lore: List<Component>
40-
get() {
41-
val lines = getTooltipLines(Item.TooltipContext.EMPTY, minecraft.player!!, TooltipFlag.ADVANCED)
42-
return lines.drop(1)
43-
}/*?} else {*/
44-
/*import dev.nyon.skylper.minecraft
45-
import net.minecraft.nbt.CompoundTag
46-
import net.minecraft.network.chat.Component
47-
import net.minecraft.world.item.ItemStack
48-
import net.minecraft.world.item.TooltipFlag
49-
50-
val ItemStack.nameAsString: String
51-
get() {
52-
return displayName.string.replace("[", "").replace("]", "")
24+
//? if <1.20.6
25+
/*return tag*/
5326
}
5427

5528
val ItemStack.extraAttributes: CompoundTag?
5629
get() {
57-
tag ?: return null
58-
val compoundTag = tag as CompoundTag
30+
val compoundTag = compoundTag ?: return null
5931
val key = "ExtraAttributes"
6032
if (!compoundTag.contains(key)) return null
6133
return compoundTag.getCompound(key)
@@ -71,16 +43,16 @@ val ItemStack.internalName: String?
7143

7244
val ItemStack.display: CompoundTag?
7345
get() {
74-
tag ?: return null
75-
val compoundTag = tag as CompoundTag
46+
val compoundTag = compoundTag ?: return null
7647
val key = "display"
7748
if (!compoundTag.contains(key)) return null
7849
return compoundTag.getCompound(key)
7950
}
8051

8152
val ItemStack.lore: List<Component>
8253
get() {
83-
val lines = getTooltipLines(minecraft.player, TooltipFlag.ADVANCED)
54+
val lines = getTooltipLines(/*? if >=1.20.6 {*/ Item.TooltipContext.EMPTY, /*?}*/ minecraft.player!!,
55+
TooltipFlag.ADVANCED
56+
)
8457
return lines.drop(1)
85-
}
86-
*//*?}*/
58+
}

0 commit comments

Comments
 (0)