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 Set<Coords> doors;
15 private final int villageHash;
17 private BoundingBoxVillage(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
18 super(center, radius, BoundingBoxType.VillageSpheres);
20 this.spawnsIronGolems = spawnsIronGolems;
22 this.villageHash = VillageHelper.computeHash(center, radius, spawnsIronGolems, doors);
23 calculateCenterOffsets(doors);
26 public static BoundingBoxVillage from(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
27 return new BoundingBoxVillage(center, radius, color, spawnsIronGolems, doors);
30 public static BoundingBoxVillage from(Coords center, Integer radius, int villageId, int population, Set<Coords> doors) {
31 boolean spawnsIronGolems = VillageHelper.shouldSpawnIronGolems(population, doors.size());
32 Color color = VillageColorCache.getColor(villageId);
33 return new BoundingBoxVillage(center, radius, color, spawnsIronGolems, doors);
36 private void calculateCenterOffsets(Set<Coords> doors) {
37 boolean processedFirstDoor = false;
42 for (Coords door : doors) {
43 if (!processedFirstDoor ||
46 if (!processedFirstDoor ||
49 if (!processedFirstDoor ||
52 if (!processedFirstDoor ||
56 processedFirstDoor = true;
58 setCenterOffsets(Math.abs(maxX - minX) % 2 == 0 ? 0.5 : (minX < 0 ? 0 : 1), 0.0d, Math.abs(maxZ - minZ) % 2 == 0 ? 0.5 : (minZ < 0 ? 0 : 1));
61 public Color getColor() {
66 public int hashCode() {
67 return TypeHelper.combineHashCodes(super.hashCode(), villageHash);
70 public boolean getSpawnsIronGolems() {
71 return spawnsIronGolems;
74 public Set<Coords> getDoors() {
78 public int getVillageHash() {