Skip to content

Commit

Permalink
Supported 'instrument'(note block).
Browse files Browse the repository at this point in the history
  • Loading branch information
cao-awa committed Nov 18, 2024
1 parent 23f7d7a commit 85cec54
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Conium lets you complete your mods only using datapacks.

### Build requirements

Conium has configured whole project, just clone the repository, and reload project and run gradle task ```remapJar```.
Conium has configured whole project, just clone the repository, and reload project then run the gradle task ```remapJar```.

| Requirement | Version | Notes |
|------------:|:------------:|:----------------------------------:|
Expand Down Expand Up @@ -94,6 +94,7 @@ For blocks, currently supporting:
| walk_velocity | No impl | Setting the movement velocity when entities walk on block |
| jump_velocity | No impl | Setting the movement velocity when entities jump on block |
| piston_behavior | No impl | Setting the behavior when piston interacting to the block |
| instrument | No impl | Setting the instrument of note block |

For entities, supported to defines 'component_groups' in bedrock schema, but unable to switching now.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.github.cao.awa.conium.block.template.instrument

import com.github.cao.awa.conium.block.template.ConiumBlockTemplate
import com.github.cao.awa.conium.template.ConiumTemplates.Block.INSTRUMENT
import com.google.gson.JsonElement
import net.minecraft.block.AbstractBlock
import net.minecraft.block.enums.NoteBlockInstrument
import net.minecraft.registry.RegistryWrapper.WrapperLookup

open class ConiumBlockInstrumentTemplate(private val instrument: NoteBlockInstrument, name: String = INSTRUMENT) : ConiumBlockTemplate(name) {
companion object {
@JvmStatic
fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockInstrumentTemplate = ConiumBlockInstrumentTemplate(createBehaviors(element.asString))

@JvmStatic
fun createBehaviors(name: String): NoteBlockInstrument {
return when (name.lowercase()) {
"harp" -> NoteBlockInstrument.HARP
"basedrum" -> NoteBlockInstrument.BASEDRUM
"snare" -> NoteBlockInstrument.SNARE
"hat" -> NoteBlockInstrument.HAT
"bass" -> NoteBlockInstrument.BASS
"flute" -> NoteBlockInstrument.FLUTE
"bell" -> NoteBlockInstrument.BELL
"guitar" -> NoteBlockInstrument.GUITAR
"chime" -> NoteBlockInstrument.CHIME
"xylophone" -> NoteBlockInstrument.XYLOPHONE
"iron_xylophone" -> NoteBlockInstrument.IRON_XYLOPHONE
"cow_bell" -> NoteBlockInstrument.COW_BELL
"didgeridoo" -> NoteBlockInstrument.DIDGERIDOO
"bit" -> NoteBlockInstrument.BIT
"banjo" -> NoteBlockInstrument.BANJO
"pling" -> NoteBlockInstrument.PLING
"zombie" -> NoteBlockInstrument.ZOMBIE
"skeleton" -> NoteBlockInstrument.SKELETON
"creeper" -> NoteBlockInstrument.CREEPER
"dragon" -> NoteBlockInstrument.DRAGON
"whiter_skeleton" -> NoteBlockInstrument.WITHER_SKELETON
"piglin" -> NoteBlockInstrument.PIGLIN
"custom_head" -> NoteBlockInstrument.CUSTOM_HEAD
else -> throw IllegalArgumentException("No note block instrument: '$name'")
}
}
}

override fun settings(settings: AbstractBlock.Settings) {
// Set piston behavior.
settings.instrument(this.instrument)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import net.minecraft.block.AbstractBlock
import net.minecraft.block.piston.PistonBehavior
import net.minecraft.registry.RegistryWrapper.WrapperLookup

open class ConiumPistonBehaviorsTemplate(private val behavior: PistonBehavior, name: String = PISTON_BEHAVIOR) : ConiumBlockTemplate(name) {
open class ConiumBlockPistonBehaviorsTemplate(private val behavior: PistonBehavior, name: String = PISTON_BEHAVIOR) : ConiumBlockTemplate(name) {
companion object {
@JvmStatic
fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumPistonBehaviorsTemplate = ConiumPistonBehaviorsTemplate(createBehaviors(element.asString))
fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockPistonBehaviorsTemplate = ConiumBlockPistonBehaviorsTemplate(createBehaviors(element.asString))

@JvmStatic
fun createBehaviors(name: String): PistonBehavior {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import com.github.cao.awa.conium.block.template.bedrock.destructible.explosion.C
import com.github.cao.awa.conium.block.template.bedrock.light.ConiumBedrockLightEmissionTemplate
import com.github.cao.awa.conium.block.template.collision.ConiumBlockCollisionTemplate
import com.github.cao.awa.conium.block.template.explosion.resistance.ConiumExplosionResistanceTemplate
import com.github.cao.awa.conium.block.template.instrument.ConiumBlockInstrumentTemplate
import com.github.cao.awa.conium.block.template.luminance.ConiumLuminanceTemplate
import com.github.cao.awa.conium.block.template.map.ConiumBedrockMapColorTemplate
import com.github.cao.awa.conium.block.template.map.ConiumMapColorTemplate
import com.github.cao.awa.conium.block.template.mining.ConiumHardnessTemplate
import com.github.cao.awa.conium.block.template.piston.ConiumPistonBehaviorsTemplate
import com.github.cao.awa.conium.block.template.piston.ConiumBlockPistonBehaviorsTemplate
import com.github.cao.awa.conium.block.template.replaceable.ConiumBlockReplaceableTemplate
import com.github.cao.awa.conium.block.template.velocity.ConiumBlockMovementVelocityTemplate
import com.github.cao.awa.conium.block.template.velocity.jump.ConiumBlockJumpVelocityTemplate
Expand Down Expand Up @@ -376,6 +377,9 @@ object ConiumTemplates {
// Piston behavior.
const val PISTON_BEHAVIOR: String = "piston_behavior"

// Note block instrument.
const val INSTRUMENT: String = "instrument"

fun initBlockTemplates() {
// Destructible.
registerBlock(
Expand Down Expand Up @@ -428,7 +432,13 @@ object ConiumTemplates {
// Piston behavior.
registerBlock(
PISTON_BEHAVIOR,
ConiumPistonBehaviorsTemplate::create
ConiumBlockPistonBehaviorsTemplate::create
)

// Note block instrument.
registerBlock(
INSTRUMENT,
ConiumBlockInstrumentTemplate::create
)
}
}
Expand Down

0 comments on commit 85cec54

Please sign in to comment.