2013-05-29 11:15:25 -07:00
|
|
|
package magicbees.world;
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
import magicbees.main.MagicBees;
|
|
|
|
|
import magicbees.main.utils.ChunkCoords;
|
|
|
|
|
import magicbees.world.feature.FeatureHive;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.world.World;
|
2013-05-29 17:49:54 -07:00
|
|
|
import net.minecraft.world.WorldType;
|
2013-05-29 11:15:25 -07:00
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
|
|
|
|
import net.minecraftforge.event.world.ChunkDataEvent;
|
|
|
|
|
import cpw.mods.fml.common.IWorldGenerator;
|
|
|
|
|
import cpw.mods.fml.common.registry.TickRegistry;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
|
2013-05-31 15:09:15 -07:00
|
|
|
public class WorldGeneratorHandler implements IWorldGenerator
|
2013-05-29 11:15:25 -07:00
|
|
|
{
|
|
|
|
|
public WorldTicker ticker;
|
|
|
|
|
|
2013-05-31 15:09:15 -07:00
|
|
|
public WorldGeneratorHandler()
|
2013-05-29 11:15:25 -07:00
|
|
|
{
|
|
|
|
|
this.ticker = new WorldTicker(this);
|
|
|
|
|
TickRegistry.registerTickHandler(this.ticker, Side.SERVER);
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
|
|
|
|
|
|
FeatureHive.initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
|
public void chunkSaveEventHandler(ChunkDataEvent.Save event)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
|
if (MagicBees.getConfig().DoHiveRetrogen)
|
|
|
|
|
{
|
|
|
|
|
tag.setBoolean("hiveRetrogen", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event.getData().setTag("MagicBees", tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
|
public void chunkLoadEventHandler(ChunkDataEvent.Load event)
|
|
|
|
|
{
|
|
|
|
|
boolean doRetrogen = false;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound tag = (NBTTagCompound)event.getData().getTag("MagicBees");
|
|
|
|
|
if (tag == null)
|
|
|
|
|
{
|
|
|
|
|
doRetrogen = true;
|
|
|
|
|
}
|
2014-01-21 14:00:32 -08:00
|
|
|
else if (MagicBees.getConfig().DoHiveRetrogen)
|
2013-06-04 13:26:44 -07:00
|
|
|
{
|
|
|
|
|
if (!tag.hasKey("hiveRetrogen") || MagicBees.getConfig().ForceHiveRegen)
|
|
|
|
|
{
|
|
|
|
|
doRetrogen = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-29 11:15:25 -07:00
|
|
|
|
|
|
|
|
if (doRetrogen)
|
|
|
|
|
{
|
|
|
|
|
ChunkCoords coords = new ChunkCoords(event.getChunk());
|
|
|
|
|
ticker.queueChunkCoords(coords);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
|
|
|
|
{
|
|
|
|
|
generateWorld(world, random, chunkX, chunkZ, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void generateWorld(World world, Random random, int chunkX, int chunkZ, boolean initialGen)
|
|
|
|
|
{
|
|
|
|
|
boolean modified = false;
|
2013-05-29 17:49:54 -07:00
|
|
|
|
|
|
|
|
if (world.provider.terrainType != WorldType.FLAT)
|
2013-05-29 11:15:25 -07:00
|
|
|
{
|
2013-05-29 17:49:54 -07:00
|
|
|
if (initialGen || MagicBees.getConfig().DoHiveRetrogen)
|
|
|
|
|
{
|
|
|
|
|
FeatureHive.generateHives(world, random, chunkX, chunkZ, initialGen);
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
2013-05-29 11:15:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!initialGen && modified)
|
|
|
|
|
{
|
|
|
|
|
world.getChunkFromChunkCoords(chunkX, chunkZ).setChunkModified();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|