I’ve been playing around with modifying world generators and after looking at the Skylands Template in the cookbook, the one thread that somewhat touches upon it in the forums, and of course the Sponge API docs (scroll to the bottom for modifyWorldGenerator), I can’t for the life of me get the modifyWorldGenerator function to be called.
As a first iteration to doing other things, I first want to make a hill defined by Ae^(ax^2 + az^2) centered around spawn. I do this by making a Generator Populator:
public class TestGeneratorPopulator implements GeneratorPopulator
{
public void populate(World arg0, MutableBlockBuffer blocks, BiomeBuffer arg2) {
// TODO Auto-generated method stub
Vector3i vec = blocks.getBlockMin();
int x = vec.getX();
int z = vec.getZ();
//define surface?
int height = (int) (64.0 + 50.0*Math.exp(-.01*x*x + -.01*z*z));
blocks.setHorizontalLayer(1,height,BlockTypes.STONE.getDefaultState());
}
}
This Generator Populator is then added to the worldGenerator by the MainGenParser:
public class MainGenParser implements WorldGeneratorModifier {
@Inject private Logger logger;
public String getName() {
// TODO Auto-generated method stub
return "GeoCraftBaseTerrainGen";
}
public String getId() {
// TODO Auto-generated method stub
return "GCBaseGen";
}
public void modifyWorldGenerator(WorldCreationSettings settings,
DataContainer container, WorldGenerator worldGenerator) {
logger.info("setting base populator");
worldGenerator.setBaseGeneratorPopulator(new TestGeneratorPopulator());
worldGenerator.setBiomeGenerator(new TestBiomeGen());
List<GeneratorPopulator> pops = worldGenerator.getGeneratorPopulators();
pops.clear();
List<Populator> popst = worldGenerator.getPopulators();
popst.clear();
}
}
Which is registered and called by a subscribed method in the main class:
@Plugin(id = "GeoCraft", name = "The Minecraft Geology Project", version = "1.0a")
public class GeoCraftMain {
@Inject private Logger logger;
@Inject private Game game;
@Inject @DefaultConfig(sharedRoot = false) private File defaultConfig;
@Subscribe
public void onServerAboutToStart(ServerAboutToStartEvent event)
{
final MainGenParser testGen = new MainGenParser();
this.logger.info("trying to add parser");
this.game.getRegistry().registerWorldGeneratorModifier(testGen);
this.logger.info("Parser Added");
this.game.getRegistry().getWorldBuilder()
.name("overworld")
.enabled(true)
.loadsOnStartup(true)
.keepsSpawnLoaded(true)
.dimensionType(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.OVERWORLD)
.generatorModifiers(testGen);
}
}
Also potentially important are my TestBiomeGen class:
public class TestBiomeGen implements BiomeGenerator {
public void generateBiomes(MutableBiomeBuffer arg0) {
// TODO Auto-generated method stub
}
}
and the server logs:
[08:57:16] [Server thread/INFO] [STDOUT]: [org.spongepowered.common.world.DimensionManager:init:52]: Proxying to Forge DimensionManager Init!
[08:57:16] [Server thread/INFO] [GeoCraft]: trying to add parser
[08:57:16] [Server thread/INFO] [GeoCraft]: Parser Added
[08:57:16] [Server thread/INFO]: Preparing level "world"
[08:57:17] [Server thread/INFO] [FML]: Loading dimension 0 (world) (net.minecraft.server.dedicated.DedicatedServer@4c5f3bf7)
[08:57:18] [Server thread/INFO] [FML]: Loading dimension 1 (DIM1) (net.minecraft.server.dedicated.DedicatedServer@4c5f3bf7)
[08:57:18] [Server thread/INFO] [FML]: Loading dimension -1 (DIM-1) (net.minecraft.server.dedicated.DedicatedServer@4c5f3bf7)
[08:57:18] [Server thread/INFO]: Preparing start region for level -1
[08:57:19] [Server thread/INFO]: Preparing spawn area: 6%
...just gonna fast foreward a bit...
[08:57:49] [Server thread/INFO]: Preparing spawn area: 97%
[08:57:50] [Server thread/INFO]: Done (33.916s)! For help, type "help" or "?"
As you can see, nothing failed and methods in the main class were called, but not the modifyWorldGenerator method in the MainGenParser. There was no “setting base parser” logged o-o.
So tell me spongemen and spongewomen, What the heck am I missing?
Edit: Formatting