]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Add mob spawner bounding boxes
authorIrtimaled <irtimaled@gmail.com>
Sun, 24 Feb 2019 07:39:08 +0000 (23:39 -0800)
committerirtimaled <irtimaled@gmail.com>
Sun, 24 Feb 2019 19:11:01 +0000 (11:11 -0800)
Includes boxes for the max spawn area, and lines for activation status.

12 files changed:
README.md
src/main/java/com/irtimaled/bbor/client/ClientBoundingBoxProvider.java
src/main/java/com/irtimaled/bbor/client/ClientRenderer.java
src/main/java/com/irtimaled/bbor/client/renderers/MobSpawnerRenderer.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/client/renderers/OffsetPoint.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/client/renderers/Renderer.java
src/main/java/com/irtimaled/bbor/client/renderers/VillageRenderer.java
src/main/java/com/irtimaled/bbor/common/DimensionProcessor.java
src/main/java/com/irtimaled/bbor/common/StructureType.java
src/main/java/com/irtimaled/bbor/common/models/BoundingBoxMobSpawner.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/common/models/Colors.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/config/ConfigManager.java

index bffbf844145b9a64ec62cf57c89614edb5eb9950..016bc21a566d0bc2971d62449bedcfcde421a72d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -14,19 +14,20 @@ This mod highlights in a variety of colours and styles the different structures
 - Nether Fortresses; red boxes bound each individual area where Blaze, Wither Skeletons & normal Skeletons will spawn. Time for a beacon methinks!
 - Witch Huts; blue boxes reveal everywhere only witches spawn. Witch farm anyone?
 - Desert Temples; orange boxes envelop the pyramid and towers. Go grab some loot but beware TNT boobie traps!
-- Jungle Temples; green boxes surround the temple. Indianna Jones would've love these!
+- Jungle Temples; dark green boxes surround the temple. Indianna Jones would've love these!
 - Ocean Monuments; cyan boxes indicate where guardians spawn. New sea lantern and prismarine block types FTW.
 - End Cities; magenta boxes show the rooms, corridors and air ships in the End. Time to fall with style!
 - Strongholds; yellow boxes show each room in the stronghold. Does anyone make anything with silverfish spawners?
 - Woodland Mansions; brown boxes show each room in the woodland mansion. Here's Johnny!
 - Mine Shafts; light gray boxes illustrate each of the mine shafts. Cobwebs... grrr!
 - Villages; multicoloured spheres encircle the village, with boxes marking if and where iron golems will spawn. You should see the iron titan... CRAZY!
-- Slime chunks; bright green boxes highlight where slimes will spawn, with a dynamic box that rises to where the players feet are to help find them from the surface. Bouncy... bouncy...
+- Slime chunks; dark green boxes highlight where slimes will spawn, with a dynamic box that rises to where the players feet are to help find them from the surface. Bouncy... bouncy...
 - World Spawn & spawn chunks; red boxes outline the world spawn and the spawn chunks (active & lazy).
 - Igloos (*); white boxes show where igloos are. Maybe you can convert the zombie villager back?
 - Shipwrecks (*); cyan boxes are like a lighthouse those wary sailors wish they'd had. Time to find some buried treasure? 
 - Ocean ruins (*); cyan boxes show the different ocean ruin structures. Watch out for those pesky drowns tho!
 - Buried treasure (*); cyan boxes highlight where the heart of the sea can be found. Conduit anyone?
+- Mob Spawners; bright green boxes show where mob spawners are, where mobs will be spawned, and red/orange/green lines help the player see if a spawner is nearby and activated.
 
 (*) Due to how Minecraft generates these structures they will initially float above where they should be, however upon re-logging they should drop down to the correct height.  Unfortunately (or fortunately?) buried treasure will always appear at y-90 (unless Mojang change something that is!)
 
@@ -63,6 +64,9 @@ Igloos | Client | Process/Render Igloos | drawIgloos | true/false | true
 Shipwrecks | Client | Process/Render Shipwrecks | drawShipwrecks | true/false | true
 Ocean Ruins | Client | Process/Render Ocean Ruins | drawOceanRuins | true/false | true
 Buried Treasure | Client | Process/Render Buried Treasure | drawBuriedTreasure | true/false | true
+Mob Spawner | Client | Process/Render Mob Spawners | drawMobSpawners | true/false | true
+Mob Spawner Spawn Area | Client | Render where mobs will be spawned | renderMobSpawnerSpawnArea | true/false | true
+Mob Spawner Activation Lines | Client | Render red/orange/green lines to show nearby spawners and if they are active | renderMobSpawnerActivationLines | true/false | true
 Villages | Both | Process/Render Villages | drawVillages | true/false | true
 Village spheres | Client | Render Villages as spheres instead of cuboids | renderVillageAsSphere | true/false | true
 Village Iron Golem Spawn Area | Client | Render Iron Golem Spawn Area within valid Villages | drawIronGolemSpawnArea | true/false | true
index 4695db517d08003d16056b1849535edf15a39fee..456298971d8885af4addb445f4fbabcd7c9f14a5 100644 (file)
@@ -1,10 +1,7 @@
 package com.irtimaled.bbor.client;
 
 import com.irtimaled.bbor.common.BoundingBoxCache;
-import com.irtimaled.bbor.common.models.BoundingBox;
-import com.irtimaled.bbor.common.models.BoundingBoxSlimeChunk;
-import com.irtimaled.bbor.common.models.BoundingBoxWorldSpawn;
-import com.irtimaled.bbor.common.models.WorldData;
+import com.irtimaled.bbor.common.models.*;
 import com.irtimaled.bbor.config.ConfigManager;
 import net.minecraft.client.Minecraft;
 import net.minecraft.util.math.BlockPos;
@@ -54,7 +51,6 @@ class ClientBoundingBoxProvider {
                 boundingBoxes.addAll(entry.getValue());
         }
 
-
         return boundingBoxes;
     }
 
@@ -94,7 +90,7 @@ class ClientBoundingBoxProvider {
                 ChunkPos chunk = new ChunkPos(chunkX, chunkZ);
                 BlockPos minBlockPos = new BlockPos(chunk.getXStart(), 1, chunk.getZStart());
                 BlockPos maxBlockPos = new BlockPos(chunk.getXEnd(), 38, chunk.getZEnd());
-                slimeChunks.add(BoundingBoxSlimeChunk.from(minBlockPos, maxBlockPos, Color.GREEN));
+                slimeChunks.add(BoundingBoxSlimeChunk.from(minBlockPos, maxBlockPos, Colors.DARK_GREEN));
             }
         }
         return slimeChunks;
index aae1bd52f2c489b8826546476d421ef291938e86..53efc1a35a000a419bc7eb16a187ede42db50d9b 100644 (file)
@@ -20,6 +20,7 @@ public class ClientRenderer {
         boundingBoxRendererMap.put(BoundingBoxSlimeChunk.class, new SlimeChunkRenderer());
         boundingBoxRendererMap.put(BoundingBoxWorldSpawn.class, new WorldSpawnRenderer());
         boundingBoxRendererMap.put(BoundingBoxStructure.class, new StructureRenderer());
+        boundingBoxRendererMap.put(BoundingBoxMobSpawner.class, new MobSpawnerRenderer());
     }
 
     public void render(DimensionType dimensionType, Boolean outerBoxesOnly) {
diff --git a/src/main/java/com/irtimaled/bbor/client/renderers/MobSpawnerRenderer.java b/src/main/java/com/irtimaled/bbor/client/renderers/MobSpawnerRenderer.java
new file mode 100644 (file)
index 0000000..fd53f47
--- /dev/null
@@ -0,0 +1,42 @@
+package com.irtimaled.bbor.client.renderers;
+
+import com.irtimaled.bbor.client.PlayerData;
+import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
+import com.irtimaled.bbor.common.models.Colors;
+import com.irtimaled.bbor.config.ConfigManager;
+import net.minecraft.util.math.AxisAlignedBB;
+import net.minecraft.util.math.BlockPos;
+
+import java.awt.*;
+
+public class MobSpawnerRenderer extends Renderer<BoundingBoxMobSpawner>
+{
+    @Override
+    public void render(BoundingBoxMobSpawner boundingBox) {
+        BlockPos center = boundingBox.getCenter();
+        Color color = boundingBox.getColor();
+        OffsetPoint centerPoint = new OffsetPoint(center)
+                .add(0.5, 0.5, 0.5);
+        double radius = boundingBox.getRadius();
+        if (ConfigManager.renderMobSpawnerSpawnArea.getBoolean()) {
+            renderBoundingBox(boundingBox);
+        } else {
+            renderCuboid(new AxisAlignedBB(center, center).expand(1, 1, 1), color, fill());
+        }
+
+        if (!ConfigManager.renderMobSpawnerActivationLines.getBoolean()) return;
+
+        OffsetPoint playerPos = new OffsetPoint(PlayerData.getX(), PlayerData.getY(), PlayerData.getZ());
+        double distance = centerPoint.getDistance(playerPos);
+        if (distance <= (radius * 1.25)) {
+            if (distance > radius) {
+                color = Colors.DARK_ORANGE;
+            }
+            if (distance > radius * 1.125) {
+                color = Color.RED;
+            }
+
+            renderLine(centerPoint, playerPos.add(0, 0.1, 0), color);
+        }
+    }
+}
diff --git a/src/main/java/com/irtimaled/bbor/client/renderers/OffsetPoint.java b/src/main/java/com/irtimaled/bbor/client/renderers/OffsetPoint.java
new file mode 100644 (file)
index 0000000..44ad539
--- /dev/null
@@ -0,0 +1,45 @@
+package com.irtimaled.bbor.client.renderers;
+
+import com.irtimaled.bbor.client.PlayerData;
+import net.minecraft.util.math.BlockPos;
+
+public class OffsetPoint {
+    private final double x;
+    private final double y;
+    private final double z;
+
+    OffsetPoint(double x, double y, double z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    OffsetPoint(BlockPos blockPos) {
+        this.x = blockPos.getX();
+        this.y = blockPos.getY();
+        this.z = blockPos.getZ();
+    }
+
+    double getX() {
+        return x - PlayerData.getX();
+    }
+
+    double getY() {
+        return y - PlayerData.getY();
+    }
+
+    double getZ() {
+        return z - PlayerData.getZ();
+    }
+
+    public OffsetPoint add(double x, double y, double z) {
+        return new OffsetPoint(this.x + x, this.y + y, this.z + z);
+    }
+
+    public double getDistance(OffsetPoint 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);
+    }
+}
index 850c800cfa436bc635a30dcaad593b01de6a7b58..6037f01e4978737f117cbbe464a8c7d074d8651d 100644 (file)
@@ -7,9 +7,12 @@ import net.minecraft.client.renderer.BufferBuilder;
 import net.minecraft.client.renderer.Tessellator;
 import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
 import net.minecraft.util.math.AxisAlignedBB;
+import net.minecraft.util.math.BlockPos;
 import org.lwjgl.opengl.GL11;
 
 import java.awt.*;
+import java.util.HashSet;
+import java.util.Set;
 
 public abstract class Renderer<T extends BoundingBox> {
     public abstract void render(T boundingBox);
@@ -27,6 +30,19 @@ public abstract class Renderer<T extends BoundingBox> {
         renderCuboid(aaBB, color, fill);
     }
 
+    void renderLine(OffsetPoint point1, OffsetPoint point2, Color color) {
+        int colorR = color.getRed();
+        int colorG = color.getGreen();
+        int colorB = color.getBlue();
+
+        Tessellator tessellator = Tessellator.getInstance();
+        BufferBuilder worldRenderer = tessellator.getBuffer();
+        worldRenderer.begin(GL11.GL_LINES, worldRenderer.getVertexFormat());
+        worldRenderer.pos(point1.getX(), point1.getY(), point1.getZ()).color(colorR, colorG, colorB, 255).endVertex();
+        worldRenderer.pos(point2.getX(), point2.getY(), point2.getZ()).color(colorR, colorG, colorB, 255).endVertex();
+        tessellator.draw();
+    }
+
     void renderCuboid(AxisAlignedBB aaBB, Color color, boolean fill) {
         aaBB = offsetAxisAlignedBB(aaBB);
         if (fill) {
index 88392e004186455fd270b0499febfec52c1216d5..e4bd07210114b051d1adc84a4b3d3dfa74ea4028 100644 (file)
@@ -1,6 +1,5 @@
 package com.irtimaled.bbor.client.renderers;
 
-import com.irtimaled.bbor.client.PlayerData;
 import com.irtimaled.bbor.common.models.BoundingBoxVillage;
 import com.irtimaled.bbor.config.ConfigManager;
 import net.minecraft.client.renderer.BufferBuilder;
@@ -89,40 +88,6 @@ public class VillageRenderer extends Renderer<BoundingBoxVillage> {
         tessellator.draw();
     }
 
-    private class OffsetPoint {
-        private final double x;
-        private final double y;
-        private final double z;
-
-        OffsetPoint(double x, double y, double z) {
-            this.x = x;
-            this.y = y;
-            this.z = z;
-        }
-
-        OffsetPoint(BlockPos blockPos) {
-            this.x = blockPos.getX();
-            this.y = blockPos.getY();
-            this.z = blockPos.getZ();
-        }
-
-        double getX() {
-            return x - PlayerData.getX();
-        }
-
-        double getY() {
-            return y - PlayerData.getY();
-        }
-
-        double getZ() {
-            return z - PlayerData.getZ();
-        }
-
-        public OffsetPoint add(double x, double y, double z) {
-            return new OffsetPoint(this.x + x, this.y + y, this.z + z);
-        }
-    }
-
     private Set<OffsetPoint> buildPoints(OffsetPoint center, double radius) {
         Set<OffsetPoint> points = new HashSet<>(1200);
 
index 899fb2b78cca3fd038318aa57e9f1e57ef9db177..63e414ce9579229a24da329cbd8594b226b78fdd 100644 (file)
@@ -2,9 +2,12 @@ package com.irtimaled.bbor.common;
 
 import com.irtimaled.bbor.Logger;
 import com.irtimaled.bbor.common.models.BoundingBox;
+import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
 import com.irtimaled.bbor.common.models.BoundingBoxStructure;
 import com.irtimaled.bbor.config.ConfigManager;
 import com.irtimaled.bbor.config.Setting;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.tileentity.TileEntityMobSpawner;
 import net.minecraft.util.math.MutableBoundingBox;
 import net.minecraft.world.chunk.Chunk;
 import net.minecraft.world.dimension.DimensionType;
@@ -12,6 +15,7 @@ import net.minecraft.world.gen.feature.structure.StructurePiece;
 import net.minecraft.world.gen.feature.structure.StructureStart;
 
 import java.awt.*;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -72,5 +76,13 @@ public class DimensionProcessor extends BoundingBoxCache {
             addStructures(ConfigManager.drawEndCities, StructureType.EndCity, structureMap);
             addStructures(ConfigManager.drawPillagerOutposts, StructureType.PillagerOutpost, structureMap);
         }
+        if(ConfigManager.drawMobSpawners.getBoolean()) {
+            Collection<TileEntity> tileEntities = chunk.getTileEntityMap().values();
+            for (TileEntity tileEntity : tileEntities) {
+                if (tileEntity instanceof TileEntityMobSpawner) {
+                    addBoundingBox(BoundingBoxMobSpawner.from((TileEntityMobSpawner) tileEntity));
+                }
+            }
+        }
     }
 }
index 32b49e7a5366be984f9a4d389462fce591c77bd3..6865476df2b7dfbf6337888995eb95fe2055b2ab 100644 (file)
@@ -1,9 +1,11 @@
 package com.irtimaled.bbor.common;
 
+import com.irtimaled.bbor.common.models.Colors;
+
 import java.awt.*;
 
 public class StructureType {
-    public final static StructureType JungleTemple = new StructureType(Color.GREEN, "Jungle_Pyramid");
+    public final static StructureType JungleTemple = new StructureType(Colors.DARK_GREEN, "Jungle_Pyramid");
     public final static StructureType DesertTemple = new StructureType(Color.ORANGE, "Desert_Pyramid");
     public final static StructureType WitchHut = new StructureType(Color.BLUE, "Swamp_Hut");
     public final static StructureType OceanMonument = new StructureType(Color.CYAN, "Monument");
diff --git a/src/main/java/com/irtimaled/bbor/common/models/BoundingBoxMobSpawner.java b/src/main/java/com/irtimaled/bbor/common/models/BoundingBoxMobSpawner.java
new file mode 100644 (file)
index 0000000..36803ec
--- /dev/null
@@ -0,0 +1,45 @@
+package com.irtimaled.bbor.common.models;
+
+import net.minecraft.tileentity.TileEntityMobSpawner;
+import net.minecraft.util.math.BlockPos;
+
+import java.awt.*;
+
+public class BoundingBoxMobSpawner extends BoundingBox {
+    private final BlockPos center;
+    private final Integer radius;
+
+    private BoundingBoxMobSpawner(BlockPos center, Integer radius, Color color, BlockPos minBlockPos, BlockPos maxBlockPos) {
+        super(minBlockPos, maxBlockPos, color);
+        this.center = center;
+        this.radius = radius;
+    }
+
+    public static BoundingBoxMobSpawner from(BlockPos center, Integer radius, Color color) {
+        BlockPos minBlockPos = new BlockPos(center.getX() - 5,
+                center.getY() - 1,
+                center.getZ() - 5);
+        BlockPos maxBlockPos = new BlockPos(center.getX() + 5,
+                center.getY() + 2,
+                center.getZ() + 5);
+        return new BoundingBoxMobSpawner(center, radius, color, minBlockPos, maxBlockPos);
+    }
+
+    public static BoundingBoxMobSpawner from(TileEntityMobSpawner mobSpawner) {
+        BlockPos center = mobSpawner.getPos();
+        return from(center, 16, Color.GREEN);
+    }
+
+    @Override
+    public String toString() {
+        return "(" + center.toString() + "; " + radius.toString() + ")";
+    }
+
+    public Integer getRadius() {
+        return radius;
+    }
+
+    public BlockPos getCenter() {
+        return center;
+    }
+}
diff --git a/src/main/java/com/irtimaled/bbor/common/models/Colors.java b/src/main/java/com/irtimaled/bbor/common/models/Colors.java
new file mode 100644 (file)
index 0000000..9df47b6
--- /dev/null
@@ -0,0 +1,8 @@
+package com.irtimaled.bbor.common.models;
+
+import java.awt.*;
+
+public class Colors {
+    public final static Color DARK_ORANGE = new Color(255, 127, 0);
+    public final static Color DARK_GREEN = new Color(0, 96, 0);
+}
index ee34edbaf896208ff9503e0dd66c2720ef48dd4a..e9bec004b91ffaf910afa64ef990359ddd4c3f7c 100644 (file)
@@ -30,6 +30,9 @@ public class ConfigManager {
     public static Setting drawOceanRuins;
     public static Setting drawBuriedTreasure;
     public static Setting drawIgloos;
+    public static Setting drawMobSpawners;
+    public static Setting renderMobSpawnerSpawnArea;
+    public static Setting renderMobSpawnerActivationLines;
 
     public static void loadConfig(File mcConfigDir) {
         configDir = mcConfigDir;
@@ -62,6 +65,9 @@ public class ConfigManager {
         drawShipwrecks = SetupBooleanProperty(config, "features", "drawShipwrecks", true, "If set to true shipwrecks will be drawn. (default: true)");
         drawOceanRuins = SetupBooleanProperty(config, "features", "drawOceanRuins", true, "If set to true ocean ruins will be drawn. (default: true)");
         drawBuriedTreasure = SetupBooleanProperty(config, "features", "drawBuriedTreasures", true, "If set to true buried treasure will be drawn. (default: true)");
+        drawMobSpawners = SetupBooleanProperty(config, "features", "drawMobSpawners", true, "If set to true mob spawners will be drawn. (default: true}");
+        renderMobSpawnerSpawnArea = SetupBooleanProperty(config, "features", "renderMobSpawnerSpawnArea", true, "If set to true a box to show the maximum possible spawn area (10x10x4) for a spawner will be drawn (default: true)");
+        renderMobSpawnerActivationLines = SetupBooleanProperty(config, "features", "renderMobSpawnerActivationLines", true, "If set to true a red/orange/green line will be drawn to show if the spawner is active (default: true)");
         config.save();
     }