diff options
Diffstat (limited to 'src/main/java')
4 files changed, 254 insertions, 156 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 38775ee7..d2603651 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -166,7 +166,7 @@ public class NEUEventListener { @SubscribeEvent public void onWorldLoad(WorldEvent.Unload event) { NotEnoughUpdates.INSTANCE.saveConfig(); - CrystalMetalDetectorSolver.reset(); + CrystalMetalDetectorSolver.reset(false); } private static long notificationDisplayMillis = 0; @@ -862,7 +862,7 @@ public class NEUEventListener { } } if (unformatted.startsWith("You found ") && SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows")){ - CrystalMetalDetectorSolver.reset(); + CrystalMetalDetectorSolver.reset(true); } if(unformatted.startsWith("[NPC] Keeper of ") | unformatted.startsWith("[NPC] Professor Robot: ") || unformatted.startsWith(" ") || unformatted.startsWith("✦") || unformatted.equals(" You've earned a Crystal Loot Bundle!")) 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 b63831ac..5f0ad94f 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 @@ -1,6 +1,8 @@ package io.github.moulberry.notenoughupdates.core.util.render; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; +import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; +import io.github.moulberry.notenoughupdates.util.SpecialColour; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -11,8 +13,7 @@ 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 net.minecraft.util.*; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; import org.lwjgl.util.vector.Vector3f; @@ -146,9 +147,173 @@ public class RenderUtils { GlStateManager.enableTexture2D(); } + private static final ResourceLocation beaconBeam = new ResourceLocation("textures/entity/beacon_beam.png"); + + private static void renderBeaconBeam(double x, double y, double z, int rgb, float alphaMult, + float partialTicks, Boolean disableDepth) { + int height = 300; + int bottomOffset = 0; + int topOffset = bottomOffset + height; + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + + if (disableDepth) { + GlStateManager.disableDepth(); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(beaconBeam); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); + GlStateManager.disableLighting(); + GlStateManager.enableCull(); + GlStateManager.enableTexture2D(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + + double time = Minecraft.getMinecraft().theWorld.getTotalWorldTime() + (double)partialTicks; + double d1 = MathHelper.func_181162_h(-time * 0.2D - (double)MathHelper.floor_double(-time * 0.1D)); + + float r = ((rgb >> 16) & 0xFF) / 255f; + float g = ((rgb >> 8) & 0xFF) / 255f; + float b = (rgb & 0xFF) / 255f; + double d2 = time * 0.025D * -1.5D; + double d4 = 0.5D + Math.cos(d2 + 2.356194490192345D) * 0.2D; + double d5 = 0.5D + Math.sin(d2 + 2.356194490192345D) * 0.2D; + double d6 = 0.5D + Math.cos(d2 + (Math.PI / 4D)) * 0.2D; + double d7 = 0.5D + Math.sin(d2 + (Math.PI / 4D)) * 0.2D; + double d8 = 0.5D + Math.cos(d2 + 3.9269908169872414D) * 0.2D; + double d9 = 0.5D + Math.sin(d2 + 3.9269908169872414D) * 0.2D; + double d10 = 0.5D + Math.cos(d2 + 5.497787143782138D) * 0.2D; + double d11 = 0.5D + Math.sin(d2 + 5.497787143782138D) * 0.2D; + double d14 = -1.0D + d1; + double d15 = (double)(height) * 2.5D + d14; + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); + tessellator.draw(); + + GlStateManager.disableCull(); + double d12 = -1.0D + d1; + double d13 = height + d12; + + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); + tessellator.draw(); + + GlStateManager.disableLighting(); + GlStateManager.enableTexture2D(); + if (disableDepth) { + GlStateManager.enableDepth(); + } + } + + private static void renderBoundingBox(double x, double y, double z, int rgb, float alphaMult, float partialTicks) { + AxisAlignedBB bb = new AxisAlignedBB(x, y, z, x+1, y+1, z+1); + + GlStateManager.disableDepth(); + GlStateManager.disableCull(); + GlStateManager.disableTexture2D(); + CustomItemEffects.drawFilledBoundingBox(bb, 1f, SpecialColour.special(0, 100, rgb)); + GlStateManager.enableTexture2D(); + GlStateManager.enableCull(); + GlStateManager.enableDepth(); + } + + public static void renderBeaconBeam(BlockPos block, int rgb, float alphaMult, float partialTicks) { + double viewerX; + double viewerY; + double viewerZ; + + Vector3f aoteInterpPos = CustomItemEffects.INSTANCE.getCurrentPosition(); + if(aoteInterpPos != null) { + viewerX = aoteInterpPos.x; + viewerY = aoteInterpPos.y; + viewerZ = aoteInterpPos.z; + } else { + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; + viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; + viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; + } + + double x = block.getX() - viewerX; + double y = block.getY() - viewerY; + double z = block.getZ() - viewerZ; + + double distSq = x*x + y*y + z*z; + + if(distSq > 10*10) { + RenderUtils.renderBeaconBeam(x, y, z, rgb, 1.0f, partialTicks, true); + } else { + RenderUtils.renderBeaconBeam(x, y, z, rgb, 1.0f, partialTicks, false); + } + } + + public static void renderBeaconBeamOrBoundingBox(BlockPos block, int rgb, float alphaMult, float partialTicks) { + double viewerX; + double viewerY; + double viewerZ; + + Vector3f aoteInterpPos = CustomItemEffects.INSTANCE.getCurrentPosition(); + if(aoteInterpPos != null) { + viewerX = aoteInterpPos.x; + viewerY = aoteInterpPos.y; + viewerZ = aoteInterpPos.z; + } else { + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; + viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; + viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; + } + + double x = block.getX() - viewerX; + double y = block.getY() - viewerY; + double z = block.getZ() - viewerZ; + + double distSq = x*x + y*y + z*z; + + if(distSq > 10*10) { + RenderUtils.renderBeaconBeam(x, y, z, rgb, 1.0f, partialTicks, true); + } else { + RenderUtils.renderBoundingBox(x, y, z, rgb, 1.0f, partialTicks); + } + } + 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); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java index 73e2b412..5e9c59ac 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -11,82 +11,113 @@ import java.util.List; public class CrystalMetalDetectorSolver { private static final Minecraft mc = Minecraft.getMinecraft(); - private static BlockPos prevPos; - private static double prevDist = 0; + private static BlockPos prevPlayerPos; + private static double prevDistToTreasure = 0; private static List<BlockPos> possibleBlocks = new ArrayList<>(); private static final List<BlockPos> locations = new ArrayList<>(); + private static Boolean chestRecentlyFound = false; + private static long chestLastFoundMillis = 0; + public static void process(IChatComponent message) { + // Delay to keep old chest location from being treated as the new chest location + if (chestRecentlyFound) { + long currentTimeMillis = System.currentTimeMillis(); + if (chestLastFoundMillis == 0) { + chestLastFoundMillis = currentTimeMillis; + return; + } else if(currentTimeMillis - chestLastFoundMillis < 1000) { + return; + } + + chestLastFoundMillis = 0; + chestRecentlyFound = false; + } + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && message.getUnformattedText().contains("TREASURE: ")) { - double dist = Double.parseDouble(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); - if (NotEnoughUpdates.INSTANCE.config.mining.metalDetectorEnabled && prevDist == dist && prevPos.getX() == mc.thePlayer.getPosition().getX() && - prevPos.getY() == mc.thePlayer.getPosition().getY() && - prevPos.getZ() == mc.thePlayer.getPosition().getZ() && !locations.contains(mc.thePlayer.getPosition())) { + double distToTreasure = Double.parseDouble(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); + if (NotEnoughUpdates.INSTANCE.config.mining.metalDetectorEnabled && prevDistToTreasure == distToTreasure && + prevPlayerPos.getX() == mc.thePlayer.getPosition().getX() && + prevPlayerPos.getY() == mc.thePlayer.getPosition().getY() && + prevPlayerPos.getZ() == mc.thePlayer.getPosition().getZ() && !locations.contains(mc.thePlayer.getPosition())) { if (possibleBlocks.size() == 0) { locations.add(mc.thePlayer.getPosition()); - for (int zOffset = (int) Math.floor(-dist); zOffset <= Math.ceil(dist); zOffset++) { + for (int zOffset = (int) Math.floor(-distToTreasure); zOffset <= Math.ceil(distToTreasure); zOffset++) { for (int y = 65; y <= 75; y++) { double calculatedDist = 0; int xOffset = 0; - while (calculatedDist < dist) { + while (calculatedDist < distToTreasure) { BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, y, Math.floor(mc.thePlayer.posZ) + zOffset); - BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, - y + 1, Math.floor(mc.thePlayer.posZ) + zOffset); calculatedDist = getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D)); - if (round(calculatedDist, 1) == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && - mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { + if (round(calculatedDist, 1) == distToTreasure && !possibleBlocks.contains(pos)) { possibleBlocks.add(pos); } xOffset++; } xOffset = 0; calculatedDist = 0; - while (calculatedDist < dist) { + while (calculatedDist < distToTreasure) { BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, y, Math.floor(mc.thePlayer.posZ) + zOffset); - BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, - y + 1, Math.floor(mc.thePlayer.posZ) + zOffset); calculatedDist = getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D)); - if (round(calculatedDist, 1) == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && - mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { + if (round(calculatedDist, 1) == distToTreasure && !possibleBlocks.contains(pos)) { possibleBlocks.add(pos); } xOffset++; } } } + removeDuplicates(); sendMessage(); } else if (possibleBlocks.size() != 1) { locations.add(mc.thePlayer.getPosition()); List<BlockPos> temp = new ArrayList<>(); for (BlockPos pos : possibleBlocks) { - if (round(getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D)), 1) == dist) { + if (round(getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D)), 1) == distToTreasure) { temp.add(pos); } } possibleBlocks = temp; + removeDuplicates(); sendMessage(); + } else if (possibleBlocks.size() == 1) { + BlockPos pos = possibleBlocks.get(0); + if (distToTreasure > (5 + getPlayerPos().distanceTo(new Vec3(pos)))) { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Previous solution is invalid.")); + reset(false); + } } + } - prevPos = mc.thePlayer.getPosition(); - prevDist = dist; + + prevPlayerPos = mc.thePlayer.getPosition(); + prevDistToTreasure = distToTreasure; } } - public static void reset() { + public static void reset(Boolean chestFound) { + chestRecentlyFound = chestFound; possibleBlocks.clear(); locations.clear(); } public static void render(float partialTicks) { + int beaconRGB = 0xa839ce; + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && SBInfo.getInstance().location.equals("Mines of Divan")) { + if (possibleBlocks.size() == 1) { + BlockPos block = possibleBlocks.get(0); + + RenderUtils.renderBeaconBeam(block, beaconRGB, 1.0f, partialTicks); RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0).add(0, 2.5, 0), partialTicks); - } else if (possibleBlocks.size() > 1 && NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) { + } else if (possibleBlocks.size() > 1 && (locations.size() > 1 || possibleBlocks.size() < 10) && + NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) { for (BlockPos block : possibleBlocks) { + RenderUtils.renderBeaconBeam(block, beaconRGB, 1.0f, partialTicks); RenderUtils.renderWayPoint("Possible Treasure Location", block.add(0, 2.5, 0), partialTicks); } } @@ -98,14 +129,35 @@ public class CrystalMetalDetectorSolver { return (double) Math.round(value * scale) / scale; } - private static boolean treasureAllowed(BlockPos pos) { - return mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block") || - mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:prismarine") || - mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest") || - mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:stained_glass") || - mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:stained_glass_pane") || - mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:wool") || - mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:stained_hardened_clay"); + private static void removeDuplicates() { + if (possibleBlocks.size() > 1 && possibleBlocks.size() < 10) { + Vec3 firstBlockVec = new Vec3( possibleBlocks.get(0).getX(), 0, possibleBlocks.get(0).getZ()); + Boolean allBlocksAreClose = true; + + double lowestY = possibleBlocks.get(0).getY(); + int lowestYIndex = 0; + + for (int i = 1; i < possibleBlocks.size(); i++) { + BlockPos blockPos = possibleBlocks.get(i); + Vec3 blockVec = new Vec3(blockPos.getX(), 0, blockPos.getZ()); + + if (firstBlockVec.distanceTo(blockVec) > 3) { + allBlocksAreClose = false; + break; + } + + if (blockPos.getY() < lowestY) { + lowestY = blockPos.getY(); + lowestYIndex = i; + } + } + + if (allBlocksAreClose) { + List<BlockPos> temp = new ArrayList<>(); + temp.add(possibleBlocks.get(lowestYIndex)); + possibleBlocks = temp; + } + } } private static void sendMessage() { @@ -114,7 +166,7 @@ public class CrystalMetalDetectorSolver { + possibleBlocks.size())); } else if (possibleBlocks.size() == 0) { mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Failed to find solution.")); - reset(); + reset(false); } else { mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java index 05591e81..ac1d2fd9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java @@ -5,26 +5,18 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.SimpleCommand; -import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import net.minecraft.client.Minecraft; 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.command.ICommandSender; -import net.minecraft.entity.Entity; import net.minecraft.util.*; -import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.vector.Vector3f; import java.io.*; import java.nio.charset.StandardCharsets; @@ -166,86 +158,6 @@ public class FairySouls { } } - private static final ResourceLocation beaconBeam = new ResourceLocation("textures/entity/beacon_beam.png"); - - private static void renderBeaconBeam(double x, double y, double z, int rgb, float alphaMult, float partialTicks) { - int height = 300; - int bottomOffset = 0; - int topOffset = bottomOffset + height; - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - - Minecraft.getMinecraft().getTextureManager().bindTexture(beaconBeam); - GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0F); - GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0F); - GlStateManager.disableLighting(); - GlStateManager.enableCull(); - GlStateManager.enableTexture2D(); - GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - - double time = Minecraft.getMinecraft().theWorld.getTotalWorldTime() + (double)partialTicks; - double d1 = MathHelper.func_181162_h(-time * 0.2D - (double)MathHelper.floor_double(-time * 0.1D)); - - float r = ((rgb >> 16) & 0xFF) / 255f; - float g = ((rgb >> 8) & 0xFF) / 255f; - float b = (rgb & 0xFF) / 255f; - double d2 = time * 0.025D * -1.5D; - double d4 = 0.5D + Math.cos(d2 + 2.356194490192345D) * 0.2D; - double d5 = 0.5D + Math.sin(d2 + 2.356194490192345D) * 0.2D; - double d6 = 0.5D + Math.cos(d2 + (Math.PI / 4D)) * 0.2D; - double d7 = 0.5D + Math.sin(d2 + (Math.PI / 4D)) * 0.2D; - double d8 = 0.5D + Math.cos(d2 + 3.9269908169872414D) * 0.2D; - double d9 = 0.5D + Math.sin(d2 + 3.9269908169872414D) * 0.2D; - double d10 = 0.5D + Math.cos(d2 + 5.497787143782138D) * 0.2D; - double d11 = 0.5D + Math.sin(d2 + 5.497787143782138D) * 0.2D; - double d14 = -1.0D + d1; - double d15 = (double)(height) * 2.5D + d14; - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); - worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0D, d15).color(r, g, b, 1.0F*alphaMult).endVertex(); - tessellator.draw(); - - GlStateManager.disableCull(); - double d12 = -1.0D + d1; - double d13 = height + d12; - - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); - worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F*alphaMult).endVertex(); - tessellator.draw(); - } - @SubscribeEvent public void onRenderLast(RenderWorldLastEvent event) { if(!enabled) return; @@ -254,44 +166,13 @@ public class FairySouls { if(location == null) return; if(currentSoulList == null || currentSoulList.isEmpty()) return; - Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); - double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * event.partialTicks; - double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * event.partialTicks; - double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * event.partialTicks; - - Vector3f aoteInterpPos = CustomItemEffects.INSTANCE.getCurrentPosition(); - if(aoteInterpPos != null) { - viewerX = aoteInterpPos.x; - viewerY = aoteInterpPos.y; - viewerZ = aoteInterpPos.z; - } - Set<Integer> found = foundSouls.computeIfAbsent(location, k -> new HashSet<>()); int rgb = 0xa839ce; for(int i=0; i<currentSoulListClose.size(); i++) { BlockPos currentSoul = currentSoulListClose.get(i); - double x = currentSoul.getX() - viewerX; - double y = currentSoul.getY() - viewerY; - double z = currentSoul.getZ() - viewerZ; - - double distSq = x*x + y*y + z*z; - - AxisAlignedBB bb = new AxisAlignedBB(x, y, z, x+1, y+1, z+1); - - GlStateManager.disableDepth(); - GlStateManager.disableCull(); - GlStateManager.disableTexture2D(); - CustomItemEffects.drawFilledBoundingBox(bb, 1f, SpecialColour.special(0, 100, rgb)); - - if(distSq > 10*10) { - renderBeaconBeam(x, y, z, rgb, 1.0f, event.partialTicks); - } + RenderUtils.renderBeaconBeamOrBoundingBox(currentSoul, rgb, 1.0f, event.partialTicks); } - - GlStateManager.disableLighting(); - GlStateManager.enableTexture2D(); - GlStateManager.enableDepth(); } public static class FairySoulsCommandAlt extends SimpleCommand { |