Register the spawn cooldown book as a saved key

SpawnModule registers SpawnCooldownBook.SAVED in setup, as the api now
requires, and the key uses ResourceId and StorageCodec.
This commit is contained in:
piexel committed 2026-11-06 12:54:19 +01:00
1 parent 62e33edfe3
commit 769a29ce83
2 files changed
+7 -5

No files matched your search

@@ -19,9 +19,10 @@
package art.arcane.iris.engine.spawn; package art.arcane.iris.engine.spawn;
import art.arcane.volmlib.util.cache.CacheKey; import art.arcane.volmlib.util.cache.CacheKey;
import com.volmit.data.Codec; import com.volmit.data.SavedKey;
import com.volmit.data.StorageCodec;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld; import com.volmit.world.PackWorld;
import com.volmit.world.SavedKey;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
@@ -38,7 +39,7 @@ import java.util.function.ToLongFunction;
* rates hold across restarts. Spawners count by the key the pack names them by. Safe for concurrent use. * rates hold across restarts. Spawners count by the key the pack names them by. Safe for concurrent use.
*/ */
final class SpawnCooldownBook { final class SpawnCooldownBook {
static final SavedKey<SpawnCooldownBook> SAVED = new SavedKey<>("iris:spawn/cooldowns", SpawnCooldownBook.class, static final SavedKey<SpawnCooldownBook> SAVED = new SavedKey<>(ResourceId.parse("iris:spawn/cooldowns"), SpawnCooldownBook.class,
codec(System::currentTimeMillis), () -> new SpawnCooldownBook(System::currentTimeMillis)); codec(System::currentTimeMillis), () -> new SpawnCooldownBook(System::currentTimeMillis));
private static final int FORMAT_VERSION = 1; private static final int FORMAT_VERSION = 1;
@@ -57,7 +58,7 @@ final class SpawnCooldownBook {
} }
/** How {@link #SAVED} is stored: the books read by this codec count time with {@code clockMilliseconds}. */ /** How {@link #SAVED} is stored: the books read by this codec count time with {@code clockMilliseconds}. */
static Codec<SpawnCooldownBook> codec(LongSupplier clockMilliseconds) { static StorageCodec<SpawnCooldownBook> codec(LongSupplier clockMilliseconds) {
return new BookCodec(clockMilliseconds); return new BookCodec(clockMilliseconds);
} }
@@ -111,7 +112,7 @@ final class SpawnCooldownBook {
return firedAt == null || clockMilliseconds.getAsLong() - firedAt > intervalMilliseconds; return firedAt == null || clockMilliseconds.getAsLong() - firedAt > intervalMilliseconds;
} }
private record BookCodec(LongSupplier clockMilliseconds) implements Codec<SpawnCooldownBook> { private record BookCodec(LongSupplier clockMilliseconds) implements StorageCodec<SpawnCooldownBook> {
@Override @Override
public int version() { public int version() {
return FORMAT_VERSION; return FORMAT_VERSION;
@@ -47,6 +47,7 @@ public final class SpawnModule implements IrisModule {
registry.registerSettings(SpawnerSettings.class); registry.registerSettings(SpawnerSettings.class);
registry.registerSettings(EffectSettings.class); registry.registerSettings(EffectSettings.class);
SpawnResources.kinds().forEach(registry::registerResourceKind); SpawnResources.kinds().forEach(registry::registerResourceKind);
registry.registerSaved(SpawnCooldownBook.SAVED);
registry.registerService(EntitySpawns.class, new EntitySpawning()); registry.registerService(EntitySpawns.class, new EntitySpawning());
registry.registerService(AmbientEffects.class, new AmbientEffecting()); registry.registerService(AmbientEffects.class, new AmbientEffecting());
} }