package com.irtimaled.bbor.client;
import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
import net.minecraft.entity.player.EntityPlayer;
public class Player {
public static Coords getCoords() {
return new Coords(x, y, z);
}
+
+ public static Point getPoint() {
+ return new Point(x, y, z);
+ }
}
package com.irtimaled.bbor.client.interop;
import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
-import com.irtimaled.bbor.client.models.Point;
import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import com.irtimaled.bbor.common.TypeHelper;
import com.irtimaled.bbor.common.models.BoundingBoxSphere;
import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
public class BoundingBoxConduit extends BoundingBoxSphere {
private final int level;
private BoundingBoxConduit(Coords coords, int level, int radius) {
- super(coords, radius, BoundingBoxType.Conduit);
- setCenterOffsets(0.5, 0.5, 0.5);
+ super(new Point(coords).offset(0.5D, 0.5D, 0.5D), radius, BoundingBoxType.Conduit);
this.level = level;
}
@Override
public int hashCode() {
- return TypeHelper.combineHashCodes(getType().hashCode(), getCenter().hashCode());
+ return TypeHelper.combineHashCodes(getType().hashCode(), getPoint().hashCode());
}
@Override
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
BoundingBoxConduit other = (BoundingBoxConduit) obj;
- return getCenter().equals(other.getCenter());
+ return getPoint().equals(other.getPoint());
}
public int getLevel() {
import com.irtimaled.bbor.common.BoundingBoxType;
import com.irtimaled.bbor.common.models.BoundingBoxSphere;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
public class BoundingBoxSpawningSphere extends BoundingBoxSphere {
public static final int SAFE_RADIUS = 24;
private Integer spawnableCount;
- public BoundingBoxSpawningSphere(Coords coords, double xOffset, double yOffset, double zOffset) {
- super(coords, 128, BoundingBoxType.AFKSphere);
- setCenterOffsets(xOffset, yOffset, zOffset);
- }
-
- public boolean isCenter(Coords coords, double xOffset, double yOffset, double zOffset) {
- return this.getCenter().equals(coords) &&
- this.getCenterOffsetX() == xOffset &&
- this.getCenterOffsetY() == yOffset &&
- this.getCenterOffsetZ() == zOffset;
+ public BoundingBoxSpawningSphere(Point point) {
+ super(point, SPAWN_RADIUS, BoundingBoxType.AFKSphere);
}
public void setSpawnableCount(int count) {
+++ /dev/null
-package com.irtimaled.bbor.client.models;
-
-import com.irtimaled.bbor.common.models.Coords;
-
-public class Point {
- private final double x;
- private final double y;
- private final double z;
-
- public Point(double x, double y, double z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- public Point(Coords Coords) {
- this.x = Coords.getX();
- this.y = Coords.getY();
- this.z = Coords.getZ();
- }
-
- public double getX() {
- return x;
- }
-
- public double getY() {
- return y;
- }
-
- public double getZ() {
- return z;
- }
-
- public Point offset(double x, double y, double z) {
- return new Point(this.x + x, this.y + y, this.z + z);
- }
-
- public double getDistance(Point point) {
- double dx = this.x - point.x;
- double dy = this.y - point.y;
- double dz = this.z - point.z;
- return Math.sqrt(dx * dx + dy * dy + dz * dz);
- }
-
- public Coords getCoords() {
- return new Coords(x, y, z);
- }
-}
import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper;
import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
-import com.irtimaled.bbor.client.models.Point;
import com.irtimaled.bbor.common.BoundingBoxType;
import com.irtimaled.bbor.common.MathHelper;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
import java.util.HashSet;
import java.util.Set;
private static Integer dimensionId;
public static void setSphere(double x, double y, double z) {
- Coords coords = new Coords(x, y, z);
- double xOffset = snapToNearestHalf(x -coords.getX());
- double yOffset = y- coords.getY();
- double zOffset = snapToNearestHalf(z-coords.getZ());
+ Point point = new Point(snapToNearestHalf(x), y, snapToNearestHalf(z));
- if(spawningSphere != null && spawningSphere.isCenter(coords, xOffset, yOffset, zOffset)) {
+ if (spawningSphere != null && spawningSphere.getPoint().equals(point)) {
return;
}
clear();
dimensionId = Player.getDimensionId();
- spawningSphere = new BoundingBoxSpawningSphere(coords, xOffset, yOffset, zOffset);
+ spawningSphere = new BoundingBoxSpawningSphere(point);
}
private static double snapToNearestHalf(double value) {
- int floor = MathHelper.floor(value * 4.0);
- if(floor % 2 == 1) floor += 1;
- return floor / 4.0;
+ int floor = MathHelper.floor(value);
+ int fraction = MathHelper.floor((value - floor) * 4.0);
+ if (fraction % 2 == 1) fraction++;
+ return floor + (fraction / 4.0);
}
public static boolean clear() {
public static int recalculateSpawnableSpacesCount() {
if (spawningSphere != null) {
- Point sphereCenter = new Point(spawningSphere.getCenter())
- .offset(spawningSphere.getCenterOffsetX(),
- spawningSphere.getCenterOffsetY(),
- spawningSphere.getCenterOffsetZ());
+ Point sphereCenter = spawningSphere.getPoint();
int spawnableSpacesCount = getSpawnableSpacesCount(sphereCenter);
spawningSphere.setSpawnableCount(spawnableSpacesCount);
return spawnableSpacesCount;
import com.irtimaled.bbor.client.config.ConfigManager;
import com.irtimaled.bbor.client.models.BoundingBoxConduit;
import com.irtimaled.bbor.common.models.Colors;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
import java.awt.*;
public class ConduitRenderer extends AbstractRenderer<BoundingBoxConduit> {
@Override
public void render(BoundingBoxConduit boundingBox) {
- Coords center = boundingBox.getCenter();
int level = boundingBox.getLevel();
Color color = boundingBox.getColor();
+ Point point = boundingBox.getPoint();
- renderCuboid(new OffsetBox(center, center), color);
+ OffsetPoint center = new OffsetPoint(point);
+ OffsetBox centerBox = new OffsetBox(center, center).grow(0.5, 0.5, 0.5);
+ renderCuboid(centerBox, color);
if (level == 6 && ConfigManager.renderConduitMobHarmArea.get()) {
- renderCuboid(new OffsetBox(center, center).grow(8, 8, 8), Colors.DARK_ORANGE);
+ renderCuboid(centerBox.grow(8, 8, 8), Colors.DARK_ORANGE);
}
if (level != 0) {
- OffsetPoint sphereCenter = new OffsetPoint(center)
- .offset(boundingBox.getCenterOffsetX(), boundingBox.getCenterOffsetY(), boundingBox.getCenterOffsetZ());
-
- renderSphere(sphereCenter, boundingBox.getRadius() + 0.5, color, 5, 5);
+ renderSphere(center, boundingBox.getRadius() + 0.5, color, 5, 5);
}
}
}
return new OffsetBox(min.offset(-x, -y, -z), max.offset(x, y, z));
}
- OffsetBox offset(double x, double y, double z) {
- return new OffsetBox(min.offset(x, y, z), max.offset(x, y, z));
- }
-
OffsetBox nudge() {
double growXZ = 0.001F;
if (min.getY() == max.getY()) {
- return grow(growXZ, 0, growXZ).offset(0, growXZ, 0);
+ return new OffsetBox(min.offset(-growXZ, growXZ, -growXZ), max.offset(growXZ, growXZ, growXZ));
}
return grow(growXZ, growXZ, growXZ);
}
package com.irtimaled.bbor.client.renderers;
import com.irtimaled.bbor.client.Player;
-import com.irtimaled.bbor.client.models.Point;
import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
class OffsetPoint {
private final Point point;
this(new Point(coords));
}
- private OffsetPoint(Point point) {
+ OffsetPoint(Point point) {
this.point = point;
}
double getDistance(OffsetPoint offsetPoint) {
return this.point.getDistance(offsetPoint.point);
}
-
- Point getPoint() {
- return this.point;
- }
}
import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
import com.irtimaled.bbor.common.MathHelper;
+import com.irtimaled.bbor.common.models.Point;
import net.minecraft.client.resources.I18n;
import java.awt.*;
public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawningSphere> {
@Override
public void render(BoundingBoxSpawningSphere boundingBox) {
- OffsetPoint sphereCenter = new OffsetPoint(boundingBox.getCenter())
- .offset(boundingBox.getCenterOffsetX(), boundingBox.getCenterOffsetY(), boundingBox.getCenterOffsetZ());
+ Point point = boundingBox.getPoint();
+ OffsetPoint sphereCenter = new OffsetPoint(point);
OffsetBox offsetBox = new OffsetBox(sphereCenter, sphereCenter).grow(0.5, 0, 0.5);
renderCuboid(offsetBox, Color.GREEN);
renderSphere(sphereCenter, BoundingBoxSpawningSphere.SPAWN_RADIUS, Color.RED, 5, 5);
if(ConfigManager.renderAFKSpawnableBlocks.get()) {
- renderSpawnableSpaces(sphereCenter);
+ renderSpawnableSpaces(point);
}
}
- private void renderSpawnableSpaces(OffsetPoint center) {
+ private void renderSpawnableSpaces(Point center) {
Integer renderDistance = ConfigManager.afkSpawnableBlocksRenderDistance.get();
int width = MathHelper.floor(Math.pow(2, 2 + renderDistance));
int height = MathHelper.floor(Math.pow(2, renderDistance));
- SpawningSphereHelper.findSpawnableSpaces(center.getPoint(), Player.getCoords(), width, height,
+ SpawningSphereHelper.findSpawnableSpaces(center, Player.getCoords(), width, height,
(x, y, z) -> {
OffsetBox offsetBox = new OffsetBox(x, y, z, x + 1, y, z + 1);
renderCuboid(offsetBox, Color.RED);
}
private void renderIronGolemSpawnArea(BoundingBoxVillage boundingBox) {
- OffsetPoint offsetCenter = new OffsetPoint(boundingBox.getCenter())
- .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
+ OffsetPoint offsetCenter = new OffsetPoint(boundingBox.getPoint());
OffsetBox bb = new OffsetBox(offsetCenter, offsetCenter)
.grow(8, 3, 8);
}
private void renderVillageDoors(BoundingBoxVillage boundingBox) {
- OffsetPoint center = new OffsetPoint(boundingBox.getCenter())
- .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
+ OffsetPoint center = new OffsetPoint(boundingBox.getPoint());
Color color = boundingBox.getColor();
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
private void renderBoundingBoxVillageAsSphere(BoundingBoxVillage boundingBox) {
- OffsetPoint center = new OffsetPoint(boundingBox.getCenter())
- .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
- int radius = boundingBox.getRadius();
+ OffsetPoint center = new OffsetPoint(boundingBox.getPoint());
+ double radius = boundingBox.getRadius();
Color color = boundingBox.getColor();
int density = ConfigManager.villageSphereDensity.get();
int dotSize = ConfigManager.villageSphereDotSize.get();
private static void serializeVillage(BoundingBoxVillage boundingBox, PayloadBuilder builder) {
builder.writeChar('V')
.writeCoords(boundingBox.getCenter())
- .writeVarInt(boundingBox.getRadius())
+ .writeVarInt((int)boundingBox.getRadius())
.writeBoolean(boundingBox.getSpawnsIronGolems())
.writeVarInt(boundingBox.getColor().getRGB());
for (Coords door : boundingBox.getDoors()) {
import com.irtimaled.bbor.common.BoundingBoxType;
public class BoundingBoxSphere extends AbstractBoundingBox {
- private final Coords center;
- private final Integer radius;
- private final int minX;
- private final int minZ;
- private final int maxX;
- private final int maxZ;
-
- private Double centerOffsetX = 0d;
- private Double centerOffsetY = 0d;
- private Double centerOffsetZ = 0d;
-
- protected BoundingBoxSphere(Coords center, Integer radius, BoundingBoxType type) {
+ private final double radius;
+ private final double minX;
+ private final double minZ;
+ private final double maxX;
+ private final double maxZ;
+ private final Point point;
+
+ protected BoundingBoxSphere(Point point, double radius, BoundingBoxType type) {
super(type);
- this.center = center;
this.radius = radius;
+ this.point = point;
+ Coords center = point.getCoords();
this.minX = center.getX() - radius;
this.minZ = center.getZ() - radius;
this.maxX = center.getX() + radius;
this.minZ <= maxZ;
}
- public Integer getRadius() {
+ public double getRadius() {
return radius;
}
- public Coords getCenter() {
- return center;
- }
-
- public Double getCenterOffsetX() {
- return centerOffsetX;
- }
-
- public Double getCenterOffsetY() {
- return centerOffsetY;
- }
-
- public Double getCenterOffsetZ() {
- return centerOffsetZ;
- }
-
- public void setCenterOffsets(double x, double y, double z) {
- this.centerOffsetX = x;
- this.centerOffsetY = y;
- this.centerOffsetZ = z;
+ public Point getPoint() {
+ return point;
}
}
public class BoundingBoxVillage extends BoundingBoxSphere {
private final boolean spawnsIronGolems;
private final Color color;
+ private final Coords center;
private final Set<Coords> doors;
private final int villageHash;
- private BoundingBoxVillage(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
- super(center, radius, BoundingBoxType.VillageSpheres);
+ private BoundingBoxVillage(Point point, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
+ super(point, radius, BoundingBoxType.VillageSpheres);
+ this.center = point.getCoords();
this.color = color;
this.spawnsIronGolems = spawnsIronGolems;
this.doors = doors;
- this.villageHash = VillageHelper.computeHash(center, radius, spawnsIronGolems, doors);
- calculateCenterOffsets(doors);
+ this.villageHash = VillageHelper.computeHash(this.center, radius, spawnsIronGolems, doors);
}
public static BoundingBoxVillage from(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
- return new BoundingBoxVillage(center, radius, color, spawnsIronGolems, doors);
+ Point point = calculateCenterPoint(center, doors);
+ return new BoundingBoxVillage(point, radius, color, spawnsIronGolems, doors);
}
public static BoundingBoxVillage from(Coords center, Integer radius, int villageId, int population, Set<Coords> doors) {
boolean spawnsIronGolems = VillageHelper.shouldSpawnIronGolems(population, doors.size());
Color color = VillageColorCache.getColor(villageId);
- return new BoundingBoxVillage(center, radius, color, spawnsIronGolems, doors);
+ return from(center, radius, color, spawnsIronGolems, doors);
}
- private void calculateCenterOffsets(Set<Coords> doors) {
+ private static Point calculateCenterPoint(Coords center, Set<Coords> doors) {
boolean processedFirstDoor = false;
int minX = 0;
int maxX = 0;
processedFirstDoor = true;
}
- 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));
+
+ double x = Math.abs(maxX - minX) % 2 == 0 ? 0.5 : (minX < 0 ? 0 : 1);
+ double z = Math.abs(maxZ - minZ) % 2 == 0 ? 0.5 : (minZ < 0 ? 0 : 1);
+ return new Point(center).offset(x, 0.0D, z);
}
public Color getColor() {
public int getVillageHash() {
return villageHash;
}
+
+ public Coords getCenter() {
+ return center;
+ }
}
--- /dev/null
+package com.irtimaled.bbor.common.models;
+
+import com.irtimaled.bbor.common.TypeHelper;
+
+public class Point {
+ private final double x;
+ private final double y;
+ private final double z;
+
+ public Point(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public Point(Coords Coords) {
+ this.x = Coords.getX();
+ this.y = Coords.getY();
+ this.z = Coords.getZ();
+ }
+
+ public double getX() {
+ return x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+ public double getZ() {
+ return z;
+ }
+
+ public Point offset(double x, double y, double z) {
+ return new Point(this.x + x, this.y + y, this.z + z);
+ }
+
+ public double getDistance(Point point) {
+ double dx = this.x - point.x;
+ double dy = this.y - point.y;
+ double dz = this.z - point.z;
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
+ }
+
+ public Coords getCoords() {
+ return new Coords(x, y, z);
+ }
+
+ @Override
+ public int hashCode() {
+ return TypeHelper.combineHashCodes(Double.hashCode(z), Double.hashCode(y), Double.hashCode(x));
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Point point = (Point) obj;
+ return getX() == point.getX() && getY() == point.getY() && getZ() == point.getZ();
+ }
+}