import { TicksPerSecond, system } from "@minecraft/server";
import { utils } from "Utils";

/* 
*******************************************************************************************************************************
DISCLAIMER: 
  This code is provided "as is" without warranty of any kind, either express or implied, including but not limited to 
  the implied warranties of merchantability and fitness for a particular purpose. ReBo and any contributors provide 
  this code for educational and informational purposes only. Users are encouraged to freely use, modify, and distribute 
  this code for non-commercial purposes. Any commercial use of this code or derivative works thereof is strictly prohibited 
  unless explicit permission is obtained from ReBo and any contributors.
******************************************************************************************************************************* 
*/

system.runInterval(() => {
  utils.serverCommandAsync(
    `tag @a remove mystical_jungle_particle`,
    `tag @a[x=50311,y=50,z=82,dx=-532,dy=180,dz=510] add mystical_jungle_particle`,
    `tag @a[x=49891,y=50,z=80,dx=-70,dy=180,dz=-25] add mystical_jungle_particle`,
    `tag @a[x=50104,y=50,z=81,dx=206,dy=180,dz=-40] add mystical_jungle_particle`,
    `tag @a[x=50185,y=50,z=43,dx=130,dy=180,dz=-100] add mystical_jungle_particle`,
  )
})

class ParticleController {
  particle = {
    id: 'spore_blossom',
    duration: 2.0
  };
  locations = [];
  selector = '@a[tag=mystical_jungle_particle]'
  
  constructor() {
    system.runInterval(() => {
      this.locations.forEach((location) => {
        utils.serverCommandAsync(`particle ${this.particle.id} ${location}` )
      })
      
      const rootEntities = utils.getEntities(this.selector);
      rootEntities.forEach((rootEntity) => {
        utils.entityCommandAsync(
          rootEntity,
          `particle ${this.particle.id} ~~~`
        )
      })
    },this.particle.duration * TicksPerSecond);
  }
}
export const particleController = new ParticleController();
