public override void Initialize(ICoreAPI api, JsonObject properties)
 {
     base.Initialize(api, properties);
     this.sound    = new AssetLocation("sounds/effect/swoosh");
     weatherSystem = Api.ModLoader.GetModSystem <WeatherSystemBase>();
     Blockentity.RegisterGameTickListener(CheckWindSpeed, 1000);
 }
        public bool checkStillLoaded(ItemSlot slot, EntityAgent interactingEntity)
        {
            if (slot == null || slot.Itemstack == null || slot.Itemstack.Attributes == null)
            {
                return(false);
            }
            if (!(interactingEntity is EntityPlayer))
            {
                return(true);
            }
            if (slot.Itemstack.Attributes.GetBool("loaded", false))
            {
                bool wetCheck = false;
                if (Attributes["waterUnloads"].AsBool(false))
                {
                    wetCheck = (interactingEntity as EntityPlayer).IsEyesSubmerged();
                    if (!wetCheck)
                    {
                        if (wsys == null)
                        {
                            wsys = interactingEntity.Api.ModLoader.GetModSystem <WeatherSystemBase>();
                        }
                        double rainLevel = 0;
                        wetCheck =
                            interactingEntity.World.Rand.NextDouble() < 0.05 &&
                            interactingEntity.World.BlockAccessor.GetRainMapHeightAt(interactingEntity.Pos.AsBlockPos.X, interactingEntity.Pos.AsBlockPos.Z) <= interactingEntity.Pos.AsBlockPos.Y &&
                            (rainLevel = wsys.GetPrecipitation(interactingEntity.Pos.XYZ)) > 0.04
                        ;
                        wetCheck = wetCheck && interactingEntity.Api.World.Rand.NextDouble() < rainLevel;
                    }
                }

                bool loadTimeoutCheck  = Attributes["unloadAfterMilliseconds"].AsInt(0) != 0 && interactingEntity.World.ElapsedMilliseconds > slot.Itemstack.Attributes.GetLong("unloadTime", 0);
                bool switchedAwayCheck = interactingEntity.World.ElapsedMilliseconds > slot.Itemstack.Attributes.GetLong("switchAwayUnloadTime", 0);
                if (loadTimeoutCheck || switchedAwayCheck || wetCheck)
                {
                    // api.Logger.Error("unload: timeout " + loadTimeoutCheck + " switchedAway " + switchedAwayCheck + " wet " + wetCheck);
                    // Weapon timed out or player no longer holding weapon, becomes unloaded.
                    slot.Itemstack.Attributes.SetInt("renderVariant", 0);
                    if (interactingEntity.World is IClientWorldAccessor)
                    {
                        slot.Itemstack.TempAttributes.RemoveAttribute("renderVariant");
                    }
                    (interactingEntity as EntityPlayer)?.Player?.InventoryManager.BroadcastHotbarSlot();
                    slot.Itemstack.Attributes.SetBool("loaded", false);
                    if (Attributes["fizzleSound"].AsString("").Length > 0)
                    {
                        interactingEntity.World.PlaySoundAt(AssetLocation.Create(Attributes["fizzleSound"].AsString(""), Code.Domain), interactingEntity, (interactingEntity as EntityPlayer)?.Player, false, 8);
                    }
                    // api.Logger.Error("weapon got unloaded");
                    return(false);
                }
                else
                {
                    // Player continues to hold weapon.
                    slot.Itemstack.Attributes.SetLong("switchAwayUnloadTime", interactingEntity.World.ElapsedMilliseconds + 100);
                    return(true);
                }
            }
            return(false);
        }