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

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

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<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 HashMap<String, Block>();
		for (Block b : aBlockRegistrationTask.getBlocksToRegister()) {
			mPlanetBlocks.put(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<String, Block> getPlanetBlocks() {
		return mPlanetBlocks;
	}
	
}