Reworked dimension population
other mods shouldnt attempt to generate in pockets/limbo now. Expect pockets to gen 40x faster on hexxit
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package StevenDimDoors.mod_pocketDim;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
||||
import StevenDimDoors.mod_pocketDim.ticking.MobObelisk;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
@@ -19,6 +23,11 @@ public class CommonTickHandler implements ITickHandler
|
||||
public int tickCount=0;
|
||||
public int tickCount2=0;
|
||||
private static DDProperties properties = null;
|
||||
public static ArrayList<int[]> chunksToPopulate= new ArrayList<int[]>();
|
||||
public static final int MAX_MONOLITH_SPAWNING_CHANCE = 100;
|
||||
private static final int MAX_MONOLITH_SPAWN_Y = 245;
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
|
||||
|
||||
public CommonTickHandler()
|
||||
{
|
||||
@@ -40,6 +49,22 @@ public class CommonTickHandler implements ITickHandler
|
||||
{
|
||||
if (type.equals(EnumSet.of(TickType.SERVER)))
|
||||
{
|
||||
if(!CommonTickHandler.chunksToPopulate.isEmpty())
|
||||
{
|
||||
for(int[] chunkData : CommonTickHandler.chunksToPopulate)
|
||||
{
|
||||
if(chunkData[0]==properties.LimboDimensionID)
|
||||
{
|
||||
this.placeMonolithsInLimbo(chunkData[0], chunkData[1], chunkData[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.placeMonolithsInPockets(chunkData[0], chunkData[1], chunkData[2]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
CommonTickHandler.chunksToPopulate.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +78,134 @@ public class CommonTickHandler implements ITickHandler
|
||||
return null;
|
||||
}
|
||||
|
||||
private void placeMonolithsInPockets(int worldID, int chunkX, int chunkZ)
|
||||
{
|
||||
World worldObj = dimHelper.getWorld(worldID);
|
||||
DimData dimData = dimHelper.dimList.get(worldObj.provider.dimensionId);
|
||||
int sanity = 0;
|
||||
int blockID = 0;
|
||||
boolean didSpawn=false;
|
||||
|
||||
if (dimData == null ||
|
||||
dimData.dungeonGenerator == null ||
|
||||
dimData.dungeonGenerator.isOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//The following initialization code is based on code from ChunkProviderGenerate.
|
||||
//It makes our generation depend on the world seed.
|
||||
Random random = new Random(worldObj.getSeed());
|
||||
long factorA = random.nextLong() / 2L * 2L + 1L;
|
||||
long factorB = random.nextLong() / 2L * 2L + 1L;
|
||||
random.setSeed((long)chunkX * factorA + (long)chunkZ * factorB ^ worldObj.getSeed());
|
||||
|
||||
int x, y, z;
|
||||
do
|
||||
{
|
||||
//Select a random column within the chunk
|
||||
x = chunkX * CHUNK_SIZE + random.nextInt(CHUNK_SIZE);
|
||||
z = chunkZ * CHUNK_SIZE + random.nextInt(CHUNK_SIZE);
|
||||
y = MAX_MONOLITH_SPAWN_Y;
|
||||
blockID = worldObj.getBlockId(x, y, z);
|
||||
|
||||
while (blockID == 0 &&y>0)
|
||||
{
|
||||
y--;
|
||||
blockID = worldObj.getBlockId(x, y, z);
|
||||
|
||||
}
|
||||
while(blockID == mod_pocketDim.blockDimWall.blockID&&y>0)
|
||||
{
|
||||
y--;
|
||||
blockID = worldObj.getBlockId(x, y, z);
|
||||
}
|
||||
while (blockID == 0 &&y>0)
|
||||
{
|
||||
y--;
|
||||
blockID = worldObj.getBlockId(x, y, z);
|
||||
|
||||
}
|
||||
if(y > 0)
|
||||
{
|
||||
|
||||
|
||||
|
||||
int jumpSanity=0;
|
||||
int jumpHeight=0;
|
||||
do
|
||||
{
|
||||
|
||||
jumpHeight = y+random.nextInt(10);
|
||||
|
||||
jumpSanity++;
|
||||
}
|
||||
while(!worldObj.isAirBlock(x,jumpHeight+6 , z)&&jumpSanity<20);
|
||||
|
||||
|
||||
|
||||
|
||||
Entity mob = new MobObelisk(worldObj);
|
||||
mob.setLocationAndAngles(x, jumpHeight, z, 1, 1);
|
||||
worldObj.spawnEntityInWorld(mob);
|
||||
didSpawn=true;
|
||||
}
|
||||
|
||||
sanity++;
|
||||
|
||||
}
|
||||
while (sanity<5&&!didSpawn);
|
||||
}
|
||||
|
||||
private void placeMonolithsInLimbo(int worldID, int var2, int var3)
|
||||
{
|
||||
World world = dimHelper.getWorld(worldID);
|
||||
|
||||
if (rand.nextInt(MAX_MONOLITH_SPAWNING_CHANCE) < properties.MonolithSpawningChance)
|
||||
{
|
||||
int y =0;
|
||||
int x = var2*16 + rand.nextInt(16);
|
||||
int z = var3*16 + rand.nextInt(16);
|
||||
int yTest;
|
||||
do
|
||||
{
|
||||
|
||||
x = var2*16 + rand.nextInt(16);
|
||||
z = var3*16 + rand.nextInt(16);
|
||||
|
||||
while(world.getBlockId(x, y, z)==0&&y<255)
|
||||
{
|
||||
y++;
|
||||
}
|
||||
y = yCoordHelper.getFirstUncovered(world,x , y+2, z);
|
||||
|
||||
yTest=yCoordHelper.getFirstUncovered(world,x , y+5, z);
|
||||
if(yTest>245)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int jumpSanity=0;
|
||||
int jumpHeight=0;
|
||||
do
|
||||
{
|
||||
jumpHeight = y+rand.nextInt(25);
|
||||
|
||||
jumpSanity++;
|
||||
}
|
||||
while(!world.isAirBlock(x,jumpHeight+6 , z)&&jumpSanity<20);
|
||||
|
||||
|
||||
Entity mob = new MobObelisk(world);
|
||||
mob.setLocationAndAngles(x, jumpHeight, z, 1, 1);
|
||||
|
||||
|
||||
world.spawnEntityInWorld(mob);
|
||||
|
||||
}
|
||||
while (yTest > y);
|
||||
}
|
||||
}
|
||||
//replaces rifts in game that have been destroyed/have blocks placed over them.
|
||||
private void onTickInGame()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user