summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Tick/GameTicks/GrassTick.java
blob: f7201f1a83d8aa75bf428853ac3559e808768df5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package net.tylermurphy.Minecraft.Tick.GameTicks;

import net.tylermurphy.Minecraft.Scene.World;
import net.tylermurphy.Minecraft.Tick.BlockUpdate;

public class GrassTick {
	
	private static boolean foundGrass(int x, int y, int z)
	{
		for(int a = x-1; a<x+2; a++) {
			for(int b = y-1; b<y+2; b++) {
				for(int c = z-1; c<z+2; c++) {
					if(x == a && c == z) continue;
					if(World.getBlock(a, b, c) == 0) return true;
				}
			}
		}
		return false;
	}
	
	private static void searchForDirt(int x, int y, int z)
	{
		for(int a = x-1; a<x+2; a++)
			for(int b = y-1; b<y+2; b++)
				for(int c = z-1; c<z+2; c++) {
					if(x == a && c == z)
						continue;
					if(World.getBlock(a, b, c) == 1 && World.getBlock(a, b+1, c) == -1) {
						BlockUpdate.createBlockUpdate(a, b, c, (byte)1, (byte)1);
					}
				}
	}
	
	public static void doGrassTick(BlockUpdate update) {
		if(update.new_block_id == 1) {
			int rand = (int)(Math.random()*100);
			if(rand>95) {
				if(World.getBlock(update.x,update.y+1,update.z) == -1 && foundGrass(update.x,update.y,update.z)) {
					World.setBlock(update.x,update.y,update.z, (byte)0);
				}
			} else {
				BlockUpdate.createBlockUpdate(update.x,update.y,update.z, (byte)1, (byte)1);
			}
		}
		if(update.new_block_id == 0) {
			searchForDirt(update.x,update.y,update.z);
		}
	}
	
}