Jump to content

Recommended Posts

Posted (edited)

Hi, I'm a new form of forge, I'm having trouble drawing a vertical line in the world, in the ItemSpada1.java class I have 2 methods to draw a line from the click block. The line is never drawn, what am I doing wrong?

Source code:

 

https://github.com/JdiJack/TutorialMod/blob/master/src/main/java/it/petitogennaro/tutorial_mod/items/ItemSpada1.java

 

the final effect must be similar to this:

 

635889646297079402.png

 

[SOLUTION]

at the bottom of the topic

Edited by JdiJack
Posted

You can't just go ahead and try to draw stuff in a method like that.

You have to do that when the game is being rendered.

Games like Minecraft commonly have a separate render and game loop.

One is for executing game logic the other one is for drawing graphics.
 

I could now go ahead and list all the different ways there are in minecraftforge to render specific kinds of graphical elements from Blocks over Entities to GUIs and using specific events.
But it would be better to know what you are trying to accomplish in the long run.

  • Like 1

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted
1 hour ago, Busti said:

You can't just go ahead and try to draw stuff in a method like that.

You have to do that when the game is being rendered.

Games like Minecraft commonly have a separate render and game loop.

One is for executing game logic the other one is for drawing graphics.
 

I could now go ahead and list all the different ways there are in minecraftforge to render specific kinds of graphical elements from Blocks over Entities to GUIs and using specific events.
But it would be better to know what you are trying to accomplish in the long run.

I thank you for the clarification. I want to draw more contour lines of a block going to the sky. Now, however, I have no idea where to place my drawlines ();

Posted

You can't just draw things to coordinates and expect them to work.
As the name implies RenderGameOverlayEvent is for drawing overlays, e.g. a minimap and whatnot.

When drawing the player becomes the origin of the rendering coordinate system.
 

You probably want to have a look at TileEntitySpecialRenderers to get a better concept of how minecrafts rendering works.
 

Is the effect you want to achieve similar to a beacon beam?

  • Like 1

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted (edited)
16 minutes ago, Busti said:

You can't just draw things to coordinates and expect them to work.
As the name implies RenderGameOverlayEvent is for drawing overlays, e.g. a minimap and whatnot.

When drawing the player becomes the origin of the rendering coordinate system.
 

You probably want to have a look at TileEntitySpecialRenderers to get a better concept of how minecrafts rendering works.
 

Is the effect you want to achieve similar to a beacon beam?

the final effect must be similar to this:

 

635889646297079402.png

Edited by JdiJack
  • Like 1
Posted
44 minutes ago, Busti said:

You probably want to hook into EntityViewRenderEvent.

I'm desolate but I can not go ahead, please give me the working code, I'm trying to draw in the "RenderWorldLastEvent" event and the lines are never drawn. I have created a new "drawLine5 ()" method in the "DrawHandler" class and it does not work.

 

 

Posted

Have a look at how botania uses the event to render a ghost preview of a block:

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


You'll also have to create a Proxy class to register your event:

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

 

Read more on events here:
https://mcforge.readthedocs.io/en/latest/events/intro/

 

Looking through other open source mods is generally a good way to get an understanding of how to approach certain things.

  • Like 1

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted
11 hours ago, Busti said:

Date un'occhiata a come botania utilizza l'evento per rendere un'anteprima fantasma di un blocco:

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


Devi anche creare una classe Proxy per registrare l'evento:

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

 

Per saperne di più sugli eventi qui:
https://mcforge.readthedocs.io/en/latest/events/intro/

 

Guardare attraverso altri mod open source è generalmente un buon modo per comprendere come affrontare determinate cose.

busti thank you for the time you are devoting to my project, I accept your suggestions, as indicated by you I went to study the mod botania, but can you tell me why my code does not work? I want to draw a simple line and I can not, what's wrong? I am going crazy

Posted

My best guess would be that either your event handler is not called, in order to test that you should try to print something to your console in your eventhandler,

or that your line is being drawn somewhere else.

When I first rendered a custom block it was drawn at the coordinates 0, 0, 0 in the world.

  • Like 1

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted
On 17/9/2017 at 1:31 AM, Busti said:

 

 

Finally a few days ago, I managed to draw my first line, my thanks go to "Butsi" who had the patience to put me on the right path.

Updated topic start, code Solution:

public static void drawBoundingBox(Vec3d player_pos, Vec3d posA, Vec3d posB, boolean smooth, float width) {

		GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
		GL11.glDisable(GL11.GL_CULL_FACE);
		GL11.glDisable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_TEXTURE_2D);

		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		GL11.glTranslated(-player_pos.x, -player_pos.y, -player_pos.z);

		Color c = new Color(255, 0, 0, 150);
		GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
		GL11.glLineWidth(width);
		GL11.glDepthMask(false);
		Tessellator tessellator = Tessellator.getInstance();
		BufferBuilder bufferBuilder = tessellator.getBuffer();
		bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);

		double dx = Math.abs(posA.x - posB.x);
		double dy = Math.abs(posA.y - posB.y);
		double dz = Math.abs(posA.z - posB.z);

		//AB
		bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();          //A
		bufferBuilder.pos(posA.x, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //B
		//BC
		bufferBuilder.pos(posA.x, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //B
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //C
		//CD
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //C
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //D
		//DA
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //D
		bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();          //A
		//EF
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //E
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //F
		//FG
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //F
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex(); //G
		//GH
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex(); //G
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //H
		//HE
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //H
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //E
		//AE
		bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();          //A
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //E
		//BF
		bufferBuilder.pos(posA.x, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //B
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //F
		//CG
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //C
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex(); //G
		//DH
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //D
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //H

		tessellator.draw();      


		GL11.glDepthMask(true);
		GL11.glPopAttrib();
	}

 

 

702ad857-90b2-47fe-8b51-30c703be4edb.jpg

  • Like 1
  • 2 years later...
Posted
On 9/28/2017 at 5:51 AM, JdiJack said:

 

Finally a few days ago, I managed to draw my first line, my thanks go to "Butsi" who had the patience to put me on the right path.

Updated topic start, code Solution:


public static void drawBoundingBox(Vec3d player_pos, Vec3d posA, Vec3d posB, boolean smooth, float width) {

		GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
		GL11.glDisable(GL11.GL_CULL_FACE);
		GL11.glDisable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_TEXTURE_2D);

		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		GL11.glTranslated(-player_pos.x, -player_pos.y, -player_pos.z);

		Color c = new Color(255, 0, 0, 150);
		GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
		GL11.glLineWidth(width);
		GL11.glDepthMask(false);
		Tessellator tessellator = Tessellator.getInstance();
		BufferBuilder bufferBuilder = tessellator.getBuffer();
		bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);

		double dx = Math.abs(posA.x - posB.x);
		double dy = Math.abs(posA.y - posB.y);
		double dz = Math.abs(posA.z - posB.z);

		//AB
		bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();          //A
		bufferBuilder.pos(posA.x, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //B
		//BC
		bufferBuilder.pos(posA.x, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //B
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //C
		//CD
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //C
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //D
		//DA
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //D
		bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();          //A
		//EF
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //E
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //F
		//FG
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //F
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex(); //G
		//GH
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex(); //G
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //H
		//HE
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //H
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //E
		//AE
		bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();          //A
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //E
		//BF
		bufferBuilder.pos(posA.x, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //B
		bufferBuilder.pos(posA.x, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //F
		//CG
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //C
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z+dz).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex(); //G
		//DH
		bufferBuilder.pos(posA.x+dx, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();       //D
		bufferBuilder.pos(posA.x+dx, posA.y+dy, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();    //H

		tessellator.draw();      


		GL11.glDepthMask(true);
		GL11.glPopAttrib();
	}

 

 

702ad857-90b2-47fe-8b51-30c703be4edb.jpg

 

Hello, I noticed you solved this problem and I have a similar problem to solve. Where did you call this method? I also want to construct a box I am unable to do this on the server side, making my game crash.

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.

×
×
  • Create New...

Important Information

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