aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt2
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/WorldReadyEvent.kt5
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinClientPlayNetworkHandler.kt17
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt27
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt17
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt28
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/config/ProfileSpecificConfigHolder.kt1
7 files changed, 78 insertions, 19 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt b/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt
index 6c75f20..997d86e 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt
@@ -29,7 +29,7 @@ fun neuCommand() = literal("neu") {
}
}
thenLiteral("dev") {
- val sbData = thenLiteral("sbdata") {
+ thenLiteral("sbdata") {
thenExecute {
source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.profile", SBData.profileCuteName))
val locrawInfo = SBData.locraw
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/WorldReadyEvent.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/WorldReadyEvent.kt
new file mode 100644
index 0000000..5f305f1
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/WorldReadyEvent.kt
@@ -0,0 +1,5 @@
+package moe.nea.notenoughupdates.events
+
+class WorldReadyEvent : NEUEvent() {
+ companion object : NEUEventBus<WorldReadyEvent>()
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinClientPlayNetworkHandler.kt b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinClientPlayNetworkHandler.kt
new file mode 100644
index 0000000..b94ff65
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinClientPlayNetworkHandler.kt
@@ -0,0 +1,17 @@
+package moe.nea.notenoughupdates.mixins
+
+import org.spongepowered.asm.mixin.Mixin
+import org.spongepowered.asm.mixin.injection.At
+import org.spongepowered.asm.mixin.injection.Inject
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
+import net.minecraft.client.network.ClientPlayNetworkHandler
+import net.minecraft.network.packet.s2c.play.PlayerSpawnPositionS2CPacket
+import moe.nea.notenoughupdates.events.WorldReadyEvent
+
+@Mixin(ClientPlayNetworkHandler::class)
+class MixinClientPlayNetworkHandler {
+ @Inject(method = ["onPlayerSpawnPosition"], at = [At("RETURN")])
+ fun onOnPlayerSpawnPosition(packet: PlayerSpawnPositionS2CPacket, ci: CallbackInfo) {
+ WorldReadyEvent.publish(WorldReadyEvent())
+ }
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
index 7dbfce3..5f9159e 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
@@ -56,18 +56,27 @@ object ItemCache : IReloadable {
null
}
+ private fun brokenItemStack(neuItem: NEUItem): ItemStack {
+ return ItemStack(Items.PAINTING).apply {
+ setCustomName(Text.literal(neuItem.displayName))
+ appendLore(listOf(Text.translatable("notenoughupdates.repo.brokenitem", neuItem.skyblockItemId)))
+ }
+ }
+
private fun NEUItem.asItemStackNow(): ItemStack {
- val oldItemTag = get10809CompoundTag()
- val modernItemTag = oldItemTag.transformFrom10809ToModern()
- ?: return ItemStack(Items.PAINTING).apply {
- setCustomName(Text.literal(this@asItemStackNow.displayName))
- appendLore(listOf(Text.translatable("notenoughupdates.repo.brokenitem", skyblockItemId)))
+ try {
+ val oldItemTag = get10809CompoundTag()
+ val modernItemTag = oldItemTag.transformFrom10809ToModern()
+ ?: return brokenItemStack(this)
+ val itemInstance = ItemStack.fromNbt(modernItemTag)
+ if (itemInstance.nbt?.contains("Enchantments") == true) {
+ itemInstance.enchantments.add(NbtCompound())
}
- val itemInstance = ItemStack.fromNbt(modernItemTag)
- if (itemInstance.nbt?.contains("Enchantments") == true) {
- itemInstance.enchantments.add(NbtCompound())
+ return itemInstance
+ } catch (e: Exception) {
+ e.printStackTrace()
+ return brokenItemStack(this)
}
- return itemInstance
}
fun NEUItem.asItemStack(): ItemStack {
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt
index 99409e0..9f3379b 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt
@@ -1,7 +1,17 @@
package moe.nea.notenoughupdates.util
-import net.minecraft.nbt.*
import java.util.*
+import net.minecraft.nbt.AbstractNbtNumber
+import net.minecraft.nbt.NbtByte
+import net.minecraft.nbt.NbtCompound
+import net.minecraft.nbt.NbtDouble
+import net.minecraft.nbt.NbtElement
+import net.minecraft.nbt.NbtFloat
+import net.minecraft.nbt.NbtInt
+import net.minecraft.nbt.NbtList
+import net.minecraft.nbt.NbtLong
+import net.minecraft.nbt.NbtShort
+import net.minecraft.nbt.NbtString
class LegacyTagParser private constructor(string: String) {
data class TagParsingException(val baseString: String, val offset: Int, val mes0: String) :
@@ -80,7 +90,7 @@ class LegacyTagParser private constructor(string: String) {
val baseTag = parseTag()
companion object {
- val digitRange = '0'..'9'
+ val digitRange = "0123456789-"
fun parse(string: String): NbtCompound {
return LegacyTagParser(string).baseTag
}
@@ -161,6 +171,7 @@ class LegacyTagParser private constructor(string: String) {
}
sb.append(escaped)
}
+
null -> racer.error("Unfinished string")
else -> {
sb.append(peek)
@@ -182,7 +193,7 @@ class LegacyTagParser private constructor(string: String) {
val SHORT = "([-+]?[0-9]+)[s|S]".toRegex()
val INTEGER = "([-+]?[0-9]+)".toRegex()
val DOUBLE_UNTYPED = "([-+]?[0-9]*\\.?[0-9]+)".toRegex()
- val ROUGH_PATTERN = "[-+]?[0-9]*\\.?[0-9]+[dDbBfFlLsS]?".toRegex()
+ val ROUGH_PATTERN = "[-+]?[0-9]*\\.?[0-9]*[dDbBfFlLsS]?".toRegex()
}
fun parseNumericTag(): AbstractNbtNumber {
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt
index 5391206..4c31b56 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt
@@ -1,15 +1,18 @@
package moe.nea.notenoughupdates.util
-import dev.architectury.event.events.client.ClientPlayerEvent
+import java.time.Instant
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource
+import net.minecraft.network.message.ArgumentSignatureDataMap
+import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.events.ServerChatLineReceivedEvent
import moe.nea.notenoughupdates.events.SkyblockServerUpdateEvent
+import moe.nea.notenoughupdates.events.WorldReadyEvent
@OptIn(ExperimentalTime::class)
object SBData {
@@ -32,15 +35,15 @@ object SBData {
val lLS = lastLocrawSent
if (tryReceiveLocraw(event.unformattedString) && lLS != null && lLS.elapsedNow() < locrawRoundtripTime) {
lastLocrawSent = null
- event.cancel()
+ // event.cancel()
}
}
}
- ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(ClientPlayerEvent.ClientPlayerJoin {
- locraw = null
+ WorldReadyEvent.subscribe {
sendLocraw()
- })
+ locraw = null
+ }
}
private fun tryReceiveLocraw(unformattedString: String): Boolean = try {
@@ -49,14 +52,27 @@ object SBData {
SkyblockServerUpdateEvent.publish(SkyblockServerUpdateEvent(lastLocraw, locraw))
true
} catch (e: SerializationException) {
+ e.printStackTrace()
false
} catch (e: IllegalArgumentException) {
+ e.printStackTrace()
false
}
fun sendLocraw() {
lastLocrawSent = TimeSource.Monotonic.markNow()
- MC.player?.sendCommand("locraw")
+ val nh = MC.player?.networkHandler ?: return
+ val ack = nh.consumeAcknowledgment()
+ nh.sendPacket(
+ CommandExecutionC2SPacket(
+ "locraw",
+ Instant.now(),
+ 0L,
+ ArgumentSignatureDataMap.EMPTY,
+ false,
+ ack
+ )
+ )
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/config/ProfileSpecificConfigHolder.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/config/ProfileSpecificConfigHolder.kt
index 44a79c4..6a39e0a 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/config/ProfileSpecificConfigHolder.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/config/ProfileSpecificConfigHolder.kt
@@ -29,6 +29,7 @@ abstract class ProfileSpecificConfigHolder<S>(
init {
allConfigs = readValues()
readValues()
+ IConfigHolder.putConfig(this::class, this)
}
private val configDirectory: Path get() = NotEnoughUpdates.CONFIG_DIR.resolve("profiles")