1
- package dev.nyon.skylper.extensions/*? if > 1.20 .5 {*/
1
+ package dev.nyon.skylper.extensions
2
+
2
3
import dev.nyon.skylper.minecraft
3
- import net.minecraft.core.component.DataComponents
4
4
import net.minecraft.nbt.CompoundTag
5
5
import net.minecraft.network.chat.Component
6
- import net.minecraft.world.item.Item
7
6
import net.minecraft.world.item.ItemStack
8
7
import net.minecraft.world.item.TooltipFlag
9
8
9
+ /* ? if >=1.20.6 {*/
10
+ import net.minecraft.core.component.DataComponents
11
+ import net.minecraft.world.item.Item
12
+ /* ?}*/
13
+
10
14
val ItemStack .nameAsString: String
11
15
get() {
12
16
return displayName.string.replace(" [" , " " ).replace(" ]" , " " )
13
17
}
14
18
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 ?
32
20
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
38
23
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*/
53
26
}
54
27
55
28
val ItemStack .extraAttributes: CompoundTag ?
56
29
get() {
57
- tag ?: return null
58
- val compoundTag = tag as CompoundTag
30
+ val compoundTag = compoundTag ? : return null
59
31
val key = " ExtraAttributes"
60
32
if (! compoundTag.contains(key)) return null
61
33
return compoundTag.getCompound(key)
@@ -71,16 +43,16 @@ val ItemStack.internalName: String?
71
43
72
44
val ItemStack .display: CompoundTag ?
73
45
get() {
74
- tag ?: return null
75
- val compoundTag = tag as CompoundTag
46
+ val compoundTag = compoundTag ? : return null
76
47
val key = " display"
77
48
if (! compoundTag.contains(key)) return null
78
49
return compoundTag.getCompound(key)
79
50
}
80
51
81
52
val ItemStack .lore: List <Component >
82
53
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
+ )
84
57
return lines.drop(1 )
85
- }
86
- */ /* ?}*/
58
+ }
0 commit comments