public WeatherSimulationRegion(WeatherSystemBase ws, int regionX, int regionZ) { this.ws = ws; this.regionX = regionX; this.regionZ = regionZ; this.SnowAccumSnapshots = new RingArray <SnowAccumSnapshot>((int)(ws.api.World.Calendar.DaysPerYear * ws.api.World.Calendar.HoursPerDay) + 1); int regsize = ws.api.World.BlockAccessor.RegionSize; LastUpdateTotalHours = ws.api.World.Calendar.TotalHours; cloudTilebasePosX = (regionX * regsize) / ws.CloudTileSize; cloudTilebasePosZ = (regionZ * regsize) / ws.CloudTileSize; regionCenterPos = new BlockPos(regionX * regsize + regsize / 2, 0, regionZ * regsize + regsize / 2); Rand = new LCGRandom(ws.api.World.Seed); Rand.InitPositionSeed(regionX / 3, regionZ / 3); weatherData.Ambient = new AmbientModifier().EnsurePopulated(); if (ws.api.Side == EnumAppSide.Client) { capi = ws.api as ICoreClientAPI; weatherData.Ambient.FogColor = capi.Ambient.Base.FogColor.Clone(); } else { wsServer = ws as WeatherSystemServer; } ReloadPatterns(ws.api.World.Seed); }
public WeatherSimulationRegion(WeatherSystemBase ws, int regionX, int regionZ) { this.ws = ws; this.regionX = regionX; this.regionZ = regionZ; int regsize = ws.api.World.BlockAccessor.RegionSize; cloudTilebasePosX = (regionX * regsize) / ws.CloudTileSize; cloudTilebasePosZ = (regionZ * regsize) / ws.CloudTileSize; regionCenterPos = new BlockPos(regionX * regsize + regsize / 2, 0, regionZ * regsize + regsize / 2); Rand = new LCGRandom(ws.api.World.Seed); Rand.InitPositionSeed(regionX / 3, regionZ / 3); weatherData.Ambient = new AmbientModifier().EnsurePopulated(); if (ws.api.Side == EnumAppSide.Client) { capi = ws.api as ICoreClientAPI; weatherData.Ambient.FogColor = capi.Ambient.Base.FogColor.Clone(); } else { wsServer = ws as WeatherSystemServer; } ReloadPatterns(ws.api.World.Seed); }
public override void Initialize(ICoreAPI api) { base.Initialize(api); totalHoursWaterRetention = Api.World.Calendar.HoursPerDay + 0.5; upPos = base.Pos.UpCopy(); wsys = api.ModLoader.GetModSystem <WeatherSystemBase>(); allowundergroundfarming = Api.World.Config.GetBool("allowUndergroundFarming", false); allowcropDeath = Api.World.Config.GetBool("allowCropDeath", true); if (api is ICoreServerAPI) { RegisterGameTickListener(Update, 3300 + rand.Next(400)); api.ModLoader.GetModSystem <POIRegistry>().AddPOI(this); roomreg = Api.ModLoader.GetModSystem <RoomRegistry>(); } if (Block.Attributes != null) { delayGrowthBelowSunLight = Block.Attributes["delayGrowthBelowSunLight"].AsInt(19); lossPerLevel = Block.Attributes["lossPerLevel"].AsFloat(0.1f); if (weedNames == null) { weedNames = Block.Attributes["weedBlockCodes"].AsObject <CodeAndChance[]>(); for (int i = 0; weedNames != null && i < weedNames.Length; i++) { totalWeedChance += weedNames[i].Chance; } } } }
public override void Initialize(ICoreAPI api) { CheckIntervalMs = 1000; wsys = api.ModLoader.GetModSystem <WeatherSystemBase>(); base.Initialize(api); }
public WeatherSimulationSnowAccum(ICoreServerAPI sapi, WeatherSystemBase ws) { this.sapi = sapi; this.ws = ws; // Get a non-relighting block accessor, because snowlayers do not block light and do not remove light blocking blocks. ba = sapi.World.GetBlockAccessorBulkMinimalUpdate(true, false); ba.UpdateSnowAccumMap = false; cuba = sapi.World.GetBlockAccessorMapChunkLoading(false, false); cuba.UpdateSnowAccumMap = false; initRandomShuffles(); sapi.Event.ChunkColumnSnowUpdate += Event_ChunkColumnLoading; sapi.Event.ChunkColumnLoaded += Event_ChunkColumnLoaded; sapi.Event.SaveGameLoaded += Event_SaveGameLoaded; sapi.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, () => isShuttingDown = true); sapi.Event.RegisterGameTickListener(OnServerTick3s, 3000); sapi.Event.RegisterGameTickListener(OnServerTick100ms, 100); sapi.Event.ServerSuspend += Event_ServerSuspend; sapi.Event.ServerResume += Event_ServerResume; snowLayerScannerThread = new Thread(new ThreadStart(onThreadStart)); snowLayerScannerThread.IsBackground = true; }
private void initSoundsAndTicking() { fuelBlock = Api.World.BlockAccessor.GetBlock(FuelPos); l1 = Blockentity.RegisterGameTickListener(OnTick, 25); if (Api.Side == EnumAppSide.Server) { l2 = Blockentity.RegisterGameTickListener(OnSlowServerTick, 1000); } wsys = Api.ModLoader.GetModSystem <WeatherSystemBase>(); if (ambientSound == null && Api.Side == EnumAppSide.Client) { ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = FirePos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f }); if (ambientSound != null) { ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble(); ambientSound.Start(); } } particleFacing = BlockFacing.FromNormal(new Vec3i(FirePos.X - FuelPos.X, FirePos.Y - FuelPos.Y, FirePos.Z - FuelPos.Z)); }
public override void Initialize(ICoreAPI api) { base.Initialize(api); RegisterGameTickListener(OnTick, 25); RegisterGameTickListener(OnSlowTick, 1000); fireBlock = api.World.GetBlock(new AssetLocation("fire")); if (fireBlock == null) { fireBlock = new Block(); } neibBlock = api.World.BlockAccessor.GetBlock(Pos.AddCopy(fromFacing.Opposite)); wsys = api.ModLoader.GetModSystem <WeatherSystemBase>(); if (ambientSound == null && api.Side == EnumAppSide.Client) { ambientSound = ((IClientWorldAccessor)api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = Pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f }); if (ambientSound != null) { ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble(); ambientSound.Start(); } } }
public WeatherSimulationLightning(ICoreAPI api, WeatherSystemBase weatherSys) { this.weatherSys = weatherSys; weatherSysc = weatherSys as WeatherSystemClient; this.capi = api as ICoreClientAPI; if (api.Side == EnumAppSide.Client) { LightningAmbient = new AmbientModifier().EnsurePopulated(); capi.Ambient.CurrentModifiers["lightningambient"] = LightningAmbient; capi.Event.ReloadShader += LoadShader; LoadShader(); capi.Event.RegisterRenderer(this, EnumRenderStage.Opaque, "lightning"); capi.RegisterCommand("lntest", "", "", onCmdLineTest); } else { api.Event.RegisterGameTickListener(OnServerTick, 40, 3); (api as ICoreServerAPI).RegisterCommand("lntest", "", "", onCmdLineTestServer); } }
public WeatherPattern(WeatherSystemBase ws, WeatherPatternConfig config, LCGRandom rand, int cloudTilebasePosX, int cloudTilebasePosZ) { this.ws = ws; this.rand = rand; this.config = config; this.api = ws.api; this.cloudTilebasePosX = cloudTilebasePosX; this.cloudTilebasePosZ = cloudTilebasePosZ; }
public override void OnGameTick(float deltaTime) { if (entity.Pos.Y < -30) { entity.ReceiveDamage(new DamageSource() { Source = EnumDamageSource.Void, Type = EnumDamageType.Gravity }, 4); } secondsSinceLastUpdate += deltaTime; if (secondsSinceLastUpdate >= 1) { secondsSinceLastUpdate = 0; if (entity.Alive && Health < MaxHealth) { float recoverySpeed = 0.01f; EntityBehaviorHunger ebh = entity.GetBehavior <EntityBehaviorHunger>(); if (ebh != null) { EntityPlayer plr = (EntityPlayer)entity; if (plr != null && entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode == EnumGameMode.Creative) { return; } // When below 75% satiety, autoheal starts dropping recoverySpeed = GameMath.Clamp(0.01f * ebh.Saturation / ebh.MaxSaturation * 1 / 0.75f, 0, 0.01f); ebh.ConsumeSaturation(150f * recoverySpeed); } Health = Math.Min(Health + recoverySpeed, MaxHealth); } int rainy = entity.World.BlockAccessor.GetRainMapHeightAt((int)entity.ServerPos.X, (int)entity.ServerPos.Z); if (entity.World.Side == EnumAppSide.Server && entity is EntityPlayer && rainy <= entity.ServerPos.Y) { WeatherSystemBase wsys = entity.Api.ModLoader.GetModSystem <WeatherSystemBase>(); var state = wsys.GetPrecipitationState(entity.ServerPos.XYZ); if (state != null && state.ParticleSize > 0.6 && state.Type == EnumPrecipitationType.Hail && entity.World.Rand.NextDouble() < state.Level / 2) { entity.ReceiveDamage(new DamageSource() { Source = EnumDamageSource.Weather, Type = EnumDamageType.BluntAttack }, (float)state.ParticleSize / 15f); } } } }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); this.Orientation = BlockFacing.FromFirstLetter(Variant["facing"][0]); this.random = new Random(); if (api is ICoreClientAPI capi) { this.weatherSystem = capi.ModLoader.GetModSystem <WeatherSystemClient>(); } }
public WeatherDataReaderBase(ICoreAPI api, WeatherSystemBase ws) { this.api = api; this.ws = ws; BlendedWeatherData.Ambient = new AmbientModifier().EnsurePopulated(); blendedWeatherDataNoPrec.Ambient = new AmbientModifier().EnsurePopulated(); AdjacentSims[0] = ws.dummySim; AdjacentSims[1] = ws.dummySim; AdjacentSims[2] = ws.dummySim; AdjacentSims[3] = ws.dummySim; }
public LightningFlash(WeatherSystemBase weatherSys, ICoreAPI api, int?seed, Vec3d startpoint) { this.weatherSys = weatherSys; this.capi = api as ICoreClientAPI; this.api = api; rand = new Random(seed == null ? capi.World.Rand.Next() : (int)seed); color = new Vec4f(1, 1, 1, 1); linewidth = 0.33f; origin = startpoint.Clone(); origin.Y = api.World.BlockAccessor.GetRainMapHeightAt((int)origin.X, (int)origin.Z) + 1; }
protected void genPoints(WeatherSystemBase weatherSys) { Vec3d pos = new Vec3d(); points = new List <Vec3d>(); pos.Y = 0; float startY = (float)(weatherSys.CloudLevelRel * capi.World.BlockAccessor.MapSizeY + 2 - origin.Y); while (pos.Y < startY) { points.Add(pos.Clone()); pos.Y += rand.NextDouble(); pos.X += rand.NextDouble() * 2.0 - 1 / 1.0; pos.Z += rand.NextDouble() * 2.0 - 1 / 1.0; } points.Reverse(); }
public override void OnGameTick(float deltaTime) { entity.World.FrameProfiler.Mark("not-bhhealth"); if (entity.Pos.Y < -30) { entity.ReceiveDamage(new DamageSource() { Source = EnumDamageSource.Void, Type = EnumDamageType.Gravity }, 4); } secondsSinceLastUpdate += deltaTime; if (secondsSinceLastUpdate >= 1) { secondsSinceLastUpdate = 0; if (entity.Alive) { float health = Health; // higher performance to read this TreeAttribute only once float maxHealth = MaxHealth; if (health < maxHealth) { float recoverySpeed = 0.01f; // Only players have the hunger behavior, and the different nutrient saturations if (entity is EntityPlayer plr) { EntityBehaviorHunger ebh = entity.GetBehavior <EntityBehaviorHunger>(); if (ebh != null) { if (entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode == EnumGameMode.Creative) { return; } // When below 75% satiety, autoheal starts dropping recoverySpeed = GameMath.Clamp(0.01f * ebh.Saturation / ebh.MaxSaturation * 1 / 0.75f, 0, 0.01f); ebh.ConsumeSaturation(150f * recoverySpeed); } } Health = Math.Min(health + recoverySpeed, maxHealth); } } if (entity is EntityPlayer && entity.World.Side == EnumAppSide.Server) { // A costly check every 1s for hail damage, but it applies only to players who are in the open int rainy = entity.World.BlockAccessor.GetRainMapHeightAt((int)entity.ServerPos.X, (int)entity.ServerPos.Z); if (entity.ServerPos.Y >= rainy) { WeatherSystemBase wsys = entity.Api.ModLoader.GetModSystem <WeatherSystemBase>(); var state = wsys.GetPrecipitationState(entity.ServerPos.XYZ); if (state != null && state.ParticleSize >= 0.5 && state.Type == EnumPrecipitationType.Hail && entity.World.Rand.NextDouble() < state.Level / 2) { entity.ReceiveDamage(new DamageSource() { Source = EnumDamageSource.Weather, Type = EnumDamageType.BluntAttack }, (float)state.ParticleSize / 15f); } } } } }
public WeatherDataReaderPreLoad(ICoreAPI api, WeatherSystemBase ws) : base(api, ws) { }