Skip to content

Commit

Permalink
🎨 Moved translation string enum to seperate class
Browse files Browse the repository at this point in the history
  • Loading branch information
asoji committed Feb 22, 2024
1 parent f08d9e2 commit 73c2d64
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/main/kotlin/gay/asoji/innerpastels/foods/RegisterFood.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gay.asoji.innerpastels.foods

import gay.asoji.innerpastels.items.CANDY_TRANSLATION_STRING
import gay.asoji.innerpastels.items.CandyTooltipItem
import gay.asoji.innerpastels.misc.CandyTranslationString
import gay.asoji.innerpastels.misc.secondsToTicks
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.effect.MobEffect
Expand All @@ -27,7 +27,7 @@ object RegisterFood {
fun registerCandy(
modID: String,
name: String,
candyTranslationString: CANDY_TRANSLATION_STRING,
candyTranslationString: CandyTranslationString,
nutrition: Int,
saturation: Int,
effect: MobEffect,
Expand Down Expand Up @@ -58,7 +58,7 @@ object RegisterFood {
* @property nutrition Candy's nutrition value in [Int]
* @property saturation Candy's saturation value in [Int]
*/
fun registerCandy(modID: String, name: String, candyTranslationString: CANDY_TRANSLATION_STRING, nutrition: Int, saturation: Int): CandyTooltipItem {
fun registerCandy(modID: String, name: String, candyTranslationString: CandyTranslationString, nutrition: Int, saturation: Int): CandyTooltipItem {
return Items.registerItem(
ResourceLocation(modID, name), CandyTooltipItem(
Item.Properties().food(
Expand All @@ -75,27 +75,27 @@ object RegisterFood {
}

fun registerTaffy(modID: String, name: String, effect: MobEffect, seconds: Int): CandyTooltipItem {
return registerCandy(modID, name, CANDY_TRANSLATION_STRING.TAFFY, 2, 2, effect, 0, seconds)
return registerCandy(modID, name, CandyTranslationString.TAFFY, 2, 2, effect, 0, seconds)
}

fun registerTaffy(modID: String, name: String): CandyTooltipItem {
return registerCandy(modID, name, CANDY_TRANSLATION_STRING.TAFFY, 2, 2)
return registerCandy(modID, name, CandyTranslationString.TAFFY, 2, 2)
}

fun registerCottonCandy(modID: String, name: String, effect: MobEffect, seconds: Int): CandyTooltipItem {
return registerCandy(modID, name, CANDY_TRANSLATION_STRING.COTTON, 3, 2, effect, 1, seconds)
return registerCandy(modID, name, CandyTranslationString.COTTON, 3, 2, effect, 1, seconds)
}

fun registerCottonCandy(modID: String, name: String): CandyTooltipItem {
return registerCandy(modID, name, CANDY_TRANSLATION_STRING.COTTON, 3, 2)
return registerCandy(modID, name, CandyTranslationString.COTTON, 3, 2)
}

fun registerHardCandy(modID: String, name: String, effect: MobEffect, seconds: Int): CandyTooltipItem {
return registerCandy(modID, name, CANDY_TRANSLATION_STRING.HARD, 3, 2, effect, 2, seconds)
return registerCandy(modID, name, CandyTranslationString.HARD, 3, 2, effect, 2, seconds)
}

fun registerHardCandy(modID: String, name: String): CandyTooltipItem {
return registerCandy(modID, name, CANDY_TRANSLATION_STRING.HARD, 3, 2)
return registerCandy(modID, name, CandyTranslationString.HARD, 3, 2)
}

fun registerIceCream(modID: String, name: String): Item {
Expand Down
13 changes: 2 additions & 11 deletions src/main/kotlin/gay/asoji/innerpastels/items/CandyTooltipItem.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gay.asoji.innerpastels.items

import gay.asoji.innerpastels.misc.CandyTranslationString
import net.minecraft.network.chat.Component
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.item.Item
Expand All @@ -9,17 +10,7 @@ import net.minecraft.world.item.alchemy.PotionUtils
import net.minecraft.world.level.Level
import java.util.*

/**
* Translation string to show which candy shows how much hunger.
* [actual strings in library's /src/main/resources/assets/innerpastels/lang/en_us.json]
*/
enum class CANDY_TRANSLATION_STRING(val candyHungerString: String) {
TAFFY("item.innerpastels.candies.hunger.description.taffy"),
COTTON("item.innerpastels.candies.hunger.description.cotton"),
HARD("item.innerpastels.candies.hunger.description.hard")
}

class CandyTooltipItem(properties: Properties, val candyTranslationString: CANDY_TRANSLATION_STRING) : Item(properties) {
class CandyTooltipItem(properties: Properties, val candyTranslationString: CandyTranslationString) : Item(properties) {
override fun appendHoverText(itemStack: ItemStack, level: Level?, list: MutableList<Component>, tooltipFlag: TooltipFlag) {
list.add(Component.translatable(candyTranslationString.candyHungerString))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gay.asoji.innerpastels.misc

/**
* Translation string to show which candy shows how much hunger.
* [actual strings in library's /src/main/resources/assets/innerpastels/lang/en_us.json]
*/
enum class CandyTranslationString(val candyHungerString: String) {
TAFFY("item.innerpastels.candies.hunger.description.taffy"),
COTTON("item.innerpastels.candies.hunger.description.cotton"),
HARD("item.innerpastels.candies.hunger.description.hard")
}

0 comments on commit 73c2d64

Please sign in to comment.