aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/kotlin/moe/nea/notenoughupdates/rei
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-07-26 11:42:48 +0200
committernea <romangraef@gmail.com>2022-07-26 11:42:48 +0200
commit37218614c6d7f8a903b6532196dfa7d1e94a948f (patch)
treef3ab92298b23ac839eaa84b3af1c769adfa52fda /common/src/main/kotlin/moe/nea/notenoughupdates/rei
parent372eec27e5e0c8ef796ed9e6bcdc68a10df84718 (diff)
downloadFirmament-37218614c6d7f8a903b6532196dfa7d1e94a948f.tar.gz
Firmament-37218614c6d7f8a903b6532196dfa7d1e94a948f.tar.bz2
Firmament-37218614c6d7f8a903b6532196dfa7d1e94a948f.zip
legacy tag parsing and transformation
Diffstat (limited to 'common/src/main/kotlin/moe/nea/notenoughupdates/rei')
-rw-r--r--common/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt138
1 files changed, 94 insertions, 44 deletions
diff --git a/common/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt b/common/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt
index de8c689..0fb3621 100644
--- a/common/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt
+++ b/common/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt
@@ -1,7 +1,8 @@
package moe.nea.notenoughupdates.rei
import com.mojang.blaze3d.vertex.PoseStack
-import io.github.moulberry.repo.NEURepository
+import com.mojang.serialization.Dynamic
+import io.github.moulberry.repo.data.NEUItem
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer
@@ -16,45 +17,105 @@ import me.shedaniel.rei.api.common.entry.type.EntryType
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
import me.shedaniel.rei.api.common.util.EntryStacks
-import net.minecraft.core.Registry
+import moe.nea.notenoughupdates.LegacyTagParser
+import moe.nea.notenoughupdates.NotEnoughUpdates.neuRepo
+import net.minecraft.ChatFormatting
+import net.minecraft.nbt.CompoundTag
+import net.minecraft.nbt.NbtOps
+import net.minecraft.nbt.StringTag
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.TextComponent
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.TagKey
-import net.minecraft.world.item.Item
+import net.minecraft.util.datafix.DataFixers.getDataFixer
+import net.minecraft.util.datafix.fixes.References
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.item.enchantment.Enchantments
-import java.nio.file.Path
+import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Stream
class NEUReiPlugin : REIClientPlugin {
- data class SBItem(val sbname: String, val backing: Item)
companion object {
- fun EntryStack<NEUReiPlugin.SBItem>.asItemStack() =
- EntryStack.of(VanillaEntryTypes.ITEM, ItemStack(this.value.backing).also {
- it.enchant(Enchantments.BINDING_CURSE, 1)
- it.hoverName = TextComponent(value.sbname)
- })
+ fun EntryStack<NEUItem>.asItemEntry(): EntryStack<ItemStack> {
+ return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack())
+ }
+
+ fun ItemStack.appendLore(args: List<Component>) {
+ val compoundTag = getOrCreateTagElement("display")
+ val loreList = compoundTag.getList("Lore", StringTag.TAG_STRING.toInt())
+ for (arg in args) {
+ loreList.add(StringTag.valueOf(Component.Serializer.toJson(arg)))
+ }
+ compoundTag.put("Lore", loreList)
+ }
+
+ val cache: MutableMap<String, ItemStack> = ConcurrentHashMap()
+
+ fun NEUItem.asItemStackNow(): ItemStack {
+ val df = getDataFixer()
+ val itemTag1_8_9 = CompoundTag()
+ itemTag1_8_9.put("tag", LegacyTagParser.parse(this.nbttag))
+ itemTag1_8_9.putString("id", this.minecraftItemId)
+ itemTag1_8_9.putByte("Count", 1)
+ itemTag1_8_9.putShort("Damage", this.damage.toShort())
+ val itemTag_modern = try {
+ df.update(
+ References.ITEM_STACK,
+ Dynamic(NbtOps.INSTANCE, itemTag1_8_9),
+ 99,
+ 2975
+ ).value as CompoundTag
+ } catch (e: Exception) {
+ e.printStackTrace()
+ return ItemStack(Items.PAINTING).apply {
+ appendLore(listOf(TextComponent("Exception rendering item: $skyblockItemId")))
+ }
+ }
+ val itemInstance = ItemStack.of(itemTag_modern)
+ return itemInstance.also {
+ if(false)it.appendLore(
+ listOf(
+ TextComponent("Old: $minecraftItemId").withStyle {
+ it.withItalic(false).withColor(ChatFormatting.RED)
+ },
+ TextComponent("Modern: $itemTag_modern").withStyle {
+ it.withItalic(false).withColor(ChatFormatting.RED)
+ },
+ )
+ )
+ it.hoverName = TextComponent(this.skyblockItemId)
+ }
+ }
+
+ fun NEUItem.asItemStack(): ItemStack {
+ var s = cache[this.skyblockItemId]
+ if (s == null) {
+ s = asItemStackNow()
+ cache[this.skyblockItemId] = s
+ }
+ return s
+ }
+
val hehe = ResourceLocation("notenoughupdates", "skyblockitems")
}
- object SBItemEntryDefinition : EntryDefinition<SBItem> {
- override fun equals(o1: SBItem?, o2: SBItem?, context: ComparisonContext?): Boolean {
+ object SBItemEntryDefinition : EntryDefinition<NEUItem> {
+ override fun equals(o1: NEUItem?, o2: NEUItem?, context: ComparisonContext?): Boolean {
return o1 == o2
}
- override fun getValueType(): Class<SBItem> = SBItem::class.java
- override fun getType(): EntryType<SBItem> =
+ override fun getValueType(): Class<NEUItem> = NEUItem::class.java
+ override fun getType(): EntryType<NEUItem> =
EntryType.deferred(hehe)
- override fun getRenderer(): EntryRenderer<SBItem> = object : EntryRenderer<SBItem> {
+ override fun getRenderer(): EntryRenderer<NEUItem> = object : EntryRenderer<NEUItem> {
override fun render(
- entry: EntryStack<SBItem>,
+ entry: EntryStack<NEUItem>,
matrices: PoseStack,
bounds: Rectangle,
mouseX: Int,
@@ -63,75 +124,64 @@ class NEUReiPlugin : REIClientPlugin {
) {
VanillaEntryTypes.ITEM.definition.renderer
.render(
- entry.asItemStack(),
+ entry.asItemEntry(),
matrices, bounds, mouseX, mouseY, delta
)
}
- override fun getTooltip(entry: EntryStack<SBItem>, mouse: Point): Tooltip? {
+ override fun getTooltip(entry: EntryStack<NEUItem>, mouse: Point): Tooltip? {
return VanillaEntryTypes.ITEM.definition.renderer
- .getTooltip(entry.asItemStack(), mouse)
+ .getTooltip(entry.asItemEntry(), mouse)
}
}
- override fun getSerializer(): EntrySerializer<SBItem>? {
+ override fun getSerializer(): EntrySerializer<NEUItem>? {
return null
}
- override fun getTagsFor(entry: EntryStack<SBItem>?, value: SBItem?): Stream<out TagKey<*>> {
+ override fun getTagsFor(entry: EntryStack<NEUItem>?, value: NEUItem?): Stream<out TagKey<*>> {
return Stream.empty()
}
- override fun asFormattedText(entry: EntryStack<SBItem>, value: SBItem): Component {
- return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemStack(), ItemStack(value.backing))
+ override fun asFormattedText(entry: EntryStack<NEUItem>, value: NEUItem): Component {
+ return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemEntry(), value.asItemStack())
}
- override fun hash(entry: EntryStack<SBItem>, value: SBItem, context: ComparisonContext): Long {
- return value.sbname.hashCode().toLong()
+ override fun hash(entry: EntryStack<NEUItem>, value: NEUItem, context: ComparisonContext): Long {
+ return value.skyblockItemId.hashCode().toLong()
}
- override fun wildcard(entry: EntryStack<SBItem>, value: SBItem): SBItem {
+ override fun wildcard(entry: EntryStack<NEUItem>, value: NEUItem): NEUItem {
return value
}
- override fun normalize(entry: EntryStack<SBItem>, value: SBItem): SBItem {
+ override fun normalize(entry: EntryStack<NEUItem>, value: NEUItem): NEUItem {
return value
}
- override fun copy(entry: EntryStack<SBItem>?, value: SBItem): SBItem {
- return value.copy()
+ override fun copy(entry: EntryStack<NEUItem>?, value: NEUItem): NEUItem {
+ return value
}
- override fun isEmpty(entry: EntryStack<SBItem>?, value: SBItem?): Boolean {
+ override fun isEmpty(entry: EntryStack<NEUItem>?, value: NEUItem?): Boolean {
return false
}
- override fun getIdentifier(entry: EntryStack<SBItem>?, value: SBItem): ResourceLocation? {
- return ResourceLocation("skyblockitem", value.sbname)
+ override fun getIdentifier(entry: EntryStack<NEUItem>?, value: NEUItem): ResourceLocation {
+ return ResourceLocation("skyblockitem", value.skyblockItemId.lowercase().replace(";", "__"))
}
}
- val neuRepo = NEURepository.of(Path.of("NotEnoughUpdates-REPO")).also {
- it.reload()
- }
-
override fun registerEntryTypes(registry: EntryTypeRegistry) {
registry.register(hehe, SBItemEntryDefinition)
}
override fun registerEntries(registry: EntryRegistry) {
neuRepo.items.items.values.forEach {
- println("Adding item: $it")
- registry.addEntry(
- EntryStack.of(
- SBItemEntryDefinition, SBItem(
- it.skyblockItemId.lowercase().replace(";", "__"), Registry.ITEM.get(ResourceLocation(it.minecraftItemId))
- )
- )
- )
+ registry.addEntry(EntryStack.of(SBItemEntryDefinition, it))
}
registry.addEntry(EntryStacks.of(ItemStack(Items.DIAMOND).also {
it.enchant(Enchantments.ALL_DAMAGE_PROTECTION, 10)