Require precipitation for Sigma soil snowfall
This commit is contained in:
parent
d7bcd912ac
commit
c11f0031fc
4 changed files with 99 additions and 1 deletions
42
.forgejo/workflows/sigma-snow-weather.yml
Normal file
42
.forgejo/workflows/sigma-snow-weather.yml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
name: Sigma Snow Weather Build
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/sigma-snow-weather-*']
|
||||
|
||||
jobs:
|
||||
sigma-snow-weather:
|
||||
runs-on: dune-ci
|
||||
steps:
|
||||
- name: Check out exact revision
|
||||
shell: bash
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init .
|
||||
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
|
||||
git checkout --detach FETCH_HEAD
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
with:
|
||||
gradle-version: '9.2.1'
|
||||
- name: Build Sigma soil class patch
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p DuneTerrain test jar
|
||||
|
||||
mkdir sigma-snow-weather-artifacts
|
||||
python3 tools/plugin_sigma_snow_weather.py DuneTerrain/build/libs/DuneRealms-Terrain.jar sigma-snow-weather-artifacts/sigma-snow-weather-classes.zip
|
||||
cp tools/plugin_sigma_snow_weather.py sigma-snow-weather-artifacts/
|
||||
printf '%s\n' "$(git rev-parse HEAD)" > sigma-snow-weather-artifacts/SOURCE_COMMIT
|
||||
(cd sigma-snow-weather-artifacts && sha256sum -- sigma-snow-weather-classes.zip *.py SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Sigma-Snow-Weather
|
||||
path: sigma-snow-weather-artifacts/
|
||||
if-no-files-found: error
|
||||
|
|
@ -31,10 +31,14 @@ public final class PlanetSoil {
|
|||
return false;
|
||||
}
|
||||
static Material target(String planet){return switch(planet){case "arrakis"->Material.SAND;case "giedi_prime"->Material.COARSE_DIRT;case "sigma_draconis_iv"->Material.GRASS_BLOCK;default->null;};}
|
||||
static boolean weatheringActive(World world){
|
||||
String name=world.getName();
|
||||
return PLANETS.contains(name)&&(!name.equals("sigma_draconis_iv")||world.hasStorm());
|
||||
}
|
||||
private void tick(){
|
||||
int current=round++;
|
||||
for(World world:Bukkit.getWorlds()){
|
||||
if(!PLANETS.contains(world.getName()))continue;
|
||||
if(!weatheringActive(world))continue;
|
||||
Chunk[] chunks=world.getLoadedChunks();if(chunks.length==0)continue;
|
||||
for(int i=0;i<Math.min(8,chunks.length);i++){
|
||||
Chunk chunk=chunks[Math.floorMod(current*8+i,chunks.length)];
|
||||
|
|
|
|||
|
|
@ -12,4 +12,16 @@ class PlanetSoilTest {
|
|||
@Test void waterAtFarmlandBoundaryHydratesButOutsideDoesNot(){World world=mock(World.class);Block block=soil(world),air=mock(Block.class),water=mock(Block.class);when(world.isChunkLoaded(anyInt(),anyInt())).thenReturn(true);when(world.getBlockAt(anyInt(),anyInt(),anyInt())).thenReturn(air);when(air.getType()).thenReturn(Material.AIR);when(water.getType()).thenReturn(Material.WATER);when(world.getBlockAt(13,64,8)).thenReturn(water);assertFalse(PlanetSoil.hydrated(block));when(world.getBlockAt(12,65,8)).thenReturn(water);assertTrue(PlanetSoil.hydrated(block));}
|
||||
@Test void waterloggedBlocksHydrateAndUnloadedNeighborsNeverLoad(){World world=mock(World.class);Block block=soil(world),air=mock(Block.class),wet=mock(Block.class);when(world.isChunkLoaded(anyInt(),anyInt())).thenReturn(true);when(world.getBlockAt(anyInt(),anyInt(),anyInt())).thenReturn(air);when(air.getType()).thenReturn(Material.AIR);var data=mock(Waterlogged.class);when(data.isWaterlogged()).thenReturn(true);when(wet.getType()).thenReturn(Material.OAK_SLAB);when(wet.getBlockData()).thenReturn(data);when(world.getBlockAt(8,64,8)).thenReturn(wet);assertTrue(PlanetSoil.hydrated(block));reset(world);when(world.isChunkLoaded(anyInt(),anyInt())).thenReturn(false);assertTrue(PlanetSoil.hydrated(block));verify(world,never()).getBlockAt(anyInt(),anyInt(),anyInt());}
|
||||
@Test void climateTouchesOnlyAgreedSoilAndWorlds(){assertTrue(PlanetSoil.source(Material.DIRT));assertTrue(PlanetSoil.source(Material.GRASS_BLOCK));assertFalse(PlanetSoil.source(Material.FARMLAND));assertEquals(Material.SAND,PlanetSoil.target("arrakis"));assertEquals(Material.COARSE_DIRT,PlanetSoil.target("giedi_prime"));assertEquals(Material.GRASS_BLOCK,PlanetSoil.target("sigma_draconis_iv"));assertNull(PlanetSoil.target("caladan"));assertNull(PlanetSoil.target("giedi_prime_nether"));}
|
||||
@Test void sigmaWeatheringRequiresPrecipitationAndLeavesOtherPlanetsAlone(){
|
||||
World world=mock(World.class);
|
||||
when(world.getName()).thenReturn("sigma_draconis_iv");
|
||||
assertFalse(PlanetSoil.weatheringActive(world));
|
||||
when(world.hasStorm()).thenReturn(true);
|
||||
assertTrue(PlanetSoil.weatheringActive(world));
|
||||
when(world.hasStorm()).thenReturn(false);
|
||||
when(world.getName()).thenReturn("arrakis","giedi_prime","sigma_draconis_iv_nether");
|
||||
assertTrue(PlanetSoil.weatheringActive(world));
|
||||
assertTrue(PlanetSoil.weatheringActive(world));
|
||||
assertFalse(PlanetSoil.weatheringActive(world));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
40
tools/plugin_sigma_snow_weather.py
Normal file
40
tools/plugin_sigma_snow_weather.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""Build and assemble the Sigma precipitation guard without altering its generator."""
|
||||
import argparse
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
BASELINE = '26e314bad6f9573a98a40569b0d85a0d53f2b45a7061c3199eaa9a8cac8edaa1'
|
||||
CLASS = 'com/example/duneterrain/PlanetSoil.class'
|
||||
|
||||
|
||||
def extract(compiled, output):
|
||||
with ZipFile(compiled) as jar, ZipFile(output, 'x') as patch:
|
||||
patch.writestr(CLASS, jar.read(CLASS))
|
||||
|
||||
|
||||
def assemble(baseline, patch, output):
|
||||
if hashlib.sha256(baseline.read_bytes()).hexdigest() != BASELINE:
|
||||
raise ValueError('Expected the exact retained Sigma Terrain')
|
||||
with ZipFile(baseline) as original, ZipFile(patch) as updates:
|
||||
entries = original.namelist()
|
||||
if len(set(entries)) != len(entries) or updates.namelist() != [CLASS]:
|
||||
raise ValueError('Expected only the reviewed soil class')
|
||||
replacement = updates.read(CLASS)
|
||||
if not replacement.startswith(b'\xca\xfe\xba\xbe') or replacement == original.read(CLASS):
|
||||
raise ValueError('Invalid or unchanged soil patch')
|
||||
with ZipFile(output, 'x') as candidate:
|
||||
for info in original.infolist():
|
||||
candidate.writestr(info, replacement if info.filename == CLASS else original.read(info))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('input', type=Path)
|
||||
parser.add_argument('output', type=Path)
|
||||
parser.add_argument('--baseline', type=Path)
|
||||
args = parser.parse_args()
|
||||
if args.baseline is None:
|
||||
extract(args.input, args.output)
|
||||
else:
|
||||
assemble(args.baseline, args.input, args.output)
|
||||
Loading…
Reference in a new issue

Staff