Skip to content

Commit

Permalink
Consistent, deterministic meteorite generation (#200)
Browse files Browse the repository at this point in the history
* Update buildscript

* Make meteorite locations independent of chunk loading order by using a grid-based system for location randomization

* Refactor MeteoritePlacer and related worldgen to be fully deterministic.

Also move around some initialization code into constructors to make it easier to read.
  • Loading branch information
eigenraven authored Nov 29, 2022
1 parent 49c77cc commit e4a1113
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 312 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1666827308
//version: 1669411416
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -338,10 +338,10 @@ dependencies {
annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3')
annotationProcessor('com.google.guava:guava:24.1.1-jre')
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor('org.spongepowered:mixin:0.8.5-GTNH:processor')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.1:processor')
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
compile('com.gtnewhorizon:gtnhmixins:2.0.1')
compile('com.gtnewhorizon:gtnhmixins:2.1.1')
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/debug/ToolMeteoritePlacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public boolean onItemUseFirst(
return false;
}

final MeteoritePlacer mp = new MeteoritePlacer();
final boolean worked = mp.spawnMeteorite(new StandardWorld(world), x, y, z);
final MeteoritePlacer mp = new MeteoritePlacer(new StandardWorld(world), System.currentTimeMillis(), x, y, z);
final boolean worked = mp.spawnMeteoriteCenter();

if (!worked) {
player.addChatMessage(new ChatComponentText("Un-suitable Location."));
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/appeng/util/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ public static float getRandomFloat() {
return RANDOM_GENERATOR.nextFloat();
}

/**
* Seed a random number generator from a world seed and grid location.
* The grid can be any arbitrary set of coordinates, e.g. chunk position or block position.
* This method guarantees that for the same inputs (worldSeed, x, z) the same seed will be used.
*
* @param rng The generator to re-seed.
* @param worldSeed Global seed independent of the grid position
* @param x X location in the grid
* @param z Z location in the grid
*/
public static void seedFromGrid(final Random rng, final long worldSeed, final long x, final long z) {
rng.setSeed(worldSeed);
final long xSeed = rng.nextLong() >> 2 + 1L;
final long zSeed = rng.nextLong() >> 2 + 1L;
final long gridSeed = (xSeed * x + zSeed * z) ^ worldSeed;
rng.setSeed(gridSeed);
}

/**
* This displays the value for encoded longs ( double *100 )
*
Expand Down
Loading

0 comments on commit e4a1113

Please sign in to comment.