aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/rei/recipes/SBMobDropRecipe.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-08-28 19:04:24 +0200
committerLinnea Gräf <nea@nea.moe>2024-08-28 19:04:24 +0200
commitd2f240ff0ca0d27f417f837e706c781a98c31311 (patch)
tree0db7aff6cc14deaf36eed83889d59fd6b3a6f599 /src/main/kotlin/rei/recipes/SBMobDropRecipe.kt
parenta6906308163aa3b2d18fa1dc1aa71ac9bbcc83ab (diff)
downloadFirmament-d2f240ff0ca0d27f417f837e706c781a98c31311.tar.gz
Firmament-d2f240ff0ca0d27f417f837e706c781a98c31311.tar.bz2
Firmament-d2f240ff0ca0d27f417f837e706c781a98c31311.zip
Refactor source layout
Introduce compat source sets and move all kotlin sources to the main directory [no changelog]
Diffstat (limited to 'src/main/kotlin/rei/recipes/SBMobDropRecipe.kt')
-rw-r--r--src/main/kotlin/rei/recipes/SBMobDropRecipe.kt108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/main/kotlin/rei/recipes/SBMobDropRecipe.kt b/src/main/kotlin/rei/recipes/SBMobDropRecipe.kt
new file mode 100644
index 0000000..a02220f
--- /dev/null
+++ b/src/main/kotlin/rei/recipes/SBMobDropRecipe.kt
@@ -0,0 +1,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
+ }
+ }
+ }
+ }
+ }
+
+}