Skip to content

Commit

Permalink
WIP: Re-Enable REI
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Dec 7, 2024
1 parent bf7795d commit 4ae0fd6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 102 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ val explosiveEnhancementSourceSet =
createIsolatedSourceSet("explosiveEnhancement", isEnabled = false) // TODO: wait for their port
val wildfireGenderSourceSet = createIsolatedSourceSet("wildfireGender", isEnabled = false) // TODO: wait on their port
val modmenuSourceSet = createIsolatedSourceSet("modmenu", isEnabled = false)
val reiSourceSet = createIsolatedSourceSet("rei", isEnabled = false)
val reiSourceSet = createIsolatedSourceSet("rei")
val moulconfigSourceSet = createIsolatedSourceSet("moulconfig", isEnabled = false)
val customTexturesSourceSet = createIsolatedSourceSet("texturePacks", "texturePacks")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,25 @@

package moe.nea.firmament.compat.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.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback
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.texture.SpriteAtlasTexture
import net.minecraft.item.ModelTransformationMode
import net.minecraft.item.tooltip.TooltipType
import moe.nea.firmament.compat.rei.FirmamentReiPlugin.Companion.asItemEntry
import moe.nea.firmament.events.ItemTooltipEvent
import moe.nea.firmament.repo.SBItemStack
import moe.nea.firmament.util.ErrorUtil
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
import moe.nea.firmament.util.mc.loreAccordingToNbt

object NEUItemEntryRenderer : EntryRenderer<SBItemStack>, BatchedEntryRenderer<SBItemStack, BakedModel> {
// TODO: make this re implement BatchedEntryRenderer, if possible (likely not, due to no-alloc rendering)
// Also it is probably not even that much faster now, with render layers.
object NEUItemEntryRenderer : EntryRenderer<SBItemStack> {
override fun render(
entry: EntryStack<SBItemStack>,
context: DrawContext,
Expand All @@ -46,7 +36,14 @@ object NEUItemEntryRenderer : EntryRenderer<SBItemStack>, BatchedEntryRenderer<S
mouseY: Int,
delta: Float
) {
entry.asItemEntry().render(context, bounds, mouseX, mouseY, delta)
context.matrices.push()
context.matrices.translate(bounds.centerX.toFloat(), bounds.centerY.toFloat(), 0F)
context.matrices.scale(bounds.width.toFloat() / 16F, bounds.height.toFloat() / 16F, 1f)
context.drawItemWithoutEntity(
entry.asItemEntry().value,
-8, -8,
)
context.matrices.pop()
}

val minecraft = MinecraftClient.getInstance()
Expand Down Expand Up @@ -85,88 +82,5 @@ object NEUItemEntryRenderer : EntryRenderer<SBItemStack>, BatchedEntryRenderer<S
return Tooltip.create(lore)
}

override fun getExtraData(entry: EntryStack<SBItemStack>): BakedModel {
return MC.itemRenderer.getModel(entry.asItemEntry().value,
MC.world,
MC.player, 0)

}

override fun getBatchIdentifier(entry: EntryStack<SBItemStack>, bounds: Rectangle?, extraData: BakedModel): Int {
return 1738923 + if (extraData.isSideLit) 1 else 0
}


override fun startBatch(entryStack: EntryStack<SBItemStack>, e: BakedModel, drawContext: DrawContext, v: Float) {
MC.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)
if (!e.isSideLit) {
DiffuseLighting.disableGuiDepthLighting()
}
}

override fun renderBase(
entryStack: EntryStack<SBItemStack>,
model: BakedModel,
drawContext: DrawContext,
immediate: VertexConsumerProvider.Immediate,
bounds: Rectangle,
i: Int,
i1: Int,
v: Float
) {
if (entryStack.isEmpty) return
drawContext.matrices.push()
drawContext.matrices.translate(bounds.centerX.toDouble(), bounds.centerY.toDouble(), 0.0)
// TODO: check the scaling here again
drawContext.matrices.scale(
bounds.width.toFloat(),
(bounds.height + bounds.height) / -2F,
(bounds.width + bounds.height) / 2f)
MC.itemRenderer.renderItem(
entryStack.value.asImmutableItemStack(),
ModelTransformationMode.GUI,
false, drawContext.matrices,
immediate, LightmapTextureManager.MAX_LIGHT_COORDINATE,
OverlayTexture.DEFAULT_UV,
model
)
drawContext.matrices.pop()
}

override fun afterBase(entryStack: EntryStack<SBItemStack>?, e: BakedModel, drawContext: DrawContext?, v: Float) {
RenderSystem.enableDepthTest()
if (!e.isSideLit)
DiffuseLighting.enableGuiDepthLighting()
}

override fun renderOverlay(
entryStack: EntryStack<SBItemStack>,
e: BakedModel,
drawContext: DrawContext,
immediate: VertexConsumerProvider.Immediate,
bounds: Rectangle,
i: Int,
i1: Int,
v: Float
) {
if (entryStack.isEmpty) return
val modelViewStack = RenderSystem.getModelViewStack()
modelViewStack.pushMatrix()
modelViewStack.mul(drawContext.matrices.peek().positionMatrix)
modelViewStack.translate(bounds.x.toFloat(), bounds.y.toFloat(), 0F)
modelViewStack.scale(bounds.width / 16.0f,
(bounds.width + bounds.height) / 2.0f / 16.0f,
1.0f) // TODO: weird scale again
drawContext.drawStackOverlay(MC.font, entryStack.value.asImmutableItemStack(), 0, 0, null)
modelViewStack.popMatrix()
}

override fun endBatch(entryStack: EntryStack<SBItemStack>?, e: BakedModel?, drawContext: DrawContext?, v: Float) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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.ItemConvertible
import net.minecraft.item.ItemStack
import net.minecraft.registry.tag.TagKey
import net.minecraft.text.Text
Expand Down Expand Up @@ -82,6 +83,8 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> {
fun getEntry(ingredient: NEUIngredient): EntryStack<SBItemStack> =
getEntry(SkyblockId(ingredient.itemId), count = ingredient.amount.toInt())

fun getPassthrough(item: ItemConvertible) = getEntry(SBItemStack.passthrough(ItemStack(item.asItem())))

fun getEntry(stack: ItemStack): EntryStack<SBItemStack> =
getEntry(
SBItemStack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.minecraft.block.Blocks
import net.minecraft.text.Text
import moe.nea.firmament.Firmament
import moe.nea.firmament.compat.rei.SBItemEntryDefinition
import moe.nea.firmament.repo.SBItemStack

class SBCraftingRecipe(override val neuRecipe: NEUCraftingRecipe) : SBRecipe() {
override fun getCategoryIdentifier(): CategoryIdentifier<*> = Category.catIdentifier
Expand All @@ -26,7 +27,7 @@ class SBCraftingRecipe(override val neuRecipe: NEUCraftingRecipe) : SBRecipe() {

override fun getTitle(): Text = Text.literal("SkyBlock Crafting")

override fun getIcon(): Renderer = EntryStacks.of(Blocks.CRAFTING_TABLE)
override fun getIcon(): Renderer = SBItemEntryDefinition.getPassthrough(Blocks.CRAFTING_TABLE)
override fun setupDisplay(display: SBCraftingRecipe, bounds: Rectangle): List<Widget> {
val point = Point(bounds.centerX - 58, bounds.centerY - 27)
return buildList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SBForgeRecipe(override val neuRecipe: NEUForgeRecipe) : SBRecipe() {
return 104
}

override fun getIcon(): Renderer = EntryStacks.of(Blocks.ANVIL)
override fun getIcon(): Renderer = SBItemEntryDefinition.getPassthrough(Blocks.ANVIL)
override fun setupDisplay(display: SBForgeRecipe, bounds: Rectangle): List<Widget> {
return buildList {
add(Widgets.createRecipeBase(bounds))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SBKatRecipe(override val neuRecipe: NEUKatUpgradeRecipe) : SBRecipe() {
return 100
}

override fun getIcon(): Renderer = EntryStacks.of(Items.BONE)
override fun getIcon(): Renderer = SBItemEntryDefinition.getPassthrough(Items.BONE)
override fun setupDisplay(display: SBKatRecipe, bounds: Rectangle): List<Widget> {
return buildList {
val arrowWidth = 24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SBMobDropRecipe(override val neuRecipe: NEUMobDropRecipe) : SBRecipe() {
return 100
}

override fun getIcon(): Renderer = EntryStacks.of(Items.DIAMOND_SWORD)
override fun getIcon(): Renderer = SBItemEntryDefinition.getPassthrough(Items.DIAMOND_SWORD)
override fun setupDisplay(display: SBMobDropRecipe, bounds: Rectangle): List<Widget> {
return buildList {
add(Widgets.createRecipeBase(bounds))
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/repo/ItemCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ object ItemCache : IReloadable {

val ItemStack.isBroken
get() = get(FirmamentDataComponentTypes.IS_BROKEN) ?: false

fun ItemStack.withFallback(fallback: ItemStack?): ItemStack {
if (isBroken && fallback != null) return fallback
return this
}

fun brokenItemStack(neuItem: NEUItem?, idHint: SkyblockId? = null): ItemStack {
return ItemStack(Items.PAINTING).apply {
setCustomName(Text.literal(neuItem?.displayName ?: idHint?.neuItem ?: "null"))
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/repo/SBItemStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.minecraft.network.codec.PacketCodecs
import net.minecraft.text.Text
import net.minecraft.util.Formatting
import moe.nea.firmament.repo.ItemCache.asItemStack
import moe.nea.firmament.repo.ItemCache.withFallback
import moe.nea.firmament.util.FirmFormatters
import moe.nea.firmament.util.LegacyFormattingCode
import moe.nea.firmament.util.SkyblockId
Expand All @@ -30,6 +31,7 @@ data class SBItemStack constructor(
val extraLore: List<Text> = emptyList(),
// TODO: grab this star data from nbt if possible
val stars: Int = 0,
val fallback: ItemStack? = null,
) {

fun getStackSize() = stackSize
Expand Down Expand Up @@ -77,6 +79,10 @@ data class SBItemStack constructor(
}
return SBItemStack(neuIngredient.skyblockId, neuIngredient.amount.toInt())
}

fun passthrough(itemStack: ItemStack): SBItemStack {
return SBItemStack(SkyblockId.NULL, null, itemStack.count, null, fallback = itemStack)
}
}

constructor(skyblockId: SkyblockId, petData: PetData) : this(
Expand Down Expand Up @@ -139,6 +145,7 @@ data class SBItemStack constructor(
val replacementData = mutableMapOf<String, String>()
injectReplacementDataForPets(replacementData)
return@run neuItem.asItemStack(idHint = skyblockId, replacementData)
.withFallback(fallback)
.copyWithCount(stackSize)
.also { it.appendLore(extraLore) }
.also { enhanceStatsByStars(it, stars) }
Expand Down

0 comments on commit 4ae0fd6

Please sign in to comment.