summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Tick/BlockUpdate.java
blob: 6c5fef1bad47366f0903b92bed921c11d150b11b (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
51
52
53
package net.tylermurphy.Minecraft.Tick;

import java.util.ArrayList;
import java.util.List;

import net.tylermurphy.Minecraft.Chunk.Cube;
import net.tylermurphy.Minecraft.Scene.World;

public class BlockUpdate {

	public int x,y,z;
	public byte old_block_id;
	public byte new_block_id;
	private long delay_of_update, creation_of_update;
	
	private static List<BlockUpdate> current_block_updates = new ArrayList<BlockUpdate>();
	private static List<BlockUpdate> waiting_block_updates = new ArrayList<BlockUpdate>();
	
	public static void createBlockUpdate(int x, int y, int z, byte old_block_id, byte new_block_id) {
		BlockUpdate update = new BlockUpdate();
		update.x = x;
		update.y = y;
		update.z = z;
		update.old_block_id = old_block_id;
		update.new_block_id = new_block_id;
		if(new_block_id != -1)
			update.delay_of_update = Cube.getBlock(new_block_id).tick_update_delay*1000000;
		else
			update.delay_of_update = Cube.getBlock("water").tick_update_delay*1000000;
		update.creation_of_update = System.nanoTime();
		waiting_block_updates.add(update);
	}
	
	public static List<BlockUpdate> loadBirthedUpdates() {
		int j = waiting_block_updates.size();
		for(int i = 0; i < j; i++) {
			BlockUpdate update = waiting_block_updates.get(i);
			if(World.getBlock(update.x, update.y, update.z) != update.new_block_id) continue;
			if(System.nanoTime() - update.creation_of_update >= update.delay_of_update) {
				waiting_block_updates.remove(i);
				j--;
				i--;
				current_block_updates.add(update);
			}
		}
		return current_block_updates;
	}
	
	public static void purgeUpdates() {
		current_block_updates.clear();
	}
	
}