aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/rei/recipes/SBMobDropRecipe.kt
blob: a02220fd10198fe9e7e923328ee056813a037bf9 (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
98
99
100
101
102
103
104
105
106
107
108
package moe.nea.firmament.rei.recipes

import io.github.moulberry.repo.data.NEUMobDropRecipe
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.client.gui.Renderer
import me.shedaniel.rei.api.client.gui.widgets.Widget
import me.shedaniel.rei.api.client.gui.widgets.Widgets
import me.shedaniel.rei.api.client.registry.display.DisplayCategory
import me.shedaniel.rei.api.common.category.CategoryIdentifier
import me.shedaniel.rei.api.common.util.EntryStacks
import net.minecraft.item.Items
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import moe.nea.firmament.Firmament
import moe.nea.firmament.gui.entity.EntityRenderer
import moe.nea.firmament.gui.entity.EntityWidget
import moe.nea.firmament.rei.SBItemEntryDefinition

class SBMobDropRecipe(override val neuRecipe: NEUMobDropRecipe) : SBRecipe() {
    override fun getCategoryIdentifier(): CategoryIdentifier<*> = Category.categoryIdentifier

    object Category : DisplayCategory<SBMobDropRecipe> {
        override fun getCategoryIdentifier(): CategoryIdentifier<SBMobDropRecipe> =
            CategoryIdentifier.of(Firmament.MOD_ID, "mob_drop_recipe")

        override fun getTitle(): Text = Text.literal("Mob Drops")
        override fun getDisplayHeight(): Int {
            return 100
        }

        override fun getIcon(): Renderer = EntryStacks.of(Items.DIAMOND_SWORD)
        override fun setupDisplay(display: SBMobDropRecipe, bounds: Rectangle): List<Widget> {
            return buildList {
                add(Widgets.createRecipeBase(bounds))
                val source = display.neuRecipe.render
                val entity = if (source.startsWith("@")) {
                    EntityRenderer.constructEntity(Identifier.of(source.substring(1)))
                } else {
                    EntityRenderer.applyModifiers(source, listOf())
                }
                if (entity != null) {
                    val level = display.neuRecipe.level
                    val fullMobName =
                        if (level > 0) Text.translatable("firmament.recipe.mobs.name", level, display.neuRecipe.name)
                        else Text.translatable("firmament.recipe.mobs.name.nolevel", display.neuRecipe.name)
                    val tt = mutableListOf<Text>()
                    tt.add((fullMobName))
                    tt.add(Text.literal(""))
                    if (display.neuRecipe.coins > 0) {
                        tt.add(Text.stringifiedTranslatable("firmament.recipe.mobs.coins", display.neuRecipe.coins))
                    }
                    if (display.neuRecipe.combatExperience > 0) {
                        tt.add(
                            Text.stringifiedTranslatable(
                                "firmament.recipe.mobs.combat",
                                display.neuRecipe.combatExperience
                            )
                        )
                    }
                    if (display.neuRecipe.enchantingExperience > 0) {
                        tt.add(
                            Text.stringifiedTranslatable(
                                "firmament.recipe.mobs.exp",
                                display.neuRecipe.enchantingExperience
                            )
                        )
                    }
                    if (display.neuRecipe.extra != null)
                        display.neuRecipe.extra.mapTo(tt) { Text.literal(it) }
                    if (tt.size == 2)
                        tt.removeAt(1)
                    add(
                        Widgets.withTooltip(
                            EntityWidget(entity, Point(bounds.minX + 5, bounds.minY + 15)),
                            tt
                        )
                    )
                }
                add(
                    Widgets.createLabel(Point(bounds.minX + 15, bounds.minY + 5), Text.literal(display.neuRecipe.name))
                        .leftAligned()
                )
                var x = bounds.minX + 60
                var y = bounds.minY + 20
                for (drop in display.neuRecipe.drops) {
                    val lore = drop.extra.mapTo(mutableListOf()) { Text.literal(it) }
                    if (drop.chance != null) {
                        lore += listOf(Text.translatable("firmament.recipe.mobs.drops", drop.chance))
                    }
                    val item = SBItemEntryDefinition.getEntry(drop.dropItem)
                        .value.copy(extraLore = lore)
                    add(
                        Widgets.createSlot(Point(x, y)).markOutput()
                            .entries(listOf(SBItemEntryDefinition.getEntry(item)))
                    )
                    x += 18
                    if (x > bounds.maxX - 30) {
                        x = bounds.minX + 60
                        y += 18
                    }
                }
            }
        }
    }

}