Reorganized Code in CommonTickHandler
Reorganized code in CommonTickHandler. Should be a little more readable now. This is in preparation for reimplementing Limbo decay.
This commit is contained in:
@@ -4,14 +4,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||||
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
||||||
import StevenDimDoors.mod_pocketDim.ticking.MobObelisk;
|
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.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.ITickHandler;
|
import cpw.mods.fml.common.ITickHandler;
|
||||||
import cpw.mods.fml.common.TickType;
|
import cpw.mods.fml.common.TickType;
|
||||||
@@ -19,15 +16,16 @@ import cpw.mods.fml.relauncher.Side;
|
|||||||
|
|
||||||
public class CommonTickHandler implements ITickHandler
|
public class CommonTickHandler implements ITickHandler
|
||||||
{
|
{
|
||||||
private Random rand = new Random();
|
private int tickCount = 0;
|
||||||
public int tickCount=0;
|
|
||||||
public int tickCount2=0;
|
|
||||||
private static DDProperties properties = null;
|
private static DDProperties properties = null;
|
||||||
public static ArrayList<int[]> chunksToPopulate= new ArrayList<int[]>();
|
public static ArrayList<int[]> chunksToPopulate = new ArrayList<int[]>();
|
||||||
|
|
||||||
|
private static final Random rand = new Random();
|
||||||
|
|
||||||
public static final int MAX_MONOLITH_SPAWNING_CHANCE = 100;
|
public static final int MAX_MONOLITH_SPAWNING_CHANCE = 100;
|
||||||
private static final int MAX_MONOLITH_SPAWN_Y = 245;
|
private static final int MAX_MONOLITH_SPAWN_Y = 245;
|
||||||
private static final int CHUNK_SIZE = 16;
|
private static final int CHUNK_SIZE = 16;
|
||||||
|
private static final int RIFT_REGENERATION_INTERVAL = 100; //Regenerate random rifts every 100 ticks
|
||||||
|
|
||||||
public CommonTickHandler()
|
public CommonTickHandler()
|
||||||
{
|
{
|
||||||
@@ -40,7 +38,7 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
{
|
{
|
||||||
if (type.equals(EnumSet.of(TickType.SERVER)))
|
if (type.equals(EnumSet.of(TickType.SERVER)))
|
||||||
{
|
{
|
||||||
onTickInGame();
|
onServerTick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,9 +49,12 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
{
|
{
|
||||||
if(!CommonTickHandler.chunksToPopulate.isEmpty())
|
if(!CommonTickHandler.chunksToPopulate.isEmpty())
|
||||||
{
|
{
|
||||||
for(int[] chunkData : CommonTickHandler.chunksToPopulate)
|
//TODO: This is bad. =/ We should not be passing around arrays of magic numbers.
|
||||||
|
//We should have an object that contains this information. ~SenseiKiwi
|
||||||
|
|
||||||
|
for (int[] chunkData : CommonTickHandler.chunksToPopulate)
|
||||||
{
|
{
|
||||||
if(chunkData[0]==properties.LimboDimensionID)
|
if(chunkData[0] == properties.LimboDimensionID)
|
||||||
{
|
{
|
||||||
this.placeMonolithsInLimbo(chunkData[0], chunkData[1], chunkData[2]);
|
this.placeMonolithsInLimbo(chunkData[0], chunkData[1], chunkData[2]);
|
||||||
}
|
}
|
||||||
@@ -68,11 +69,13 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumSet ticks()
|
@Override
|
||||||
|
public EnumSet<TickType> ticks()
|
||||||
{
|
{
|
||||||
return EnumSet.of(TickType.SERVER);
|
return EnumSet.of(TickType.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getLabel()
|
public String getLabel()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -98,7 +101,7 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
Random random = new Random(worldObj.getSeed());
|
Random random = new Random(worldObj.getSeed());
|
||||||
long factorA = random.nextLong() / 2L * 2L + 1L;
|
long factorA = random.nextLong() / 2L * 2L + 1L;
|
||||||
long factorB = random.nextLong() / 2L * 2L + 1L;
|
long factorB = random.nextLong() / 2L * 2L + 1L;
|
||||||
random.setSeed((long)chunkX * factorA + (long)chunkZ * factorB ^ worldObj.getSeed());
|
random.setSeed(chunkX * factorA + chunkZ * factorB ^ worldObj.getSeed());
|
||||||
|
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
do
|
do
|
||||||
@@ -207,14 +210,28 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onTickInGame()
|
private void onServerTick()
|
||||||
|
{
|
||||||
|
tickCount++; //There is no need to reset the counter. Let it overflow.
|
||||||
|
|
||||||
|
if (tickCount % RIFT_REGENERATION_INTERVAL == 0)
|
||||||
|
{
|
||||||
|
regenerateRifts();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (mod_pocketDim.teleTimer > 0)
|
||||||
|
{
|
||||||
|
mod_pocketDim.teleTimer--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void regenerateRifts()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Replace rifts that have been replaced (not permanently removed) by players
|
//Replace rifts that have been replaced (not permanently removed) by players
|
||||||
if (tickCount > 100)
|
|
||||||
{
|
|
||||||
tickCount = 0;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < 15 && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
while (i < 15 && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||||
@@ -228,9 +245,9 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
if(link!=null)
|
if(link!=null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(dimHelper.getWorld(link.locDimID)!=null)
|
if (dimHelper.getWorld(link.locDimID)!=null)
|
||||||
{
|
{
|
||||||
World world=dimHelper.getWorld(link.locDimID);
|
World world = dimHelper.getWorld(link.locDimID);
|
||||||
|
|
||||||
int blocktoReplace = world.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord);
|
int blocktoReplace = world.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord);
|
||||||
|
|
||||||
@@ -246,21 +263,10 @@ public class CommonTickHandler implements ITickHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
System.out.println("An exception occurred in CommonTickHandler.onGameTick():");
|
System.out.println("An exception occurred in CommonTickHandler.onServerTick():");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
tickCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mod_pocketDim.teleTimer > 0)
|
|
||||||
{
|
|
||||||
mod_pocketDim.teleTimer--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user