1 package com.irtimaled.bbor.client.renderers;
3 import com.irtimaled.bbor.common.models.BoundingBoxVillage;
4 import com.irtimaled.bbor.config.ConfigManager;
5 import net.minecraft.client.renderer.BufferBuilder;
6 import net.minecraft.client.renderer.Tessellator;
7 import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
8 import net.minecraft.util.math.AxisAlignedBB;
9 import net.minecraft.util.math.BlockPos;
10 import org.lwjgl.opengl.GL11;
13 import java.util.HashSet;
16 public class VillageRenderer extends Renderer<BoundingBoxVillage> {
18 public void render(BoundingBoxVillage boundingBox) {
19 if (ConfigManager.renderVillageAsSphere.getBoolean()) {
20 renderBoundingBoxVillageAsSphere(boundingBox);
22 renderBoundingBox(boundingBox);
24 if (ConfigManager.drawIronGolemSpawnArea.getBoolean() &&
25 boundingBox.getSpawnsIronGolems()) {
26 renderIronGolemSpawnArea(boundingBox);
28 if (ConfigManager.drawVillageDoors.getBoolean()) {
29 renderVillageDoors(boundingBox);
33 private void renderIronGolemSpawnArea(BoundingBoxVillage boundingBox) {
34 BlockPos center = boundingBox.getCenter();
35 AxisAlignedBB abb = new AxisAlignedBB(new BlockPos(center.getX() - 8,
38 new BlockPos(center.getX() + 8,
41 .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
43 renderCuboid(abb, boundingBox.getColor(), false);
46 private void renderVillageDoors(BoundingBoxVillage boundingBox) {
47 OffsetPoint center = new OffsetPoint(boundingBox.getCenter())
48 .add(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
49 Color color = boundingBox.getColor();
50 GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
51 Tessellator tessellator = Tessellator.getInstance();
52 BufferBuilder worldRenderer = tessellator.getBuffer();
54 int colorR = color.getRed();
55 int colorG = color.getGreen();
56 int colorB = color.getBlue();
58 worldRenderer.begin(GL11.GL_LINES, worldRenderer.getVertexFormat());
59 for (BlockPos door : boundingBox.getDoors()) {
60 OffsetPoint point = new OffsetPoint(door).add(0.5, 0, 0.5);
62 worldRenderer.pos(point.getX(), point.getY(), point.getZ()).color(colorR, colorG, colorB, 255).endVertex();
63 worldRenderer.pos(center.getX(), center.getY(), center.getZ()).color(colorR, colorG, colorB, 255).endVertex();
68 private void renderBoundingBoxVillageAsSphere(BoundingBoxVillage boundingBox) {
69 OffsetPoint center = new OffsetPoint(boundingBox.getCenter())
70 .add(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
71 int radius = boundingBox.getRadius();
72 Color color = boundingBox.getColor();
73 renderSphere(center, radius, color);
76 private void renderSphere(OffsetPoint center, double radius, Color color) {
77 GL11.glEnable(GL11.GL_POINT_SMOOTH);
80 Tessellator tessellator = Tessellator.getInstance();
81 BufferBuilder worldRenderer = tessellator.getBuffer();
82 worldRenderer.begin(GL11.GL_POINTS, DefaultVertexFormats.POSITION_COLOR);
83 for (OffsetPoint point : buildPoints(center, radius)) {
84 worldRenderer.pos(point.getX(), point.getY(), point.getZ())
85 .color(color.getRed(), color.getGreen(), color.getBlue(), 255)
91 private Set<OffsetPoint> buildPoints(OffsetPoint center, double radius) {
92 Set<OffsetPoint> points = new HashSet<>(1200);
94 double tau = 6.283185307179586D;
96 double segment = tau / 48D;
98 for (double t = 0.0D; t < tau; t += segment)
99 for (double theta = 0.0D; theta < pi; theta += segment) {
100 double dx = radius * Math.sin(t) * Math.cos(theta);
101 double dz = radius * Math.sin(t) * Math.sin(theta);
102 double dy = radius * Math.cos(t);
104 points.add(center.add(dx, dy, dz));