aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java
blob: 948a4e52a50ed04be78640d32baae2a360ea6d0e (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package bloodasp.galacticgreg.schematics;

import bloodasp.galacticgreg.GalacticGreg;
import bloodasp.galacticgreg.api.BlockMetaComb;
import bloodasp.galacticgreg.api.Enums.SpaceObjectType;
import bloodasp.galacticgreg.api.Enums.TargetBlockPosition;
import bloodasp.galacticgreg.api.ISpaceObjectGenerator;
import bloodasp.galacticgreg.api.StructureInformation;
import bloodasp.galacticgreg.schematics.SpaceSchematic.BaseStructureInfo;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.util.Vec3;

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

/**
 * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with 
 * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod.
 * However, feel free to copy this code to your own mod to implement structures. If you have questions, find me on github
 * and ask 
 */
public class SpaceSchematicWrapper implements ISpaceObjectGenerator {
	private SpaceSchematic _mSchematic;
	private Vec3 _mCenter = Vec3.createVectorHelper(0, 0, 0);
	private List<StructureInformation> _mFinalizedStructure;
	
	public SpaceSchematicWrapper(SpaceSchematic pSchematic)
	{
		_mSchematic = pSchematic;
	}
	
	public boolean isCalculated()
	{
		return _mFinalizedStructure != null && _mFinalizedStructure.size() > 0;
	}
	
	/**
	 * Recalculate the Structures position, center it around _mCenter 
	 */
	private void RecalculatePosition()
	{
		_mFinalizedStructure = new ArrayList<>();
		
		for (BaseStructureInfo bsi: _mSchematic.coordInfo())
		{
			try
			{
				String tModID = bsi.blockName.split(":")[0];
				String tBlockName = bsi.blockName.split(":")[1];
				
				Block tBlock = GameRegistry.findBlock(tModID, tBlockName);
				if (tBlock != null)
				{
					BlockMetaComb bmc = new BlockMetaComb(tBlock, bsi.blockMeta);
					Vec3 tCenteredPos = _mCenter.addVector(bsi.posX, bsi.posY, bsi.posZ);
					StructureInformation tnewSI = new StructureInformation(tCenteredPos, TargetBlockPosition.StructureBlock, bmc);
					_mFinalizedStructure.add(tnewSI);
				}
				else
					GalacticGreg.Logger.warn("Block %s:%s could not be found. Schematic will be incomplete!", tModID, tBlockName);
			}
			catch (Exception e)
			{
				e.printStackTrace();
				GalacticGreg.Logger.error("Error while recalculating blocks position");
			}
		}
	}
	
	@Override
	public Vec3 getCenterPoint() {
		return _mCenter;
	}

	@Override
	public void setCenterPoint(int pX, int pY, int pZ) {
		_mCenter = Vec3.createVectorHelper(pX, pY, pZ);
	}

	@Override
	public void setCenterPoint(Vec3 pCenter) {
		_mCenter = pCenter;
	}

	@Override
	public List<StructureInformation> getStructure() {
		return _mFinalizedStructure;
	}
	
	@Override
	public void calculate() {
		RecalculatePosition();
	}

	@Override
	public void randomize(int pSizeMin, int pSizeMax) {}

	@Override
	public SpaceObjectType getType() {
		return SpaceObjectType.NonOreSchematic;
	}

	@Override
	public void reset() {
		
	}

}