2013-06-30 09:14:10 +00:00
|
|
|
package biomesoplenty.handlers;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.world.ChunkCoordIntPair;
|
|
|
|
import net.minecraft.world.EnumSkyBlock;
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
import net.minecraft.world.biome.BiomeGenBase;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
import biomesoplenty.api.Blocks;
|
2013-07-01 01:12:33 +00:00
|
|
|
import biomesoplenty.configuration.BOPConfiguration;
|
2013-06-30 09:14:10 +00:00
|
|
|
import cpw.mods.fml.common.ITickHandler;
|
|
|
|
import cpw.mods.fml.common.TickType;
|
|
|
|
|
|
|
|
public class TickHandlerServer implements ITickHandler
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
|
|
|
{
|
|
|
|
WorldServer worldserver = (WorldServer)tickData[0];
|
|
|
|
|
|
|
|
Iterator iterator = worldserver.activeChunkSet.iterator();
|
|
|
|
|
|
|
|
int rand = new Random().nextInt();
|
|
|
|
|
2013-08-03 00:07:43 +00:00
|
|
|
if (BOPConfiguration.Misc.rainCreatesPuddles)
|
2013-07-13 22:49:00 +00:00
|
|
|
{
|
|
|
|
while (iterator.hasNext())
|
|
|
|
{
|
|
|
|
ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator.next();
|
|
|
|
int k = chunkcoordintpair.chunkXPos * 16;
|
|
|
|
int l = chunkcoordintpair.chunkZPos * 16;
|
|
|
|
worldserver.theProfiler.startSection("getChunk");
|
|
|
|
Chunk chunk = worldserver.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
|
|
|
|
worldserver.theProfiler.endStartSection("tickChunk");
|
|
|
|
|
2013-08-07 02:03:47 +00:00
|
|
|
if (worldserver.provider.canDoRainSnowIce(chunk) && worldserver.rand.nextInt(200) == 0)
|
2013-07-13 22:49:00 +00:00
|
|
|
{
|
|
|
|
rand = rand * 3 + 1013904223;
|
|
|
|
int i1 = rand >> 2;
|
|
|
|
int j1 = i1 & 15;
|
|
|
|
int k1 = i1 >> 8 & 15;
|
|
|
|
int l1 = worldserver.getPrecipitationHeight(j1 + k, k1 + l);
|
2013-06-30 09:14:10 +00:00
|
|
|
|
2013-07-13 22:49:00 +00:00
|
|
|
if (worldserver.isRaining() && canCreatePuddle(worldserver, j1 + k, l1, k1 + l))
|
|
|
|
{
|
|
|
|
worldserver.setBlock(j1 + k, l1 - 1, k1 + l, Blocks.puddle.get().blockID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-30 09:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canCreatePuddle(WorldServer worldserver, int par1, int par2, int par3)
|
|
|
|
{
|
|
|
|
BiomeGenBase biomegenbase = worldserver.getBiomeGenForCoords(par1, par3);
|
|
|
|
float f = biomegenbase.getFloatTemperature();
|
|
|
|
|
2013-07-01 01:12:33 +00:00
|
|
|
if (f > 0.15F && f < 2.0F)
|
2013-06-30 09:14:10 +00:00
|
|
|
{
|
|
|
|
if (par2 >= 0 && par2 < 256 && worldserver.getSavedLightValue(EnumSkyBlock.Block, par1, par2, par3) < 10)
|
|
|
|
{
|
|
|
|
int l = worldserver.getBlockId(par1, par2 - 1, par3);
|
|
|
|
|
|
|
|
if (l == Block.dirt.blockID || l == Block.grass.blockID)
|
|
|
|
{
|
2013-07-04 00:22:41 +00:00
|
|
|
if (worldserver.getBlockId(par1, par2, par3) == 0)
|
2013-06-30 09:14:10 +00:00
|
|
|
{
|
2013-07-04 00:22:41 +00:00
|
|
|
if (worldserver.isBlockSolidOnSide(par1 + 1, par2 - 1, par3, ForgeDirection.UP) && worldserver.isBlockSolidOnSide(par1 - 1, par2 - 1, par3, ForgeDirection.UP) && worldserver.isBlockSolidOnSide(par1, par2 - 1, par3 + 1, ForgeDirection.UP) && worldserver.isBlockSolidOnSide(par1, par2 - 1, par3 - 1, ForgeDirection.UP))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-30 09:14:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumSet<TickType> ticks()
|
|
|
|
{
|
|
|
|
return EnumSet.of(TickType.WORLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getLabel()
|
|
|
|
{
|
|
|
|
return "BiomesOPlenty - World tick";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|