Skip to content

Commit

Permalink
📝More unfinished docs + candy string enum
Browse files Browse the repository at this point in the history
  • Loading branch information
asoji committed Feb 22, 2024
1 parent 36b3676 commit f08d9e2
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Mod Properties
mod_version=1.0.0
mod_version=1.0.1
maven_group=gay.asoji
archives_base_name=innerpastels

Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/gay/asoji/innerpastels/InnerPastels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package gay.asoji.innerpastels

import net.fabricmc.api.ModInitializer

/**
* Inner Pastels Internal Library, meant to be used for Softer Pastels, Desolated Pastels, and any other future *Pastel mods.
* This library adds a lot of common code and helper functions to assist with development for *Pastel mods, especially for Blocks, Items, and Data Generation.
*
* @author asojidev
* @version 1.0.1
*/
object InnerPastels : ModInitializer {
override fun onInitialize() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.world.level.block.Block

/**
* Model Generators used for Model Data Generation, creating required JSON models for certain blocks
* Model Generators used for Model Data Generation, creating required JSON models for certain blocks, meant to be used with your ModelProvider datagen.
*/
object ModelGenerators {
/**
* Creates a slab model based off another block, `block:` being the reference block, `slab:` being the target slab, and just call your normal BlockStateModelGenerator after
*
* Example:
* ```kotlin
* class SofterPastelsModelProvider(generator: FabricDataOutput) : FabricModelProvider(generator) {
* override fun generateBlockStateModels(blockStateModelGenerator: BlockModelGenerators) {
* createSlabs(SofterPastelsBlocks.WHITE_PASTEL_BLOCK, SofterPastelsBlocks.WHITE_PASTEL_SLAB_BLOCK, blockStateModelGenerator)
* }
* }
* ```
*/
fun createSlabs(block: Block, slab: Block, blockStateModelGenerator: BlockModelGenerators) {
val texturedModel = TexturedModel.CUBE[block]
val fullSlabModel = ModelLocationUtils.getModelLocation(block)
Expand All @@ -35,6 +47,18 @@ object ModelGenerators {
blockStateModelGenerator.delegateItemModel(slab, bottomSlab)
}

/**
* Creates a stair model based off another block, `block:` being the reference block, `stair:` being the target stair, and just call your normal BlockStateModelGenerator after
*
* Example:
* ```kotlin
* class SofterPastelsModelProvider(generator: FabricDataOutput) : FabricModelProvider(generator) {
* override fun generateBlockStateModels(blockStateModelGenerator: BlockModelGenerators) {
* createStairs(SofterPastelsBlocks.WHITE_PASTEL_BLOCK, SofterPastelsBlocks.WHITE_PASTEL_STAIR_BLOCK, blockStateModelGenerator)
* }
* }
* ```
*/
fun createStairs(block: Block, stairs: Block, blockStateModelGenerator: BlockModelGenerators) {
val texturedModel = TexturedModel.CUBE[block]
val innerStairs: ResourceLocation = ModelTemplates.STAIRS_INNER.create(
Expand Down Expand Up @@ -63,6 +87,18 @@ object ModelGenerators {
blockStateModelGenerator.delegateItemModel(stairs, straightStairs)
}

/**
* Creates a fence model based off another block, `block:` being the reference block, `fence:` being the target fence, and just call your normal BlockStateModelGenerator after
*
* Example:
* ```kotlin
* class SofterPastelsModelProvider(generator: FabricDataOutput) : FabricModelProvider(generator) {
* override fun generateBlockStateModels(blockStateModelGenerator: BlockModelGenerators) {
* createFence(SofterPastelsBlocks.WHITE_PASTEL_BLOCK, SofterPastelsBlocks.WHITE_PASTEL_FENCE_BLOCK, blockStateModelGenerator)
* }
* }
* ```
*/
fun createFence(block: Block, fence: Block, blockStateModelGenerator: BlockModelGenerators) {
val texturedModel = TexturedModel.CUBE[block]
val fencePost: ResourceLocation = ModelTemplates.FENCE_POST.create(
Expand Down Expand Up @@ -90,6 +126,18 @@ object ModelGenerators {
blockStateModelGenerator.delegateItemModel(fence, fenceInventoryModel)
}

/**
* Creates a fence gate model based off another block, `block:` being the reference block, `fenceGate:` being the target fence gate, and just call your normal BlockStateModelGenerator after
*
* Example:
* ```kotlin
* class SofterPastelsModelProvider(generator: FabricDataOutput) : FabricModelProvider(generator) {
* override fun generateBlockStateModels(blockStateModelGenerator: BlockModelGenerators) {
* createFenceGate(SofterPastelsBlocks.WHITE_PASTEL_BLOCK, SofterPastelsBlocks.WHITE_PASTEL_FENCE_GATE_BLOCK, blockStateModelGenerator)
* }
* }
* ```
*/
fun createFenceGate(block: Block, fenceGate: Block, blockStateModelGenerator: BlockModelGenerators) {
val texturedModel = TexturedModel.CUBE[block]
val fenceGateOpen: ResourceLocation = ModelTemplates.FENCE_GATE_OPEN.create(
Expand Down Expand Up @@ -125,6 +173,18 @@ object ModelGenerators {
blockStateModelGenerator.delegateItemModel(fenceGate, fenceGateClosed)
}

/**
* Creates a wall model based off another block, `block:` being the reference block, `wall:` being the target wall, and just call your normal BlockStateModelGenerator after
*
* Example:
* ```kotlin
* class SofterPastelsModelProvider(generator: FabricDataOutput) : FabricModelProvider(generator) {
* override fun generateBlockStateModels(blockStateModelGenerator: BlockModelGenerators) {
* createWall(SofterPastelsBlocks.WHITE_PASTEL_BLOCK, SofterPastelsBlocks.WHITE_PASTEL_WALL_BLOCK, blockStateModelGenerator)
* }
* }
* ```
*/
fun createWall(block: Block, wall: Block, blockStateModelGenerator: BlockModelGenerators) {
val texturedModel = TexturedModel.CUBE[block]
val wallPost: ResourceLocation = ModelTemplates.WALL_POST.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import net.minecraft.world.item.Items
import net.minecraft.world.level.ItemLike

/**
* Recipe Generators used for Recipe Generation via Fabric Recipe Provider, generating the required recipe JSONs
* Recipe Generators used for Recipe Generation via Fabric Recipe Provider, generating the required recipe JSONs, meant to be used with your RecipeProvider datagen.
*
* im craving tomato soup now
*/
Expand Down
44 changes: 35 additions & 9 deletions src/main/kotlin/gay/asoji/innerpastels/foods/RegisterFood.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gay.asoji.innerpastels.foods

import gay.asoji.innerpastels.items.CANDY_TRANSLATION_STRING
import gay.asoji.innerpastels.items.CandyTooltipItem
import gay.asoji.innerpastels.misc.secondsToTicks
import net.minecraft.resources.ResourceLocation
Expand All @@ -9,10 +10,24 @@ import net.minecraft.world.food.FoodProperties
import net.minecraft.world.item.Item
import net.minecraft.world.item.Items


object RegisterFood {
/**
* Registers a candy food item
*
* @property modID The namespace you're using, like `SofterPastels.MOD_ID`
* @property name Candy's Item ID [like `white_taffy`]
* @property candyTranslationString Type of candy for hunger translation string
* @property nutrition Candy's nutrition value in [Int]
* @property saturation Candy's saturation value in [Int]
* @property effect [MobEffect] tied to eating the candy
* @property amplifier Potency of said [MobEffect] after eating it
* @property seconds Amount of time the effect lasts in seconds
*/
fun registerCandy(
modID: String,
name: String,
candyTranslationString: CANDY_TRANSLATION_STRING,
nutrition: Int,
saturation: Int,
effect: MobEffect,
Expand All @@ -28,12 +43,22 @@ object RegisterFood {
.fast()
.alwaysEat()
.effect(MobEffectInstance(effect, seconds.secondsToTicks(), amplifier), 1.0f).build()
)
),
candyTranslationString
)
) as CandyTooltipItem
}

fun registerCandy(modID: String, name: String, nutrition: Int, saturation: Int, amplifier: Int): CandyTooltipItem {
/**
* Registers a candy food item
*
* @property modID The namespace you're using, like `SofterPastels.MOD_ID`
* @property name Candy's Item ID [like `white_taffy`]
* @property candyTranslationString Type of candy for hunger translation string
* @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 {
return Items.registerItem(
ResourceLocation(modID, name), CandyTooltipItem(
Item.Properties().food(
Expand All @@ -43,33 +68,34 @@ object RegisterFood {
.fast()
.alwaysEat()
.build()
)
),
candyTranslationString
)
) as CandyTooltipItem
}

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

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

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

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

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

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

fun registerIceCream(modID: String, name: String): Item {
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/gay/asoji/innerpastels/items/CandyTooltipItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ import net.minecraft.world.item.alchemy.PotionUtils
import net.minecraft.world.level.Level
import java.util.*

class CandyTooltipItem(properties: Properties) : Item(properties) {
/**
* 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) {
override fun appendHoverText(itemStack: ItemStack, level: Level?, list: MutableList<Component>, tooltipFlag: TooltipFlag) {
list.add(Component.translatable("item.innerpastels.candies.hunger.description"))
list.add(Component.translatable(candyTranslationString.candyHungerString))

val effects = LinkedList<MobEffectInstance>()

Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/gay/asoji/innerpastels/items/RegisterItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import net.minecraft.world.item.Item
import net.minecraft.world.level.block.Block

object RegisterItems {
/**
* Registers an item under the Item Registry, with a resource location of your mod's namespace and item ID
*/
fun registerItem(modID: String, name: String, item: Item): Item {
return Registry.register(BuiltInRegistries.ITEM, ResourceLocation(modID, name), item)
}


fun registerRegularItem(modID: String, name: String): Item {
return registerItem(modID, name, Item(Item.Properties()))
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/innerpastels/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"item.innerpastels.candies.hunger.description": "§61.0 x Hunger",
"item.innerpastels.candies.hunger.description.taffy": "§61.0 x Hunger",
"item.innerpastels.candies.hunger.description.cotton": "§61.5 x Hunger",
"item.innerpastels.candies.hunger.description.hard": "§61.5 x Hunger",
"item.innerpastels.candies.hunger.alwayseat": "§aYou can always gulp these down!",

"tag.block.innerpastels.carpets": "Carpets",
Expand Down

0 comments on commit f08d9e2

Please sign in to comment.