KubeJS-Mods / KubeJS

https://kubejs.com
GNU Lesser General Public License v3.0
307 stars 90 forks source link

ParticleTypes and SoundEvents #836

Open Notenoughmail opened 4 months ago

Notenoughmail commented 4 months ago

Description

Provides asset generation capabilities for SoundEvents and ParticleTypes as well as a new event for registering ParticleProviders for custom particles

Allows for custom sounds to work out of the box as long as scriptors have a sound file in the right auto-genned location and custom particle to work once they have a provider registered through the added event

Example Script

Startup:

StartupEvents.registry('sound_event', e => {
  e.create('test');
})

StartupEvents.registry('particle_type', e => {
  e.create('test');
})

Client:

ClientEvents.particleProviderRegistry(e => {
  e.register('kubejs:test', (options, clientLevel, spriteSet, x, y, z, xSpeed, ySpeed, zSpeed) => {
    let particle = Client.customParticle(clientLevel, spriteSet, x, y, z);
    particle.gravity = 0;
    particle.friction = 1;
    particle.setParticleSpeed(0, 0, 0);
    particle.lifetime = 100;
    return particle;
  });
  // Or
  e.registerSimple('kubejs:test', (particle) => {
    particle.gravity = 0;
    particle.friction = 1;
    particle.setParticleSpeed(0, 0, 0);
    particle.lifetime = 100;
  });
  // Or
  e.registerSimple('kubejs:test'); // No modification of particle's properties
})

Other details

A new subclass of SimpleAnimatedParticle was made, for use in providers, which can be made through the Client binding, but I'd like some input on renaming the method and/or if it would be better to move it to ClientLevelKJS so its use in the provider would look like clientLevel.customParticle(...