package squeek.veganoption.blocks;

import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;

public class BlockCompost extends Block
{
	// weird way to do this, but this will effectively make the direction
	// to check totally random, as this value is shared between all BlockCompost instances
	public int dirToCheck = 0;

	public BlockCompost()
	{
		super(Material.ground);
		setHarvestLevel("shovel", 0);
		setTickRandomly(true);
	}

	@Override
	// passive and very subtle soil building
	public void updateTick(World world, int x, int y, int z, Random random)
	{
		super.updateTick(world, x, y, z, random);

		if (dirToCheck == 0)
			attemptSoilBuilding(world, x + 1, y, z, random, false);
		else if (dirToCheck == 1)
			attemptSoilBuilding(world, x - 1, y, z, random, false);
		else if (dirToCheck == 2)
			attemptSoilBuilding(world, x, y, z + 1, random, false);
		else if (dirToCheck == 3)
			attemptSoilBuilding(world, x, y, z - 1, random, false);
		else if (dirToCheck == 4)
			attemptSoilBuilding(world, x, y + 1, z, random, true);

		dirToCheck = (dirToCheck + 1) % 5;
	}

	public void attemptSoilBuilding(World world, int x, int y, int z, Random random, boolean growPlantDirectly)
	{
		Block block = world.getBlock(x, y, z);
		if (block == Blocks.farmland)
		{
			Block blockToHelpGrow = world.getBlock(x, y + 1, z);
			blockToHelpGrow.updateTick(world, x, y + 1, z, random);
		}
		else if (growPlantDirectly && block instanceof IPlantable)
		{
			block.updateTick(world, x, y, z, random);
		}
	}
}

@@ -119,25 +119,17 @@
 ock.
-material.Material
+IGrowable
 ;%0Aim
@@ -151,19 +151,31 @@
 aft.
-init.Blocks
+block.material.Material
 ;%0Aim
@@ -255,238 +255,104 @@
 le;%0A
-%0Apublic class BlockCompost extends Block%0A%7B%0A%09// weird way to do this, but this will effectively make the direction%0A%09// to check totally random, as this value is shared between all BlockCompost instances%0A%09public int dirToCheck = 0;%0A
+import net.minecraftforge.common.util.ForgeDirection;%0A%0Apublic class BlockCompost extends Block%0A%7B
 %0A%09pu
@@ -641,117 +641,264 @@
 %0A%0A%09%09
-if (dirToCheck == 0)%0A%09%09%09attemptSoilBuilding(world, x + 1, y, z, random, false);%0A%09%09else if (dirToCheck == 1)%0A%09
+// skip ForgeDirection.DOWN%0A%09%09ForgeDirection randomDirection = ForgeDirection.getOrientation(random.nextInt(ForgeDirection.VALID_DIRECTIONS.length - 1) + 1);%0A%0A%09%09x += randomDirection.offsetX;%0A%09%09y += randomDirection.offsetY;%0A%09%09z += randomDirection.offsetZ;%0A%0A
 %09%09at
@@ -923,20 +923,16 @@
 world, x
- - 1
 , y, z, 
@@ -943,240 +943,300 @@
 om, 
-false);%0A%09%09else if (dirToCheck == 2)%0A%09%09%09attemptSoilBuilding(world, x, y, z + 1, r
+randomDirection == ForgeDirection.UP);%0A%09%7D%0A%0A%09public static boolean tryGrowthTickAt(World world, int x, int y, int z, R
 andom
-, false);%0A%09%09else if (dirToCheck == 3)%0A%09%09%09attemptSoilBuilding(world, x, y, z - 1, random, false);%0A%09%09else if (dirToCheck == 4)%0A%09%09%09attemptSoilBuilding
+ random)%0A%09%7B%0A%09%09Block block = world.getBlock(x, y, z);%0A%09%09if ((block instanceof IPlantable %7C%7C block instanceof IGrowable) && block.getTickRandomly())%0A%09%09%7B%0A%09%09%09block.updateTick
 (wor
@@ -1235,36 +1235,32 @@
 Tick(world, x, y
- + 1
 , z, random, tru
@@ -1258,53 +1258,45 @@
 ndom
-,
+);%0A%09%09%09return
  true
-)
 ;%0A
-%0A%09%09dirToCheck = (dirToCheck + 1) %25 5
+%09%09%7D%0A%09%09return false
 ;%0A%09%7D
@@ -1415,168 +1415,23 @@
 %7B%0A%09%09
-Block block = world.getBlock(x, y, z);%0A%09%09if (block == Blocks.farmland)%0A%09%09%7B%0A%09%09%09Block blockToHelpGrow = world.getBlock(x, y + 1, z);%0A%09%09%09blockToHelpGrow.update
+tryGrowth
 Tick
+At
 (wor
@@ -1438,20 +1438,16 @@
 ld, x, y
- + 1
 , z, ran
@@ -1456,19 +1456,11 @@
 m);%0A
+%0A
 %09%09
-%7D%0A%09%09else 
 if (
@@ -1480,64 +1480,28 @@
 ctly
- && block instanceof IPlantable)%0A%09%09%7B%0A%09%09%09block.update
+)%0A%09%09%09tryGrowth
 Tick
+At
 (wor
@@ -1500,32 +1500,36 @@
 ckAt(world, x, y
+ + 1
 , z, random);%0A%09%09
@@ -1526,17 +1526,13 @@
 andom);%0A
-%09%09%7D%0A
 %09%7D%0A%7D%0A

Make compost soil building farmland-agnostic and truly random * Closes #32 * Remove the farmland check and just check for updateTick-able plants instead * No clue why I used that weird pseudo-random nonsense