DimDoors/StevenDimDoors/mod_pocketDim/CommonTickHandler.java
2013-05-30 02:30:17 -04:00

185 lines
No EOL
4.7 KiB
Java

package StevenDimDoors.mod_pocketDim;
import java.util.EnumSet;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.relauncher.Side;
public class CommonTickHandler implements ITickHandler
{
Random rand= new Random();
public int tickCount=0;
public int tickCount2=0;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
if (type.equals(EnumSet.of(TickType.SERVER)))
{
onTickInGame();
}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
if (type.equals(EnumSet.of(TickType.SERVER)))
{
}
}
public EnumSet ticks()
{
return EnumSet.of(TickType.SERVER);
}
public String getLabel()
{
return null;
}
//replaces rifts in game that have been destroyed/have blocks placed over them.
private void onTickInGame()
{
try
{
if(tickCount>100)
{
tickCount=0;
int i=0;
while (i<15&&FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)
{
i++;
LinkData link;
//actually gets the random rift based on the size of the list
link = (LinkData) dimHelper.instance.getRandomLinkData(true);
if(link!=null)
{
if(dimHelper.getWorld(link.locDimID)!=null)
{
World world=dimHelper.getWorld(link.locDimID);
int blocktoReplace = world.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord);
if(!mod_pocketDim.blocksImmuneToRift.contains(blocktoReplace))//makes sure the rift doesnt replace a door or something
{
if(dimHelper.instance.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID)==null)
{
}
else
{
dimHelper.getWorld(link.locDimID).setBlock(link.locXCoord, link.locYCoord, link.locZCoord, mod_pocketDim.blockRiftID);
TileEntityRift.class.cast(dimHelper.getWorld(link.locDimID).getBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord)).hasGrownRifts=true;
}
}
}
}
}
}
}
catch (Exception e)
{
tickCount++;
System.out.println("something on tick went wrong");
}
tickCount++;
//this section regulates decay in Limbo- it records any blocks placed by the player and later progresss them through the decay cycle
if(tickCount2>10&&dimHelper.blocksToDecay!=null)
{
tickCount2=0;
if(!dimHelper.blocksToDecay.isEmpty()&&dimHelper.getWorld(mod_pocketDim.limboDimID)!=null)
{
if(dimHelper.blocksToDecay.size()>rand.nextInt(400))
{
int index = rand.nextInt(dimHelper.blocksToDecay.size());
Point3D point = (Point3D) dimHelper.blocksToDecay.get(index);
int blockID = dimHelper.getWorld(mod_pocketDim.limboDimID).getBlockId(point.getX(), point.getY(), point.getZ());
int idToSet=Block.stone.blockID;
if(blockID==0||blockID==mod_pocketDim.blockLimboID)
{
dimHelper.blocksToDecay.remove(index);
}
else
{
if(Block.blocksList[idToSet] instanceof BlockContainer)
{
idToSet=-1;
dimHelper.blocksToDecay.remove(index);
}
if(blockID==Block.cobblestone.blockID)
{
idToSet=Block.gravel.blockID;
}
if(blockID==Block.stone.blockID)
{
idToSet=Block.cobblestone.blockID;
}
if(blockID==Block.gravel.blockID&&!dimHelper.getWorld(mod_pocketDim.limboDimID).isAirBlock(point.getX(), point.getY()-1, point.getZ()))
{
idToSet=mod_pocketDim.blockLimboID;
dimHelper.getWorld(mod_pocketDim.limboDimID).scheduleBlockUpdate(point.getX(), point.getY(), point.getZ(),10, idToSet);
}
else if(blockID==Block.gravel.blockID)
{
dimHelper.blocksToDecay.remove(index);
idToSet=-1;
}
if(idToSet!=-1)
{
dimHelper.getWorld(mod_pocketDim.limboDimID).setBlock(point.getX(), point.getY(), point.getZ(), idToSet);
}
}
}
}
}
tickCount2++;
if(mod_pocketDim.teleTimer>0)
{
mod_pocketDim.teleTimer--;
}
}
}