feat: Add pickobulus blocker on private island
This commit is contained in:
@@ -92,12 +92,12 @@ object MC {
|
||||
inline val inGameHud: InGameHud get() = instance.inGameHud
|
||||
inline val font get() = instance.textRenderer
|
||||
inline val soundManager get() = instance.soundManager
|
||||
inline val player: ClientPlayerEntity? get() = instance.player
|
||||
inline val player: ClientPlayerEntity? get() = TestUtil.unlessTesting { instance.player }
|
||||
inline val camera: Entity? get() = instance.cameraEntity
|
||||
inline val guiAtlasManager get() = instance.guiAtlasManager
|
||||
inline val world: ClientWorld? get() = instance.world
|
||||
inline val world: ClientWorld? get() = TestUtil.unlessTesting { instance.world }
|
||||
inline var screen: Screen?
|
||||
get() = instance.currentScreen
|
||||
get() = TestUtil.unlessTesting{ instance.currentScreen }
|
||||
set(value) = instance.setScreen(value)
|
||||
val screenName get() = screen?.title?.unformattedString?.trim()
|
||||
inline val handledScreen: HandledScreen<*>? get() = instance.currentScreen as? HandledScreen<*>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package moe.nea.firmament.util
|
||||
|
||||
object TestUtil {
|
||||
inline fun <T> unlessTesting(block: () -> T): T? = if (isInTest) null else block()
|
||||
val isInTest =
|
||||
Thread.currentThread().stackTrace.any {
|
||||
it.className.startsWith("org.junit.") || it.className.startsWith("io.kotest.")
|
||||
|
||||
131
src/main/kotlin/util/json/KJsonOps.kt
Normal file
131
src/main/kotlin/util/json/KJsonOps.kt
Normal file
@@ -0,0 +1,131 @@
|
||||
package moe.nea.firmament.util.json
|
||||
|
||||
import com.google.gson.internal.LazilyParsedNumber
|
||||
import com.mojang.datafixers.util.Pair
|
||||
import com.mojang.serialization.DataResult
|
||||
import com.mojang.serialization.DynamicOps
|
||||
import java.util.stream.Stream
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonNull
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.boolean
|
||||
import kotlinx.serialization.json.booleanOrNull
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
class KJsonOps : DynamicOps<JsonElement> {
|
||||
companion object {
|
||||
val INSTANCE = KJsonOps()
|
||||
}
|
||||
|
||||
override fun empty(): JsonElement {
|
||||
return JsonNull
|
||||
}
|
||||
|
||||
override fun createNumeric(num: Number): JsonElement {
|
||||
return JsonPrimitive(num)
|
||||
}
|
||||
|
||||
override fun createString(str: String): JsonElement {
|
||||
return JsonPrimitive(str)
|
||||
}
|
||||
|
||||
override fun remove(input: JsonElement, key: String): JsonElement {
|
||||
if (input is JsonObject) {
|
||||
return JsonObject(input.filter { it.key != key })
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
||||
|
||||
override fun createList(stream: Stream<JsonElement>): JsonElement {
|
||||
return JsonArray(stream.toList())
|
||||
}
|
||||
|
||||
override fun getStream(input: JsonElement): DataResult<Stream<JsonElement>> {
|
||||
if (input is JsonArray)
|
||||
return DataResult.success(input.stream())
|
||||
return DataResult.error { "Not a json array: $input" }
|
||||
}
|
||||
|
||||
override fun createMap(map: Stream<Pair<JsonElement, JsonElement>>): JsonElement {
|
||||
return JsonObject(map.asSequence()
|
||||
.map { ((it.first as JsonPrimitive).content) to it.second }
|
||||
.toMap())
|
||||
}
|
||||
|
||||
override fun getMapValues(input: JsonElement): DataResult<Stream<Pair<JsonElement, JsonElement>>> {
|
||||
if (input is JsonObject) {
|
||||
return DataResult.success(input.entries.stream().map { Pair.of(createString(it.key), it.value) })
|
||||
}
|
||||
return DataResult.error { "Not a JSON object: $input" }
|
||||
}
|
||||
|
||||
override fun mergeToMap(map: JsonElement, key: JsonElement, value: JsonElement): DataResult<JsonElement> {
|
||||
if (key !is JsonPrimitive || key.isString) {
|
||||
return DataResult.error { "key is not a string: $key" }
|
||||
}
|
||||
val jKey = key.content
|
||||
val extra = mapOf(jKey to value)
|
||||
if (map == empty()) {
|
||||
return DataResult.success(JsonObject(extra))
|
||||
}
|
||||
if (map is JsonObject) {
|
||||
return DataResult.success(JsonObject(map + extra))
|
||||
}
|
||||
return DataResult.error { "mergeToMap called with not a map: $map" }
|
||||
}
|
||||
|
||||
override fun mergeToList(list: JsonElement, value: JsonElement): DataResult<JsonElement> {
|
||||
if (list == empty())
|
||||
return DataResult.success(JsonArray(listOf(value)))
|
||||
if (list is JsonArray) {
|
||||
return DataResult.success(JsonArray(list + value))
|
||||
}
|
||||
return DataResult.error { "mergeToList called with not a list: $list" }
|
||||
}
|
||||
|
||||
override fun getStringValue(input: JsonElement): DataResult<String> {
|
||||
if (input is JsonPrimitive && input.isString) {
|
||||
return DataResult.success(input.content)
|
||||
}
|
||||
return DataResult.error { "Not a string: $input" }
|
||||
}
|
||||
|
||||
override fun getNumberValue(input: JsonElement): DataResult<Number> {
|
||||
if (input is JsonPrimitive && !input.isString && input.booleanOrNull == null)
|
||||
return DataResult.success(LazilyParsedNumber(input.content))
|
||||
return DataResult.error { "not a number: $input" }
|
||||
}
|
||||
|
||||
override fun createBoolean(value: Boolean): JsonElement {
|
||||
return JsonPrimitive(value)
|
||||
}
|
||||
|
||||
override fun getBooleanValue(input: JsonElement): DataResult<Boolean> {
|
||||
if (input is JsonPrimitive) {
|
||||
if (input.booleanOrNull != null)
|
||||
return DataResult.success(input.boolean)
|
||||
return super.getBooleanValue(input)
|
||||
}
|
||||
return DataResult.error { "Not a boolean: $input" }
|
||||
}
|
||||
|
||||
override fun <U : Any?> convertTo(output: DynamicOps<U>, input: JsonElement): U {
|
||||
if (input is JsonObject)
|
||||
return output.createMap(
|
||||
input.entries.stream().map { Pair.of(output.createString(it.key), convertTo(output, it.value)) })
|
||||
if (input is JsonArray)
|
||||
return output.createList(input.stream().map { convertTo(output, it) })
|
||||
if (input is JsonNull)
|
||||
return output.empty()
|
||||
if (input is JsonPrimitive) {
|
||||
if (input.isString)
|
||||
return output.createString(input.content)
|
||||
if (input.booleanOrNull != null)
|
||||
return output.createBoolean(input.boolean)
|
||||
}
|
||||
error("Unknown json value: $input")
|
||||
}
|
||||
}
|
||||
@@ -32,10 +32,15 @@ value class ItemType private constructor(val name: String) {
|
||||
val SWORD = ofName("SWORD")
|
||||
val DRILL = ofName("DRILL")
|
||||
val PICKAXE = ofName("PICKAXE")
|
||||
val GAUNTLET = ofName("GAUNTLET")
|
||||
|
||||
/**
|
||||
* This one is not really official (it never shows up in game).
|
||||
*/
|
||||
val PET = ofName("PET")
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user