You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Creates an [ItemStack] based on the current properties. The returned item stack must not be modified by the
50
+
* caller.
51
+
*/
52
+
funtoImmutableStack(): ItemStack {
53
+
var cached = itemCache
54
+
if (cached ==null) {
55
+
cached = createStack()
56
+
itemCache = cached
57
+
}
58
+
return cached
59
+
}
60
+
61
+
data classPartialStack<T>(
62
+
vallastAppliedModifier:SBItemProperty<T>?,
63
+
valdata:T?,
64
+
valstack:ItemStack,
65
+
)
66
+
67
+
companionobject {
68
+
/**
69
+
* Create an [SBItemData] from only the given characteristica. Any unspecified characteristica will be non-existent.
70
+
* If you want to compute all other properties based on the given properties, use [roundtrip].
71
+
*/
72
+
funfromCharacteristica(
73
+
varargchar:SBItemProperty.BoundState<*>
74
+
): SBItemData {
75
+
val store =SBItemData()
76
+
char.forEach {
77
+
it.applyTo(store)
78
+
}
79
+
return store
80
+
}
81
+
82
+
funfromStack(itemStack:ItemStack): SBItemData {
83
+
val store =SBItemData()
84
+
store.loadFrom(itemStack)
85
+
return store
86
+
}
87
+
}
88
+
89
+
/**
90
+
* Creates a new [SBItemData] from the item stack this [SBItemData] produces. This will initialize all properties.
91
+
*/
92
+
funroundtrip(): SBItemData {
93
+
return fromStack(toImmutableStack())
94
+
}
95
+
96
+
/**
97
+
* Creates a new [SBItemData] with cheap inferences completed only by using data available in [io.github.moulberry.repo.data.NEUItem]. This is a cheaper version of [roundtrip], that does not create any [ItemStack]s, and preserves all properties already provided. Check if the property you need overrides [SBItemProperty.fromNeuItem].
98
+
*/
99
+
funcheapInfer(): SBItemData {
100
+
val neuItem = getData(SBItemId)?.let { RepoManager.getNEUItem(it) } ?:returnthis
101
+
val store =SBItemData()
102
+
SBItemProperty.allProperties.forEach {
103
+
it.fromNeuItem(neuItem, this)
104
+
}
105
+
store.data.putAll(this.data)
106
+
return store
107
+
}
108
+
109
+
privatefunloadFrom(stack:ItemStack) {
110
+
SBItemProperty.allProperties.forEach {
111
+
loadModifier(stack, it)
112
+
}
113
+
}
114
+
115
+
privatefun <T> loadModifier(
116
+
stack:ItemStack,
117
+
modifier:SBItemProperty<T>
118
+
) {
119
+
val data = modifier.fromStack(stack, this) ?:return
* A property of a skyblock item. Not every skyblock item must have this property, but some should.
10
+
*
11
+
* Access to this class should be limited to [State.bindWith] and [SBItemData.getData].
12
+
* @see State
13
+
*/
14
+
abstractclassSBItemProperty<T> {
15
+
data classBoundState<T>(valproperty:State<T>, valdata:T) {
16
+
funapplyTo(store:SBItemData) {
17
+
store.set(property, data)
18
+
}
19
+
}
20
+
21
+
// TODO: Actually implement and make use of this method.
22
+
/**
23
+
* Extract this property's state from a [NEUItem]. If this method returns something, it may be equivalent to [fromStack] with the neu item resolved to an item stack according to [asItemStack], but *should not* instantiate an item stack. This method may return null to indicate that it needs a fully constructed item stack to extract a property. This method return one value and then later return another value from [fromStack], but behaviour is generally discouraged.
* Extract this property's state from an [ItemStack]. This should be fully reversible (i.e. all info used to in [fromStack] needs to be set by [State.applyToStack].
0 commit comments