aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt
blob: c851758f322c14e938879ef0252fe80623edd1af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package moe.nea.notenoughupdates.rei

import io.github.moulberry.repo.data.NEUItem
import me.shedaniel.math.Rectangle
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.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 moe.nea.notenoughupdates.rei.NEUReiPlugin.Companion.asItemEntry
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
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> {
    override fun equals(o1: NEUItem?, o2: NEUItem?, context: ComparisonContext?): Boolean {
        return o1 === o2
    }

    override fun cheatsAs(entry: EntryStack<NEUItem>?, value: NEUItem?): ItemStack? {
        return value?.asItemStack()
    }

    override fun getValueType(): Class<NEUItem> = NEUItem::class.java
    override fun getType(): EntryType<NEUItem> =
        EntryType.deferred(NEUReiPlugin.SKYBLOCK_ITEM_TYPE_ID)

    override fun getRenderer(): EntryRenderer<NEUItem> = object : EntryRenderer<NEUItem> {
        override fun render(
            entry: EntryStack<NEUItem>,
            matrices: MatrixStack,
            bounds: Rectangle,
            mouseX: Int,
            mouseY: Int,
            delta: Float
        ) {
            VanillaEntryTypes.ITEM.definition.renderer
                .render(
                    entry.asItemEntry(),
                    matrices, bounds, mouseX, mouseY, delta
                )
        }

        override fun getTooltip(entry: EntryStack<NEUItem>, tooltipContext: TooltipContext): Tooltip? {
            return VanillaEntryTypes.ITEM.definition.renderer
                .getTooltip(entry.asItemEntry(), tooltipContext)
        }

    }

    override fun getSerializer(): EntrySerializer<NEUItem>? {
        return null
    }

    override fun getTagsFor(entry: EntryStack<NEUItem>?, value: NEUItem?): Stream<out TagKey<*>> {
        return Stream.empty()
    }

    override fun asFormattedText(entry: EntryStack<NEUItem>, value: NEUItem): Text {
        return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemEntry(), value.asItemStack())
    }

    override fun hash(entry: EntryStack<NEUItem>, value: NEUItem, context: ComparisonContext): Long {
        return System.identityHashCode(value) * 31L
    }

    override fun wildcard(entry: EntryStack<NEUItem>, value: NEUItem): NEUItem {
        return value
    }

    override fun normalize(entry: EntryStack<NEUItem>, value: NEUItem): NEUItem {
        return value
    }

    override fun copy(entry: EntryStack<NEUItem>?, value: NEUItem): NEUItem {
        return value
    }

    override fun isEmpty(entry: EntryStack<NEUItem>?, value: NEUItem?): Boolean {
        return false
    }

    override fun getIdentifier(entry: EntryStack<NEUItem>?, value: NEUItem): Identifier {
        return value.getIdentifier()
    }


}