aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/util')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt18
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt23
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt30
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt12
4 files changed, 42 insertions, 41 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
index 07a9b4c..7827708 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
@@ -5,9 +5,10 @@ import kotlinx.serialization.SerializationException
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.events.NEUScreenEvents
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
-import net.minecraft.client.Minecraft
-import net.minecraft.commands.CommandSource
-import net.minecraft.network.chat.Component
+import net.minecraft.client.MinecraftClient
+import net.minecraft.command.CommandSource
+import net.minecraft.server.command.CommandOutput
+import net.minecraft.text.Text
import java.io.IOException
import java.nio.file.Path
import java.util.concurrent.CopyOnWriteArrayList
@@ -102,10 +103,10 @@ abstract class ConfigHolder<T>(
}
}
- private fun warnForResetConfigs(player: CommandSource) {
+ private fun warnForResetConfigs(player: CommandOutput) {
if (badLoads.isNotEmpty()) {
- player.sendSystemMessage(
- Component.literal(
+ player.sendMessage(
+ Text.literal(
"The following configs have been reset: ${badLoads.joinToString(", ")}. " +
"This can be intentional, but probably isn't."
)
@@ -117,7 +118,7 @@ abstract class ConfigHolder<T>(
fun registerEvents() {
NEUScreenEvents.SCREEN_OPEN.register(NEUScreenEvents.OnScreenOpen { old, new ->
performSaves()
- val p = Minecraft.getInstance().player
+ val p = MinecraftClient.getInstance().player
if (p != null) {
warnForResetConfigs(p)
}
@@ -128,6 +129,5 @@ abstract class ConfigHolder<T>(
})
}
-
}
-} \ No newline at end of file
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
index d5b8881..2fbff87 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
@@ -1,23 +1,24 @@
package moe.nea.notenoughupdates.util
-import net.minecraft.nbt.CompoundTag
-import net.minecraft.nbt.ListTag
-import net.minecraft.nbt.StringTag
-import net.minecraft.network.chat.Component
-import net.minecraft.world.item.ItemStack
+import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NbtCompound
+import net.minecraft.nbt.NbtList
+import net.minecraft.nbt.NbtString
+import net.minecraft.text.Text
-fun ItemStack.appendLore(args: List<Component>) {
- val compoundTag = getOrCreateTagElement("display")
- val loreList = compoundTag.getOrCreateList("Lore", StringTag.TAG_STRING)
+
+fun ItemStack.appendLore(args: List<Text>) {
+ val compoundTag = getOrCreateSubNbt("display")
+ val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE)
for (arg in args) {
- loreList.add(StringTag.valueOf(Component.Serializer.toJson(arg)))
+ loreList.add(NbtString.of(Text.Serializer.toJson(arg)))
}
}
-fun CompoundTag.getOrCreateList(label: String, tag: Byte): ListTag = getList(label, tag.toInt()).also {
+fun NbtCompound.getOrCreateList(label: String, tag: Byte): NbtList = getList(label, tag.toInt()).also {
put(label, it)
}
-fun CompoundTag.getOrCreateCompoundTag(label: String): CompoundTag = getCompound(label).also {
+fun NbtCompound.getOrCreateCompoundTag(label: String): NbtCompound = getCompound(label).also {
put(label, it)
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt
index a4ec7e1..99409e0 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt
@@ -81,7 +81,7 @@ class LegacyTagParser private constructor(string: String) {
companion object {
val digitRange = '0'..'9'
- fun parse(string: String): CompoundTag {
+ fun parse(string: String): NbtCompound {
return LegacyTagParser(string).baseTag
}
}
@@ -90,11 +90,11 @@ class LegacyTagParser private constructor(string: String) {
racer.consumeWhile { Character.isWhitespace(it.last()) } // Only check last since other chars are always checked before.
}
- fun parseTag(): CompoundTag {
+ fun parseTag(): NbtCompound {
skipWhitespace()
racer.expect("{", "Expected '{’ at start of tag")
skipWhitespace()
- val tag = CompoundTag()
+ val tag = NbtCompound()
while (!racer.tryConsume("}")) {
skipWhitespace()
val lhs = parseIdentifier()
@@ -109,7 +109,7 @@ class LegacyTagParser private constructor(string: String) {
return tag
}
- private fun parseAny(): Tag {
+ private fun parseAny(): NbtElement {
skipWhitespace()
val nextChar = racer.peekReq(1) ?: racer.error("Expected new object, found EOF")
return when {
@@ -121,11 +121,11 @@ class LegacyTagParser private constructor(string: String) {
}
}
- fun parseList(): ListTag {
+ fun parseList(): NbtList {
skipWhitespace()
racer.expect("[", "Expected '[' at start of tag")
skipWhitespace()
- val list = ListTag()
+ val list = NbtList()
while (!racer.tryConsume("]")) {
skipWhitespace()
racer.pushState()
@@ -170,8 +170,8 @@ class LegacyTagParser private constructor(string: String) {
return sb.toString()
}
- fun parseStringTag(): StringTag {
- return StringTag.valueOf(parseQuotedString())
+ fun parseStringTag(): NbtString {
+ return NbtString.of(parseQuotedString())
}
object Patterns {
@@ -185,7 +185,7 @@ class LegacyTagParser private constructor(string: String) {
val ROUGH_PATTERN = "[-+]?[0-9]*\\.?[0-9]+[dDbBfFlLsS]?".toRegex()
}
- fun parseNumericTag(): NumericTag {
+ fun parseNumericTag(): AbstractNbtNumber {
skipWhitespace()
val textForm = racer.consumeWhile { Patterns.ROUGH_PATTERN.matchEntire(it) != null }
if (textForm.isEmpty()) {
@@ -193,27 +193,27 @@ class LegacyTagParser private constructor(string: String) {
}
val doubleMatch = Patterns.DOUBLE.matchEntire(textForm) ?: Patterns.DOUBLE_UNTYPED.matchEntire(textForm)
if (doubleMatch != null) {
- return DoubleTag.valueOf(doubleMatch.groups[1]!!.value.toDouble())
+ return NbtDouble.of(doubleMatch.groups[1]!!.value.toDouble())
}
val floatMatch = Patterns.FLOAT.matchEntire(textForm)
if (floatMatch != null) {
- return FloatTag.valueOf(floatMatch.groups[1]!!.value.toFloat())
+ return NbtFloat.of(floatMatch.groups[1]!!.value.toFloat())
}
val byteMatch = Patterns.BYTE.matchEntire(textForm)
if (byteMatch != null) {
- return ByteTag.valueOf(byteMatch.groups[1]!!.value.toByte())
+ return NbtByte.of(byteMatch.groups[1]!!.value.toByte())
}
val longMatch = Patterns.LONG.matchEntire(textForm)
if (longMatch != null) {
- return LongTag.valueOf(longMatch.groups[1]!!.value.toLong())
+ return NbtLong.of(longMatch.groups[1]!!.value.toLong())
}
val shortMatch = Patterns.SHORT.matchEntire(textForm)
if (shortMatch != null) {
- return ShortTag.valueOf(shortMatch.groups[1]!!.value.toShort())
+ return NbtShort.of(shortMatch.groups[1]!!.value.toShort())
}
val integerMatch = Patterns.INTEGER.matchEntire(textForm)
if (integerMatch != null) {
- return IntTag.valueOf(integerMatch.groups[1]!!.value.toInt())
+ return NbtInt.of(integerMatch.groups[1]!!.value.toInt())
}
throw IllegalStateException("Could not properly parse numeric tag '$textForm', despite passing rough verification. This is a bug in the LegacyTagParser")
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt
index 95dc982..6c86c41 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt
@@ -2,19 +2,19 @@ package moe.nea.notenoughupdates.util
import moe.nea.notenoughupdates.NotEnoughUpdates
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
-import net.minecraft.client.Minecraft
-import net.minecraft.client.gui.screens.Screen
+import net.minecraft.client.MinecraftClient
+import net.minecraft.client.gui.screen.Screen
object ScreenUtil {
init {
ClientTickEvents.START_CLIENT_TICK.register(::onTick)
}
- private fun onTick(minecraft: Minecraft) {
+ private fun onTick(minecraft: MinecraftClient) {
if (nextOpenedGui != null) {
val p = minecraft.player
- if (p?.containerMenu != null) {
- p.closeContainer()
+ if (p?.currentScreenHandler != null) {
+ p.closeHandledScreen()
}
minecraft.setScreen(nextOpenedGui)
nextOpenedGui = null
@@ -33,4 +33,4 @@ object ScreenUtil {
}
-} \ No newline at end of file
+}