diff options
| author | Linnea Gräf <nea@nea.moe> | 2024-10-28 12:07:55 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2024-10-28 12:07:55 +0100 |
| commit | c38dcee2c5f483ef5990ae9204355e1bc3c2bf74 (patch) | |
| tree | 3b70359076001e14514c496e3c44980fdbd92d01 /src/main | |
| parent | 8ab44088546bf3360564e1a09f0831fea7659d2e (diff) | |
| download | Firmament-c38dcee2c5f483ef5990ae9204355e1bc3c2bf74.tar.gz Firmament-c38dcee2c5f483ef5990ae9204355e1bc3c2bf74.tar.bz2 Firmament-c38dcee2c5f483ef5990ae9204355e1bc3c2bf74.zip | |
Make REI optional
Diffstat (limited to 'src/main')
24 files changed, 267 insertions, 1373 deletions
diff --git a/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt b/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt index 825cd6c..5151862 100644 --- a/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt +++ b/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt @@ -15,8 +15,8 @@ import moe.nea.firmament.events.WorldReadyEvent import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.gui.hud.MoulConfigHud -import moe.nea.firmament.rei.SBItemEntryDefinition import moe.nea.firmament.repo.ItemNameLookup +import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.MC import moe.nea.firmament.util.SHORT_NUMBER_FORMAT import moe.nea.firmament.util.SkyblockId @@ -197,9 +197,9 @@ object AnniversaryFeatures : FirmamentFeature { } val itemStack = if (backedBy is Reward.Items) { - SBItemEntryDefinition.getEntry(backedBy.item, backedBy.amount) + SBItemStack(backedBy.item, backedBy.amount) } else { - SBItemEntryDefinition.getEntry(SkyblockId.NULL) + SBItemStack(SkyblockId.NULL) } @Bind @@ -207,7 +207,7 @@ object AnniversaryFeatures : FirmamentFeature { return when (backedBy) { is Reward.Coins -> "Coins" is Reward.EXP -> backedBy.skill - is Reward.Items -> itemStack.value.asItemStack().name.string + is Reward.Items -> itemStack.asImmutableItemStack().name.string is Reward.Unknown -> backedBy.text } } diff --git a/src/main/kotlin/features/inventory/CraftingOverlay.kt b/src/main/kotlin/features/inventory/CraftingOverlay.kt index 8e75478..a958e25 100644 --- a/src/main/kotlin/features/inventory/CraftingOverlay.kt +++ b/src/main/kotlin/features/inventory/CraftingOverlay.kt @@ -1,5 +1,6 @@ package moe.nea.firmament.features.inventory +import io.github.moulberry.repo.data.NEUCraftingRecipe import net.minecraft.client.gui.screen.ingame.GenericContainerScreen import net.minecraft.item.ItemStack import net.minecraft.util.Formatting @@ -7,15 +8,14 @@ import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.SlotRenderEvents import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry -import moe.nea.firmament.rei.SBItemEntryDefinition -import moe.nea.firmament.rei.recipes.SBCraftingRecipe +import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.MC +import moe.nea.firmament.util.skyblockId object CraftingOverlay : FirmamentFeature { private var screen: GenericContainerScreen? = null - private var recipe: SBCraftingRecipe? = null + private var recipe: NEUCraftingRecipe? = null private var useNextScreen = false private val craftingOverlayIndices = listOf( 10, 11, 12, @@ -24,7 +24,7 @@ object CraftingOverlay : FirmamentFeature { ) val CRAFTING_SCREEN_NAME = "Craft Item" - fun setOverlay(screen: GenericContainerScreen?, recipe: SBCraftingRecipe) { + fun setOverlay(screen: GenericContainerScreen?, recipe: NEUCraftingRecipe) { this.screen = screen if (screen == null) { useNextScreen = true @@ -52,10 +52,12 @@ object CraftingOverlay : FirmamentFeature { if (slot.inventory != screen?.screenHandler?.inventory) return val recipeIndex = craftingOverlayIndices.indexOf(slot.index) if (recipeIndex < 0) return - val expectedItem = recipe.neuRecipe.inputs[recipeIndex] + val expectedItem = recipe.inputs[recipeIndex] val actualStack = slot.stack ?: ItemStack.EMPTY!! - val actualEntry = SBItemEntryDefinition.getEntry(actualStack).value - if ((actualEntry.skyblockId.neuItem != expectedItem.itemId || actualEntry.getStackSize() < expectedItem.amount) && expectedItem.amount.toInt() != 0) { + val actualEntry = SBItemStack(actualStack) + if ((actualEntry.skyblockId != expectedItem.skyblockId || actualEntry.getStackSize() < expectedItem.amount) + && expectedItem.amount.toInt() != 0 + ) { event.context.fill( event.slot.x, event.slot.y, @@ -65,7 +67,7 @@ object CraftingOverlay : FirmamentFeature { ) } if (!slot.hasStack()) { - val itemStack = SBItemEntryDefinition.getEntry(expectedItem).asItemEntry().value + val itemStack = SBItemStack(expectedItem)?.asImmutableItemStack() ?: return event.context.drawItem(itemStack, event.slot.x, event.slot.y) event.context.drawItemInSlot( MC.font, diff --git a/src/main/kotlin/gui/entity/EntityWidget.kt b/src/main/kotlin/gui/entity/EntityWidget.kt deleted file mode 100644 index 2e49072..0000000 --- a/src/main/kotlin/gui/entity/EntityWidget.kt +++ /dev/null @@ -1,35 +0,0 @@ - -package moe.nea.firmament.gui.entity - -import me.shedaniel.math.Dimension -import me.shedaniel.math.Point -import me.shedaniel.math.Rectangle -import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.Element -import net.minecraft.entity.LivingEntity - -class EntityWidget(val entity: LivingEntity, val point: Point) : WidgetWithBounds() { - override fun children(): List<Element> { - return emptyList() - } - - var hasErrored = false - - override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { - try { - if (!hasErrored) - EntityRenderer.renderEntity(entity, context, point.x, point.y, mouseX.toFloat(), mouseY.toFloat()) - } catch (ex: Exception) { - EntityRenderer.logger.error("Failed to render constructed entity: $entity", ex) - hasErrored = true - } - if (hasErrored) { - context.fill(point.x, point.y, point.x + 50, point.y + 80, 0xFFAA2222.toInt()) - } - } - - override fun getBounds(): Rectangle { - return Rectangle(point, Dimension(50, 80)) - } -} diff --git a/src/main/kotlin/gui/entity/ModifyEquipment.kt b/src/main/kotlin/gui/entity/ModifyEquipment.kt index 11dfb52..a558936 100644 --- a/src/main/kotlin/gui/entity/ModifyEquipment.kt +++ b/src/main/kotlin/gui/entity/ModifyEquipment.kt @@ -1,4 +1,3 @@ - package moe.nea.firmament.gui.entity import com.google.gson.JsonObject @@ -6,50 +5,49 @@ import net.minecraft.component.DataComponentTypes import net.minecraft.component.type.DyedColorComponent import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.LivingEntity -import net.minecraft.item.ArmorItem import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.item.Items -import moe.nea.firmament.rei.SBItemStack +import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.mc.setEncodedSkullOwner import moe.nea.firmament.util.mc.zeroUUID object ModifyEquipment : EntityModifier { - val names = mapOf( - "hand" to EquipmentSlot.MAINHAND, - "helmet" to EquipmentSlot.HEAD, - "chestplate" to EquipmentSlot.CHEST, - "leggings" to EquipmentSlot.LEGS, - "feet" to EquipmentSlot.FEET, - ) + val names = mapOf( + "hand" to EquipmentSlot.MAINHAND, + "helmet" to EquipmentSlot.HEAD, + "chestplate" to EquipmentSlot.CHEST, + "leggings" to EquipmentSlot.LEGS, + "feet" to EquipmentSlot.FEET, + ) - override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity { - names.forEach { (key, slot) -> - info[key]?.let { - entity.equipStack(slot, createItem(it.asString)) - } - } - return entity - } + override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity { + names.forEach { (key, slot) -> + info[key]?.let { + entity.equipStack(slot, createItem(it.asString)) + } + } + return entity + } - private fun createItem(item: String): ItemStack { - val split = item.split("#") - if (split.size != 2) return SBItemStack(SkyblockId(item)).asImmutableItemStack() - val (type, data) = split - return when (type) { - "SKULL" -> ItemStack(Items.PLAYER_HEAD).also { it.setEncodedSkullOwner(zeroUUID, data) } - "LEATHER_LEGGINGS" -> coloredLeatherArmor(Items.LEATHER_LEGGINGS, data) - "LEATHER_BOOTS" -> coloredLeatherArmor(Items.LEATHER_BOOTS, data) - "LEATHER_HELMET" -> coloredLeatherArmor(Items.LEATHER_HELMET, data) - "LEATHER_CHESTPLATE" -> coloredLeatherArmor(Items.LEATHER_CHESTPLATE, data) - else -> error("Unknown leather piece: $type") - } - } + private fun createItem(item: String): ItemStack { + val split = item.split("#") + if (split.size != 2) return SBItemStack(SkyblockId(item)).asImmutableItemStack() + val (type, data) = split + return when (type) { + "SKULL" -> ItemStack(Items.PLAYER_HEAD).also { it.setEncodedSkullOwner(zeroUUID, data) } + "LEATHER_LEGGINGS" -> coloredLeatherArmor(Items.LEATHER_LEGGINGS, data) + "LEATHER_BOOTS" -> coloredLeatherArmor(Items.LEATHER_BOOTS, data) + "LEATHER_HELMET" -> coloredLeatherArmor(Items.LEATHER_HELMET, data) + "LEATHER_CHESTPLATE" -> coloredLeatherArmor(Items.LEATHER_CHESTPLATE, data) + else -> error("Unknown leather piece: $type") + } + } - private fun coloredLeatherArmor(leatherArmor: Item, data: String): ItemStack { - val stack = ItemStack(leatherArmor) - stack.set(DataComponentTypes.DYED_COLOR, DyedColorComponent(data.toInt(16), false)) - return stack - } + private fun coloredLeatherArmor(leatherArmor: Item, data: String): ItemStack { + val stack = ItemStack(leatherArmor) + stack.set(DataComponentTypes.DYED_COLOR, DyedColorComponent(data.toInt(16), false)) + return stack + } } diff --git a/src/main/kotlin/rei/FirmamentReiPlugin.kt b/src/main/kotlin/rei/FirmamentReiPlugin.kt deleted file mode 100644 index f234f3e..0000000 --- a/src/main/kotlin/rei/FirmamentReiPlugin.kt +++ /dev/null @@ -1,142 +0,0 @@ -package moe.nea.firmament.rei - -import me.shedaniel.rei.api.client.plugins.REIClientPlugin -import me.shedaniel.rei.api.client.registry.category.CategoryRegistry -import me.shedaniel.rei.api.client.registry.display.DisplayRegistry -import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry -import me.shedaniel.rei.api.client.registry.entry.EntryRegistry -import me.shedaniel.rei.api.client.registry.screen.ExclusionZones -import me.shedaniel.rei.api.client.registry.screen.OverlayDecider -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry -import me.shedaniel.rei.api.client.registry.transfer.TransferHandler -import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry -import me.shedaniel.rei.api.common.entry.EntryStack -import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes -import net.minecraft.client.gui.screen.Screen -import net.minecraft.client.gui.screen.ingame.GenericContainerScreen -import net.minecraft.client.gui.screen.ingame.HandledScreen -import net.minecraft.item.ItemStack -import net.minecraft.text.Text -import net.minecraft.util.ActionResult -import net.minecraft.util.Identifier -import moe.nea.firmament.events.HandledScreenPushREIEvent -import moe.nea.firmament.features.inventory.CraftingOverlay -import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlayScreen -import moe.nea.firmament.rei.recipes.SBCraftingRecipe -import moe.nea.firmament.rei.recipes.SBEssenceUpgradeRecipe -import moe.nea.firmament.rei.recipes.SBForgeRecipe -import moe.nea.firmament.rei.recipes.SBKatRecipe -import moe.nea.firmament.rei.recipes.SBMobDropRecipe -import moe.nea.firmament.repo.RepoManager -import moe.nea.firmament.util.MC -import moe.nea.firmament.util.ScreenUtil -import moe.nea.firmament.util.SkyblockId -import moe.nea.firmament.util.guessRecipeId -import moe.nea.firmament.util.skyblockId -import moe.nea.firmament.util.unformattedString - - -class FirmamentReiPlugin : REIClientPlugin { - - companion object { - fun EntryStack<SBItemStack>.asItemEntry(): EntryStack<ItemStack> { - return EntryStack.of(VanillaEntryTypes.ITEM, value.asImmutableItemStack()) - } - - val SKYBLOCK_ITEM_TYPE_ID = Identifier.of("firmament", "skyblockitems") - } - - override fun registerTransferHandlers(registry: TransferHandlerRegistry) { - registry.register(TransferHandler { context -> - val screen = context.containerScreen - val display = context.display - if (display !is SBCraftingRecipe) return@TransferHandler TransferHandler.Result.createNotApplicable() - val neuItem = RepoManager.getNEUItem(SkyblockId(display.neuRecipe.output.itemId)) - ?: error("Could not find neu item ${display.neuRecipe.output.itemId} which is used in a recipe output") - val useSuperCraft = context.isStackedCrafting || RepoManager.Config.alwaysSuperCraft - if (neuItem.isVanilla && useSuperCraft) return@TransferHandler TransferHandler.Result.createFailed(Text.translatable( - "firmament.recipe.novanilla")) - var shouldReturn = true - if (context.isActuallyCrafting && !useSuperCraft) { - if (screen !is GenericContainerScreen || screen.title?.unformattedString != CraftingOverlay.CRAFTING_SCREEN_NAME) { - MC.sendCommand("craft") - shouldReturn = false - } - CraftingOverlay.setOverlay(screen as? GenericContainerScreen, display) - } - if (context.isActuallyCrafting && useSuperCraft) { - shouldReturn = false - MC.sendCommand("viewrecipe ${neuItem.guessRecipeId()}") - } - return@TransferHandler TransferHandler.Result.createSuccessful().blocksFurtherHandling(shouldReturn) - }) - } - - override fun registerEntryTypes(registry: EntryTypeRegistry) { - registry.register(SKYBLOCK_ITEM_TYPE_ID, SBItemEntryDefinition) - } - - override fun registerCategories(registry: CategoryRegistry) { - registry.add(SBCraftingRecipe.Category) - registry.add(SBForgeRecipe.Category) - registry.add(SBMobDropRecipe.Category) - registry.add(SBKatRecipe.Category) - registry.add(SBEssenceUpgradeRecipe.Category) - } - - override fun registerExclusionZones(zones: ExclusionZones) { - zones.register(HandledScreen::class.java) { HandledScreenPushREIEvent.publish(HandledScreenPushREIEvent(it)).rectangles } - zones.register(StorageOverlayScreen::class.java) { it.getBounds() } - } - - override fun registerDisplays(registry: DisplayRegistry) { - registry.registerDisplayGenerator( - SBCraftingRecipe.Category.catIdentifier, - SkyblockCraftingRecipeDynamicGenerator) - registry.registerDisplayGenerator( - SBForgeRecipe.Category.categoryIdentifier, - SkyblockForgeRecipeDynamicGenerator) - registry.registerDisplayGenerator( - SBMobDropRecipe.Category.categoryIdentifier, - SkyblockMobDropRecipeDynamicGenerator) - registry.registerDisplayGenerator( - SBKatRecipe.Category.categoryIdentifier, - SkyblockKatRecipeDynamicGenerator) - registry.registerDisplayGenerator( - SBEssenceUpgradeRecipe.Category.categoryIdentifier, - SkyblockEssenceRecipeDynamicGenerator - ) - } - - override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { - if (!RepoManager.Config.disableItemGroups) - RepoManager.neuRepo.constants.parents.parents - .forEach { (parent, children) -> - registry.group( - SkyblockId(parent).identifier, - Text.literal(RepoManager.getNEUItem(SkyblockId(parent))?.displayName ?: parent), - (children + parent).map { SBItemEntryDefinition.getEntry(SkyblockId(it)) }) - } - } - - override fun registerScreens(registry: ScreenRegistry) { - registry.registerDecider(object : OverlayDecider { - override fun <R : Screen?> isHandingScreen(screen: Class<R>?): Boolean { - return screen == StorageOverlayScreen::class.java - } - - override fun <R : Screen?> shouldScreenBeOverlaid(screen: R): ActionResult { - return ActionResult.SUCCESS - } - }) - registry.registerFocusedStack(SkyblockItemIdFocusedStackProvider) - } - - override fun registerEntries(registry: EntryRegistry) { - registry.removeEntryIf { true } - RepoManager.neuRepo.items?.items?.values?.forEach { neuItem -> - registry.addEntry(SBItemEntryDefinition.getEntry(neuItem.skyblockId)) - } - } -} diff --git a/src/main/kotlin/rei/NEUItemEntryRenderer.kt b/src/main/kotlin/rei/NEUItemEntryRenderer.kt deleted file mode 100644 index ba99b30..0000000 --- a/src/main/kotlin/rei/NEUItemEntryRenderer.kt +++ /dev/null @@ -1,186 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2018-2023 shedaniel <daniel@shedaniel.me> - * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> - * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> - * - * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-License-Identifier: MIT - */ - -package moe.nea.firmament.rei - -import com.mojang.blaze3d.platform.GlStateManager.DstFactor -import com.mojang.blaze3d.platform.GlStateManager.SrcFactor -import com.mojang.blaze3d.systems.RenderSystem -import me.shedaniel.math.Rectangle -import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer -import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer -import me.shedaniel.rei.api.client.gui.widgets.Tooltip -import me.shedaniel.rei.api.client.gui.widgets.TooltipContext -import me.shedaniel.rei.api.common.entry.EntryStack -import net.minecraft.client.MinecraftClient -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.render.DiffuseLighting -import net.minecraft.client.render.LightmapTextureManager -import net.minecraft.client.render.OverlayTexture -import net.minecraft.client.render.VertexConsumerProvider -import net.minecraft.client.render.model.BakedModel -import net.minecraft.client.render.model.json.ModelTransformationMode -import net.minecraft.client.texture.SpriteAtlasTexture -import net.minecraft.item.Item -import net.minecraft.item.ItemStack -import net.minecraft.item.tooltip.TooltipType -import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry - -object NEUItemEntryRenderer : EntryRenderer<SBItemStack>, BatchedEntryRenderer<SBItemStack, BakedModel> { - override fun render( - entry: EntryStack<SBItemStack>, - context: DrawContext, - bounds: Rectangle, - mouseX: Int, - mouseY: Int, - delta: Float - ) { - entry.asItemEntry().render(context, bounds, mouseX, mouseY, delta) - } - - val minecraft = MinecraftClient.getInstance() - - override fun getTooltip(entry: EntryStack<SBItemStack>, tooltipContext: TooltipContext): Tooltip? { - val stack = entry.value.asImmutableItemStack() - val lore = stack.getTooltip( - Item.TooltipContext.DEFAULT, - null, - TooltipType.BASIC - ) - return Tooltip.create(lore) - } - - override fun getExtraData(entry: EntryStack<SBItemStack>): BakedModel { - return minecraft.itemRenderer.getModel(entry.asItemEntry().value, minecraft.world, minecraft.player, 0) - } - - override fun getBatchIdentifier(entry: EntryStack<SBItemStack>?, bounds: Rectangle?, extraData: BakedModel): Int { - return 1738923 + if (extraData.isSideLit) 1 else 0 - } - - override fun startBatch( - entry: EntryStack<SBItemStack>, - model: BakedModel, - graphics: DrawContext, - delta: Float - ) { - val modelViewStack = RenderSystem.getModelViewStack() - modelViewStack.pushMatrix() - modelViewStack.scale(20.0f, 20.0f, 1.0f) - RenderSystem.applyModelViewMatrix() - setupGL(model) - } - - fun setupGL(model: BakedModel) { - minecraft.textureManager.getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE) - .setFilter(false, false) - RenderSystem.setShaderTexture(0, SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE) - RenderSystem.enableBlend() - RenderSystem.blendFunc(SrcFactor.SRC_ALPHA, DstFactor.ONE_MINUS_SRC_ALPHA) - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f) - val sideLit = model.isSideLit - if (!sideLit) { - DiffuseLighting.disableGuiDepthLighting() - } - } - - override fun renderBase( - entry: EntryStack<SBItemStack>, - model: BakedModel, - graphics: DrawContext, - immediate: VertexConsumerProvider.Immediate, - bounds: Rectangle, - mouseX: Int, - mouseY: Int, - delta: Float - ) { - if (entry.isEmpty) return - val value = entry.asItemEntry().value - graphics.matrices.push() - graphics.matrices.translate(bounds.centerX.toFloat() / 20.0f, bounds.centerY.toFloat() / 20.0f, 0.0f) - graphics.matrices.scale( - bounds.getWidth().toFloat() / 20.0f, - -(bounds.getWidth() + bounds.getHeight()).toFloat() / 2.0f / 20.0f, - 1.0f - ) - minecraft - .itemRenderer - .renderItem( - value, - ModelTransformationMode.GUI, - false, - graphics.matrices, - immediate, - LightmapTextureManager.MAX_LIGHT_COORDINATE, - OverlayTexture.DEFAULT_UV, - model - ) - graphics.matrices.pop() - - } - - override fun afterBase( - entry: EntryStack<SBItemStack>, - model: BakedModel, - graphics: DrawContext, - delta: Float - ) { - RenderSystem.getModelViewStack().popMatrix() - RenderSystem.applyModelViewMatrix() - this.endGL(model) - } - - fun endGL(model: BakedModel) { - RenderSystem.enableDepthTest() - val sideLit = model.isSideLit - if (!sideLit) { - DiffuseLighting.enableGuiDepthLighting() - } - } - - override fun renderOverlay( - entry: EntryStack<SBItemStack>, - extraData: BakedModel, - graphics: DrawContext, - immediate: VertexConsumerProvider.Immediate, - bounds: Rectangle, - mouseX: Int, - mouseY: Int, - delta: Float - ) { - val modelViewStack = RenderSystem.getModelViewStack() - modelViewStack.pushMatrix() - modelViewStack.mul(graphics.matrices.peek().positionMatrix) - modelViewStack.translate(bounds.x.toFloat(), bounds.y.toFloat(), 0.0f) - modelViewStack.scale( - bounds.width.toFloat() / 16.0f, - -(bounds.getWidth() + bounds.getHeight()).toFloat() / 2.0f / 16.0f, - 1.0f - ) - RenderSystem.applyModelViewMatrix() - renderOverlay(DrawContext(minecraft, graphics.vertexConsumers), entry.asItemEntry()) - modelViewStack.popMatrix() - RenderSystem.applyModelViewMatrix() - } - - fun renderOverlay(graphics: DrawContext, entry: EntryStack<ItemStack>) { - if (!entry.isEmpty) { - graphics.drawItemInSlot(MinecraftClient.getInstance().textRenderer, entry.value, 0, 0, null) - } - } - - override fun endBatch( - entry: EntryStack<SBItemStack>?, - extraData: BakedModel?, - graphics: DrawContext?, - delta: Float - ) { - } - -} diff --git a/src/main/kotlin/rei/NEUItemEntrySerializer.kt b/src/main/kotlin/rei/NEUItemEntrySerializer.kt deleted file mode 100644 index a35d75f..0000000 --- a/src/main/kotlin/rei/NEUItemEntrySerializer.kt +++ /dev/null @@ -1,29 +0,0 @@ - - -package moe.nea.firmament.rei - -import me.shedaniel.rei.api.common.entry.EntrySerializer -import me.shedaniel.rei.api.common.entry.EntryStack -import net.minecraft.nbt.NbtCompound -import moe.nea.firmament.util.SkyblockId - -object NEUItemEntrySerializer : EntrySerializer<SBItemStack> { - const val SKYBLOCK_ID_ENTRY = "SKYBLOCK_ID" - const val SKYBLOCK_ITEM_COUNT = "SKYBLOCK_ITEM_COUNT" - - override fun supportSaving(): Boolean = true - override fun supportReading(): Boolean = true - - override fun read(tag: NbtCompound): SBItemStack { - val id = SkyblockId(tag.getString(SKYBLOCK_ID_ENTRY)) - val count = if (tag.contains(SKYBLOCK_ITEM_COUNT)) tag.getInt(SKYBLOCK_ITEM_COUNT) else 1 - return SBItemStack(id, count) - } - - override fun save(entry: EntryStack<SBItemStack>, value: SBItemStack): NbtCompound { - return NbtCompound().apply { - putString(SKYBLOCK_ID_ENTRY, value.skyblockId.neuItem) - putInt(SKYBLOCK_ITEM_COUNT, value.getStackSize()) - } - } -} diff --git a/src/main/kotlin/rei/SBItemEntryDefinition.kt b/src/main/kotlin/rei/SBItemEntryDefinition.kt deleted file mode 100644 index 3df8fa3..0000000 --- a/src/main/kotlin/rei/SBItemEntryDefinition.kt +++ /dev/null @@ -1,254 +0,0 @@ - - -package moe.nea.firmament.rei - -import io.github.moulberry.repo.constants.PetNumbers -import io.github.moulberry.repo.data.NEUIngredient -import io.github.moulberry.repo.data.NEUItem -import io.github.moulberry.repo.data.Rarity -import java.util.stream.Stream -import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer -import me.shedaniel.rei.api.common.entry.EntrySerializer -import me.shedaniel.rei.api.common.entry.EntryStack -import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext -import me.shedaniel.rei.api.common.entry.type.EntryDefinition -import me.shedaniel.rei.api.common.entry.type.EntryType -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes -import net.minecraft.item.ItemStack -import net.minecraft.registry.tag.TagKey -import net.minecraft.text.Text -import net.minecraft.util.Formatting -import net.minecraft.util.Identifier -import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry -import moe.nea.firmament.repo.ExpLadders -import moe.nea.firmament.repo.ItemCache -import moe.nea.firmament.repo.ItemCache.asItemStack -import moe.nea.firmament.repo.RepoManager -import moe.nea.firmament.util.FirmFormatters -import moe.nea.firmament.util.HypixelPetInfo -import moe.nea.firmament.util.LegacyFormattingCode -import moe.nea.firmament.util.SkyblockId -import moe.nea.firmament.util.mc.appendLore -import moe.nea.firmament.util.mc.displayNameAccordingToNbt -import moe.nea.firmament.util.petData -import moe.nea.firmament.util.skyBlockId -import moe.nea.firmament.util.withColor - -// TODO: add in extra data like pet info, into this structure -data class PetData( - val rarity: Rarity, - val petId: String, - val exp: Double, - val isStub: Boolean = false, -) { - companion object { - fun fromHypixel(petInfo: HypixelPetInfo) = PetData( - petInfo.tier, petInfo.type, petInfo.exp, - ) - - fun forLevel(petId: String, rarity: Rarity, level: Int) = PetData( - rarity, petId, ExpLadders.getExpLadder(petId, rarity).getPetExpForLevel(level).toDouble() - ) - } - - val levelData by lazy { ExpLadders.getExpLadder(petId, rarity).getPetLevel(exp) } -} - -data class SBItemStack constructor( - val skyblockId: SkyblockId, - val neuItem: NEUItem?, - private var stackSize: Int, - private var petData: PetData?, - val extraLore: List<Text> = emptyList(), - // TODO: grab this star data from nbt if possible - val stars: Int = 0, -) { - - fun getStackSize() = stackSize - fun setStackSize(newSize: Int) { - this.stackSize = newSize - this.itemStack_ = null - } - - fun getPetData() = petData - fun setPetData(petData: PetData?) { - this.petData = petData - this.itemStack_ = null - } - - constructor(skyblockId: SkyblockId, petData: PetData) : this( - skyblockId, - RepoManager.getNEUItem(skyblockId), - 1, - petData - ) - - constructor(skyblockId: SkyblockId, stackSize: Int = 1) : this( - skyblockId, - RepoManager.getNEUItem(skyblockId), - stackSize, - RepoManager.getPotentialStubPetData(skyblockId) - ) - - private fun injectReplacementDataForPetLevel( - petInfo: PetNumbers, - level: Int, - replacementData: MutableMap<String, String> - ) { - val stats = petInfo.interpolatedStatsAtLevel(level) ?: return - stats.otherNumbers.forEachIndexed { index, it -> - replacementData[index.toString()] = FirmFormatters.formatCommas(it, 1) - } - stats.statNumbers.forEach { (t, u) -> - replacementData[t] = FirmFormatters.formatCommas(u, 1) - } - } - - private fun injectReplacementDataForPets(replacementData: MutableMap<String, String>) { - val petData = this.petData ?: return - val petInfo = RepoManager.neuRepo.constants.petNumbers[petData.petId]?.get(petData.rarity) ?: return - if (petData.isStub) { - val mapLow = mutableMapOf<String, String>() - injectReplacementDataForPetLevel(petInfo, petInfo.lowLevel, mapLow) - val mapHigh = mutableMapOf<String, String>() - injectReplacementDataForPetLevel(petInfo, petInfo.highLevel, mapHigh) - mapHigh.forEach { (key, highValue) -> - mapLow.merge(key, highValue) { a, b -> "$a → $b" } - } - r |
