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
  On 9/15/2017 at 11:41 AM, 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.

Expand  

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)
  On 9/15/2017 at 4:55 PM, 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?

Expand  

the final effect must be similar to this:

 

635889646297079402.png

Edited by JdiJack
  • Like 1
Posted
  On 9/15/2017 at 5:59 PM, Busti said:

You probably want to hook into EntityViewRenderEvent.

Expand  

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
  On 9/15/2017 at 9:34 PM, 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.

Expand  

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 9/16/2017 at 11:31 PM, Busti said:

 

Expand  

 

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 10: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

Expand  

 

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • As a stay-at-home dad and a farmer in Kentucky, my primary focus has always been on nurturing my family and managing our land. When Bitcoin began to gain traction, I saw it as a potential opportunity to secure our financial future. With my wife encouragement, I decided to invest $10,000 from our savings into cryptocurrency. Over time, my investment flourished beyond my wildest dreams, eventually soaring to an astonishing $200,000. Just as I began to feel a sense of financial security, disaster struck. In a shocking act of betrayal fueled by jealousy, my wife hacked into my email and gained access to my Bitcoin wallet. The devastation I felt was overwhelming years of careful planning and smart investing were wiped out in an instant. I was left feeling helpless and uncertain, grappling with the fear that I might never recover what I had lost. In the midst of this turmoil, a close friend reached out to me and mentioned RAPID DIGITAL RECOVERY. Desperate for a solution but still holding onto a glimmer of hope, I contacted them, praying for a lifeline. Their team responded promptly, providing both reassurance and a clear plan of action. With remarkable expertise, they tracked down the digital footprints left by the theft and successfully recovered a substantial portion of my stolen funds. But their assistance didn’t end there. Understanding the vulnerability I felt after such a betrayal, they also offered invaluable advice on how to strengthen my digital security to prevent future breaches. Their support was not just technical; it was a source of empowerment that helped me regain my confidence and sense of control over my financial situation. While the betrayal was a painful lesson, it ultimately taught me resilience and the importance of safeguarding my assets. Thanks to RAPID DIGITAL RECOVERY, I didn’t just reclaim my lost Bitcoin; I also regained my peace of mind. This experience has transformed my perspective on both trust and security in the digital age. I now approach investments with a renewed sense of caution and awareness, ensuring that I protect not only my financial future but also my emotional well-being. The journey has been challenging, but it has also been a testament to my strength and determination to rise above adversity as I continue to balance my roles as a dad and a farmer.
    • Same issue without Oculus Flywheel Compat?
    • When i start my game with a shader active the game crashes with this Error: java.lang.NoSuchFieldError: TESSELATION_SHADERS Minecraft java 1.20.1 in forge 47.4.0 crash report in pastebin: https://pastebin.com/6xiwHqZW thanks in advance
    • If you are using AMD/ATI, update your drivers - get the drivers from their website - do not update via system
    • Not sure why this is happening, but I would love some help. The reason I restarted the server was because I was getting an error while trying to join regarding this "Internal Exception: io.netty.handler.codec.DecoderException: io.netty.handler.codec.EncoderException: java.io.IOException: Root tag must be a named compound tag" Im using ServerMiner if thats any help
  • Topics

×
×
  • Create New...

Important Information

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