aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java9
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java85
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java128
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java88
4 files changed, 228 insertions, 82 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
index 610d6931..882dd965 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
@@ -787,6 +787,7 @@ public class NEUEventListener {
@SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
public void onGuiChat(ClientChatReceivedEvent e) {
if(e.type == 2) {
+ CrystalMetalDetectorSolver.process(e.message);
e.message = processChatComponent(e.message);
return;
}
@@ -834,6 +835,9 @@ public class NEUEventListener {
e.message = new ChatComponentText(m2);
}
}
+ if (unformatted.startsWith("You found ") && SBInfo.getInstance().getLocation().equals("crystal_hollows")){
+ CrystalMetalDetectorSolver.reset();
+ }
}
public static boolean drawingGuiScreen = false;
@@ -2446,4 +2450,9 @@ public class NEUEventListener {
}
}
}
+
+ @SubscribeEvent
+ public void onRenderLast(RenderWorldLastEvent event){
+ CrystalMetalDetectorSolver.render(event.partialTicks);
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java
index a43eb0e6..b63831ac 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java
@@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.core.util.render;
import io.github.moulberry.notenoughupdates.core.BackgroundBlur;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
@@ -9,8 +10,12 @@ import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
+import net.minecraft.entity.Entity;
+import net.minecraft.util.BlockPos;
+import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
+import org.lwjgl.util.vector.Vector3f;
public class RenderUtils {
@@ -141,4 +146,84 @@ public class RenderUtils {
GlStateManager.enableTexture2D();
}
+ public static void renderWayPoint(String str, BlockPos loc, float partialTicks) {
+ renderWayPoint(str, new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks);
+ }
+ public static void renderWayPoint(String str, Vector3f loc, float partialTicks) {
+ GlStateManager.alphaFunc(516, 0.1F);
+
+ GlStateManager.pushMatrix();
+
+ Entity viewer = Minecraft.getMinecraft().getRenderViewEntity();
+ double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks;
+ double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks;
+ double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks;
+
+ double x = loc.x-viewerX+0.5f;
+ double y = loc.y-viewerY-viewer.getEyeHeight();
+ double z = loc.z-viewerZ+0.5f;
+
+ double distSq = x*x + y*y + z*z;
+ double dist = Math.sqrt(distSq);
+ if(distSq > 144) {
+ x *= 12/dist;
+ y *= 12/dist;
+ z *= 12/dist;
+ }
+ GlStateManager.translate(x, y, z);
+ GlStateManager.translate(0, viewer.getEyeHeight(), 0);
+
+ renderNametag(str);
+
+ GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
+ GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
+ GlStateManager.translate(0, -0.25f, 0);
+ GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
+ GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
+
+ renderNametag(EnumChatFormatting.YELLOW.toString()+Math.round(dist)+"m");
+
+ GlStateManager.popMatrix();
+
+ GlStateManager.disableLighting();
+ }
+
+ public static void renderNametag(String str) {
+ FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj;
+ float f = 1.6F;
+ float f1 = 0.016666668F * f;
+ GlStateManager.pushMatrix();
+ GL11.glNormal3f(0.0F, 1.0F, 0.0F);
+ GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
+ GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
+ GlStateManager.scale(-f1, -f1, f1);
+ GlStateManager.disableLighting();
+ GlStateManager.depthMask(false);
+ GlStateManager.disableDepth();
+ GlStateManager.enableBlend();
+ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
+ Tessellator tessellator = Tessellator.getInstance();
+ WorldRenderer worldrenderer = tessellator.getWorldRenderer();
+ int i = 0;
+
+ int j = fontrenderer.getStringWidth(str) / 2;
+ GlStateManager.disableTexture2D();
+ worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
+ worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
+ worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
+ worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
+ worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
+ tessellator.draw();
+ GlStateManager.enableTexture2D();
+ fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127);
+ GlStateManager.depthMask(true);
+
+ fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1);
+
+ GlStateManager.enableDepth();
+ GlStateManager.enableBlend();
+ GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
+ GlStateManager.popMatrix();
+ }
+
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
new file mode 100644
index 00000000..7ed2414a
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
@@ -0,0 +1,128 @@
+package io.github.moulberry.notenoughupdates.miscfeatures;
+
+import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
+import io.github.moulberry.notenoughupdates.util.SBInfo;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.WorldRenderer;
+import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
+import net.minecraft.entity.Entity;
+import net.minecraft.util.BlockPos;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.IChatComponent;
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.util.vector.Vector3f;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CrystalMetalDetectorSolver {
+ private static final Minecraft mc = Minecraft.getMinecraft();
+ private static float prev;
+ private static List<BlockPos> possibleBlocks = new ArrayList<>();
+ private static final List<Float> distances = new ArrayList<>();
+
+ public static void process(IChatComponent message) {
+ if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows")
+ && message.getUnformattedText().contains("TREASURE: ")) {
+ float dist = Float.parseFloat(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", ""));
+ if (prev == dist && dist > 5 && !distances.contains(dist) && possibleBlocks.size() != 1) { //Distance 5 minimum because distance calculation is inaccurate under 5
+ distances.add(dist);
+ List<BlockPos> temp = new ArrayList<>();
+ for (int zOffset = Math.round(-dist); zOffset <= dist; zOffset++) {
+ float calculatedDist = 0;
+ int xOffset = 0;
+ int yOffset = 0;
+ int loops = 0;
+ while (calculatedDist < dist) {
+ loops++;
+ BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset,
+ Math.floor(mc.thePlayer.posY - 1) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset);
+ BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset,
+ Math.floor(mc.thePlayer.posY) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset);
+ if (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:air")) {
+ yOffset--;
+ System.out.println("-" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " +
+ mc.theWorld.getBlockState(above).getBlock().getRegistryName());
+ } else if (mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:gold_block")) {
+ yOffset++;
+ System.out.println("+" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " +
+ mc.theWorld.getBlockState(above).getBlock().getRegistryName());
+ } else {
+ System.out.println("Calculating block distance");
+ xOffset++;
+ calculatedDist = (float) round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1);
+ if (calculatedDist == dist && (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block")
+ || mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest")) &&
+ (possibleBlocks.size() == 0 || possibleBlocks.contains(pos))) {
+ temp.add(pos);
+ }
+ }
+ if (loops > 500) break;
+ }
+ xOffset = 0;
+ calculatedDist = 0;
+ yOffset = 0;
+ loops = 0;
+ while (calculatedDist < dist) {
+ loops++;
+ BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset,
+ Math.floor(mc.thePlayer.posY - 1) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset);
+ BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset,
+ Math.floor(mc.thePlayer.posY) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset);
+ if (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:air")) {
+ yOffset--;
+ System.out.println("-" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " +
+ mc.theWorld.getBlockState(above).getBlock().getRegistryName());
+ } else if (mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:gold_block")) {
+ yOffset++;
+ System.out.println("+" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " +
+ mc.theWorld.getBlockState(above).getBlock().getRegistryName());
+ } else {
+ System.out.println("Calculating block distance");
+ xOffset++;
+ calculatedDist = (float) round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1);
+ if (calculatedDist == dist && (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block")
+ || mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest")) &&
+ (possibleBlocks.size() == 0 || possibleBlocks.contains(pos))) {
+ temp.add(pos);
+ }
+ }
+ if (loops > 500) break;
+ }
+ }
+ possibleBlocks = temp;
+ System.out.println(possibleBlocks);
+ if (possibleBlocks.size() > 1) {
+ mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Need another position to find solution. Possible blocks: "
+ + possibleBlocks.size()));
+ } else if (possibleBlocks.size() == 0) {
+ mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Failed to find solution."));
+ } else {
+ mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution."));
+ }
+ }
+ prev = dist;
+ }
+ }
+
+ public static void reset() {
+ possibleBlocks.clear();
+ distances.clear();
+ }
+
+ public static void render(float partialTicks){
+ if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && possibleBlocks.size() == 1){
+ RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0), partialTicks);
+ }
+ }
+
+ private static double round(double value, int precision) {
+ int scale = (int) Math.pow(10, precision);
+ return (double) Math.round(value * scale) / scale;
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java
index 96f86c36..5c4fb61d 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java
@@ -1,6 +1,7 @@
package io.github.moulberry.notenoughupdates.miscfeatures;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.overlays.MiningOverlay;
import io.github.moulberry.notenoughupdates.util.SBInfo;
@@ -197,7 +198,7 @@ public class DwarvenMinesWaypoints {
System.currentTimeMillis() - dynamicMillis < 30*1000) {
for(Map.Entry<String, Vector3f> entry : waypointsMap.entrySet()) {
if(entry.getKey().equals(dynamicLocation)) {
- renderWayPoint(dynamicName, new Vector3f(entry.getValue()).translate(0, 15, 0), event.partialTicks);
+ RenderUtils.renderWayPoint(dynamicName, new Vector3f(entry.getValue()).translate(0, 15, 0), event.partialTicks);
break;
}
}
@@ -206,14 +207,14 @@ public class DwarvenMinesWaypoints {
if(locWaypoint >= 1) {
for(Map.Entry<String, Vector3f> entry : waypointsMap.entrySet()) {
if(locWaypoint >= 2) {
- renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks);
+ RenderUtils.renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks);
} else {
for(String commissionName : MiningOverlay.commissionProgress.keySet()) {
if(commissionName.toLowerCase().contains(entry.getKey().toLowerCase())) {
if(commissionName.contains("Titanium")) {
- renderWayPoint(EnumChatFormatting.WHITE+entry.getKey(), entry.getValue(), event.partialTicks);
+ RenderUtils.renderWayPoint(EnumChatFormatting.WHITE+entry.getKey(), entry.getValue(), event.partialTicks);
} else {
- renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks);
+ RenderUtils.renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks);
}
}
}
@@ -247,7 +248,7 @@ public class DwarvenMinesWaypoints {
double distSq = dX*dX + dY*dY + dZ*dZ;
if(distSq >= 12*12) {
- renderWayPoint(EnumChatFormatting.GOLD+emissary.name,
+ RenderUtils.renderWayPoint(EnumChatFormatting.GOLD+emissary.name,
new Vector3f(emissary.loc).translate(0.5f, 2.488f, 0.5f),
event.partialTicks);
}
@@ -258,81 +259,4 @@ public class DwarvenMinesWaypoints {
}
}
- private void renderWayPoint(String str, Vector3f loc, float partialTicks) {
- GlStateManager.alphaFunc(516, 0.1F);
-
- GlStateManager.pushMatrix();
-
- Entity viewer = Minecraft.getMinecraft().getRenderViewEntity();
- double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks;
- double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks;
- double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks;
-
- double x = loc.x-viewerX+0.5f;
- double y = loc.y-viewerY-viewer.getEyeHeight();
- double z = loc.z-viewerZ+0.5f;
-
- double distSq = x*x + y*y + z*z;
- double dist = Math.sqrt(distSq);
- if(distSq > 144) {
- x *= 12/dist;
- y *= 12/dist;
- z *= 12/dist;
- }
- GlStateManager.translate(x, y, z);
- GlStateManager.translate(0, viewer.getEyeHeight(), 0);
-
- renderNametag(str);
-
- GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
- GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
- GlStateManager.translate(0, -0.25f, 0);
- GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
- GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
-
- renderNametag(EnumChatFormatting.YELLOW.toString()+Math.round(dist)+"m");
-
- GlStateManager.popMatrix();
-
- GlStateManager.disableLighting();
- }
-
- private void renderNametag(String str) {
- FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj;
- float f = 1.6F;
- float f1 = 0.016666668F * f;
- GlStateManager.pushMatrix();
- GL11.glNormal3f(0.0F, 1.0F, 0.0F);
- GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
- GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
- GlStateManager.scale(-f1, -f1, f1);
- GlStateManager.disableLighting();
- GlStateManager.depthMask(false);
- GlStateManager.disableDepth();
- GlStateManager.enableBlend();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
- Tessellator tessellator = Tessellator.getInstance();
- WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- int i = 0;
-
- int j = fontrenderer.getStringWidth(str) / 2;
- GlStateManager.disableTexture2D();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
- worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
- worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
- worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
- worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
- tessellator.draw();
- GlStateManager.enableTexture2D();
- fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127);
- GlStateManager.depthMask(true);
-
- fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1);
-
- GlStateManager.enableDepth();
- GlStateManager.enableBlend();
- GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
- GlStateManager.popMatrix();
- }
-
}