]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Add conduit processing and rendering
authorIrtimaled <irtimaled@gmail.com>
Wed, 6 May 2020 06:52:23 +0000 (23:52 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 18 May 2020 00:31:26 +0000 (17:31 -0700)
src/main/java/com/irtimaled/bbor/ReflectionHelper.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/client/ClientRenderer.java
src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
src/main/java/com/irtimaled/bbor/client/models/BoundingBoxConduit.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/client/providers/ConduitProvider.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/client/renderers/ConduitRenderer.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java
src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java
src/main/java/com/irtimaled/bbor/config/ConfigManager.java
src/main/resources/assets/bbor/lang/en_us.json

diff --git a/src/main/java/com/irtimaled/bbor/ReflectionHelper.java b/src/main/java/com/irtimaled/bbor/ReflectionHelper.java
new file mode 100644 (file)
index 0000000..c685b30
--- /dev/null
@@ -0,0 +1,48 @@
+package com.irtimaled.bbor;
+
+import com.irtimaled.bbor.common.TypeHelper;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.function.Function;
+
+public class ReflectionHelper {
+    public static <T, R> Function<T, R> getPrivateFieldGetter(Class<?> clazz, Type fieldType, Type... genericTypeArguments) {
+        Field field = findField(clazz, fieldType, genericTypeArguments);
+        if (field == null) return obj -> null;
+
+        field.setAccessible(true);
+        return obj -> {
+            try {
+                return (R) field.get(obj);
+            } catch (IllegalAccessException ignored) {
+                return null;
+            }
+        };
+    }
+
+    private static Field findField(Class<?> clazz, Type fieldType, Type[] genericTypeArguments) {
+        for (Field field : clazz.getDeclaredFields()) {
+            Type type = field.getGenericType();
+            ParameterizedType genericType = TypeHelper.as(type, ParameterizedType.class);
+            if (genericType == null) {
+                if (type != fieldType || genericTypeArguments.length > 0) continue;
+                return field;
+            }
+
+            Type rawType = genericType.getRawType();
+            if (rawType != fieldType) continue;
+
+            Type[] actualTypeArguments = genericType.getActualTypeArguments();
+            if (actualTypeArguments.length != genericTypeArguments.length) continue;
+
+            for (int typeIndex = 0; typeIndex < actualTypeArguments.length; typeIndex++) {
+                if (actualTypeArguments[typeIndex] != genericTypeArguments[typeIndex]) return null;
+            }
+
+            return field;
+        }
+        return null;
+    }
+}
index 681817b7448636c9de7b3f9bc6ffa65f38d28c79..f69096e92c5efd499222d80fe39bc060d3fe9ac9 100644 (file)
@@ -1,6 +1,7 @@
 package com.irtimaled.bbor.client;
 
 import com.irtimaled.bbor.client.interop.ClientInterop;
+import com.irtimaled.bbor.client.models.BoundingBoxConduit;
 import com.irtimaled.bbor.client.providers.*;
 import com.irtimaled.bbor.client.renderers.*;
 import com.irtimaled.bbor.common.MathHelper;
@@ -44,6 +45,7 @@ public class ClientRenderer {
         registerRenderer(BoundingBoxSpawningSphere.class, new SpawningSphereRenderer());
         registerRenderer(BoundingBoxBeacon.class, new BeaconRenderer());
         registerRenderer(BoundingBoxBiomeBorder.class, new BiomeBorderRenderer());
+        registerRenderer(BoundingBoxConduit.class, new ConduitRenderer());
 
         registerProvider(new SlimeChunkProvider());
         registerProvider(new WorldSpawnProvider());
@@ -53,6 +55,7 @@ public class ClientRenderer {
         registerProvider(new CustomBeaconProvider());
         registerProvider(new BiomeBorderProvider());
         registerProvider(new MobSpawnerProvider());
+        registerProvider(new ConduitProvider());
     }
 
     public static <T extends AbstractBoundingBox> void registerProvider(IBoundingBoxProvider<T> provider) {
index 4f0c74de0ecd1c912a4815a0b93b6aaefebfe171..0c580852ac6cca851a74080277d4225933dc1e60 100644 (file)
@@ -65,6 +65,10 @@ public class SettingsScreen extends ListScreen {
                         (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.mobSpawners"), BoundingBoxType.MobSpawner),
                         (x, width) -> new BoolSettingButton(width, I18n.format("bbor.features.mobSpawners.spawnArea"), ConfigManager.renderMobSpawnerSpawnArea),
                         (x, width) -> new BoolSettingButton(width, I18n.format("bbor.features.mobSpawners.activationLines"), ConfigManager.renderMobSpawnerActivationLines))
+                .section(I18n.format("bbor.sections.beaconsAndConduits"),
+                        (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.beacons"), BoundingBoxType.Beacon),
+                        (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.conduits"), BoundingBoxType.Conduit),
+                        (x, width) -> new BoolSettingButton(width, I18n.format("bbor.features.conduits.mobHarmArea"), ConfigManager.renderConduitMobHarmArea))
                 .section(I18n.format("bbor.features.spawningSpheres"),
                         (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.spawningSpheres"), BoundingBoxType.AFKSphere),
                         (x, width) -> new BoolSettingButton(width, I18n.format("bbor.features.spawningSpheres.spawnableBlocks"), ConfigManager.renderAFKSpawnableBlocks),
diff --git a/src/main/java/com/irtimaled/bbor/client/models/BoundingBoxConduit.java b/src/main/java/com/irtimaled/bbor/client/models/BoundingBoxConduit.java
new file mode 100644 (file)
index 0000000..878317f
--- /dev/null
@@ -0,0 +1,39 @@
+package com.irtimaled.bbor.client.models;
+
+import com.irtimaled.bbor.common.BoundingBoxType;
+import com.irtimaled.bbor.common.TypeHelper;
+import com.irtimaled.bbor.common.models.BoundingBoxSphere;
+import com.irtimaled.bbor.common.models.Coords;
+
+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);
+
+        this.level = level;
+    }
+
+    public static BoundingBoxConduit from(Coords coords, int level) {
+        int radius = 16 * level;
+        return new BoundingBoxConduit(coords, level, radius);
+    }
+
+    @Override
+    public int hashCode() {
+        return TypeHelper.combineHashCodes(getTypeName().hashCode(), getCenter().hashCode());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj == null || getClass() != obj.getClass()) return false;
+        BoundingBoxConduit other = (BoundingBoxConduit) obj;
+        return getCenter().equals(other.getCenter());
+    }
+
+    public int getLevel() {
+        return level;
+    }
+}
diff --git a/src/main/java/com/irtimaled/bbor/client/providers/ConduitProvider.java b/src/main/java/com/irtimaled/bbor/client/providers/ConduitProvider.java
new file mode 100644 (file)
index 0000000..6b4034b
--- /dev/null
@@ -0,0 +1,27 @@
+package com.irtimaled.bbor.client.providers;
+
+import com.irtimaled.bbor.ReflectionHelper;
+import com.irtimaled.bbor.client.interop.TileEntitiesHelper;
+import com.irtimaled.bbor.client.models.BoundingBoxConduit;
+import com.irtimaled.bbor.common.models.Coords;
+import net.minecraft.tileentity.TileEntityConduit;
+import net.minecraft.util.math.BlockPos;
+
+import java.util.List;
+import java.util.function.Function;
+
+public class ConduitProvider implements IBoundingBoxProvider<BoundingBoxConduit> {
+    private static final Function<TileEntityConduit, List<BlockPos>> blocksFetcher =
+            ReflectionHelper.getPrivateFieldGetter(TileEntityConduit.class, List.class, BlockPos.class);
+
+    @Override
+    public Iterable<BoundingBoxConduit> get(int dimensionId) {
+        return TileEntitiesHelper.map(TileEntityConduit.class, conduit -> {
+            List<BlockPos> blocks = blocksFetcher.apply(conduit);
+            if (blocks == null) return null;
+
+            Coords coords = new Coords(conduit.getPos());
+            return BoundingBoxConduit.from(coords, conduit.isActive() ? blocks.size() / 7 : 0);
+        });
+    }
+}
diff --git a/src/main/java/com/irtimaled/bbor/client/renderers/ConduitRenderer.java b/src/main/java/com/irtimaled/bbor/client/renderers/ConduitRenderer.java
new file mode 100644 (file)
index 0000000..65e1d8c
--- /dev/null
@@ -0,0 +1,28 @@
+package com.irtimaled.bbor.client.renderers;
+
+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.config.ConfigManager;
+
+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();
+
+        renderCuboid(new OffsetBox(center, center), color);
+        if (level == 6 && ConfigManager.renderConduitMobHarmArea.get()) {
+            renderCuboid(new OffsetBox(center, center).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);
+        }
+    }
+}
index 1f625c4233aef67b3592764a34d2d2d675430527..559df88849bf198a5a9478f09f014832c722df9a 100644 (file)
@@ -38,6 +38,7 @@ public class BoundingBoxType {
     public static final BoundingBoxType NetherFossil = register(Color.WHITE, "Nether_Fossil", ConfigManager.drawNetherFossils);
     public static final BoundingBoxType BastionRemnant = register(Color.LIGHT_GRAY, "Bastion_Remnant", ConfigManager.drawBastionRemnants);
     public static final BoundingBoxType RuinedPortal = register(Colors.COOL_PURPLE, "Ruined_Portal", ConfigManager.drawRuinedPortals);
+    public static final BoundingBoxType Conduit = register(Color.CYAN, "Conduit", ConfigManager.drawConduits);
     public static final BoundingBoxType Custom = register(Color.WHITE, "Custom", ConfigManager.drawCustomBoxes);
 
     private static BoundingBoxType register(Color color, String name, Setting<Boolean> shouldRenderSetting) {
index af8f7584f290ff00c383bd934ecb02bf40293386..b51edd7b9234b04fb511735f7e9a94949dac19c7 100644 (file)
@@ -53,7 +53,7 @@ public class BoundingBoxSphere extends AbstractBoundingBox {
         return centerOffsetZ;
     }
 
-    void setCenterOffsets(double x, double y, double z) {
+    public void setCenterOffsets(double x, double y, double z) {
         this.centerOffsetX = x;
         this.centerOffsetY = y;
         this.centerOffsetZ = z;
index 8b37fec4be185157993a672677d7bec465f42cc6..512bb57b242aced2d282bb3d447bfd926f91ec13 100644 (file)
@@ -52,6 +52,8 @@ public class ConfigManager {
     public static Setting<Boolean> drawNetherFossils;
     public static Setting<Boolean> drawBastionRemnants;
     public static Setting<Boolean> drawRuinedPortals;
+    public static Setting<Boolean> drawConduits;
+    public static Setting<Boolean> renderConduitMobHarmArea;
 
     public static void loadConfig(File mcConfigDir) {
         configDir = new File(mcConfigDir, "config");
@@ -62,8 +64,13 @@ public class ConfigManager {
         outerBoxesOnly = setup(config, "general", "outerBoxesOnly", false, "If set to true only the outer bounding boxes are rendered.");
         alwaysVisible = setup(config, "general", "alwaysVisible", false, "If set to true boxes will be visible even through other blocks.");
         keepCacheBetweenSessions = setup(config, "general", "keepCacheBetweenSessions", false, "If set to true bounding box caches will be kept between sessions.");
-        drawBeacons = setup(config, "general", "drawBeacons", true, "If set to true beacon bounding boxes will be drawn.");
         drawCustomBoxes = setup(config, "general", "drawCustomBoxes", true, "If set to true custom bounding boxes will be drawn.");
+
+        drawBeacons = setup(config, "beacons", "drawBeacons", true, "If set to true beacon bounding boxes will be drawn.");
+
+        drawConduits = setup(config, "conduits", "drawConduits", true, "If set to true conduit bounding spheres will be drawn.");
+        renderConduitMobHarmArea = setup(config, "conduits", "renderConduitMobHarmArea", true, "If set to true a box to show the area where hostile mobs are harmed will be drawn");
+
         drawBiomeBorders = setup(config, "biomeBorders", "drawBiomeBorders", true, "If set to true biome borders will be drawn.");
         renderOnlyCurrentBiome = setup(config, "biomeBorders", "renderOnlyCurrentBiome", true, "If set to true only the biome border for the current biome will be drawn.");
         biomeBordersRenderDistance = setup(config, "biomeBorders", "biomeBordersRenderDistance", 3, "The distance from the player where biome borders will be drawn.");
index 4043f9a19945bb1127b2d969c69324071a5f0e2b..dea0e6313802b77bc23222f23797e8415e81f507 100644 (file)
   "bbor.features.spawningSpheres.spawnableBlocks": "Spawnable Blocks",
   "bbor.features.biomeBorders": "Biome Borders",
 
+  "bbor.sections.beaconsAndConduits": "Beacons & Conduits",
+  "bbor.features.beacons": "Beacons",
+  "bbor.features.conduits": "Conduits",
+  "bbor.features.conduits.mobHarmArea": "Mob Harm Area",
+
   "bbor.structures.desertTemples": "Desert Temples",
   "bbor.structures.jungleTemples": "Jungle Temples",
   "bbor.structures.witchHuts": "Witch Huts",