Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Render texture from entity angle


Recommended Posts

I am currently drawing a compass to my ingame gui as follows:

    private static void renderCompass(MatrixStack matrixStack, int width, int height) {
        TextureDrawer.drawGuiTexture(matrixStack, width / 2 - 110, 10, 0, 37, 221, 14);

        int rot;
        boolean f0 = mc.player.yRot < 0.0f;

        if(f0) rot = -MathHelper.floor(mc.player.yRot % 360);
        else rot = MathHelper.floor(mc.player.yRot % 360);

        boolean f1 = rot > 0 && rot < 180;
        boolean f2 = rot <= 270 && rot >= 90;
        boolean f3 = rot <= 180 && rot >= 0;

        AtomicInteger targetAngle = new AtomicInteger(-1);
        mc.player.getCapability(ISkyrimPlayerDataProvider.SKYRIM_PLAYER_DATA_CAPABILITY).ifPresent(cap -> {
            if(cap.getCurrentTarget() != null && cap.getCurrentTarget().isAlive()) {
                Vector3d playerPos = mc.player.getLookAngle();
                Vector3d targetPos = cap.getCurrentTarget().position();
                Vector3d norm = playerPos.subtract(targetPos);

                double angleDir = (Math.atan2(norm.z, norm.x) / 2 / Math.PI * 360 + 360) % 360;
                double angleLook = (Math.atan2(playerPos.z, playerPos.x) / 2 / Math.PI * 360 + 360) % 360;
                targetAngle.set((int)(angleDir - angleLook + 360) % 360);
            } else targetAngle.set(-1);
        });
        int targetEntityAngle = targetAngle.get();

        if(targetEntityAngle > 0 && targetEntityAngle <= 90)
            TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle, 14, 105, 52, 6, 6);
        else if(targetEntityAngle > 90 && targetEntityAngle <= 180)
            TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle + 90, 14, 105, 52, 6, 6);

        if (rot == 0) {
            drawCenteredString(matrixStack, fontRenderer, "S", width / 2, 13, 16777215);
            drawCenteredString(matrixStack, fontRenderer, "E", (width / 2) - 90, 13, 16777215);
            drawCenteredString(matrixStack, fontRenderer, "W", (width / 2) + 90, 13, 16777215);
        } else if (!f0) {
            drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 - rot) + 180, 13, 16777215);
            if (!f1) rot -= 360;
            drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 - rot, 13, 16777215);
            drawCenteredString(matrixStack, fontRenderer, !f3 ? "E" : "", (width / 2 - rot) - 90, 13, 16777215);
            drawCenteredString(matrixStack, fontRenderer, f3 ? "W" : "", (width / 2 - rot) + 90, 13, 16777215);
        } else if(f0) {
            drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 + rot) - 180, 13, 16777215);
            if (!f1) rot -= 360;
            drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 + rot, 13, 16777215);
            drawCenteredString(matrixStack, fontRenderer, !f3 ? "W" : "", (width / 2 + rot) + 90, 13, 16777215);
            drawCenteredString(matrixStack, fontRenderer, f3 ? "E" : "", (width / 2 + rot) - 90, 13, 16777215);
        }
    }

What I'm trying to do is only render the entity texture (the calls including targetEntityAngle) when it is in compass view.

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • biome.getRegistryName().equals(Biomes.SWAMP.location())  
    • Java 16 is not yet supported.
    • It is about the Java version. You cannot use Java 16. 
    • C:\Users\rauno\OneDrive\Töölaud\Uus kaust>java -Xmx2048M -Xms2048M -jar forgeserver.jar nogui 2021-06-21 10:09:17,374 main WARN Advanced terminal features are not available in this environment [10:09:17] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.1.0, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [10:09:17] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 16.0.1 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0x29f69090) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0x29f69090         at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41)         at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95)         at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41)         at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55)         at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47)         at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62)         at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55)         at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63)         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60)         at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) C:\Users\rauno\OneDrive\Töölaud\Uus kaust>PAUSE is it saying for me when i am first opening it 
    • You need to register your Attributes void to the Mod Eventbus.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.