mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-21 03:33:23 +00:00
add iris data setup hook
This commit is contained in:
parent
50db1d11a7
commit
c01a7def5d
@ -24,6 +24,7 @@ import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.scripting.ExecutionEnvironment;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
@ -54,6 +55,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
private static final KMap<File, IrisData> dataLoaders = new KMap<>();
|
||||
private final File dataFolder;
|
||||
private final int id;
|
||||
private final ExecutionEnvironment.Pack environment;
|
||||
private boolean closed = false;
|
||||
private ResourceLoader<IrisBiome> biomeLoader;
|
||||
private ResourceLoader<IrisLootTable> lootLoader;
|
||||
@ -87,6 +89,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
this.engine = null;
|
||||
this.dataFolder = dataFolder;
|
||||
this.id = RNG.r.imax();
|
||||
this.environment = ExecutionEnvironment.createPack(this);
|
||||
hotloaded();
|
||||
}
|
||||
|
||||
@ -319,6 +322,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
}
|
||||
|
||||
public synchronized void hotloaded() {
|
||||
environment.close();
|
||||
possibleSnippets = new KMap<>();
|
||||
builder = new GsonBuilder()
|
||||
.addDeserializationExclusionStrategy(this)
|
||||
@ -359,6 +363,10 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
}
|
||||
|
||||
gson = builder.create();
|
||||
dimensionLoader.streamAll()
|
||||
.map(IrisDimension::getDataScripts)
|
||||
.flatMap(KList::stream)
|
||||
.forEach(environment::execute);
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
|
@ -44,8 +44,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
@ -216,6 +216,10 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
return j;
|
||||
}
|
||||
|
||||
public Stream<T> streamAll() {
|
||||
return streamAll(Arrays.stream(getPossibleKeys()));
|
||||
}
|
||||
|
||||
public Stream<T> streamAll(Stream<String> s) {
|
||||
return s.map(this::load);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class ExecutionEnvironment {
|
||||
private static final String VERSION = System.getProperty("iris.scriptVersion", "e08b6f893e");
|
||||
private static final String VERSION = System.getProperty("iris.scriptVersion", "master-ffbf167eba-1");
|
||||
private static final String BASE_URL = "https://jitpack.io/com/github/VolmitSoftware/Iris-Scripts/" + VERSION + "/Iris-Scripts-" + VERSION + "-all.jar";
|
||||
private static final Provider PROVIDER = ServiceLoader.load(Provider.class, buildLoader())
|
||||
.findFirst()
|
||||
|
@ -173,7 +173,7 @@ public class IrisEngine implements Engine {
|
||||
effects = new IrisEngineEffects(this);
|
||||
hash32 = new CompletableFuture<>();
|
||||
setupMode();
|
||||
getDimension().getSetupScripts().forEach(execution::execute);
|
||||
getDimension().getEngineScripts().forEach(execution::execute);
|
||||
J.a(this::computeBiomeMaxes);
|
||||
J.a(() -> {
|
||||
File[] roots = getData().getLoaders()
|
||||
|
@ -247,7 +247,11 @@ public class IrisDimension extends IrisRegistrant {
|
||||
@Desc("A list of scripts executed on engine setup")
|
||||
@RegistryListResource(IrisScript.class)
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
private KList<String> setupScripts = new KList<>();
|
||||
private KList<String> engineScripts = new KList<>();
|
||||
@Desc("A list of scripts executed on data setup")
|
||||
@RegistryListResource(IrisScript.class)
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
private KList<String> dataScripts = new KList<>();
|
||||
|
||||
public int getMaxHeight() {
|
||||
return (int) getDimensionHeight().getMax();
|
||||
|
Loading…
x
Reference in New Issue
Block a user