public class BaseStructureEntityShape implements StructureEntityShape {
private final double specialNumber = 0.375;
private final double specialNumber2 = 0.625;
private final Map<String, Entry<EulerAngle, Material>> shapeIdMap;
private final Map<Integer, Map<Integer, String[]>> roofShapeMap;
public BaseStructureEntityShape(Map<String, Entry<EulerAngle, Material>> shapeIdMap,
Map<Integer, Map<Integer, String[]>> roofShapeMap) {
this.shapeIdMap = shapeIdMap;
this.roofShapeMap = roofShapeMap;
}
@Override
public Structure createStructure(Location l) {
final List<StructureEntity> structureEntities = new ArrayList<>();
for (int roof : roofShapeMap.keySet()) {
double x = 0;
double y = calculate(roof) + specialNumber2;
double z = 0;
Map<Integer, String[]> shapes = roofShapeMap.get(roof);
for (int li = 0; li < shapes.size(); li++) {
double distanceZ = shapes.size() / 2.0 - li + 1;
z = calculate(distanceZ);
String[] ids = shapes.get(li);
for (int idi = 0; idi < ids.length; idi++) {
double distanceX = ids.length / 2.0 - (idi + 1);
x = calculate(distanceX);
String id = String.valueOf(ids[idi]);
Entry<EulerAngle, Material> tempMap = shapeIdMap.get(id);
if (tempMap == null) continue;
if (tempMap.getValue() == Material.AIR) continue;
Material material = tempMap.getValue();
EulerAngle angle = tempMap.getKey();
Location newLoc = newLoc(l, x, y, z);
StructureEntity structureEntity = new BaseStructureEntity(material, newLoc);
structureEntity.pose(angle);
structureEntity.rotate(newLoc);
structureEntities.add(structureEntity);
}
}
}
return new BaseStructure(structureEntities.toArray(new StructureEntity[0]), l);
}
private Location newLoc(Location location, double x, double y, double z) {
return location.clone().add(x,y,z);
}
private double calculate(double index) {
double i = 0;
if (index > 0) {
i = index - index * specialNumber;
} else if (index < 0) {
i = index + index * -specialNumber;
}
return i - 2;
}
private int calculateSize() {
int i = 0;
for (Map<Integer, String[]> roofShapeMapValues : roofShapeMap.values()) {
for (String[] roofShapeMapValuesString : roofShapeMapValues.values()) {
for (String ids : roofShapeMapValuesString) {
Entry<EulerAngle, Material> tempMap = shapeIdMap.get(ids);
if (tempMap != null) {
if (tempMap.getValue() != Material.AIR) i++;
}
}
}
}
return i;
}
}