Jump to content

Recommended Posts

Posted (edited)

I don't know why this doesn't work, it looks like the line is relative to the camera position, but it only shows if you're near 0,0,0 in the world

@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
    ClientPlayerEntity player = Minecraft.getInstance().player;

    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);

    double d0 = player.prevPosX + (player.getPosX() - player.prevPosX) * (double)event.getPartialTicks();
    double d1 = player.prevPosY + (player.getPosY() - player.prevPosY) * (double)event.getPartialTicks();
    double d2 = player.prevPosZ + (player.getPosZ() - player.prevPosZ) * (double)event.getPartialTicks();
    Vec3d player_pos = new Vec3d(d0, d1, d2);

    GL11.glTranslated(-player_pos.x, -player_pos.y, -player_pos.z);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_DEPTH_TEST);

    Vec3d blockA = new Vec3d (0,0,0);
    Vec3d blockB = new Vec3d (0,10,0);

    GL11.glColor4f(1,1,1,1);
    GL11.glBegin(GL11.GL_LINE_STRIP);
    GL11.glVertex3d(blockA.x, blockA.y, blockA.z);
    GL11.glVertex3d(blockB.x, blockB.y, blockB.z);
    GL11.glEnd();

    GL11.glPopAttrib();
    GL11.glPopMatrix();
}

2020-06-21_07_11_34.png.a9cd83811987175295b71211a9073f11.png

Its supposed to draw a line from 0,0,0 (that bedrock) to 0,10,0 but i get something like this with the line moving randomly as i move around

Edited by DiamondMiner88
Posted
4 hours ago, DiamondMiner88 said:

it looks like the line is relative to the camera position

This is true for all rendering. That's why translation matrices exist.

 

4 hours ago, DiamondMiner88 said:

double d0 = player.prevPosX + (player.getPosX() - player.prevPosX) * (double)event.getPartialTicks();

double d1 = player.prevPosY + (player.getPosY() - player.prevPosY) * (double)event.getPartialTicks();

double d2 = player.prevPosZ + (player.getPosZ() - player.prevPosZ) * (double)event.getPartialTicks();

Check for a method in the player class that does this calculation for you, the last time I did something like this I had a line that called player.getPosition(event.partialTicks);

 

Beyond that I can't see any problems.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
1 hour ago, Draco18s said:

player.getPosition(event.partialTicks);

I already tested nearly all of them that returned a Vec3d, and got the same exact results as in the screenshot; just a line that won't stay in one position

Even with the current calculation i get the exact same thing

With some of the methods in the screenshot below the hand appears detached

image.png.c26445abd39ddbdfe968854b1e72fc95.png

Edited by DiamondMiner88
Posted (edited)

  

11 hours ago, TheGreyGhost said:

Howdy

In 1.15.2 you should use RenderBuffers, not direct GL11 calls, and use the MatrixStack.

Check out this post

https://gist.github.com/williewillus/30d7e3f775fe93c503bddf054ef3f93e

 

And also this working example

https://github.com/Vazkii/Botania/blob/master/src/main/java/vazkii/botania/client/core/handler/BlockHighlightRenderHandler.java

 

-TGG

Thank you very much, that got me off the ground really fast!

 

The last things I would like to ask is,

I managed to make an outline that shows though blocks, however the highlighted rectangle does not.

EDIT: If i disable drawing the highlight aka #drawCube then the outline stops being able to be seen though blocks however is still seen if you have a direct path to it. no idea why this is happening

2020-06-22_13_54_39.png.328677b7f9af62e7f81efdd73e5597ef.png

And the drawing is locked to a block, it can't be not centered on a block. Is there a way around this?

Heres an example:

spacer.pngspacer.png

Heres the code:

@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
    MatrixStack ms = event.getMatrixStack();
    IRenderTypeBuffer.Impl buffers = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer());
    RenderSystem.disableCull();
    ms.push();

    for (Entity e : Minecraft.getInstance().world.getAllEntities()) {
        if (!Minecraft.getInstance().player.equals(e) && !(e instanceof ItemEntity) && !(e instanceof ExperienceOrbEntity)) {
            drawCube(ms, buffers, new AxisAlignedBB(e.getPosition()).expand(0, 1, 0), new Color(0, 255, 0, 127));
            draw3dOutline(ms, buffers, new AxisAlignedBB(e.getPosition()).expand(0, 1, 0), new Color(255, 255, 255, 255));
        }
    }
    draw3dOutline(ms, buffers, new AxisAlignedBB(new BlockPos(0, 10, 0)), new Color(255, 255, 255, 255));

    ms.pop();
    buffers.finish();
}

public static void drawCube(MatrixStack ms, IRenderTypeBuffer buffers, AxisAlignedBB aabb, Color color) {
    draw3dRectangle(ms, buffers, aabb, color, "TOP");
    draw3dRectangle(ms, buffers, aabb, color, "BOTTOM");
    draw3dRectangle(ms, buffers, aabb, color, "NORTH");
    draw3dRectangle(ms, buffers, aabb, color, "EAST");
    draw3dRectangle(ms, buffers, aabb, color, "SOUTH");
    draw3dRectangle(ms, buffers, aabb, color, "WEST");
}

public static void draw3dRectangle(MatrixStack ms, IRenderTypeBuffer buffers, AxisAlignedBB aabb, Color color, String side) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    int a = color.getAlpha();
    double renderPosX = Minecraft.getInstance().getRenderManager().info.getProjectedView().getX();
    double renderPosY = Minecraft.getInstance().getRenderManager().info.getProjectedView().getY();
    double renderPosZ = Minecraft.getInstance().getRenderManager().info.getProjectedView().getZ();

    ms.push();
    ms.translate(aabb.minX - renderPosX, aabb.minY - renderPosY, aabb.minZ - renderPosZ);

    IVertexBuilder buffer = buffers.getBuffer(RenderType.makeType(HypixelClient.MODID + ":rectangle_highlight", DefaultVertexFormats.POSITION_COLOR, GL11.GL_QUADS, 256, false, true, RenderType.State.getBuilder().transparency(ObfuscationReflectionHelper.getPrivateValue(RenderState.class, null, "field_228515_g_")).cull(new RenderState.CullState(false)).build(false)));
    Matrix4f mat = ms.getLast().getMatrix();

    float x = (float) (aabb.maxX - aabb.minX);
    float y = (float) (aabb.maxY - aabb.minY);
    float z = (float) (aabb.maxZ - aabb.minZ);

    switch (side) {
        case "TOP":
            buffer.pos(mat, x, y, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, y, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, y, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, y, z).color(r, g, b, a).endVertex();
            break;
        case "BOTTOM":
            buffer.pos(mat, x, 0, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, 0, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, 0, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, 0, z).color(r, g, b, a).endVertex();
            break;
        case "NORTH":
            buffer.pos(mat, 0, y, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, 0, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, 0, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, y, 0).color(r, g, b, a).endVertex();
            break;
        case "EAST":
            buffer.pos(mat, x, y, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, 0, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, 0, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, y, z).color(r, g, b, a).endVertex();
            break;
        case "SOUTH":
            buffer.pos(mat, 0, y, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, 0, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, 0, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, x, y, z).color(r, g, b, a).endVertex();
            break;
        case "WEST":
            buffer.pos(mat, 0, y, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, 0, 0).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, 0, z).color(r, g, b, a).endVertex();
            buffer.pos(mat, 0, y, z).color(r, g, b, a).endVertex();
            break;
    }
    ms.pop();
}

public static void draw3dOutline(MatrixStack ms, IRenderTypeBuffer buffers, AxisAlignedBB aabb, Color color) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    int a = color.getAlpha();
    double renderPosX = Minecraft.getInstance().getRenderManager().info.getProjectedView().getX();
    double renderPosY = Minecraft.getInstance().getRenderManager().info.getProjectedView().getY();
    double renderPosZ = Minecraft.getInstance().getRenderManager().info.getProjectedView().getZ();

    ms.push();
    ms.translate(aabb.minX - renderPosX, aabb.minY - renderPosY, aabb.minZ - renderPosZ);

    RenderType.State glState = RenderType.State.getBuilder().line(new RenderState.LineState(OptionalDouble.of(1))).layer(ObfuscationReflectionHelper.getPrivateValue(RenderState.class, null, "field_228500_J_")).transparency(ObfuscationReflectionHelper.getPrivateValue(RenderState.class, null, "field_228515_g_")).writeMask(new RenderState.WriteMaskState(true, false)).depthTest(new RenderState.DepthTestState(GL11.GL_ALWAYS)).build(false);
    IVertexBuilder buffer = buffers.getBuffer(RenderType.makeType(HypixelClient.MODID + ":line_1_no_depth", DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 128, glState));
    Matrix4f mat = ms.getLast().getMatrix();

    float x = (float) (aabb.maxX - aabb.minX);
    float y = (float) (aabb.maxY - aabb.minY);
    float z = (float) (aabb.maxZ - aabb.minZ);

    // Top edges
    buffer.pos(mat, x, y, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, y, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, y, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, y, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, y, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, y, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, y, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, y, 0).color(r, g, b, a).endVertex();

    // Bottom edges
    buffer.pos(mat, x, 0, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, 0, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, 0, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, 0, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, 0, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, 0, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, 0, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, 0, 0).color(r, g, b, a).endVertex();

    // Side edges
    buffer.pos(mat, x, 0, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, y, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, y, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, 0, 0).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, y, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, 0, 0, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, 0, z).color(r, g, b, a).endVertex();
    buffer.pos(mat, x, y, z).color(r, g, b, a).endVertex();

    ms.pop();
}
Edited by DiamondMiner88
Posted

Howdy

The visibility-behind-blocks is related to the renderbuffer settings - related to the depth buffer.  If you google for depth buffer you should find a stack of stuff.

Basically - your line drawing is ignoring the depth buffer, and your green rectangles are checking the depth buffer (i.e. they check to see if they are behind a block that has already been drawn).  You may need a custom renderbuffer to achieve that (see the williewillus link I sent, Botania has a few custom renderbuffers which should help you out; or alternatively this one

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/usefultools/RenderTypeHelper.java)

 

To move the rendering relative to the block , use something similar to this:

 

    // When the TER::render method is called, the origin [0,0,0] is at the current [x,y,z] of the block being rendered.
    // The tetrahedron-drawing method draws the tetrahedron in a cube region from [0,0,0] to [1,1,1] but we want it
    //   to be in the block one above this, i.e. from [0,1,0] to [1,2,1],
    //   so we need to translate up by one block, i.e. by [0,1,0]
    final Vec3d TRANSLATION_OFFSET = new Vec3d(0, 1, 0);

    matrixStack.push(); // push the current transformation matrix + normals matrix
    matrixStack.translate(TRANSLATION_OFFSET.x,TRANSLATION_OFFSET.y,TRANSLATION_OFFSET.z); // translate
    Color artifactColour = tileEntityMBE21.getArtifactColour();

    drawTetrahedronWireframe(matrixStack, renderBuffers, artifactColour);
    matrixStack.pop(); // restore the original transformation matrix + normals matrix

 

Cheers

  TGG

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I'm not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.