Bassebombecraft

Bassebombecraft

18.5k Downloads

1.14.3: Unsupported feature : Class World doesn't support method addParticle(...) with custom colors

Closed this issue ยท 2 comments

commented

The class World dosen't support a method for spawning particles with a custom color.
This feature is used in the class bassebombecraft.event.particle.ParticleRenderingEventHandler:

	/**
	 * Render single particle with custom color.
	 * 
	 * Assumes that the particle is of a type which supports custom colors, e.g.
	 * {@linkplain ParticleTypes.SPELL_MOB}.
	 * 
	 * The particle is rendered without any acceleration
	 * 
	 * @param world    world object
	 * @param particle particle to render.
	 */
	static void renderParticleWithCustomColor(World world, ParticleRendering particle) {
		Random random = getBassebombeCraft().getRandom();
		float r = particle.getRedColorComponent(random);
		float g = particle.getGreenColorComponent(random);
		float b = particle.getBlueColorComponent(random);

		double x = particle.getPosition().getX() + 0.5D;
		double y = particle.getPosition().getY() + 1;
		double z = particle.getPosition().getZ() + 0.5D;
		world.addParticle(particle.getParticleType(), x, y, z, r, g, b);
	}

The feature is only used with if ParticleTypes.SPELL_MOB.
SPELL_MOB isn't supported in 1.14 either.

Observations in 1.14:

It seems that classes in 1.14 implements the interface net.minecraft.client.particle,IParticleFactory interface for creation of particles with change of color:

@OnlyIn(Dist.CLIENT)
public interface IParticleFactory<T extends IParticleData> {
   @Nullable
   Particle makeParticle(T typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed);
}

Example:

@OnlyIn(Dist.CLIENT)
public class SpellParticle extends SpriteTexturedParticle {

   @OnlyIn(Dist.CLIENT)
   public static class AmbientMobFactory implements IParticleFactory<BasicParticleType> {
      private final IAnimatedSprite field_217542_a;

      public AmbientMobFactory(IAnimatedSprite p_i50846_1_) {
         this.field_217542_a = p_i50846_1_;
      }

      public Particle makeParticle(BasicParticleType typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
         Particle particle = new SpellParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.field_217542_a);
         particle.setAlphaF(0.15F);
         particle.setColor((float)xSpeed, (float)ySpeed, (float)zSpeed);
         return particle;
      }
   }

   @OnlyIn(Dist.CLIENT)
   public static class WitchFactory implements IParticleFactory<BasicParticleType> {
      private final IAnimatedSprite field_217546_a;

      public WitchFactory(IAnimatedSprite p_i50842_1_) {
         this.field_217546_a = p_i50842_1_;
      }

      public Particle makeParticle(BasicParticleType typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
         SpellParticle spellparticle = new SpellParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.field_217546_a);
         float f = worldIn.rand.nextFloat() * 0.5F + 0.35F;
         spellparticle.setColor(1.0F * f, 0.0F * f, 1.0F * f);
         return spellparticle;
      }
   }
}

The different particle factories are registered with the particle manager:

@OnlyIn(Dist.CLIENT)
public class ParticleManager implements IFutureReloadListener {

   private void registerFactories() {
      this.func_215234_a(ParticleTypes.AMBIENT_ENTITY_EFFECT, SpellParticle.AmbientMobFactory::new);
      this.func_215234_a(ParticleTypes.WITCH, SpellParticle.WitchFactory::new);

And the used by the entities:

public class WitchEntity extends AbstractRaiderEntity implements IRangedAttackMob {

   /**
    * Handler for {@link World#setEntityState}
    */
   @OnlyIn(Dist.CLIENT)
   public void handleStatusUpdate(byte id) {
      if (id == 15) {
         for(int i = 0; i < this.rand.nextInt(35) + 10; ++i) {
            this.world.addParticle(ParticleTypes.WITCH, this.posX + this.rand.nextGaussian() * (double)0.13F, this.getBoundingBox().maxY + 0.5D + this.rand.nextGaussian() * (double)0.13F, this.posZ + this.rand.nextGaussian() * (double)0.13F, 0.0D, 0.0D, 0.0D);

commented

Solution: Create particle using the particle manager and set the colors.

commented

Closed with commit commit 69812db.