1 package com.irtimaled.bbor.common.models;
3 import com.irtimaled.bbor.common.BoundingBoxType;
4 import com.irtimaled.bbor.common.TypeHelper;
5 import com.irtimaled.bbor.common.VillageColorCache;
6 import com.irtimaled.bbor.common.VillageHelper;
11 public class BoundingBoxVillage extends BoundingBoxSphere {
12 private final boolean spawnsIronGolems;
13 private final Color color;
14 private final Coords center;
15 private final Set<Coords> doors;
16 private final int villageHash;
18 private BoundingBoxVillage(Point point, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
19 super(point, radius, BoundingBoxType.VillageSpheres);
20 this.center = point.getCoords();
22 this.spawnsIronGolems = spawnsIronGolems;
24 this.villageHash = VillageHelper.computeHash(this.center, radius, spawnsIronGolems, doors);
27 public static BoundingBoxVillage from(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
28 Point point = calculateCenterPoint(center, doors);
29 return new BoundingBoxVillage(point, radius, color, spawnsIronGolems, doors);
32 public static BoundingBoxVillage from(Coords center, Integer radius, int villageId, int population, Set<Coords> doors) {
33 boolean spawnsIronGolems = VillageHelper.shouldSpawnIronGolems(population, doors.size());
34 Color color = VillageColorCache.getColor(villageId);
35 return from(center, radius, color, spawnsIronGolems, doors);
38 private static Point calculateCenterPoint(Coords center, Set<Coords> doors) {
39 boolean processedFirstDoor = false;
44 for (Coords door : doors) {
45 if (!processedFirstDoor ||
48 if (!processedFirstDoor ||
51 if (!processedFirstDoor ||
54 if (!processedFirstDoor ||
58 processedFirstDoor = true;
61 double x = Math.abs(maxX - minX) % 2 == 0 ? 0.5 : (minX < 0 ? 0 : 1);
62 double z = Math.abs(maxZ - minZ) % 2 == 0 ? 0.5 : (minZ < 0 ? 0 : 1);
63 return new Point(center).offset(x, 0.0D, z);
66 public Color getColor() {
71 public int hashCode() {
72 return TypeHelper.combineHashCodes(super.hashCode(), villageHash);
75 public boolean getSpawnsIronGolems() {
76 return spawnsIronGolems;
79 public Set<Coords> getDoors() {
83 public int getVillageHash() {
87 public Coords getCenter() {