This commit is contained in:
nea
2022-10-09 04:58:37 +02:00
parent 4d73331a44
commit ebffedd08c
8 changed files with 81 additions and 21 deletions

View File

@@ -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

View File

@@ -0,0 +1,5 @@
package moe.nea.notenoughupdates.events
class WorldReadyEvent : NEUEvent() {
companion object : NEUEventBus<WorldReadyEvent>()
}

View File

@@ -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())
}
}

View File

@@ -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 {
try {
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)))
}
?: return brokenItemStack(this)
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)
}
}
fun NEUItem.asItemStack(): ItemStack {

View File

@@ -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 {

View File

@@ -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
)
)
}

View File

@@ -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")

View File

@@ -3,6 +3,7 @@
"package": "moe.nea.notenoughupdates.mixins",
"compatibilityLevel": "JAVA_16",
"client": [
"MixinClientPlayNetworkHandler",
"MixinMessageHandler",
"MixinMinecraft",
"MixinWorldRenderer"