Add SkyBlockIsland type

[no changelog]
This commit is contained in:
Linnea Gräf
2024-08-04 21:10:08 +02:00
parent 95c1b75a14
commit 9b277bd897
8 changed files with 73 additions and 28 deletions

View File

@@ -8,13 +8,9 @@
package moe.nea.firmament.mixins; package moe.nea.firmament.mixins;
import moe.nea.firmament.events.BakeExtraModelsEvent; import moe.nea.firmament.events.BakeExtraModelsEvent;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.model.ModelLoader; import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.resource.Resource;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -24,21 +20,20 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction;
@Mixin(ModelLoader.class) @Mixin(ModelLoader.class)
public abstract class CustomModelBakerPatch { public abstract class CustomModelBakerPatch {
@Shadow
@Final
private Map<ModelIdentifier, UnbakedModel> modelsToBake;
@Shadow @Shadow
protected abstract void loadItemModel(ModelIdentifier id); protected abstract void loadItemModel(ModelIdentifier id);
@Shadow @Shadow
abstract UnbakedModel getOrLoadModel(Identifier id); abstract UnbakedModel getOrLoadModel(Identifier id);
@Shadow
@Final
private Map<ModelIdentifier, UnbakedModel> modelsToBake;
@Inject(method = "bake", at = @At("HEAD")) @Inject(method = "bake", at = @At("HEAD"))
public void onBake(ModelLoader.SpriteGetter spliteGetter, CallbackInfo ci) { public void onBake(ModelLoader.SpriteGetter spliteGetter, CallbackInfo ci) {
BakeExtraModelsEvent.Companion.publish(new BakeExtraModelsEvent(this::loadItemModel)); BakeExtraModelsEvent.Companion.publish(new BakeExtraModelsEvent(this::loadItemModel));

View File

@@ -19,6 +19,7 @@ import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.events.subscription.SubscriptionOwner import moe.nea.firmament.events.subscription.SubscriptionOwner
import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.WarpUtil import moe.nea.firmament.util.WarpUtil
import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.render.RenderInWorldContext
@@ -34,7 +35,7 @@ object AncestralSpadeSolver : SubscriptionOwner {
private var lastTeleportAttempt = TimeMark.farPast() private var lastTeleportAttempt = TimeMark.farPast()
fun isEnabled() = fun isEnabled() =
DianaWaypoints.TConfig.ancestralSpadeSolver && SBData.skyblockLocation == "hub" DianaWaypoints.TConfig.ancestralSpadeSolver && SBData.skyblockLocation == SkyBlockIsland.HUB
@Subscribe @Subscribe
fun onKeyBind(event: WorldKeyboardEvent) { fun onKeyBind(event: WorldKeyboardEvent) {
@@ -42,7 +43,7 @@ object AncestralSpadeSolver : SubscriptionOwner {
if (!event.matches(DianaWaypoints.TConfig.ancestralSpadeTeleport)) return if (!event.matches(DianaWaypoints.TConfig.ancestralSpadeTeleport)) return
if (lastTeleportAttempt.passedTime() < 3.seconds) return if (lastTeleportAttempt.passedTime() < 3.seconds) return
WarpUtil.teleportToNearestWarp("hub", nextGuess ?: return) WarpUtil.teleportToNearestWarp(SkyBlockIsland.HUB, nextGuess ?: return)
lastTeleportAttempt = TimeMark.now() lastTeleportAttempt = TimeMark.now()
} }

View File

@@ -31,6 +31,7 @@ import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.CommonSoundEffects import moe.nea.firmament.util.CommonSoundEffects
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.data.ProfileSpecificDataHolder
import moe.nea.firmament.util.item.displayNameAccordingToNbt import moe.nea.firmament.util.item.displayNameAccordingToNbt
import moe.nea.firmament.util.item.loreAccordingToNbt import moe.nea.firmament.util.item.loreAccordingToNbt
@@ -66,7 +67,7 @@ object SlotLocking : FirmamentFeature {
val lockedSlots val lockedSlots
get() = when (SBData.skyblockLocation) { get() = when (SBData.skyblockLocation) {
"rift" -> DConfig.data?.lockedSlotsRift SkyBlockIsland.RIFT -> DConfig.data?.lockedSlotsRift
null -> null null -> null
else -> DConfig.data?.lockedSlots else -> DConfig.data?.lockedSlots
} }

View File

@@ -1,5 +1,6 @@
/* /*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
* *
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
@@ -20,6 +21,7 @@ import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.blockPos import moe.nea.firmament.util.blockPos
import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.data.ProfileSpecificDataHolder
import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.render.RenderInWorldContext
@@ -32,7 +34,7 @@ object FairySouls : FirmamentFeature {
@Serializable @Serializable
data class Data( data class Data(
val foundSouls: MutableMap<String, MutableSet<Int>> = mutableMapOf() val foundSouls: MutableMap<SkyBlockIsland, MutableSet<Int>> = mutableMapOf()
) )
override val config: ManagedConfig override val config: ManagedConfig
@@ -55,7 +57,7 @@ object FairySouls : FirmamentFeature {
val playerReach = 5 val playerReach = 5
val playerReachSquared = playerReach * playerReach val playerReachSquared = playerReach * playerReach
var currentLocationName: String? = null var currentLocationName: SkyBlockIsland? = null
var currentLocationSouls: List<Coordinate> = emptyList() var currentLocationSouls: List<Coordinate> = emptyList()
var currentMissingSouls: List<Coordinate> = emptyList() var currentMissingSouls: List<Coordinate> = emptyList()
@@ -71,7 +73,7 @@ object FairySouls : FirmamentFeature {
fun updateWorldSouls() { fun updateWorldSouls() {
currentLocationSouls = emptyList() currentLocationSouls = emptyList()
val loc = currentLocationName ?: return val loc = currentLocationName ?: return
currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc] ?: return currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc.locrawMode] ?: return
} }
fun findNearestClickableSoul(): Coordinate? { fun findNearestClickableSoul(): Coordinate? {
@@ -79,7 +81,7 @@ object FairySouls : FirmamentFeature {
val pos = player.pos val pos = player.pos
val location = SBData.skyblockLocation ?: return null val location = SBData.skyblockLocation ?: return null
val soulLocations: List<Coordinate> = val soulLocations: List<Coordinate> =
RepoManager.neuRepo.constants.fairySouls.soulLocations[location] ?: return null RepoManager.neuRepo.constants.fairySouls.soulLocations[location.locrawMode] ?: return null
return soulLocations return soulLocations
.map { it to it.blockPos.getSquaredDistance(pos) } .map { it to it.blockPos.getSquaredDistance(pos) }
.filter { it.second < playerReachSquared } .filter { it.second < playerReachSquared }
@@ -101,11 +103,6 @@ object FairySouls : FirmamentFeature {
fun onWorldRender(it: WorldRenderLastEvent) { fun onWorldRender(it: WorldRenderLastEvent) {
if (!TConfig.displaySouls) return if (!TConfig.displaySouls) return
renderInWorld(it) { renderInWorld(it) {
text(Vec3d(0.0, 0.0, 0.0),
Text.literal("Test String"),
Text.literal("Short"),
Text.literal("just lik"),
verticalAlign = RenderInWorldContext.VerticalAlign.BOTTOM)
color(1F, 1F, 0F, 0.8F) color(1F, 1F, 0F, 0.8F)
currentMissingSouls.forEach { currentMissingSouls.forEach {
block(it.blockPos) block(it.blockPos)

View File

@@ -1,5 +1,6 @@
/* /*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
* *
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
@@ -7,8 +8,10 @@
package moe.nea.firmament.util package moe.nea.firmament.util
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable @Serializable
data class Locraw(val server: String, val gametype: String? = null, val mode: String? = null, val map: String? = null) { data class Locraw(val server: String, val gametype: String? = null, val mode: String? = null, val map: String? = null) {
val skyblockLocation = if (gametype == "SKYBLOCK") mode else null @Transient
val skyblockLocation = if (gametype == "SKYBLOCK") mode?.let(SkyBlockIsland::forMode) else null
} }

View File

@@ -1,5 +1,6 @@
/* /*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
* *
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
@@ -28,7 +29,7 @@ object SBData {
private var hasReceivedProfile = false private var hasReceivedProfile = false
private var hasSentLocraw = false private var hasSentLocraw = false
var locraw: Locraw? = null var locraw: Locraw? = null
val skyblockLocation: String? get() = locraw?.skyblockLocation val skyblockLocation: SkyBlockIsland? get() = locraw?.skyblockLocation
val hasValidLocraw get() = locraw?.server !in listOf("limbo", null) val hasValidLocraw get() = locraw?.server !in listOf("limbo", null)
val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK" val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK"

View File

@@ -0,0 +1,47 @@
/*
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.util
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import moe.nea.firmament.repo.RepoManager
@Serializable(with = SkyBlockIsland.Serializer::class)
class SkyBlockIsland
private constructor(
val locrawMode: String,
) {
object Serializer : KSerializer<SkyBlockIsland> {
override val descriptor: SerialDescriptor
get() = PrimitiveSerialDescriptor("SkyBlockIsland", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): SkyBlockIsland {
return forMode(decoder.decodeString())
}
override fun serialize(encoder: Encoder, value: SkyBlockIsland) {
encoder.encodeString(value.locrawMode)
}
}
companion object {
private val allIslands = mutableMapOf<String, SkyBlockIsland>()
fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland)
val HUB = forMode("hub")
val PRIVATE_ISLAND = forMode("dynamic")
val RIFT = forMode("rift")
}
val userFriendlyName
get() = RepoManager.neuRepo.constants.islands.areaNames
.getOrDefault(locrawMode, locrawMode)
}

View File

@@ -30,9 +30,9 @@ object WarpUtil {
private var lastAttemptedWarp = "" private var lastAttemptedWarp = ""
private var lastWarpAttempt = TimeMark.farPast() private var lastWarpAttempt = TimeMark.farPast()
fun findNearestWarp(locrawMode: String, pos: Position): Islands.Warp? { fun findNearestWarp(island: SkyBlockIsland, pos: Position): Islands.Warp? {
return warps.minByOrNull { return warps.minByOrNull {
if (locrawMode != it.mode || (DConfig.data?.excludedWarps?.contains(it.warp) == true)) { if (island.locrawMode != it.mode || (DConfig.data?.excludedWarps?.contains(it.warp) == true)) {
return@minByOrNull Double.MAX_VALUE return@minByOrNull Double.MAX_VALUE
} else { } else {
return@minByOrNull squaredDist(pos, it) return@minByOrNull squaredDist(pos, it)
@@ -47,10 +47,10 @@ object WarpUtil {
return dx * dx + dy * dy + dz * dz return dx * dx + dy * dy + dz * dz
} }
fun teleportToNearestWarp(locrawMode: String, pos: Position) { fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) {
val nearestWarp = findNearestWarp(locrawMode, pos) ?: return val nearestWarp = findNearestWarp(island, pos) ?: return
if (locrawMode == SBData.skyblockLocation if (island == SBData.skyblockLocation
&& sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp)) && sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp))
) { ) {
return return