Repository navigation
1.10.2 API Cookbook
Minecraft 1.10.2 · Sky’s Realistic Weather 0.1.22.110021 · API 8 · config 8. See version support before using these examples in another port.
This Java 8 utility uses only public Sky API classes, normal Minecraft types and the JDK. The code is checked against the documented build. It deliberately returns Optional results where an absent reading matters.
package example.weather;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.Random;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import zone.moddev.mc.skysrealisticweather.api.ClimateSample;
import zone.moddev.mc.skysrealisticweather.api.LocalWeather;
import zone.moddev.mc.skysrealisticweather.api.PlantGrowthSample;
import zone.moddev.mc.skysrealisticweather.api.TemperatureSample;
import zone.moddev.mc.skysrealisticweather.api.TemperatureZone;
import zone.moddev.mc.skysrealisticweather.api.WeatherApi;
import zone.moddev.mc.skysrealisticweather.api.WeatherEpisode;
public final class WeatherIntegrationExamples {
private WeatherIntegrationExamples() { }
public static double toCelsius(double mc) {
return (mc - WeatherApi.SNOW_LINE) / 0.045;
}
public static double toFahrenheit(double mc) {
return toCelsius(mc) * 1.8 + 32;
}
public static float fromCelsius(float celsius) {
return WeatherApi.SNOW_LINE + celsius * 0.045F;
}
public static OptionalDouble outdoorCelsius(World world, BlockPos pos) {
OptionalDouble value=WeatherApi.getTemperature(world,pos);
if (!value.isPresent() || !Double.isFinite(value.getAsDouble())) {
return OptionalDouble.empty();
}
return OptionalDouble.of(toCelsius(value.getAsDouble()));
}
public static OptionalDouble effectiveCelsius(World world, BlockPos pos) {
Optional<TemperatureSample> value=WeatherApi.getTemperatureSample(world,pos);
if (!value.isPresent()) return OptionalDouble.empty();
return OptionalDouble.of(toCelsius(value.get().temperature));
}
public static Optional<LocalWeather.Precipitation> fallingAt(World world, BlockPos pos) {
return WeatherApi.getWeather(world,pos).map(value -> value.precipitation);
}
public static Optional<ClimateSample> generationClimate(World world, BlockPos surface, Biome selectedBiome) {
// No getBiome, getHeight, sky test or chunk lookup here.
return WeatherApi.getClimate(world,surface,selectedBiome);
}
public static OptionalDouble localEpisodeIntensity(World world, BlockPos pos) {
Optional<WeatherEpisode> value=WeatherApi.getWeatherEpisode(world,pos);
if (!value.isPresent()) return OptionalDouble.empty();
WeatherEpisode episode=value.get();
long time=episode.time(world.getWorldTime(),world.getTotalWorldTime());
return OptionalDouble.of(episode.covers(pos.getX(),pos.getZ(),time)
? episode.intensity(time) : 0);
}
public static boolean allowCustomNaturalGrowth(World world, BlockPos pos, Random random) {
// Only for a custom natural-growth path not already hooked by Sky.
// Call after your own soil/light/maturity/native eligibility checks.
Optional<PlantGrowthSample> value=WeatherApi.getPlantGrowth(world,pos);
if (!value.isPresent()) return true;
float multiplier=value.get().naturalGrowthMultiplier;
return multiplier>=1 || multiplier>0 && random.nextFloat()<multiplier;
}
public static boolean putRoom(World serverWorld, ResourceLocation id, BlockPos first, BlockPos second, float celsius) {
// Server logical thread only. The owning controller restores/removes it.
return WeatherApi.putTemperatureZone(serverWorld,
TemperatureZone.celsius(id,first,second,celsius));
}
public static boolean putMinimumRoom(World serverWorld, ResourceLocation id, BlockPos first, BlockPos second, float celsius) {
return WeatherApi.putTemperatureZone(serverWorld,
new TemperatureZone(id,first,second,fromCelsius(celsius),0,TemperatureZone.Mode.MINIMUM));
}
public static boolean removeRoom(World serverWorld, ResourceLocation id) {
return WeatherApi.removeTemperatureZone(serverWorld,id);
}
}-
Outdoor temperature:
outdoorCelsiusfollows the atmosphere, biome, altitude and temporary weather. It does not include a furnace or a child-mod room. -
Effective temperature:
effectiveCelsiusincludes the winning controlled climate or local heater.TemperatureSample.ambientTemperaturelets you compare it with outdoors;sourceand nullablezoneIdidentify the reason. -
Falling precipitation:
fallingAtincludes local storm coverage and shelter. A roof can remove falling precipitation without changing atmospheric temperature. - World generation: pass the exact biome chosen by your generator and the surface position. Do not call the loaded-position overload just to obtain a biome for terrain that does not exist yet.
-
Episodes: use the episode’s selected clock; an event’s peak intensity is not its current intensity or a guarantee it covers this block. Final in-world precipitation still comes from
getWeather. - Custom growth: only call the helper on an eligible natural attempt in a path Sky is not already checking. Its fallback is native growth. It is not a new bonemeal, watering or yield policy.
-
Rooms: the Celsius convenience factory is an exact override, not a warmth bonus.
MINIMUMis an absolute floor compared with ambient. Zone IDs are world-scoped and must remain stable across controller updates.
Absolute conversion uses C = (MC - 0.15) / 0.045 and F = C × 1.8 + 32. A difference uses deltaC = deltaMC / 0.045; Fahrenheit differences multiply by 1.8 without adding 32. These are the mod’s display conventions, not a claim that Minecraft’s underlying temperature parameter is a physical thermodynamics model.
Keep simulation and registration values in MC units. Player Celsius/Fahrenheit preferences do not change API values. The supported public API does not expose a general per-player display-preference getter; use your own presentation setting when implementing an independent UI.
Creating LocalWeather, TemperatureSample or WeatherEpisode objects does not apply weather to a world. The public API supplies reads, startup registrations and runtime temperature zones; operator commands are the documented weather-control interface.
Sky’s Realistic Weather · Version support · Source · Issues
Home · Version support · Languages
- Version guide
- Port status and builds
- Getting started
- Mod integrations
- Java API and examples
- API reference
- Generator compatibility
- Multiplayer and performance
- JEI client checks
- Integration versions
- Dependency metadata and publishing
- Getting started
- Configuration
- Climate presets and biomes
- Weather events
- Farming
- Thermometers
- Distant weather
- Pack workflow
- Mod integrations
- CraftTweaker
- Generator compatibility
- Administration
- Saved world settings
- Real-world requests