summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Main.java
blob: ea10bd999b6ce8421a5bddeece8473b9e1d2208e (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package net.tylermurphy.Minecraft;

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

import net.tylermurphy.Minecraft.Audio.SoundManager;
import net.tylermurphy.Minecraft.Chunk.Cube;
import net.tylermurphy.Minecraft.Command.CommandHandler;
import net.tylermurphy.Minecraft.Input.*;
import net.tylermurphy.Minecraft.Render.MainRenderer;
import net.tylermurphy.Minecraft.Render.Data.Texture;
import net.tylermurphy.Minecraft.Scripts.*;
import net.tylermurphy.Minecraft.Render.Data.Display;
import net.tylermurphy.Minecraft.Util.Flags;

public class Main {
	
	private static long currentTime = System.nanoTime();
	private static long nanoSeconendsPassed;
	private static int tps,ticks;

	public static String currentWorld = "test";
	
	private static final List<Script> scripts = new ArrayList<>();
	
	public static void main(String[] args) {

		Display.create(1280, 720, "Minecraft", Texture.loadRawTextureData("gui/icon"));

		Input.addInput(new GameInput());
		Input.addInput(new CoreInput());
		Input.addInput(new CommandInput());
		Input.setEnabled("CommandInput", false);

		SoundManager.init();

		scripts.add(new GameScript());
		scripts.add(new PlayerScript());
		scripts.add(new UIScript());

		CommandHandler.registerCommands();

		for(Script script : scripts) script.Init();

		MainRenderer renderer = new MainRenderer();

		Cube.init();

		while(Display.closed() && !Flags.actionForceClose) {
			
			long lastTime = currentTime;
			currentTime = System.nanoTime();
			nanoSeconendsPassed += currentTime - lastTime;
			
			Display.update();
			
			for(Script script : scripts) script.Update();

			if(nanoSeconendsPassed >= 50000000) {
				tps = Math.round((50000000f/nanoSeconendsPassed)*20);
				for(Script script : scripts) script.Tick();
				nanoSeconendsPassed -= 50000000;
				if(nanoSeconendsPassed >= 5000000000L)
					nanoSeconendsPassed = 0;
				ticks++;
			}
			renderer.update();
			Display.swapBuffers();
			
		}
		
		for(Script script : scripts) script.End();
		
		renderer.update();
		Display.swapBuffers();
		renderer.close();
		
		for(Script script : scripts) script.Stop();
		
		SoundManager.cleanUp();
		Display.close();
		
		System.exit(0);
		
	}
	
	public static int getTPS() {
		return tps;
	}
	
	public static int getTicks() {
		return ticks;
	}
	
}