下面列出了怎么用net.minecraftforge.fml.common.IWorldGenerator的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void serverStopped(FMLServerStoppedEvent evt)
{
Set<IWorldGenerator> worldGens = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGenerators");
Map<IWorldGenerator,Integer> worldGenIdx = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGeneratorIndex");
for (TargetWorldWrapper tww : delegates.values())
{
worldGens.remove(tww);
Integer idx = worldGenIdx.remove(tww);
worldGens.add(tww.delegate);
worldGenIdx.put(tww.delegate,idx);
}
delegates.clear();
}
@Mod.EventHandler
public void preinit(FMLPreInitializationEvent init)
{
final Logger modLog = init.getModLog();
IWorldGenerator gen = new IWorldGenerator() {
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
{
modLog.log(Level.INFO, "Calling!");
}
};
GameRegistry.registerWorldGenerator(gen, 10);
}
@EventHandler
public void serverAboutToStart(FMLServerAboutToStartEvent evt)
{
this.pendingWork = new MapMaker().weakKeys().makeMap();
this.completedWork = new MapMaker().weakKeys().makeMap();
this.completedWorkLocks = new MapMaker().weakKeys().makeMap();
Set<IWorldGenerator> worldGens = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGenerators");
Map<IWorldGenerator,Integer> worldGenIdx = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGeneratorIndex");
for (String retro : ImmutableSet.copyOf(retros.keySet()))
{
if (!delegates.containsKey(retro))
{
FMLLog.info("Substituting worldgenerator %s with delegate", retro);
for (Iterator<IWorldGenerator> iterator = worldGens.iterator(); iterator.hasNext();)
{
IWorldGenerator wg = iterator.next();
if (wg.getClass().getName().equals(retro))
{
iterator.remove();
TargetWorldWrapper tww = new TargetWorldWrapper();
tww.delegate = wg;
tww.tag = retro;
worldGens.add(tww);
Integer idx = worldGenIdx.remove(wg);
worldGenIdx.put(tww, idx);
FMLLog.info("Successfully substituted %s with delegate", retro);
delegates.put(retro, tww);
break;
}
}
if (!delegates.containsKey(retro))
{
FMLLog.warning("WorldRetrogen was not able to locate world generator class %s, it will be skipped, found %s", retro, worldGens);
retros.remove(retro);
}
}
}
}