diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2023-08-18 00:02:04 -0400 |
---|---|---|
committer | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2023-08-18 00:02:04 -0400 |
commit | 8de54765d001fda6a48d01505dc1ac3404c54693 (patch) | |
tree | 06d86335dafbd96a547ba195b2ad9f0a24615406 | |
parent | 5fb9f5bdb98c919433d6d9319074c5fa0469eb61 (diff) | |
download | Skyblocker-8de54765d001fda6a48d01505dc1ac3404c54693.tar.gz Skyblocker-8de54765d001fda6a48d01505dc1ac3404c54693.tar.bz2 Skyblocker-8de54765d001fda6a48d01505dc1ac3404c54693.zip |
Blaze Solver Enhancements
5 files changed, 132 insertions, 23 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 6c046d50..104c9c7a 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -414,6 +414,7 @@ public class SkyblockerConfig implements ConfigData { public int mapX = 2; public int mapY = 2; public boolean solveThreeWeirdos = true; + @ConfigEntry.Gui.Tooltip public boolean blazesolver = true; public boolean solveTrivia = true; @ConfigEntry.Gui.CollapsibleObject diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java index 219f4258..a4b920de 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java @@ -1,8 +1,11 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; +import it.unimi.dsi.fastutil.objects.ObjectIntImmutablePair; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.Utils; import me.xmrvizzy.skyblocker.utils.color.QuadColor; +import me.xmrvizzy.skyblocker.utils.RenderHelper; import me.xmrvizzy.skyblocker.utils.RenderUtils; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; @@ -10,70 +13,103 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.util.math.Box; +import net.minecraft.util.math.Vec3d; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.*; + public class DungeonBlaze { private static final Logger LOGGER = LoggerFactory.getLogger(DungeonBlaze.class.getName()); + private static final float[] WHITE_COLOR_COMPONENTS = { 1.0f, 1.0f, 1.0f }; static Entity highestBlaze = null; static Entity lowestBlaze = null; + static Entity nextHighestBlaze = null; + static Entity nextLowestBlaze = null; static boolean renderHooked = false; public static void update() { ClientWorld world = MinecraftClient.getInstance().world; if (world == null || !Utils.isInDungeons()) return; - if(!renderHooked){ + if (!renderHooked){ - WorldRenderEvents.END.register(DungeonBlaze::blazeRenderer); + WorldRenderEvents.BEFORE_DEBUG_RENDER.register(DungeonBlaze::blazeRenderer); renderHooked = true; } Iterable<Entity> entities = world.getEntities(); - int highestHealth = 0; - int lowestHealth = 99999999; + List<ObjectIntPair<Entity>> blazes = new ArrayList<ObjectIntPair<Entity>>(); for (Entity entity : entities) { - if (entity.getName().getString().contains("Blaze") && entity.getName().getString().contains("/")) { - - String blazeName = entity.getName().getString(); + String blazeName = entity.getName().getString(); + + if (blazeName.contains("Blaze") && blazeName.contains("/")) { try { - int health = Integer.parseInt(blazeName.substring(blazeName.indexOf("/") + 1, blazeName.length() - 1)); - - if (health > highestHealth) { - highestHealth = health; - - highestBlaze = entity; - - } - if (health < lowestHealth) { - lowestHealth = health; - lowestBlaze = entity; - } + + blazes.add(new ObjectIntImmutablePair<Entity>(entity, health)); } catch (NumberFormatException ex) { ex.printStackTrace(); } } } + + // Order the blazes in the list from highest health to lowest health + Collections.sort(blazes, new Comparator<>() { + @Override + public int compare(ObjectIntPair<Entity> o1, ObjectIntPair<Entity> o2) { + return -Integer.compare(o1.rightInt(), o2.rightInt()); + } + }); + + // Ensure that there are blazes in the list + if (blazes.size() >= 1) { + highestBlaze = blazes.get(0).left(); + + int lowestIndex = blazes.size() - 1; + lowestBlaze = blazes.get(lowestIndex).left(); + + // If there's more than 1 blaze + if (blazes.size() > 1) { + nextHighestBlaze = blazes.get(1).left(); + nextLowestBlaze = blazes.get(lowestIndex - 1).left(); + } + } + } public static void blazeRenderer(WorldRenderContext wrc) { QuadColor outlineColorRed = QuadColor.single( 0.0F, 1.0F, 0.0F, 1f); QuadColor outlineColorGreen = QuadColor.single(1.0F, 0.0F, 0.0F, 1f); + QuadColor outlineColorWhite = QuadColor.single(1.0f, 1.0f, 1.0f, 1.0f); + try { - if(highestBlaze != null && lowestBlaze != null && highestBlaze.isAlive() && lowestBlaze.isAlive() && SkyblockerConfig.get().locations.dungeons.blazesolver){ + if (highestBlaze != null && lowestBlaze != null && highestBlaze.isAlive() && lowestBlaze.isAlive() && SkyblockerConfig.get().locations.dungeons.blazesolver){ /* Outline */ - if(highestBlaze.getY() <69) { + if (highestBlaze.getY() < 69) { Box blaze = highestBlaze.getBoundingBox().expand(0.3, 0.9, 0.3).offset(0, -1.1, 0); RenderUtils.drawBoxOutline(blaze, outlineColorRed, 5f); + + if (nextHighestBlaze != null && nextHighestBlaze.isAlive() && nextHighestBlaze != highestBlaze) { + Box nextBlaze = nextHighestBlaze.getBoundingBox().expand(0.3, 0.9, 0.3).offset(0, -1.1, 0); + RenderUtils.drawBoxOutline(nextBlaze, outlineColorWhite, 5f); + RenderHelper.renderLinesFromPoints(wrc, new Vec3d[] { blaze.getCenter(), nextBlaze.getCenter() }, WHITE_COLOR_COMPONENTS, 1f, 5f); + } } /* Outline */ - if(lowestBlaze.getY() >69) { + if (lowestBlaze.getY() > 69) { Box blaze = lowestBlaze.getBoundingBox().expand(0.3, 0.9, 0.3).offset(0, -1.1, 0); RenderUtils.drawBoxOutline(blaze, outlineColorRed, 5f); + + if (nextLowestBlaze != null && nextLowestBlaze.isAlive() && nextLowestBlaze != lowestBlaze) { + Box nextBlaze = nextLowestBlaze.getBoundingBox().expand(0.3, 0.9, 0.3).offset(0, -1.1, 0); + RenderUtils.drawBoxOutline(nextBlaze, outlineColorWhite, 5f); + RenderHelper.renderLinesFromPoints(wrc, new Vec3d[] { blaze.getCenter(), nextBlaze.getCenter() }, WHITE_COLOR_COMPONENTS, 1f, 5f); + } } } - }catch(Exception e) { + } catch (Exception e) { LOGGER.warn("[Skyblocker BlazeRenderer] " + e); + e.printStackTrace(); } } }
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java index a1221549..8f0f7860 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java @@ -9,8 +9,11 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.render.VertexFormat.DrawMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; @@ -20,6 +23,13 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import java.awt.*; +import org.joml.Matrix3f; +import org.joml.Matrix4f; +import org.joml.Vector3f; +import org.lwjgl.opengl.GL11; + +import com.mojang.blaze3d.platform.GlStateManager.DstFactor; +import com.mojang.blaze3d.platform.GlStateManager.SrcFactor; import com.mojang.blaze3d.systems.RenderSystem; public class RenderHelper { @@ -67,6 +77,65 @@ public class RenderHelper { matrices.pop(); } } + + /** + * Draws lines from point to point.<br><br> + * + * Tip: To draw lines from the center of a block, offset the X, Y and Z each by 0.5 + * + * @param context The WorldRenderContext which supplies the matrices and tick delta + * @param points The points from which to draw lines between + * @param colorComponents An array of R, G and B color components + * @param alpha The alpha of the lines + * @param lineWidth The width of the lines + */ + public static void renderLinesFromPoints(WorldRenderContext context, Vec3d[] points, float[] colorComponents, float alpha, float lineWidth) { + Vec3d camera = context.camera().getPos(); + MatrixStack matrices = context.matrixStack(); + + matrices.push(); + matrices.translate(-camera.x, -camera.y, -camera.z); + + Tessellator tessellator = RenderSystem.renderThreadTesselator(); + BufferBuilder buffer = tessellator.getBuffer(); + Matrix4f projectionMatrix = matrices.peek().getPositionMatrix(); + Matrix3f normalMatrix = matrices.peek().getNormalMatrix(); + + GL11.glEnable(GL11.GL_LINE_SMOOTH); + GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); + + RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); + RenderSystem.setShaderColor(1f, 1f, 1f, 1f); + RenderSystem.lineWidth(lineWidth); + RenderSystem.enableBlend(); + RenderSystem.blendFunc(SrcFactor.SRC_ALPHA, DstFactor.ONE_MINUS_SRC_ALPHA); + RenderSystem.disableCull(); + RenderSystem.enableDepthTest(); + + buffer.begin(DrawMode.LINE_STRIP, VertexFormats.LINES); + + for (int i = 0; i < points.length; i++) { + Vec3d point = points[i]; + Vec3d nextPoint = (i + 1 == points.length) ? points[i - 1] : points[i + 1]; + Vector3f normalVec = new Vector3f((float) nextPoint.getX(), (float) nextPoint.getY(), (float) nextPoint.getZ()).sub((float) point.getX(), (float) point.getY(), (float) point.getZ()).normalize(); + + buffer + .vertex(projectionMatrix, (float) point.getX(), (float) point.getY(), (float) point.getZ()) + .color(colorComponents[0], colorComponents[1], colorComponents[2], alpha) + .normal(normalMatrix, normalVec.x, normalVec.y, normalVec.z) + .next(); + } + + tessellator.draw(); + + matrices.pop(); + GL11.glDisable(GL11.GL_LINE_SMOOTH); + RenderSystem.lineWidth(1f); + RenderSystem.disableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.enableCull(); + RenderSystem.disableDepthTest(); + } public static void displayTitleAndPlaySound(int stayTicks, int fadeOutTicks, String titleKey, Formatting formatting) { MinecraftClient.getInstance().inGameHud.setTitleTicks(0, stayTicks, fadeOutTicks); diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java index 61f79ae1..d20cfefe 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java @@ -41,6 +41,7 @@ public class RenderUtils { BufferBuilder buffer = tessellator.getBuffer(); // Outline + RenderSystem.enableDepthTest(); RenderSystem.disableCull(); RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); RenderSystem.lineWidth(lineWidth); @@ -50,6 +51,7 @@ public class RenderUtils { tessellator.draw(); RenderSystem.enableCull(); + RenderSystem.disableDepthTest(); cleanup(); } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 1e5e883e..39a215d2 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -206,6 +206,7 @@ "text.autoconfig.skyblocker.option.locations.dungeons.mapY": "Map Y", "text.autoconfig.skyblocker.option.locations.dungeons.solveThreeWeirdos": "Solve Three Weirdos Puzzle", "text.autoconfig.skyblocker.option.locations.dungeons.blazesolver": "Solve Blaze Puzzle", + "text.autoconfig.skyblocker.option.locations.dungeons.blazesolver.@Tooltip": "Boxes the correct blaze in green, also draws a line to and boxes the next blaze to kill in white.", "text.autoconfig.skyblocker.option.locations.dungeons.solveTrivia": "Solve Trivia Puzzle", "text.autoconfig.skyblocker.option.locations.dungeons.lividColor": "Livid Color", "text.autoconfig.skyblocker.option.locations.dungeons.lividColor.enableLividColor": "Enable Livid Color", |