From: Irtimaled Date: Mon, 24 Aug 2020 00:29:00 +0000 (-0700) Subject: Add: flower forest overlay X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=309b2db7459deb2cac75993eb14905024c1a7dbb;p=BoundingBoxOutlineReloaded.git Add: flower forest overlay --- diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ec15f5e..a4459c2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -4,3 +4,4 @@ - cameron-gagnon - plusls - LoupDuQc +- OroArmor diff --git a/src/main/java/com/irtimaled/bbor/client/ClientProxy.java b/src/main/java/com/irtimaled/bbor/client/ClientProxy.java index c09764c..efee94a 100644 --- a/src/main/java/com/irtimaled/bbor/client/ClientProxy.java +++ b/src/main/java/com/irtimaled/bbor/client/ClientProxy.java @@ -4,6 +4,7 @@ import com.irtimaled.bbor.client.config.ConfigManager; import com.irtimaled.bbor.client.events.*; import com.irtimaled.bbor.client.gui.LoadSavesScreen; import com.irtimaled.bbor.client.gui.SettingsScreen; +import com.irtimaled.bbor.client.interop.FlowerForestHelper; import com.irtimaled.bbor.client.keyboard.Key; import com.irtimaled.bbor.client.keyboard.KeyListener; import com.irtimaled.bbor.client.providers.*; @@ -77,6 +78,7 @@ public class ClientProxy extends CommonProxy { protected void setSeed(long seed) { super.setSeed(seed); SlimeChunkProvider.setSeed(seed); + FlowerForestHelper.setSeed(seed); } @Override diff --git a/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java b/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java index 49a6afa..fab8e3b 100644 --- a/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java +++ b/src/main/java/com/irtimaled/bbor/client/ClientRenderer.java @@ -46,6 +46,7 @@ public class ClientRenderer { registerRenderer(BoundingBoxSpawnableBlocks.class, new SpawnableBlocksRenderer()); registerRenderer(BoundingBoxLine.class, new LineRenderer()); registerRenderer(BoundingBoxSphere.class, new SphereRenderer()); + registerRenderer(BoundingBoxFlowerForest.class, new FlowerForestRenderer()); registerProvider(new SlimeChunkProvider()); registerProvider(new WorldSpawnProvider()); @@ -59,6 +60,7 @@ public class ClientRenderer { registerProvider(new SpawnableBlocksProvider()); registerProvider(new CustomLineProvider()); registerProvider(new CustomSphereProvider()); + registerProvider(new FlowerForestProvider()); } public static void registerProvider(IBoundingBoxProvider provider) { diff --git a/src/main/java/com/irtimaled/bbor/client/config/BoundingBoxTypeHelper.java b/src/main/java/com/irtimaled/bbor/client/config/BoundingBoxTypeHelper.java index 7781810..3688627 100644 --- a/src/main/java/com/irtimaled/bbor/client/config/BoundingBoxTypeHelper.java +++ b/src/main/java/com/irtimaled/bbor/client/config/BoundingBoxTypeHelper.java @@ -25,6 +25,7 @@ public class BoundingBoxTypeHelper { registerType(BoundingBoxType.Custom, ConfigManager.drawConduits, ConfigManager.colorCustom); registerType(BoundingBoxType.Conduit, ConfigManager.drawConduits, ConfigManager.colorConduits); registerType(BoundingBoxType.SpawnableBlocks, ConfigManager.drawSpawnableBlocks, ConfigManager.colorSpawnableBlocks); + registerType(BoundingBoxType.FlowerForest, ConfigManager.drawFlowerForests, null); registerType(BoundingBoxType.JungleTemple, ConfigManager.drawJungleTemples, ConfigManager.colorJungleTemples); registerType(BoundingBoxType.DesertTemple, ConfigManager.drawDesertTemples, ConfigManager.colorDesertTemples); diff --git a/src/main/java/com/irtimaled/bbor/client/config/ConfigManager.java b/src/main/java/com/irtimaled/bbor/client/config/ConfigManager.java index 6e2f8a3..a659e62 100644 --- a/src/main/java/com/irtimaled/bbor/client/config/ConfigManager.java +++ b/src/main/java/com/irtimaled/bbor/client/config/ConfigManager.java @@ -53,6 +53,8 @@ public class ConfigManager { public static Setting spawnableBlocksRenderHeight; public static Setting invertBoxColorPlayerInside; public static Setting renderSphereAsDots; + public static Setting drawFlowerForests; + public static Setting flowerForestsRenderDistance; public static Setting colorWorldSpawn; public static Setting colorLazySpawnChunks; @@ -87,6 +89,17 @@ public class ConfigManager { public static Setting colorNetherFossils; public static Setting colorBastionRemnants; public static Setting colorRuinedPortals; + public static Setting colorFlowerForestDandelion; + public static Setting colorFlowerForestPoppy; + public static Setting colorFlowerForestAllium; + public static Setting colorFlowerForestAzureBluet; + public static Setting colorFlowerForestRedTulip; + public static Setting colorFlowerForestOrangeTulip; + public static Setting colorFlowerForestWhiteTulip; + public static Setting colorFlowerForestPinkTulip; + public static Setting colorFlowerForestOxeyeDaisy; + public static Setting colorFlowerForestCornflower; + public static Setting colorFlowerForestLilyOfTheValley; public static Setting buttonOnOverlay; @@ -113,6 +126,9 @@ public class ConfigManager { biomeBordersRenderDistance = setup(config, "biomeBorders", "biomeBordersRenderDistance", 3, "The distance from the player where biome borders will be drawn."); biomeBordersMaxY = setup(config, "biomeBorders", "biomeBordersMaxY", -1, "The maximum top of the biome borders. If set to -1 it will use the value when activated, if set to 0 it will always track the players feet."); + drawFlowerForests = setup(config, "flowerForests", "drawFlowerForests", true, "If set to true flower forest flower overlays will be drawn."); + flowerForestsRenderDistance = setup(config, "flowerForests", "flowerForestsRenderDistance", 3, "The distance from the player where flower forests will be drawn."); + drawVillages = setup(config, "structures", "drawVillages", false, "If set to true village bounding boxes will be drawn."); drawDesertTemples = setup(config, "structures", "drawDesertTemples", true, "If set to true desert temple bounding boxes are drawn."); drawJungleTemples = setup(config, "structures", "drawJungleTemples", true, "If set to true jungle temple bounding boxes are drawn."); @@ -184,6 +200,17 @@ public class ConfigManager { colorNetherFossils = setup(config, "colors", "colorNetherFossils", HexColor.from("#ffffff"), "Color of nether fossils."); colorBastionRemnants = setup(config, "colors", "colorBastionRemnants", HexColor.from("#c0c0c0"), "Color of bastion remnants."); colorRuinedPortals = setup(config, "colors", "colorRuinedPortals", HexColor.from("#c800ff"), "Color of ruined portals."); + colorFlowerForestDandelion = setup(config, "colors", "colorFlowerForestDandelion", HexColor.from("#ffff00"), "Color of Flower Forest Dandelion"); + colorFlowerForestPoppy = setup(config, "colors", "colorFlowerForestPoppy", HexColor.from("#ff0000"), "Color of Flower Forest Poppy"); + colorFlowerForestAllium = setup(config, "colors", "colorFlowerForestAllium", HexColor.from("#ff00ff"), "Color of Flower Forest Allium"); + colorFlowerForestAzureBluet = setup(config, "colors", "colorFlowerForestAzureBluet", HexColor.from("#d3d3d3"), "Color of Flower Forest Azure Bluet"); + colorFlowerForestRedTulip = setup(config, "colors", "colorFlowerForestRedTulip", HexColor.from("#ff0000"), "Color of Flower Forest Red Tulip"); + colorFlowerForestOrangeTulip = setup(config, "colors", "colorFlowerForestOrangeTulip", HexColor.from("#ff681f"), "Color of Flower Forest Orange Tulip"); + colorFlowerForestWhiteTulip = setup(config, "colors", "colorFlowerForestWhiteTulip", HexColor.from("#d3d3d3"), "Color of Flower Forest White Tulip"); + colorFlowerForestPinkTulip = setup(config, "colors", "colorFlowerForestPinkTulip", HexColor.from("#ff69b4"), "Color of Flower Forest Pink Tulip"); + colorFlowerForestOxeyeDaisy = setup(config, "colors", "colorFlowerForestOxeyeDaisy", HexColor.from("#d3d3d3"), "Color of Flower Forest Oxeye Daisy"); + colorFlowerForestCornflower = setup(config, "colors", "colorFlowerForestCornflower", HexColor.from("#0000ff"), "Color of Flower Forest Cornflower"); + colorFlowerForestLilyOfTheValley = setup(config, "colors", "colorFlowerForestLilyOfTheValley", HexColor.from("#ffffff"), "Color of Flower Forest Lily Of The Valley"); config.save(); } 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 cce48a2..28761cc 100644 --- a/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java +++ b/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java @@ -62,6 +62,12 @@ public class SettingsScreen extends ListScreen { .addDisplayValue(1, I18n.format("bbor.options.distance.nearest")) .addDisplayValue(2, I18n.format("bbor.options.distance.nearer")) .addDisplayValue(3, I18n.format("bbor.options.distance.normal"))) + .section(I18n.format("bbor.features.flowerForests"), + width -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.flowerForests"), BoundingBoxType.FlowerForest), + width -> new IntSettingSlider(width, 1, 3, "bbor.options.distance", ConfigManager.flowerForestsRenderDistance) + .addDisplayValue(1, I18n.format("bbor.options.distance.nearest")) + .addDisplayValue(2, I18n.format("bbor.options.distance.nearer")) + .addDisplayValue(3, I18n.format("bbor.options.distance.normal"))) .section(I18n.format("bbor.features.mobSpawners"), width -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.mobSpawners"), BoundingBoxType.MobSpawner), width -> new BoolSettingButton(width, I18n.format("bbor.features.mobSpawners.spawnArea"), ConfigManager.renderMobSpawnerSpawnArea), diff --git a/src/main/java/com/irtimaled/bbor/client/interop/FlowerForestHelper.java b/src/main/java/com/irtimaled/bbor/client/interop/FlowerForestHelper.java new file mode 100644 index 0000000..1d64707 --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/interop/FlowerForestHelper.java @@ -0,0 +1,56 @@ +package com.irtimaled.bbor.client.interop; + +import com.irtimaled.bbor.client.config.ConfigManager; +import com.irtimaled.bbor.client.config.HexColor; +import com.irtimaled.bbor.client.config.Setting; +import com.irtimaled.bbor.common.models.Coords; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.client.Minecraft; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.gen.feature.DecoratedFeatureConfig; +import net.minecraft.world.gen.feature.FlowersFeature; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class FlowerForestHelper { + private static final Random random = new Random(); + + private static final Map> flowerColorMap = new HashMap<>(); + private static final FlowersFeature flowersFeature; + + static { + flowerColorMap.put(Blocks.DANDELION.getDefaultState(), ConfigManager.colorFlowerForestDandelion); + flowerColorMap.put(Blocks.POPPY.getDefaultState(), ConfigManager.colorFlowerForestPoppy); + flowerColorMap.put(Blocks.ALLIUM.getDefaultState(), ConfigManager.colorFlowerForestAllium); + flowerColorMap.put(Blocks.AZURE_BLUET.getDefaultState(), ConfigManager.colorFlowerForestAzureBluet); + flowerColorMap.put(Blocks.RED_TULIP.getDefaultState(), ConfigManager.colorFlowerForestRedTulip); + flowerColorMap.put(Blocks.ORANGE_TULIP.getDefaultState(), ConfigManager.colorFlowerForestOrangeTulip); + flowerColorMap.put(Blocks.WHITE_TULIP.getDefaultState(), ConfigManager.colorFlowerForestWhiteTulip); + flowerColorMap.put(Blocks.PINK_TULIP.getDefaultState(), ConfigManager.colorFlowerForestPinkTulip); + flowerColorMap.put(Blocks.OXEYE_DAISY.getDefaultState(), ConfigManager.colorFlowerForestOxeyeDaisy); + flowerColorMap.put(Blocks.CORNFLOWER.getDefaultState(), ConfigManager.colorFlowerForestCornflower); + flowerColorMap.put(Blocks.LILY_OF_THE_VALLEY.getDefaultState(), ConfigManager.colorFlowerForestLilyOfTheValley); + + DecoratedFeatureConfig config = (DecoratedFeatureConfig) Biomes.FLOWER_FOREST.getFlowers().get(0).config; + flowersFeature = (FlowersFeature) config.feature.feature; + } + + public static Setting getFlowerColorAtPos(Coords coords) { + int x = coords.getX(); + int z = coords.getZ(); + BlockState blockState = flowersFeature.getRandomFlower(random, new BlockPos(x, coords.getY(), z)); + return flowerColorMap.get(blockState); + } + + public static void setSeed(long seed) { + random.setSeed(seed); + } + + public static boolean canGrowFlower(int x, int y, int z) { + return Minecraft.getInstance().world.getBlockState(new BlockPos(x, y, z)).getBlock() == Blocks.GRASS_BLOCK; + } +} diff --git a/src/main/java/com/irtimaled/bbor/client/models/BoundingBoxFlowerForest.java b/src/main/java/com/irtimaled/bbor/client/models/BoundingBoxFlowerForest.java new file mode 100644 index 0000000..2f598cd --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/models/BoundingBoxFlowerForest.java @@ -0,0 +1,49 @@ +package com.irtimaled.bbor.client.models; + +import com.irtimaled.bbor.client.config.ColorHelper; +import com.irtimaled.bbor.client.config.HexColor; +import com.irtimaled.bbor.client.config.Setting; +import com.irtimaled.bbor.common.BoundingBoxType; +import com.irtimaled.bbor.common.models.AbstractBoundingBox; +import com.irtimaled.bbor.common.models.Coords; + +import java.awt.*; + +public class BoundingBoxFlowerForest extends AbstractBoundingBox { + private final Coords coords; + private final Setting colorSetting; + + public BoundingBoxFlowerForest(Coords coords, Setting colorSetting) { + super(BoundingBoxType.FlowerForest); + this.coords = coords; + this.colorSetting = colorSetting; + } + + @Override + public Boolean intersectsBounds(int minX, int minZ, int maxX, int maxZ) { + return coords.getX() >= minX && coords.getZ() >= minZ && coords.getX() <= maxX && coords.getZ() <= maxZ; + } + + public Color getColor() { + return ColorHelper.getColor(colorSetting); + } + + public Coords getCoords() { + return coords; + } + + @Override + public double getDistanceX(double x) { + return x - coords.getX(); + } + + @Override + public double getDistanceY(double y) { + return y - coords.getY(); + } + + @Override + public double getDistanceZ(double z) { + return z - coords.getZ(); + } +} diff --git a/src/main/java/com/irtimaled/bbor/client/providers/FlowerForestProvider.java b/src/main/java/com/irtimaled/bbor/client/providers/FlowerForestProvider.java new file mode 100644 index 0000000..cd6b46a --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/providers/FlowerForestProvider.java @@ -0,0 +1,88 @@ +package com.irtimaled.bbor.client.providers; + +import com.irtimaled.bbor.client.Player; +import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper; +import com.irtimaled.bbor.client.config.ConfigManager; +import com.irtimaled.bbor.client.interop.BiomeBorderHelper; +import com.irtimaled.bbor.client.interop.FlowerForestHelper; +import com.irtimaled.bbor.client.models.BoundingBoxFlowerForest; +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.DimensionId; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.biome.Biomes; + +import java.util.HashMap; +import java.util.Map; + +public class FlowerForestProvider implements IBoundingBoxProvider { + public static final int FLOWER_FOREST_BIOME_ID = Registry.BIOME.getId(Biomes.FLOWER_FOREST); + private static Coords lastPlayerCoords = null; + private static Integer lastRenderDistance = null; + private static Map lastBoundingBoxes = new HashMap<>(); + + @Override + public boolean canProvide(DimensionId dimensionId) { + return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.FlowerForest); + } + + @Override + public Iterable get(DimensionId dimensionId) { + Coords playerCoords = Player.getCoords(); + Integer renderDistance = ConfigManager.flowerForestsRenderDistance.get(); + if (!playerCoords.equals(lastPlayerCoords) || !renderDistance.equals(lastRenderDistance)) { + lastPlayerCoords = playerCoords; + lastRenderDistance = renderDistance; + lastBoundingBoxes = getBoundingBoxes(); + } + return lastBoundingBoxes.values(); + } + + public static void clear() { + lastBoundingBoxes = new HashMap<>(); + lastPlayerCoords = null; + } + + private Map getBoundingBoxes() { + int renderDistance = lastRenderDistance; + Coords playerCoords = lastPlayerCoords; + + int width = MathHelper.floor(Math.pow(2, 2 + renderDistance)); + + int blockX = playerCoords.getX(); + int minX = blockX - width; + int maxX = blockX + width; + + int blockZ = playerCoords.getZ(); + int minZ = blockZ - width; + int maxZ = blockZ + width; + + Map boundingBoxes = new HashMap<>(); + for (int x = minX; x <= maxX; x++) { + for (int z = minZ; z <= maxZ; z++) { + int biomeId = BiomeBorderHelper.getBiomeId(x, 255, z); + if (biomeId == FLOWER_FOREST_BIOME_ID) { + int y = getMaxYForPos(x, playerCoords.getY() + 1, z); + if (y == 0) { + continue; + } + Coords coords = new Coords(x, y + 1, z); + BoundingBoxFlowerForest boundingBox = lastBoundingBoxes.containsKey(coords) + ? lastBoundingBoxes.get(coords) + : new BoundingBoxFlowerForest(coords, FlowerForestHelper.getFlowerColorAtPos(coords)); + boundingBoxes.put(coords, boundingBox); + } + } + } + return boundingBoxes; + } + + private static int getMaxYForPos(int x, int y, int z) { + while (y > 0) { + if (FlowerForestHelper.canGrowFlower(x, y, z)) return y; + y--; + } + return 0; + } +} diff --git a/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java b/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java index de22773..26f2279 100644 --- a/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java +++ b/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java @@ -106,11 +106,15 @@ public abstract class AbstractRenderer { } void renderFilledFaces(OffsetPoint min, OffsetPoint max, Color color) { + renderFilledFaces(min, max, color, 30); + } + + void renderFilledFaces(OffsetPoint min, OffsetPoint max, Color color, int alpha) { if (!ConfigManager.fill.get()) return; RenderHelper.polygonModeFill(); RenderHelper.enableBlend(); - renderFaces(min, max, color, 30, Renderer::startQuads); + renderFaces(min, max, color, alpha, Renderer::startQuads); RenderHelper.disableBlend(); RenderHelper.enablePolygonOffsetLine(); RenderHelper.polygonOffsetMinusOne(); diff --git a/src/main/java/com/irtimaled/bbor/client/renderers/FlowerForestRenderer.java b/src/main/java/com/irtimaled/bbor/client/renderers/FlowerForestRenderer.java new file mode 100644 index 0000000..570e202 --- /dev/null +++ b/src/main/java/com/irtimaled/bbor/client/renderers/FlowerForestRenderer.java @@ -0,0 +1,17 @@ +package com.irtimaled.bbor.client.renderers; + +import com.irtimaled.bbor.client.models.BoundingBoxFlowerForest; +import com.irtimaled.bbor.common.models.Coords; + +public class FlowerForestRenderer extends AbstractRenderer { + @Override + public void render(BoundingBoxFlowerForest boundingBox) { + Coords coords = boundingBox.getCoords(); + int x = coords.getX(); + int y = coords.getY(); + int z = coords.getZ(); + renderFilledFaces(new OffsetPoint(x, y + 0.01d, z), + new OffsetPoint(x + 1, y + 0.01d, z + 1), + boundingBox.getColor(), 127); + } +} diff --git a/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java b/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java index 9c1a9b6..65728f6 100644 --- a/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java +++ b/src/main/java/com/irtimaled/bbor/common/BoundingBoxType.java @@ -17,6 +17,7 @@ public class BoundingBoxType { public static final BoundingBoxType Beacon = register("Beacon"); public static final BoundingBoxType Conduit = register("Conduit"); public static final BoundingBoxType SpawnableBlocks = register("Spawnable Blocks"); + public static final BoundingBoxType FlowerForest = register("Flower Forest"); public static final BoundingBoxType JungleTemple = register("Jungle_Pyramid"); public static final BoundingBoxType DesertTemple = register("Desert_Pyramid"); diff --git a/src/main/resources/assets/bbor/lang/en_us.json b/src/main/resources/assets/bbor/lang/en_us.json index ac14fa3..c531bd0 100644 --- a/src/main/resources/assets/bbor/lang/en_us.json +++ b/src/main/resources/assets/bbor/lang/en_us.json @@ -29,6 +29,7 @@ "bbor.features.spawningSpheres": "Spawning Spheres", "bbor.features.spawnableBlocks": "Spawnable Blocks", "bbor.features.biomeBorders": "Biome Borders", + "bbor.features.flowerForests": "Flower Forests", "bbor.sections.beaconsAndConduits": "Beacons & Conduits", "bbor.features.beacons": "Beacons",