private void rainStopFunc(IServerPlayer player, int groupId, bool skipForward = false) { WeatherSystemServer wsys = api.ModLoader.GetModSystem <WeatherSystemServer>(); if (wsys.OverridePrecipitation != null) { player.SendMessage(groupId, string.Format("Override precipitation set, rain pattern will not change. Fix by typing /weather setprecip auto."), EnumChatType.CommandSuccess); return; } Vec3d pos = player.Entity.Pos.XYZ; float days = 0; float daysrainless = 0f; float firstRainLessDay = 0f; bool found = false; while (days < 21) { float precip = wsys.GetPrecipitation(pos.X, pos.Y, pos.Z, sapi.World.Calendar.TotalDays + days); if (precip < 0.04f) { if (!found) { firstRainLessDay = days; } found = true; daysrainless += 1f / sapi.World.Calendar.HoursPerDay; } else { if (found) { break; } } days += 1f / sapi.World.Calendar.HoursPerDay; } if (daysrainless > 0) { if (skipForward) { wsys.RainCloudDaysOffset += daysrainless; player.SendMessage(groupId, string.Format("Ok, forwarded rain simulation by {0:0.##} days. The rain should stop for about {1:0.##} days now", firstRainLessDay, daysrainless), EnumChatType.CommandSuccess); return; } player.SendMessage(groupId, string.Format("In about {0:0.##} days the rain should stop for about {1:0.##} days", firstRainLessDay, daysrainless), EnumChatType.CommandSuccess); } else { player.SendMessage(groupId, string.Format("No rain less days found for the next 3 in-game weeks :O"), EnumChatType.CommandSuccess); } }
public override bool ShouldExecute() { if (rand.NextDouble() > searchFrequency) { return(false); } reason = EnumRestReason.NoReason; float dayLightStrength = entity.World.Calendar.GetDayLightStrength(entity.Pos.X, entity.Pos.Z); if (cooldownUntilTotalHours < entity.World.Calendar.TotalHours) { reason = EnumRestReason.TakingABreak; } else if (dayLightStrength < 0.6) { // Hardcoded: Rest at night reason = EnumRestReason.Night; } else if (wsys?.WeatherDataSlowAccess.GetWindSpeed(entity.ServerPos.XYZ) > 0.75 || wsys?.GetPrecipitation(entity.ServerPos.XYZ) > 0.1) { // Hardcoded: Rest during heavy winds or during rain reason = EnumRestReason.Wind; } if (reason == EnumRestReason.NoReason) { return(false); } double dx = rand.NextDouble() * 4 - 2; double dz = rand.NextDouble() * 4 - 2; for (int i = 1; i >= 0; i--) { tmpPos.Set((int)(entity.ServerPos.X + dx), 0, (int)(entity.ServerPos.Z + dz)); tmpPos.Y = entity.World.BlockAccessor.GetTerrainMapheightAt(tmpPos) + i; Block block = entity.World.BlockAccessor.GetBlock(tmpPos); if (block.IsLiquid()) { return(false); } if (block.Attributes?.IsTrue("butterflyFeed") == true) { double topPos = block.Attributes["sitHeight"].AsDouble(block.TopMiddlePos.Y); entity.WatchedAttributes.SetDouble("windWaveIntensity", block.VertexFlags.GrassWindWave ? (block.VertexFlags.WeakWave ? topPos / 2 : topPos) : 0); MainTarget = tmpPos.ToVec3d().Add(block.TopMiddlePos.X, topPos, block.TopMiddlePos.Z); return(true); } if (block.SideSolid[BlockFacing.UP.Index]) { double topPos = block.TopMiddlePos.Y; entity.WatchedAttributes.SetDouble("windWaveIntensity", block.VertexFlags?.GrassWindWave == true ? (block.VertexFlags.WeakWave ? topPos / 2 : topPos) : 0); MainTarget = tmpPos.ToVec3d().Add(block.TopMiddlePos.X, topPos, block.TopMiddlePos.Z); return(true); } } return(false); }
private void cmdPrecTestServer(IServerPlayer player, int groupId, CmdArgs args) { WeatherSystemServer wsys = api.ModLoader.GetModSystem <WeatherSystemServer>(); EntityPos pos = player.Entity.Pos; int wdt = 400; float hourStep = 4f; float days = 1f; float posStep = 2f; double totaldays = api.World.Calendar.TotalDays; string subarg = args.PopWord(); bool climateTest = subarg == "climate"; if (subarg == "pos") { float precip = wsys.GetPrecipitation(pos.X, pos.Y, pos.Z, totaldays); player.SendMessage(groupId, "Prec here: " + precip, EnumChatType.CommandSuccess); return; } ClimateCondition conds = api.World.BlockAccessor.GetClimateAt(new BlockPos((int)pos.X, (int)pos.Y, (int)pos.Z), EnumGetClimateMode.WorldGenValues, totaldays); int offset = wdt / 2; Bitmap bmp; int[] pixels; if (subarg == "here") { wdt = 400; bmp = new Bitmap(wdt, wdt, PixelFormat.Format32bppArgb); pixels = new int[wdt * wdt]; posStep = 3f; offset = wdt / 2; for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { float x = dx * posStep - offset; float z = dz * posStep - offset; if ((int)x == 0 && (int)z == 0) { pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(255, 0, 0, 255); continue; } float precip = wsys.GetPrecipitation(pos.X + x, pos.Y, pos.Z + z, totaldays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } bmp.SetPixels(pixels); bmp.Save("preciphere.png"); player.SendMessage(groupId, "Ok exported", EnumChatType.CommandSuccess); return; } bmp = new Bitmap(wdt, wdt, PixelFormat.Format32bppArgb); pixels = new int[wdt * wdt]; using (var gif = AnimatedGif.AnimatedGif.Create("precip.gif", 100, -1)) { for (int i = 0; i < days * 24f; i++) { if (climateTest) { for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { conds.Rainfall = (float)i / (days * 24f); float precip = wsys.GetRainCloudness(conds, pos.X + dx * posStep - offset, pos.Z + dz * posStep - offset, api.World.Calendar.TotalDays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } } else { for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { float precip = wsys.GetPrecipitation(pos.X + dx * posStep - offset, pos.Y, pos.Z + dz * posStep - offset, totaldays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } } totaldays += hourStep / 24f; bmp.SetPixels(pixels); gif.AddFrame(bmp, 100, GifQuality.Grayscale); } } player.SendMessage(groupId, "Ok exported", EnumChatType.CommandSuccess); }