From: Irtimaled Date: Wed, 6 May 2020 06:52:23 +0000 (-0700) Subject: Add conduit processing and rendering X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=46f531e1fa7b692150bb9f9f206dcef7d2bcebf5;p=BoundingBoxOutlineReloaded.git Add conduit processing and rendering --- diff --git a/src/main/java/com/irtimaled/bbor/ReflectionHelper.java b/src/main/java/com/irtimaled/bbor/ReflectionHelper.java new file mode 100644 index 0000000..c685b30 --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/ReflectionHelper.java @@ -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 Function 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; + } +} diff --git a/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java b/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java index 681817b..f69096e 100644 --- a/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java +++ b/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java @@ -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 void registerProvider(IBoundingBoxProvider provider) { diff --git a/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java b/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java index 4f0c74d..0c58085 100644 --- a/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java +++ b/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java @@ -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 index 0000000..878317f --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/models/BoundingBoxConduit.java @@ -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 index 0000000..6b4034b --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/providers/ConduitProvider.java @@ -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 { + private static final Function> blocksFetcher = + ReflectionHelper.getPrivateFieldGetter(TileEntityConduit.class, List.class, BlockPos.class); + + @Override + public Iterable get(int dimensionId) { + return TileEntitiesHelper.map(TileEntityConduit.class, conduit -> { + List 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 index 0000000..65e1d8c --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/renderers/ConduitRenderer.java @@ -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 { + @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); + } + } +} diff --git a/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java b/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java index 1f625c4..559df88 100644 --- a/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java +++ b/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java @@ -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 shouldRenderSetting) { diff --git a/src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java b/src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java index af8f758..b51edd7 100644 --- a/src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java +++ b/src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java @@ -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; diff --git a/src/main/java/com/irtimaled/bbor/config/ConfigManager.java b/src/main/java/com/irtimaled/bbor/config/ConfigManager.java index 8b37fec..512bb57 100644 --- a/src/main/java/com/irtimaled/bbor/config/ConfigManager.java +++ b/src/main/java/com/irtimaled/bbor/config/ConfigManager.java @@ -52,6 +52,8 @@ public class ConfigManager { public static Setting drawNetherFossils; public static Setting drawBastionRemnants; public static Setting drawRuinedPortals; + public static Setting drawConduits; + public static Setting 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."); diff --git a/src/main/resources/assets/bbor/lang/en_us.json b/src/main/resources/assets/bbor/lang/en_us.json index 4043f9a..dea0e63 100644 --- a/src/main/resources/assets/bbor/lang/en_us.json +++ b/src/main/resources/assets/bbor/lang/en_us.json @@ -28,6 +28,11 @@ "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",