Skip to content

Commit

Permalink
TerrainAPI Lock
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed Nov 13, 2023
1 parent 5702766 commit bd102c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/useless/terrainapi/TerrainMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ public class TerrainMain implements ModInitializer {
public static final Gson GSON = (new GsonBuilder()).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
public static final String MOD_ID = "terrain-api";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
/**
* Prevents accidental use of API Features outside the proper initialization environment
*/
public static boolean LOCK_API = true;
@Override
public void onInitialize() {
LOGGER.info("TerrainMain initialized.");
}
@ApiStatus.Internal
public static void loadModules(){
LOCK_API = false;
new TerrainInitialization().onInitialize();
FabricLoader.getInstance().getEntrypoints("terrain-api", TerrainAPI.class).forEach(api -> {
// Make sure the method is implemented
Expand All @@ -33,5 +38,6 @@ public static void loadModules(){
}
});
ConfigManager.saveAll();
LOCK_API = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.world.generate.feature.WorldFeature;
import org.jetbrains.annotations.ApiStatus;
import useless.terrainapi.TerrainMain;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,6 +25,9 @@ public class GeneratorFeatures {
* @param densityParameters Object[] of additional parameters that will be included with the Parameters object passed into the density function
*/
public void addFeature(Function<Parameters, WorldFeature> featureFunction, Object[] featureParameters, Function<Parameters, Integer> densityFunction, Object[] densityParameters){
if (TerrainMain.LOCK_API){
throw new RuntimeException("Illegal use of Terrain Initialization outside of the main terrain-api entrypoint loop!!!");
}
featureFunctionsList.add(featureFunction);
featureParametersList.add(featureParameters);
densityFunctionsList.add(densityFunction);
Expand Down

0 comments on commit bd102c3

Please sign in to comment.