Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21] SoundEvent and ParticleType Utilities #877

Merged

Conversation

Notenoughmail
Copy link
Contributor

Description

Adds asset generation capabilities for SoundEvents and ParticleTypes and adds an event for registering particle providers

A port of #836 for 1.21

Example Script

Startup:

StartupEvents.registry('sound_event', e => {
  e.create('test')
    .sounds(g => {
      g.subtitle('kubejs.sound.test')
      g.sounds('minecraft:item/bucket/empty1', 'minecraft:item/bucket/empty2', 'minecraft:item/bucket/empty3')
  })
})

StartupEvents.registry('particle_type', e => {
  e.create('test')
    .textures([
      'minecraft:big_smoke_0',
      'minecraft:big_smoke_1',
      'minecraft:big_smoke_2',
      'minecraft:big_smoke_3'
    ])
  e.create('kubejs:mod')
    .texture('minecraft:big_smoke_11')
  e.create('kubejs:custom')
  e.create('special')
})

Client:

const HugeExplosionSeedParticle$Provider = Java.loadClass('net.minecraft.client.particle.HugeExplosionSeedParticle$Provider')

ClientEvents.particleProviderRegistry(event => {
  // Registers a default, simple provider for kubejs:test
  event.register('kubejs:test')
  // Registers a default, simple provider for kubejs:mod and allows users to edit the particle
  event.register('kubejs:mod', particle => {
    // Modify particle's options
    particle.friction = 1
    particle.gravity = 0.5
    particle.color = 0xFF4545
    particle.fasterWhenYMotionBlocked = true
  })
  // Registers a custom provider
  event.register('kubejs:custom', (type, clientlevel, x, y, z, spriteSet, xSpeed, ySpeed, zSpeed) => {
    var kube = clientLevel.kubeParticle(x, y, z, spriteSet);
    kube.color = 0xDD232D
    kube.onTick(particle => {
      particle.speed = [0, particle.ySpeed * 1.1, 0]
    })
    return kube
  })

  // Register a 'special' provider (does not have a SpriteSet provided)
  event.registerSpecial('kubejs:special', new HugeExplosionSeedParticle$Provider())
})

ClientEvents.lang('en_us', event => {
  event.add('kubejs.sound.test', 'Test Sound')
})

Other details

There is a new method in ClientLevelKJS which enables the create of new KubeAnimatedParticles, it may be better to put it (and other particle classes?) into a generic Particle wrapper

- Implement particle and sound asset gen
- Implement particle provider registration
@LatvianModder LatvianModder merged commit e1b0b2d into KubeJS-Mods:main Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants