package totemic_commons.pokefenn.tileentity.totem;

import totemic_commons.pokefenn.api.music.MusicInstrument;

public class StateTotemEffect extends TotemState
{
    private int musicAmount = 0;

    public StateTotemEffect(TileTotemBase tile)
    {
        super(tile);
    }

    @Override
    public void update()
    {
        tile.getTotemEffectSet().entrySet().forEach(e -> {
            int horizontal = e.getElement().getHorizontalRange(); //TODO
            int vertical = e.getElement().getVerticalRange();
            e.getElement().effect(tile.getWorld(), tile.getPos(), tile, e.getCount(), horizontal, vertical);
        });

        //Diminish melody over time
        if(musicAmount > 0 && tile.getWorld().getTotalWorldTime() % 47 == 0)
        {
            musicAmount--;
            tile.markDirty();
        }
    }

    @Override
    public boolean addMusic(MusicInstrument instr, int amount)
    {
        int previous = musicAmount;
        musicAmount = Math.min(previous + amount / 2, TileTotemBase.MAX_EFFECT_MUSIC);
        return musicAmount > previous;
    }

    public int getMusicAmount()
    {
        return musicAmount;
    }
}

@@ -45,16 +45,102 @@
 totem;%0A%0A
+import net.minecraft.util.EnumParticleTypes;%0Aimport net.minecraft.util.math.BlockPos;%0A
 import t
@@ -908,16 +908,566 @@
        %7D
+%0A%0A        if(tile.getWorld().isRemote && tile.getWorld().getTotalWorldTime() %25 40 == 0)%0A            spawnParticles();%0A    %7D%0A%0A    private void spawnParticles()%0A    %7B%0A        for(int i = 0; i %3C musicAmount / 16; i++)%0A        %7B%0A            float xoff = 2 * tile.getWorld().rand.nextFloat() - 1;%0A            float zoff = 2 * tile.getWorld().rand.nextFloat() - 1;%0A            BlockPos pos = tile.getPos();%0A            tile.getWorld().spawnParticle(EnumParticleTypes.NOTE, pos.getX() + 0.5 + xoff, pos.getY(), pos.getZ() + 0.5 + zoff, 0, 0.5, 0);%0A        %7D
 %0A    %7D%0A%0A

Add totem effect music particles