Skip to content

Commit 659962d

Browse files
committed
Merge branch '1.21.5' into improvement/build-simulator
2 parents 59cead9 + b2446b0 commit 659962d

File tree

5 files changed

+44
-41
lines changed

5 files changed

+44
-41
lines changed

src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,23 @@ abstract class NumericSetting<T>(
9696
}
9797
}
9898

99-
@SettingGroup.SettingEditorDsl
100-
@Suppress("unchecked_cast")
101-
fun SettingGroup.TypedEditBuilder<T>.range(range: ClosedRange<T>) {
102-
(settings as Collection<NumericSetting<T>>).forEach { it.range = range }
103-
}
99+
companion object {
100+
@SettingGroup.SettingEditorDsl
101+
@Suppress("unchecked_cast")
102+
fun <T> SettingGroup.TypedEditBuilder<T>.range(range: ClosedRange<T>) where T : Number, T : Comparable<T> {
103+
(settings as Collection<NumericSetting<T>>).forEach { it.range = range }
104+
}
104105

105-
@SettingGroup.SettingEditorDsl
106-
@Suppress("unchecked_cast")
107-
fun SettingGroup.TypedEditBuilder<T>.step(step: T) {
108-
(settings as Collection<NumericSetting<T>>).forEach { it.step = step }
109-
}
106+
@SettingGroup.SettingEditorDsl
107+
@Suppress("unchecked_cast")
108+
fun <T> SettingGroup.TypedEditBuilder<T>.step(step: T) where T : Number, T : Comparable<T> {
109+
(settings as Collection<NumericSetting<T>>).forEach { it.step = step }
110+
}
110111

111-
@SettingGroup.SettingEditorDsl
112-
@Suppress("unchecked_cast")
113-
fun SettingGroup.TypedEditBuilder<*>.unit(unit: String) {
114-
(settings as Collection<NumericSetting<T>>).forEach { it.unit = unit}
112+
@SettingGroup.SettingEditorDsl
113+
@Suppress("unchecked_cast")
114+
fun <T> SettingGroup.TypedEditBuilder<T>.unit(unit: String) where T : Number, T : Comparable<T> {
115+
(settings as Collection<NumericSetting<T>>).forEach { it.unit = unit}
116+
}
115117
}
116118
}

src/main/kotlin/com/lambda/config/settings/StringSetting.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ class StringSetting(
6363
}
6464
}
6565

66-
@SettingGroup.SettingEditorDsl
67-
@Suppress("unchecked_cast")
68-
fun SettingGroup.TypedEditBuilder<String>.multiline(multiline: Boolean) {
69-
(settings as Collection<StringSetting>).forEach { it.multiline = multiline }
70-
}
66+
companion object {
67+
@SettingGroup.SettingEditorDsl
68+
@Suppress("unchecked_cast")
69+
fun SettingGroup.TypedEditBuilder<String>.multiline(multiline: Boolean) {
70+
(settings as Collection<StringSetting>).forEach { it.multiline = multiline }
71+
}
7172

72-
@SettingGroup.SettingEditorDsl
73-
@Suppress("unchecked_cast")
74-
fun SettingGroup.TypedEditBuilder<String>.flags(flags: Int) {
75-
(settings as Collection<StringSetting>).forEach { it.flags = flags }
73+
@SettingGroup.SettingEditorDsl
74+
@Suppress("unchecked_cast")
75+
fun SettingGroup.TypedEditBuilder<String>.flags(flags: Int) {
76+
(settings as Collection<StringSetting>).forEach { it.flags = flags }
77+
}
7678
}
7779
}

src/main/kotlin/com/lambda/config/settings/collections/ListSetting.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ class ListSetting<T : Any>(
7474
value = strList
7575
}
7676

77-
@SettingGroup.SettingEditorDsl
78-
@Suppress("unchecked_cast")
79-
fun <T> SettingGroup.TypedEditBuilder<MutableList<T>>.immutableList(immutableList: List<T>) {
80-
(settings as Collection<ListSetting<T>>).forEach { it.immutableList = immutableList }
77+
companion object {
78+
@SettingGroup.SettingEditorDsl
79+
@Suppress("unchecked_cast")
80+
fun <T : Any> SettingGroup.TypedEditBuilder<MutableList<T>>.immutableList(immutableList: List<T>) {
81+
(settings as Collection<ListSetting<T>>).forEach { it.immutableList = immutableList }
82+
}
8183
}
8284
}

src/main/kotlin/com/lambda/config/settings/collections/SetSetting.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ class SetSetting<T : Any>(
7575
value = strSet
7676
}
7777

78-
@SettingGroup.SettingEditorDsl
79-
@Suppress("unchecked_cast")
80-
fun <T> SettingGroup.TypedEditBuilder<MutableSet<T>>.immutableSet(immutableSet: Set<T>) {
81-
(settings as Collection<SetSetting<T>>).forEach { it.immutableSet = immutableSet }
78+
companion object {
79+
@SettingGroup.SettingEditorDsl
80+
@Suppress("unchecked_cast")
81+
fun <T : Any> SettingGroup.TypedEditBuilder<MutableSet<T>>.immutableSet(immutableSet: Set<T>) {
82+
(settings as Collection<SetSetting<T>>).forEach { it.immutableSet = immutableSet }
83+
}
8284
}
8385
}

src/main/kotlin/com/lambda/util/EnchantmentUtils.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,29 @@ object EnchantmentUtils {
3434
get() = getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT)
3535

3636
/**
37-
* Returns whether the given [ItemStack] has enchantments
37+
* Returns whether the given [ItemStack] has enchantments, including enchantments on books
3838
*/
3939
val ItemStack.hasEnchantments: Boolean
4040
get() = !getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT).isEmpty
41-
|| getOrDefault(DataComponentTypes.STORED_ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT).isEmpty
41+
|| !getOrDefault(DataComponentTypes.STORED_ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT).isEmpty
4242

4343
/**
4444
* Returns the given enchantment level from a [net.minecraft.item.ItemStack]
4545
*/
4646
fun ItemStack.getEnchantment(key: RegistryKey<Enchantment>) =
47-
getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT)
48-
.enchantmentEntries.find { it.key?.matchesKey(key) == true }
49-
?.intValue
50-
?: 0
47+
enchantments.enchantmentEntries.find { it.key?.matchesKey(key) == true }?.intValue ?: 0
5148

5249
/**
5350
* Iterates over all the enchantments for the given [ItemStack]
5451
*/
5552
fun <T> ItemStack.forEachEnchantment(block: (RegistryEntry<Enchantment>, Int) -> T) =
56-
enchantments.enchantmentEntries.asSequence()
57-
.map { block(it.key, it.intValue) }
53+
enchantments.enchantmentEntries.map { block(it.key, it.intValue) }
5854

5955
/**
6056
* Iterates over all the enchantments of the given [net.minecraft.entity.LivingEntity]'s [EquipmentSlot]
6157
*/
6258
fun <T> LivingEntity.forEachSlot(
6359
vararg slots: EquipmentSlot,
6460
block: (entry: RegistryEntry<Enchantment>, level: Int) -> T
65-
) =
66-
slots.flatMap { getEquippedStack(it).forEachEnchantment(block) }
61+
) = slots.flatMap { getEquippedStack(it).forEachEnchantment(block) }
6762
}

0 commit comments

Comments
 (0)