Jump to content

Recommended Posts

Posted

This may sound like a trivial question: how should I draw lines "on top" of the terrain?

On top, as in, on a layer that's above the world so that they are visible whether they are underground or above ground.

I am quite new to modding and frankly have no idea how Minecraft renders its screen. All I managed to find out was it uses the Tessellator and WorldRenderer (which is a BufferBuilder) objects to draw things.

Currently, I'm using the same method as how Minecraft draws its block selection boxes (EXCEPT subscribed to the onWorldRenderFinish event instead of onDrawSelectionBox):

/* the vanilla wireframe box renderer: */
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
... // some functions to set up the vertices
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(3, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(minX, minY, minZ).color(red, green, blue, 0.0F).endVertex();
buffer.pos(minX, minY, minZ).color(red, green, blue, alpha).endVertex();
Tessellator.draw();
... // a long chain of vertices
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();

I looked into the BufferBuilder class and it seems to create "ByteBuffers" which contain chains of vertices and their color. As for how the Tessellator or WorldRenderer actually draws it, I have no clue.

I don't think the GlStateManager has anything to do with my issue, as it's mostly just for compositing already rendered images together.

Please give some pointers or links to helpful documents.

Posted

If what you're trying to render is related to a block, tileentity, item or entity, then you would make an appropriate model and textures.

 

However, it sounds like you want to do more of an "overlay" / HUD, meaning a visual guide for a player that isn't exactly any particular object? If the overlay is simple (like a 2D set of lines, or even 3D that is on top of everything else) then you can simply handle the RenderGameOverlay event. But I suspect you want something fancier where the lines have perspective and actually follow the terrain? The problem in that case is the order of rendering as some parts of your line would be behind other things in view. Is that what you want?

 

Maybe if you drew an illustration it would better help those who try to advise you.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted (edited)

Actually, what you described is exactly what I was trying to achieve.

I was trying to draw 3D lines that overlay on top of the world.

3D as in they "physically" exist in the world, with 3D coordinates that align with the world.

However, they are displayed on top of the world at all times.

Kind of like how the old Zombe Mob Highlighter's lines work, except they are static and not attached to mobs.

Edited by uranophane
Posted

Found the solution. It was the simple command 

GLStateManager.depthfunc(519);
... //draw stuff
GLStateManager.depthfunc(515);

Found it by digging through the glowing entity renderer.

Posted

Those numbers (519, 515) aren't magic. The decompiled minecraft code uses them because the numbers came from an enum.

I'm away from dev, so I can't point you at the right place, but they stand for GL_ALWAYS and GL_LEQUAL respectively.

I suggest you update your code to use the enum reference so that your code is more readable and doesn't contain these arbitrary magic numbers.

  • Like 1

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)
37 minutes ago, Draco18s said:

I suggest you update your code to use the enum reference so that your code is more readable and doesn't contain these arbitrary magic numbers.

I copied those numbers from the GL11 class, but I have trouble finding the file in which the Enum was declared.

I haven't been using Eclipse for very long. Sorry if it sounds like I'm asking for a java tutorial, I just wish to know how I can navigate to the enum declaration.

 

EDIT:

Nevermind, there was no enum. Those constants were declared directly in the GL11 class. I ended up including it and doing GL11.GL_LESS.

Edited by uranophane
Posted
56 minutes ago, uranophane said:

Nevermind, there was no enum. Those constants were declared directly in the GL11 class. I ended up including it and doing GL11.GL_LESS.

Yep, that. That's what I meant.

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.

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

    • ahh yes I mean waystone. Thank you very much helped alot  cheers mate!
    • Do you mean waystones?   You can use KubeJS to remove and add a changed recipe for it: https://www.curseforge.com/minecraft/mc-mods/kubejs   Add KubeJS and start the modpack once to generate the files for the mod   In your modpack folder, you will find now a kubejs folder Go to server_scripts (create the folder if missing) - yes, also for singleplayer, use the server_scripts folder Create a new file "reciperemove.js" Edit this file and add the recipe for the waypoint mod: ServerEvents.recipes(event => { let toRemove = [ {output: 'waystones:example_item'}, ]; for (const remove of toRemove) { event.remove(remove); } }) Just make sure you are using the correct item ID   Create another file "recipes.js" in the server_scripts folder and use: ServerEvents.recipes(event => { event.shaped( Item.of('waystones:example_item'), [ 'AAA', 'BCB', 'AAA' ], { A: 'minecraft:stone', B: 'waystones:item_1', C: 'waystones:item_2' } ) })   The Letter Block with AAA etc is a crafting table - so there you define the recipe and the items      
    • I am currently making a modpack for myself and I want to change the recipe for waypoints*. How do I do this? Is there a simply way to change an existing recipe (or to delete the old one and make a new one). I only need a for 1 single player world. My coding Knowledge is limited to arduinos but I feel I could teach myself some Java if needed *waypoint mod by BlayTheNinth
    • Tired of the same old iron sword and pickaxe? Dive into a world of enhanced possibilities with Droid's Implements! This exciting addition to your Minecraft experience introduces:   Four Unique Weapons:    Daggers: Quick, cheap, and effective, great for agility. Applies Weakness for one minute. Warhammers: A powerful option for defeating strong enemies. Applies Harming for a quarter of a second, making it ineffective against the undead. Spears: A balanced weapon with fair damage and speed. Applies Mining Fatigue, making escape difficult for cornered enemies. Clubs: Hard-hitting yet slow, the club is a robust alternative to the sword. Applies Slowness, increasing the chance of catching your enemy.   Two Handy Tools:   The Mining Hammer: A worthwhile alternative to the pickaxe, the Mining Hammer mines in a 3x3 area, making mining stone more efficient. The Heavy Shovel: A beneficial substitute to the shovel, the Mining Hammer mines in a 3x3 area, making mining sand and gravel more efficient.   Damage Comparison: Dagger > Spear > Sword = Club > Warhammer     Check it out now!
  • Topics

×
×
  • Create New...

Important Information

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