Skip to content

Commit db59b8b

Browse files
committed
Extend the API to allow mods to register their feature-generators at run-time. The feature will be added to _features.json if it is written out after this point.
1 parent ba1b906 commit db59b8b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/main/java/com/mcmoddev/orespawn/api/OreSpawnAPI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public interface OreSpawnAPI {
1919
OreSpawnWorldGen getWorldGenerator();
2020

2121
void registerSpawns();
22+
23+
void addFeatureGenerator(String name, String className);
2224
}

src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public void addFeature(JsonObject entry) {
7373
}
7474
}
7575

76+
public void addFeature(String name, String className) {
77+
IFeature feature = getInstance(className);
78+
if( feature != null ) {
79+
features.put(name, feature);
80+
featuresInverse.put(feature, name);
81+
}
82+
}
83+
7684
private IFeature getInstance(String className) {
7785
Class<?> featureClazz;
7886
Constructor<?> featureCons;

src/main/java/com/mcmoddev/orespawn/impl/OreSpawnImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public void registerSpawns() {
6161
public OreSpawnWorldGen getWorldGenerator() {
6262
return worldGenerator;
6363
}
64+
65+
@Override
66+
public void addFeatureGenerator(String name, String className) {
67+
OreSpawn.FEATURES.addFeature(name, className);
68+
}
6469
}

0 commit comments

Comments
 (0)