Improve performance of Item List
This commit is contained in:
9
LICENSES/MIT.txt
Normal file
9
LICENSES/MIT.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) <year> <copyright holders>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -37,7 +37,7 @@ class FirmamentReiPlugin : REIClientPlugin {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun EntryStack<SBItemStack>.asItemEntry(): EntryStack<ItemStack> {
|
fun EntryStack<SBItemStack>.asItemEntry(): EntryStack<ItemStack> {
|
||||||
return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack())
|
return EntryStack.of(VanillaEntryTypes.ITEM, value.asImmutableItemStack())
|
||||||
}
|
}
|
||||||
|
|
||||||
val SKYBLOCK_ITEM_TYPE_ID = Identifier("firmament", "skyblockitems")
|
val SKYBLOCK_ITEM_TYPE_ID = Identifier("firmament", "skyblockitems")
|
||||||
|
|||||||
@@ -1,20 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
|
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
|
||||||
|
* SPDX-FileCopyrightText: 2018-2023 shedaniel <daniel@shedaniel.me>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package moe.nea.firmament.rei
|
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.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.entry.renderer.EntryRenderer
|
||||||
import me.shedaniel.rei.api.client.gui.widgets.Tooltip
|
import me.shedaniel.rei.api.client.gui.widgets.Tooltip
|
||||||
import me.shedaniel.rei.api.client.gui.widgets.TooltipContext
|
import me.shedaniel.rei.api.client.gui.widgets.TooltipContext
|
||||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||||
import net.minecraft.client.gui.DrawContext
|
|
||||||
import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry
|
import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry
|
||||||
|
import net.minecraft.client.MinecraftClient
|
||||||
|
import net.minecraft.client.gui.DrawContext
|
||||||
|
import net.minecraft.client.render.DiffuseLighting
|
||||||
|
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.ItemStack
|
||||||
|
|
||||||
object NEUItemEntryRenderer : EntryRenderer<SBItemStack> {
|
object NEUItemEntryRenderer : EntryRenderer<SBItemStack>, BatchedEntryRenderer<SBItemStack, BakedModel> {
|
||||||
override fun render(
|
override fun render(
|
||||||
entry: EntryStack<SBItemStack>,
|
entry: EntryStack<SBItemStack>,
|
||||||
context: DrawContext,
|
context: DrawContext,
|
||||||
@@ -26,8 +40,136 @@ object NEUItemEntryRenderer : EntryRenderer<SBItemStack> {
|
|||||||
entry.asItemEntry().render(context, bounds, mouseX, mouseY, delta)
|
entry.asItemEntry().render(context, bounds, mouseX, mouseY, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val minecraft = MinecraftClient.getInstance()
|
||||||
|
|
||||||
override fun getTooltip(entry: EntryStack<SBItemStack>, tooltipContext: TooltipContext): Tooltip? {
|
override fun getTooltip(entry: EntryStack<SBItemStack>, tooltipContext: TooltipContext): Tooltip? {
|
||||||
return entry.asItemEntry().getTooltip(tooltipContext, false)
|
return entry.asItemEntry().getTooltip(tooltipContext, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
) {
|
||||||
|
setupGL(model)
|
||||||
|
val modelViewStack = RenderSystem.getModelViewStack()
|
||||||
|
modelViewStack.push()
|
||||||
|
modelViewStack.scale(20.0f, -20.0f, 1.0f)
|
||||||
|
RenderSystem.applyModelViewMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
15728880,
|
||||||
|
OverlayTexture.DEFAULT_UV,
|
||||||
|
model
|
||||||
|
)
|
||||||
|
graphics.matrices.pop()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun afterBase(
|
||||||
|
entry: EntryStack<SBItemStack>,
|
||||||
|
model: BakedModel,
|
||||||
|
graphics: DrawContext,
|
||||||
|
delta: Float
|
||||||
|
) {
|
||||||
|
this.endGL(model)
|
||||||
|
RenderSystem.getModelViewStack().pop()
|
||||||
|
RenderSystem.applyModelViewMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
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.push()
|
||||||
|
modelViewStack.multiplyPositionMatrix(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.pop()
|
||||||
|
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
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ package moe.nea.firmament.rei
|
|||||||
import io.github.moulberry.repo.data.NEUIngredient
|
import io.github.moulberry.repo.data.NEUIngredient
|
||||||
import io.github.moulberry.repo.data.NEUItem
|
import io.github.moulberry.repo.data.NEUItem
|
||||||
import io.github.moulberry.repo.data.Rarity
|
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.client.entry.renderer.EntryRenderer
|
||||||
import me.shedaniel.rei.api.common.entry.EntrySerializer
|
import me.shedaniel.rei.api.common.entry.EntrySerializer
|
||||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||||
@@ -17,20 +16,17 @@ 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.EntryDefinition
|
||||||
import me.shedaniel.rei.api.common.entry.type.EntryType
|
import me.shedaniel.rei.api.common.entry.type.EntryType
|
||||||
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
|
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.Identifier
|
|
||||||
import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry
|
import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry
|
||||||
import moe.nea.firmament.repo.ExpLadders
|
import moe.nea.firmament.repo.ExpLadders
|
||||||
import moe.nea.firmament.repo.ItemCache
|
import moe.nea.firmament.repo.ItemCache
|
||||||
import moe.nea.firmament.repo.ItemCache.asItemStack
|
import moe.nea.firmament.repo.ItemCache.asItemStack
|
||||||
import moe.nea.firmament.repo.RepoManager
|
import moe.nea.firmament.repo.RepoManager
|
||||||
import moe.nea.firmament.util.FirmFormatters
|
import moe.nea.firmament.util.*
|
||||||
import moe.nea.firmament.util.HypixelPetInfo
|
import net.minecraft.item.ItemStack
|
||||||
import moe.nea.firmament.util.SkyblockId
|
import net.minecraft.registry.tag.TagKey
|
||||||
import moe.nea.firmament.util.petData
|
import net.minecraft.text.Text
|
||||||
import moe.nea.firmament.util.skyBlockId
|
import net.minecraft.util.Identifier
|
||||||
|
import java.util.stream.Stream
|
||||||
|
|
||||||
// TODO: add in extra data like pet info, into this structure
|
// TODO: add in extra data like pet info, into this structure
|
||||||
data class PetData(
|
data class PetData(
|
||||||
@@ -67,7 +63,7 @@ data class SBItemStack(
|
|||||||
RepoManager.getPotentialStubPetData(skyblockId)
|
RepoManager.getPotentialStubPetData(skyblockId)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val itemStack by lazy {
|
private val itemStack by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
if (skyblockId == SkyblockId.COINS)
|
if (skyblockId == SkyblockId.COINS)
|
||||||
return@lazy ItemCache.coinItem(stackSize)
|
return@lazy ItemCache.coinItem(stackSize)
|
||||||
val replacementData = mutableMapOf<String, String>()
|
val replacementData = mutableMapOf<String, String>()
|
||||||
@@ -87,6 +83,10 @@ data class SBItemStack(
|
|||||||
return@lazy neuItem.asItemStack(idHint = skyblockId, replacementData).copyWithCount(stackSize)
|
return@lazy neuItem.asItemStack(idHint = skyblockId, replacementData).copyWithCount(stackSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun asImmutableItemStack(): ItemStack {
|
||||||
|
return itemStack
|
||||||
|
}
|
||||||
|
|
||||||
fun asItemStack(): ItemStack {
|
fun asItemStack(): ItemStack {
|
||||||
return itemStack.copy()
|
return itemStack.copy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user