aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/galacticraft/system/objects/PlanetGenerator.java
blob: fad40e5f410fc83b2a387d285424477abcadfad2 (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
package gtPlusPlus.xmod.galacticraft.system.objects;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import gtPlusPlus.api.objects.data.Pair;
import micdoodle8.mods.galacticraft.api.galaxies.Planet;
import net.minecraft.block.Block;

public class PlanetGenerator {

	private final Planet mPlanet;
	private final IPlanetBlockRegister mTask;
	private final Map<Integer, Pair<String, Block>> mPlanetBlocks;
	private final Thread mTaskThread;
	
	public static final Map<String, PlanetGenerator> mGlobalPlanetCache = new HashMap<String, PlanetGenerator>();
	
	public PlanetGenerator(Planet aPlanet, IPlanetBlockRegister aBlockRegistrationTask) {
		mPlanet = aPlanet;
		mTask = aBlockRegistrationTask;
		mPlanetBlocks = new LinkedHashMap<Integer, Pair<String, Block>>();
		for (int i=0;i<4;i++) {
			Block b = aBlockRegistrationTask.getBlocks().get(i);
			if (b != null)
			mPlanetBlocks.put(i, new Pair<String, Block>(b.getUnlocalizedName(), b));
		}
		if (mGlobalPlanetCache.get(mPlanet.getName().toUpperCase()) == null) {
			mGlobalPlanetCache.put(mPlanet.getName().toUpperCase(), this);
		}
		else {
			try {
				this.finalize();
			} catch (Throwable e) {
			}
		}
		mTaskThread = new Thread(aBlockRegistrationTask);
		mTaskThread.start();
	}

	public synchronized final Planet getPlanet() {
		return mPlanet;
	}

	public synchronized final IPlanetBlockRegister getTask() {
		return mTask;
	}

	public synchronized final Map<Integer, Pair<String, Block>> getPlanetBlocks() {
		return mPlanetBlocks;
	}
	
}