diff --git a/README.md b/README.md index fcecd80..cadf649 100644 --- a/README.md +++ b/README.md @@ -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 | |------------:|:------------:|:----------------------------------:| @@ -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. diff --git a/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt new file mode 100644 index 0000000..0bc1231 --- /dev/null +++ b/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt @@ -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) + } +} diff --git a/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumPistonBehaviorsTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt similarity index 82% rename from src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumPistonBehaviorsTemplate.kt rename to src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt index 1a140eb..1b6d9ab 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumPistonBehaviorsTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt @@ -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 { diff --git a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt index f161969..8cd25aa 100644 --- a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt +++ b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt @@ -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 @@ -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( @@ -428,7 +432,13 @@ object ConiumTemplates { // Piston behavior. registerBlock( PISTON_BEHAVIOR, - ConiumPistonBehaviorsTemplate::create + ConiumBlockPistonBehaviorsTemplate::create + ) + + // Note block instrument. + registerBlock( + INSTRUMENT, + ConiumBlockInstrumentTemplate::create ) } }