-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: drop Axiom compat for normal teleport handling
- Loading branch information
Showing
7 changed files
with
115 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
[versions] | ||
gearyPaper = "0.31.3" | ||
gearyPaper = "0.31.10" | ||
guiy="0.12.5" | ||
|
||
[libraries] | ||
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" } | ||
guiy = { module = "com.mineinabyss:guiy-compose", version.ref = "guiy" } | ||
|
||
minecraft-plugin-protectionlib = "io.th0rgal:protectionlib:1.7.0" | ||
minecraft-plugin-axiompaper = "com.moulberry:axiom:4.0.1" | ||
minecraft-plugin-protectionlib = "io.th0rgal:protectionlib:1.8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/kotlin/com/mineinabyss/blocky/helpers/FastUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.mineinabyss.blocky.helpers | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList | ||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet | ||
import java.util.* | ||
|
||
inline fun <T, R> Iterable<T>.flatMapFast(transform: (T) -> Iterable<R>): ObjectArrayList<R> { | ||
return flatMapTo(ObjectArrayList<R>(), transform) | ||
} | ||
|
||
inline fun <T, R> Iterable<T>.flatMapSetFast(transform: (T) -> Iterable<R>): ObjectOpenHashSet<R> { | ||
return flatMapTo(ObjectOpenHashSet<R>(), transform) | ||
} | ||
|
||
inline fun <T, R> Iterable<T>.mapFast(transform: (T) -> R): ObjectArrayList<R> { | ||
return mapTo(ObjectArrayList<R>((this as? Collection)?.size ?: 10), transform) | ||
} | ||
|
||
inline fun <T, R : Any> Iterable<T>.mapNotNullFast(transform: (T) -> R?): ObjectArrayList<R> { | ||
return mapNotNullTo(ObjectArrayList<R>(), transform) | ||
} | ||
|
||
inline fun <T, R> Iterable<T>.mapFastSet(transform: (T) -> R): ObjectOpenHashSet<R> { | ||
return mapTo(ObjectOpenHashSet<R>((this as? Collection)?.size ?: 10), transform) | ||
} | ||
|
||
inline fun <T, K, V> Iterable<T>.associateFast(transform: (T) -> Pair<K, V>): Object2ObjectOpenHashMap<K, V> { | ||
val capacity = mapCapacity((this as? Collection)?.size ?: 10).coerceAtLeast(16) | ||
return associateTo(Object2ObjectOpenHashMap<K, V>(capacity), transform) | ||
} | ||
|
||
inline fun <K, V> Iterable<K>.associateFastWith(valueSelector: (K) -> V): Object2ObjectOpenHashMap<K, V> { | ||
val result = Object2ObjectOpenHashMap<K, V>(mapCapacity((this as? Collection)?.size ?: 10).coerceAtLeast(16)) | ||
return associateWithTo(result, valueSelector) | ||
} | ||
|
||
inline fun <reified R> Iterable<*>.filterFastIsInstance(): ObjectArrayList<R> { | ||
return filterIsInstanceTo(ObjectArrayList<R>()) | ||
} | ||
|
||
inline fun <reified R> Iterable<*>.filterFastIsInstance(predicate: (R) -> Boolean): ObjectArrayList<R> { | ||
val result = ObjectArrayList<R>() | ||
for (element in this) if (element is R && predicate(element)) result.add(element) | ||
return result | ||
} | ||
|
||
inline fun <T> Iterable<T>.filterFast(predicate: (T) -> Boolean): ObjectArrayList<T> { | ||
return filterTo(ObjectArrayList<T>(), predicate) | ||
} | ||
|
||
inline fun <T> Iterable<T>.filterFastSet(predicate: (T) -> Boolean): ObjectOpenHashSet<T> { | ||
return filterTo(ObjectOpenHashSet<T>(), predicate) | ||
} | ||
|
||
inline fun <K, V> Map<out K, V>.filterFast(predicate: (Map.Entry<K, V>) -> Boolean): Object2ObjectOpenHashMap<K, V> { | ||
return filterTo(Object2ObjectOpenHashMap<K, V>(), predicate) | ||
} | ||
|
||
fun <K, V> Iterable<Pair<K, V>>.toFastMap(): Object2ObjectOpenHashMap<K, V> { | ||
if (this is Collection) { | ||
return when (size) { | ||
0 -> Object2ObjectOpenHashMap() | ||
1 -> fastMapOf(if (this is List) this[0] else iterator().next()) | ||
else -> toMap(Object2ObjectOpenHashMap<K, V>(mapCapacity(size))) | ||
} | ||
} | ||
return toMap(LinkedHashMap<K, V>()).optimizeReadOnlyMap() | ||
} | ||
|
||
fun <K, V> fastMapOf(pair: Pair<K, V>): Object2ObjectOpenHashMap<K, V> = Object2ObjectOpenHashMap<K, V>().apply { put(pair.first, pair.second) } | ||
|
||
fun mapCapacity(expectedSize: Int): Int = when { | ||
// We are not coercing the value to a valid one and not throwing an exception. It is up to the caller to | ||
// properly handle negative values. | ||
expectedSize < 0 -> expectedSize | ||
expectedSize < 3 -> expectedSize + 1 | ||
expectedSize < INT_MAX_POWER_OF_TWO -> ((expectedSize / 0.75F) + 1.0F).toInt() | ||
// any large value | ||
else -> Int.MAX_VALUE | ||
} | ||
|
||
internal fun <K, V> Map<K, V>.optimizeReadOnlyMap() = when (size) { | ||
0 -> Object2ObjectOpenHashMap() | ||
1 -> Object2ObjectOpenHashMap(with(entries.iterator().next()) { Collections.singletonMap(key, value) }) | ||
else -> Object2ObjectOpenHashMap(this) | ||
} | ||
|
||
private const val INT_MAX_POWER_OF_TWO: Int = 1 shl (Int.SIZE_BITS - 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters