package common.item;

import common.color.TextColor;
import common.entity.npc.EntityNPC;
import common.init.SoundEvent;
import common.world.Weather;
import common.world.World;
import common.world.AWorldServer;

public class ItemWeatherToken extends ItemMagnetic {
	private final Weather weather;
	
	public ItemWeatherToken(Weather weather) {
		this.weather = weather;
		this.setMaxStackSize(1);
		this.setColor(TextColor.VIOLET);
	}
	
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
    {
    	if(worldIn.dimension.getType().weather) {
//	        if (!playerIn.creative)
	        --itemStackIn.stackSize;
	        worldIn.playSoundAtEntity(playerIn, SoundEvent.SPELL, 0.5F);
	        if (!worldIn.client)
	        {
	            AWorldServer world = (AWorldServer)worldIn;
	            if(!world.isExterminated()) {
	            	world.setWeather(this.weather);
	            	world.resetWeather();
	            }
	        }
    	}

//        playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
        return itemStackIn;
    }
    
    public String getDisplay(ItemStack stack) {
        return super.getDisplay(stack) + " (" + this.weather.getDisplay() + ")";
    }
}
