From 863cd4f4e8360f246a8771e51405c3ada70f4e47 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 30 Jun 2013 19:14:10 +1000 Subject: [PATCH] It's raining it's pouring the old man is snoring... --- .../biomesoplenty/BiomesOPlenty.java | 2 + src/minecraft/biomesoplenty/ClientProxy.java | 1 + .../biomesoplenty/blocks/BlockPuddle.java | 48 ++++----- .../blocks/renderers/PuddleRender.java | 19 ++-- .../handlers/TickHandlerServer.java | 99 +++++++++++++++++++ 5 files changed, 132 insertions(+), 37 deletions(-) create mode 100644 src/minecraft/biomesoplenty/handlers/TickHandlerServer.java diff --git a/src/minecraft/biomesoplenty/BiomesOPlenty.java b/src/minecraft/biomesoplenty/BiomesOPlenty.java index 8cedf7ea5..faf3eda69 100644 --- a/src/minecraft/biomesoplenty/BiomesOPlenty.java +++ b/src/minecraft/biomesoplenty/BiomesOPlenty.java @@ -18,6 +18,7 @@ import biomesoplenty.handlers.BreakSpeedHandler; import biomesoplenty.handlers.EntityEventHandler; import biomesoplenty.handlers.SoundHandler; import biomesoplenty.handlers.TickHandlerClient; +import biomesoplenty.handlers.TickHandlerServer; import biomesoplenty.helpers.AchievementHelper; import biomesoplenty.helpers.BOPLiquidHelper; import biomesoplenty.helpers.CreativeTabsBOP; @@ -120,5 +121,6 @@ public class BiomesOPlenty BOPCrossIntegration.postInit(); TickRegistry.registerTickHandler(new TickHandlerClient(), Side.CLIENT); + TickRegistry.registerTickHandler(new TickHandlerServer(), Side.SERVER); } } \ No newline at end of file diff --git a/src/minecraft/biomesoplenty/ClientProxy.java b/src/minecraft/biomesoplenty/ClientProxy.java index 00aa098eb..a0d534e53 100644 --- a/src/minecraft/biomesoplenty/ClientProxy.java +++ b/src/minecraft/biomesoplenty/ClientProxy.java @@ -32,6 +32,7 @@ import cpw.mods.fml.client.registry.RenderingRegistry; public class ClientProxy extends CommonProxy { public static Minecraft mc = Minecraft.getMinecraft(); + public static int puddleRenderPass; @Override public void registerRenderers() diff --git a/src/minecraft/biomesoplenty/blocks/BlockPuddle.java b/src/minecraft/biomesoplenty/blocks/BlockPuddle.java index 558e6fd9e..47c5c3d3b 100644 --- a/src/minecraft/biomesoplenty/blocks/BlockPuddle.java +++ b/src/minecraft/biomesoplenty/blocks/BlockPuddle.java @@ -3,8 +3,8 @@ package biomesoplenty.blocks; import java.util.Random; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.ClientProxy; import biomesoplenty.blocks.renderers.PuddleRender; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -12,6 +12,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.IPlantable; @@ -41,7 +42,7 @@ public class BlockPuddle extends Block public boolean isOpaqueCube() { - return false; + return false; } public boolean renderAsNormalBlock() @@ -49,24 +50,25 @@ public class BlockPuddle extends Block return false; } - public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) + public void updateTick(World world, int x, int y, int z, Random par5Random) { - par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 1); - - return par9; + if (!world.isRaining() && world.rand.nextInt(750) == 0) + { + world.setBlock(x, y, z, Block.dirt.blockID); + } } - public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) + @Override + public int getRenderBlockPass() { - Material material1 = par1World.getBlockMaterial(par2 + 1, par3, par4); - Material material2 = par1World.getBlockMaterial(par2 - 1, par3, par4); - Material material3 = par1World.getBlockMaterial(par2, par3, par4 + 1); - Material material4 = par1World.getBlockMaterial(par2, par3, par4 - 1); - - if (!material1.isSolid() || !material2.isSolid() || !material3.isSolid() || !material1.isSolid()) - { - par1World.setBlock(par2, par3, par4, Block.dirt.blockID); - } + return 1; + } + + @Override + public boolean canRenderInPass(int pass) + { + ClientProxy.puddleRenderPass = pass; + return true; } @Override @@ -81,20 +83,6 @@ public class BlockPuddle extends Block { return Block.dirt.getBlockTextureFromSide(par1); } - - - public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) - { - super.onNeighborBlockChange(par1World, par2, par3, par4, par5); - Material material = par1World.getBlockMaterial(par2, par3 + 1, par4); - - if (material.isSolid()) - { - par1World.setBlock(par2, par3, par4, Block.dirt.blockID); - } - - par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 1); - } public int idDropped(int par1, Random par2Random, int par3) { diff --git a/src/minecraft/biomesoplenty/blocks/renderers/PuddleRender.java b/src/minecraft/biomesoplenty/blocks/renderers/PuddleRender.java index 65cb71ba4..c51d6af88 100644 --- a/src/minecraft/biomesoplenty/blocks/renderers/PuddleRender.java +++ b/src/minecraft/biomesoplenty/blocks/renderers/PuddleRender.java @@ -11,7 +11,7 @@ import net.minecraftforge.liquids.LiquidStack; import org.lwjgl.opengl.GL11; import biomesoplenty.BiomesOPlenty; - +import biomesoplenty.ClientProxy; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.RenderingRegistry; @@ -33,13 +33,18 @@ public class PuddleRender implements ISimpleBlockRenderingHandler { if (modelID == puddleID) { - renderer.renderStandardBlock(block, x, y, z); - - //Liquid - renderer.setRenderBounds(0.0, 0.8135, 0.0, 1.0, 0.8880, 1.0); + if (ClientProxy.puddleRenderPass == 0) + { + renderer.renderStandardBlock(block, x, y, z); + } + else + { + //Liquid + renderer.setRenderBounds(0.0, 0.8135, 0.0, 1.0, 0.8880, 1.0); - Block liquidBlock = Block.blocksList[Block.waterStill.blockID]; - BlockSkinRenderHelper.renderMetadataBlock(liquidBlock, 0, x, y, z, renderer, world); + Block liquidBlock = Block.blocksList[Block.waterStill.blockID]; + BlockSkinRenderHelper.renderMetadataBlock(liquidBlock, 0, x, y, z, renderer, world); + } } return true; } diff --git a/src/minecraft/biomesoplenty/handlers/TickHandlerServer.java b/src/minecraft/biomesoplenty/handlers/TickHandlerServer.java new file mode 100644 index 000000000..75772a93e --- /dev/null +++ b/src/minecraft/biomesoplenty/handlers/TickHandlerServer.java @@ -0,0 +1,99 @@ +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; +import cpw.mods.fml.common.ITickHandler; +import cpw.mods.fml.common.TickType; + +public class TickHandlerServer implements ITickHandler +{ + @Override + public void tickStart(EnumSet type, Object... tickData) + { + WorldServer worldserver = (WorldServer)tickData[0]; + + Iterator iterator = worldserver.activeChunkSet.iterator(); + + int rand = new Random().nextInt(); + + 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"); + + if (worldserver.provider.canDoRainSnowIce(chunk) && worldserver.rand.nextInt(1000) == 0) + { + 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); + + if (worldserver.isRaining() && canCreatePuddle(worldserver, j1 + k, l1, k1 + l)) + { + worldserver.setBlock(j1 + k, l1 - 1, k1 + l, Blocks.puddle.get().blockID); + } + } + } + } + + public boolean canCreatePuddle(WorldServer worldserver, int par1, int par2, int par3) + { + BiomeGenBase biomegenbase = worldserver.getBiomeGenForCoords(par1, par3); + float f = biomegenbase.getFloatTemperature(); + + if (f > 0.15F) + { + 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) + { + 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; + } + } + } + + return false; + } + else + { + return false; + } + } + + @Override + public void tickEnd(EnumSet type, Object... tickData) + { + } + + @Override + public EnumSet ticks() + { + return EnumSet.of(TickType.WORLD); + } + + @Override + public String getLabel() + { + return "BiomesOPlenty - World tick"; + } + +}