aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt10
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/NEUScreenEvents.kt8
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt26
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/gui/repogui.kt22
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/hud/RepoDownloadProgress.kt4
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMinecraft.kt12
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt7
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt20
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt38
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt14
-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
14 files changed, 122 insertions, 122 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
index 125bc86..35671a3 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
@@ -23,8 +23,8 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
-import net.minecraft.commands.CommandBuildContext
-import net.minecraft.network.chat.Component
+import net.minecraft.command.CommandRegistryAccess
+import net.minecraft.text.Text
import org.apache.logging.log4j.LogManager
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder
import java.nio.file.Files
@@ -68,16 +68,16 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
private fun registerCommands(
dispatcher: CommandDispatcher<FabricClientCommandSource>,
@Suppress("UNUSED_PARAMETER")
- _ctx: CommandBuildContext
+ _ctx: CommandRegistryAccess
) {
dispatcher.register(ClientCommandManager.literal("neureload")
.then(ClientCommandManager.literal("fetch").executes {
- it.source.sendFeedback(Component.literal("Trying to redownload the repository")) // TODO better reporting
+ it.source.sendFeedback(Text.literal("Trying to redownload the repository")) // TODO better reporting
RepoManager.launchAsyncUpdate()
Command.SINGLE_SUCCESS
})
.executes {
- it.source.sendFeedback(Component.translatable("notenoughupdates.repo.reload.disk"))
+ it.source.sendFeedback(Text.translatable("notenoughupdates.repo.reload.disk"))
RepoManager.reload()
Command.SINGLE_SUCCESS
})
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/NEUScreenEvents.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/NEUScreenEvents.kt
index f118be5..64edda0 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/events/NEUScreenEvents.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/NEUScreenEvents.kt
@@ -2,13 +2,13 @@ package moe.nea.notenoughupdates.events
import moe.nea.notenoughupdates.events.NEUScreenEvents.OnScreenOpen
import net.fabricmc.fabric.api.event.EventFactory
-import net.minecraft.client.gui.screens.Screen
-import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.screen.Screen
+import net.minecraft.client.MinecraftClient
object NEUScreenEvents {
fun interface OnScreenOpen {
/**
- * Called when a new Screen is opened via [Minecraft.setScreen]. If [new] is null, this corresponds to closing a [Screen].
+ * Called when a new Screen is opened via [MinecraftClient.setScreen]. If [new] is null, this corresponds to closing a [Screen].
* @return true to prevent this event from happening.
*/
fun onScreenOpen(old: Screen?, new: Screen?): Boolean
@@ -20,4 +20,4 @@ object NEUScreenEvents {
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt
index c6c2420..3792d80 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt
@@ -10,7 +10,7 @@ import io.github.cottonmc.cotton.gui.widget.data.Insets
import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.util.ConfigHolder
-import net.minecraft.network.chat.Component
+import net.minecraft.text.Text
import kotlin.reflect.KMutableProperty1
class ConfigGui<K>(val holder: ConfigHolder<K>, val build: ConfigGui<K>.() -> Unit) : LightweightGuiDescription() {
@@ -24,48 +24,48 @@ class ConfigGui<K>(val holder: ConfigHolder<K>, val build: ConfigGui<K>.() -> Un
reload()
}
- fun title(component: Component) {
+ fun title(text: Text) {
if (col != 0) {
NotEnoughUpdates.logger.warn("Set title not at the top of the ConfigGui")
}
- val label = WLabel(component)
+ val label = WLabel(text)
label.verticalAlignment = VerticalAlignment.TOP
label.horizontalAlignment = HorizontalAlignment.CENTER
root.add(label, 0, col, 11, 1)
col++
}
- private fun label(component: Component) {
- val label = WLabel(component)
+ private fun label(text: Text) {
+ val label = WLabel(text)
label.verticalAlignment = VerticalAlignment.CENTER
root.add(label, 0, col, 5, 1)
}
- fun toggle(component: Component, prop: KMutableProperty1<K, Boolean>) {
- val toggle = WToggleButton(component)
+ fun toggle(text: Text, prop: KMutableProperty1<K, Boolean>) {
+ val toggle = WToggleButton(text)
reloadables.add { toggle.toggle = prop.get(holder.config) }
toggle.setOnToggle {
prop.set(holder.config, true)
holder.markDirty()
}
root.add(toggle, 5, col, 6, 1)
- label(component)
+ label(text)
col++
}
- fun button(component: Component, buttonText: Component, runnable: () -> Unit) {
+ fun button(text: Text, buttonText: Text, runnable: () -> Unit) {
val button = WButton(buttonText)
button.setOnClick {
runnable.invoke()
}
root.add(button, 5, col, 6, 1)
- label(component)
+ label(text)
col++
}
fun textfield(
- component: Component,
- background: Component,
+ text: Text,
+ background: Text,
prop: KMutableProperty1<K, String>,
maxLength: Int = 255
) {
@@ -80,7 +80,7 @@ class ConfigGui<K>(val holder: ConfigHolder<K>, val build: ConfigGui<K>.() -> Un
holder.markDirty()
}
root.add(textfield, 5, col, 6, 11)
- label(component)
+ label(text)
col++
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/repogui.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/repogui.kt
index 40301fd..00bc099 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/gui/repogui.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/repogui.kt
@@ -1,31 +1,31 @@
package moe.nea.notenoughupdates.gui
import moe.nea.notenoughupdates.repo.RepoManager
-import net.minecraft.network.chat.Component
+import net.minecraft.text.Text
fun repoGui(): ConfigGui<RepoManager.Config> {
return ConfigGui(RepoManager) {
- title(Component.literal("NotEnoughUpdates Repo Settings"))
- toggle(Component.literal("Auto Update"), RepoManager.Config::autoUpdate)
+ title(Text.literal("NotEnoughUpdates Repo Settings"))
+ toggle(Text.literal("Auto Update"), RepoManager.Config::autoUpdate)
textfield(
- Component.literal("Repo Username"),
- Component.literal("<github user>"),
+ Text.literal("Repo Username"),
+ Text.literal("<github user>"),
RepoManager.Config::user,
maxLength = 255
)
textfield(
- Component.literal("Repo Name"),
- Component.literal("<repo name>"),
+ Text.literal("Repo Name"),
+ Text.literal("<repo name>"),
RepoManager.Config::repo
)
textfield(
- Component.literal("Repo Branch"),
- Component.literal("<repo branch>"),
+ Text.literal("Repo Branch"),
+ Text.literal("<repo branch>"),
RepoManager.Config::branch
)
button(
- Component.literal("Reset to Defaults"),
- Component.literal("Reset"),
+ Text.literal("Reset to Defaults"),
+ Text.literal("Reset"),
) {
RepoManager.config.user = "NotEnoughUpdates"
RepoManager.config.repo = "NotEnoughUpdates-REPO"
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/hud/RepoDownloadProgress.kt b/src/main/kotlin/moe/nea/notenoughupdates/hud/RepoDownloadProgress.kt
index 462f0bc..5ef6c5b 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/hud/RepoDownloadProgress.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/hud/RepoDownloadProgress.kt
@@ -1,10 +1,10 @@
package moe.nea.notenoughupdates.hud
-import com.mojang.blaze3d.vertex.PoseStack
import io.github.cottonmc.cotton.gui.client.ScreenDrawing
import io.github.cottonmc.cotton.gui.widget.WWidget
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment
import io.github.cottonmc.cotton.gui.widget.data.Insets
+import net.minecraft.client.util.math.MatrixStack
import kotlin.math.roundToInt
import kotlin.math.sin
@@ -31,7 +31,7 @@ class ProgressBar(
}
- override fun paint(matrices: PoseStack, x: Int, y: Int, mouseX: Int, mouseY: Int) {
+ override fun paint(matrices: MatrixStack, x: Int, y: Int, mouseX: Int, mouseY: Int) {
ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF808080.toInt())
val (l, prog) = synchronized(this) {
label to (progress to total)
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMinecraft.kt b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMinecraft.kt
index f017604..21834e9 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMinecraft.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMinecraft.kt
@@ -1,19 +1,19 @@
package moe.nea.notenoughupdates.mixins
import moe.nea.notenoughupdates.events.NEUScreenEvents
-import net.minecraft.client.Minecraft
-import net.minecraft.client.gui.screens.Screen
+import net.minecraft.client.MinecraftClient
+import net.minecraft.client.gui.screen.Screen
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
@Suppress("CAST_NEVER_SUCCEEDS")
-@Mixin(Minecraft::class)
+@Mixin(MinecraftClient::class)
class MixinMinecraft {
@Inject(method = ["setScreen"], at = [At("HEAD")], cancellable = true)
- fun momo(screen: Screen?, ci: CallbackInfo) {
- if (NEUScreenEvents.SCREEN_OPEN.invoker().onScreenOpen((this as Minecraft).screen, screen))
+ fun onScreenChange(screen: Screen?, ci: CallbackInfo) {
+ if (NEUScreenEvents.SCREEN_OPEN.invoker().onScreenOpen((this as MinecraftClient).currentScreen, screen))
ci.cancel()
}
-} \ No newline at end of file
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt
index 624f5d8..475a5c9 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt
@@ -8,19 +8,18 @@ import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
import moe.nea.notenoughupdates.repo.RepoManager
-import net.minecraft.resources.ResourceLocation
-import net.minecraft.world.item.ItemStack
+import net.minecraft.item.ItemStack
+import net.minecraft.util.Identifier
class NEUReiPlugin : REIClientPlugin {
companion object {
-
fun EntryStack<NEUItem>.asItemEntry(): EntryStack<ItemStack> {
return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack())
}
- val SKYBLOCK_ITEM_TYPE_ID = ResourceLocation("notenoughupdates", "skyblockitems")
+ val SKYBLOCK_ITEM_TYPE_ID = Identifier("notenoughupdates", "skyblockitems")
}
override fun registerEntryTypes(registry: EntryTypeRegistry) {
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt
index 5ae154d..c851758 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt
@@ -1,6 +1,5 @@
package moe.nea.notenoughupdates.rei
-import com.mojang.blaze3d.vertex.PoseStack
import io.github.moulberry.repo.data.NEUItem
import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer
@@ -14,11 +13,12 @@ import me.shedaniel.rei.api.common.entry.type.EntryType
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
import moe.nea.notenoughupdates.rei.NEUReiPlugin.Companion.asItemEntry
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
-import moe.nea.notenoughupdates.repo.ItemCache.getResourceLocation
-import net.minecraft.network.chat.Component
-import net.minecraft.resources.ResourceLocation
-import net.minecraft.tags.TagKey
-import net.minecraft.world.item.ItemStack
+import moe.nea.notenoughupdates.repo.ItemCache.getIdentifier
+import net.minecraft.client.util.math.MatrixStack
+import net.minecraft.item.ItemStack
+import net.minecraft.tag.TagKey
+import net.minecraft.text.Text
+import net.minecraft.util.Identifier
import java.util.stream.Stream
object SBItemEntryDefinition : EntryDefinition<NEUItem> {
@@ -37,7 +37,7 @@ object SBItemEntryDefinition : EntryDefinition<NEUItem> {
override fun getRenderer(): EntryRenderer<NEUItem> = object : EntryRenderer<NEUItem> {
override fun render(
entry: EntryStack<NEUItem>,
- matrices: PoseStack,
+ matrices: MatrixStack,
bounds: Rectangle,
mouseX: Int,
mouseY: Int,
@@ -65,7 +65,7 @@ object SBItemEntryDefinition : EntryDefinition<NEUItem> {
return Stream.empty()
}
- override fun asFormattedText(entry: EntryStack<NEUItem>, value: NEUItem): Component {
+ override fun asFormattedText(entry: EntryStack<NEUItem>, value: NEUItem): Text {
return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemEntry(), value.asItemStack())
}
@@ -89,8 +89,8 @@ object SBItemEntryDefinition : EntryDefinition<NEUItem> {
return false
}
- override fun getIdentifier(entry: EntryStack<NEUItem>?, value: NEUItem): ResourceLocation {
- return value.getResourceLocation()
+ override fun getIdentifier(entry: EntryStack<NEUItem>?, value: NEUItem): Identifier {
+ return value.getIdentifier()
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
index 9255867..1cf6efc 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
@@ -10,36 +10,36 @@ import kotlinx.coroutines.launch
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.util.LegacyTagParser
import moe.nea.notenoughupdates.util.appendLore
-import net.minecraft.nbt.CompoundTag
+import net.minecraft.datafixer.Schemas
+import net.minecraft.datafixer.TypeReferences
+import net.minecraft.item.ItemStack
+import net.minecraft.item.Items
+import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtOps
-import net.minecraft.network.chat.Component
-import net.minecraft.resources.ResourceLocation
-import net.minecraft.util.datafix.DataFixers
-import net.minecraft.util.datafix.fixes.References
-import net.minecraft.world.item.ItemStack
-import net.minecraft.world.item.Items
+import net.minecraft.text.Text
+import net.minecraft.util.Identifier
import java.util.concurrent.ConcurrentHashMap
object ItemCache : IReloadable {
val cache: MutableMap<String, ItemStack> = ConcurrentHashMap()
- val df = DataFixers.getDataFixer()
+ val df = Schemas.getFixer()
var isFlawless = true
- private fun NEUItem.get10809CompoundTag(): CompoundTag = CompoundTag().apply {
+ private fun NEUItem.get10809CompoundTag(): NbtCompound = NbtCompound().apply {
put("tag", LegacyTagParser.parse(nbttag))
putString("id", minecraftItemId)
putByte("Count", 1)
putShort("Damage", damage.toShort())
}
- private fun CompoundTag.transformFrom10809ToModern(): CompoundTag? =
+ private fun NbtCompound.transformFrom10809ToModern(): NbtCompound? =
try {
df.update(
- References.ITEM_STACK,
+ TypeReferences.ITEM_STACK,
Dynamic(NbtOps.INSTANCE, this),
-1,
2975
- ).value as CompoundTag
+ ).value as NbtCompound
} catch (e: Exception) {
NotEnoughUpdates.logger.error("Failed to datafixer an item", e)
isFlawless = false
@@ -50,12 +50,12 @@ object ItemCache : IReloadable {
val oldItemTag = get10809CompoundTag()
val modernItemTag = oldItemTag.transformFrom10809ToModern()
?: return ItemStack(Items.PAINTING).apply {
- hoverName = Component.literal(this@asItemStackNow.displayName)
- appendLore(listOf(Component.literal("Exception rendering item: $skyblockItemId")))
+ setCustomName(Text.literal(this@asItemStackNow.displayName))
+ appendLore(listOf(Text.literal("Exception rendering item: $skyblockItemId")))
}
- val itemInstance = ItemStack.of(modernItemTag)
- if (itemInstance.tag?.contains("Enchantments") == true) {
- itemInstance.enchantmentTags.add(CompoundTag())
+ val itemInstance = ItemStack.fromNbt(modernItemTag)
+ if (itemInstance.nbt?.contains("Enchantments") == true) {
+ itemInstance.enchantments.add(NbtCompound())
}
return itemInstance
}
@@ -69,8 +69,8 @@ object ItemCache : IReloadable {
return s
}
- fun NEUItem.getResourceLocation() =
- ResourceLocation("skyblockitem", skyblockItemId.lowercase().replace(";", "__"))
+ fun NEUItem.getIdentifier() =
+ Identifier("skyblockitem", skyblockItemId.lowercase().replace(";", "__"))
var job: Job? = null
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
index 2c0b4ec..ac595ca 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
@@ -11,9 +11,9 @@ import moe.nea.notenoughupdates.NotEnoughUpdates.logger
import moe.nea.notenoughupdates.hud.ProgressBar
import moe.nea.notenoughupdates.util.ConfigHolder
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
-import net.minecraft.client.Minecraft
-import net.minecraft.network.chat.Component
-import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket
+import net.minecraft.client.MinecraftClient
+import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket
+import net.minecraft.text.Text
object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Config) {
@Serializable
@@ -43,8 +43,8 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
}
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
- return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(
- ClientboundUpdateRecipesPacket(mutableListOf())
+ return MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().networkHandler?.onSynchronizeRecipes(
+ SynchronizeRecipesS2CPacket(mutableListOf())
) != null
}
@@ -71,8 +71,8 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
CottonHud.add(progressBar)
neuRepo.reload()
} catch (exc: NEURepositoryException) {
- Minecraft.getInstance().player?.sendSystemMessage(
- Component.literal("Failed to reload repository. This will result in some mod features not working.")
+ MinecraftClient.getInstance().player?.sendMessage(
+ Text.literal("Failed to reload repository. This will result in some mod features not working.")
)
CottonHud.remove(progressBar)
exc.printStackTrace()
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
+}