Skip to content

Commit

Permalink
🚀 Sounds, Block Properties, and Models shit
Browse files Browse the repository at this point in the history
  • Loading branch information
asoji committed Mar 1, 2024
1 parent d4fee08 commit 45fede1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 15 deletions.
20 changes: 9 additions & 11 deletions src/main/kotlin/gay/asoji/innerpastels/blocks/Properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,11 @@ object Properties {
/**
* Default properties for a Pastel Leaves, being a copy of OAK_LEAVES
*/
fun PastelLeaves(): LeavesBlock {
return LeavesBlock(
FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.nonOpaque()
.blockVision(Blocks::never)
.suffocates(Blocks::never)
)
fun PastelLeaves(): BlockBehaviour.Properties {
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.nonOpaque()
.blockVision(Blocks::never)
.suffocates(Blocks::never)
}

/**
Expand All @@ -126,8 +124,8 @@ object Properties {
/**
* Default properties for a Pastel Plank, being a copy of OAK_PLANKS
*/
fun PastelPlanks(): Block {
return Block(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS))
fun PastelPlanks(): BlockBehaviour.Properties {
return FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)
}

/**
Expand All @@ -138,7 +136,7 @@ object Properties {
/**
* Default properties for a Pastel Sand, being a copy of SAND
*/
fun PastelSand(): Block {
return Block(FabricBlockSettings.copyOf(Blocks.SAND))
fun PastelSand(): BlockBehaviour.Properties {
return FabricBlockSettings.copyOf(Blocks.SAND)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gay.asoji.innerpastels.datagen

import net.minecraft.data.models.model.ModelTemplate
import net.minecraft.data.models.model.TextureSlot
import net.minecraft.resources.ResourceLocation
import java.util.*

/**
* Quick way to use model templates that don't exist in vanilla like `template_spawn_egg`, using strings alone or with texture slots
*/
object CustomModelTemplates {

// TODO: KDocs later, not in the mood to do them at the moment
fun createCustomBlockModel(modID: String, string: String): ModelTemplate {
return ModelTemplate(Optional.of(ResourceLocation(modID, "block/$string")), Optional.empty())
}

fun createCustomBlockModel(modID: String, string: String, textureSlots: TextureSlot): ModelTemplate {
return ModelTemplate(Optional.of(ResourceLocation(modID, "block/$string")), Optional.empty(), textureSlots)
}

fun createCustomBlockModel(modID: String, string: String, suffix: String, textureSlots: TextureSlot): ModelTemplate {
return ModelTemplate(Optional.of(ResourceLocation(modID, "block/$string")), Optional.of(suffix), textureSlots)
}

// maybe have `template_spawn_egg` or some shit for the string belong be a string enum? idk lol
fun createCustomItemModel(modID: String, string: String): ModelTemplate {
return ModelTemplate(Optional.of(ResourceLocation(modID, "item/$string")), Optional.empty())
}

fun createCustomItemModel(modID: String, string: String, textureSlots: TextureSlot): ModelTemplate {
return ModelTemplate(Optional.of(ResourceLocation(modID, "item/$string")), Optional.empty(), textureSlots)
}

fun createCustomItemModel(modID: String, string: String, suffix: String, textureSlots: TextureSlot): ModelTemplate {
return ModelTemplate(Optional.of(ResourceLocation(modID, "item/$string")), Optional.of(suffix), textureSlots)
}
}
21 changes: 17 additions & 4 deletions src/main/kotlin/gay/asoji/innerpastels/datagen/ModelGenerators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package gay.asoji.innerpastels.datagen

import gay.asoji.innerpastels.crab.CrabInTheCode
import net.minecraft.data.models.BlockModelGenerators
import net.minecraft.data.models.model.ModelLocationUtils
import net.minecraft.data.models.model.ModelTemplates
import net.minecraft.data.models.model.TextureMapping
import net.minecraft.data.models.model.TexturedModel
import net.minecraft.data.models.model.*
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.RotatedPillarBlock
import java.util.*

/**
* Model Generators used for Model Data Generation, creating required JSON models for certain blocks, meant to be used with your ModelProvider datagen.
Expand Down Expand Up @@ -242,6 +240,21 @@ object ModelGenerators {
blockStateModelGenerator.delegateItemModel(wall, wallInventoryModel)
}

/**
* Creates a pillar model
*
* Example:
* ```kotlin
* class DesolatedPastelsModelProvider(generator: FabricDataOutput) : FabricModelProvider(generator) {
* override fun generateBlockStateModels(blockStateModelGenerator: BlockModelGenerators) {
* ModelGenerators.createPillar(DesolatedPastelsBlocks.LIGHT_GREEN_LOG as RotatedPillarBlock, blockStateModelGenerator)
* }
* }
* ```
*
* @property pillarBlock The target pillar block
* @property blockStateModelGenerator The Block Model Generator for your block
*/
fun createPillar(pillarBlock: RotatedPillarBlock, blockStateModelGenerator: BlockModelGenerators) {
val texture = TextureMapping.logColumn(pillarBlock)
val pillarMain: ResourceLocation = ModelTemplates.CUBE_COLUMN.create(
Expand Down
22 changes: 22 additions & 0 deletions src/main/kotlin/gay/asoji/innerpastels/sounds/RegisterSounds.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gay.asoji.innerpastels.sounds

import net.minecraft.core.Registry
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.resources.ResourceLocation
import net.minecraft.sounds.SoundEvent
import net.minecraft.world.item.Item
import net.minecraft.world.item.RecordItem

/**
* Quickly register sound-related stuff, like a music disc or sound event.
*/
object RegisterSounds {
// TODO: Work on docs for this later, not in the mood to do it right now
fun registerSoundEvent(modID: String, name: String): SoundEvent {
return Registry.register(BuiltInRegistries.SOUND_EVENT, ResourceLocation(modID, name), SoundEvent.createVariableRangeEvent(ResourceLocation(modID, name)))
}

fun registerMusicDisc(modID: String, name: String, analogOutput: Int, soundEvent: SoundEvent, seconds: Int): RecordItem {
return Registry.register(BuiltInRegistries.ITEM, ResourceLocation(modID, name), RecordItem(analogOutput, soundEvent, Item.Properties().stacksTo(1), seconds))
}
}

0 comments on commit 45fede1

Please sign in to comment.