Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Right now what I am trying to do is in my mod I have an element that gets rendered into the world and onto a Gui, instead of specifying the color of it, I would like to color it based on rgb values entered with a slider. right now I have the sliders working but it doesn't give the correct color.

 

This is the code:

 

 

public int red;

public int green;

public int blue;

 

public Point(int red, int green, int blue)

{

this.red = red;

this.green = green;

this.blue = blue;

}

 

// Renders the element into the world

public void drawIconInWorld(WorldRenderer worldrenderer, Tessellator tessellator)

{

int i = this.red >> 16 & 255;

int i1 = this.green >> 8 & 255;

int i2 = this.blue & 255;

 

GlStateManager.disableTexture2D();

worldrenderer.startDrawingQuads();

worldrenderer.setColorRGBA(i, i1, i2, 120);

worldrenderer.addVertex(-5.0D, -9.0D, 0.0D);

worldrenderer.addVertex(-5.0D, 0.0D, 0.0D);

worldrenderer.addVertex(4.0D, 0.0D, 0.0D);

worldrenderer.addVertex(4.0D, -9.0D, 0.0D);

tessellator.draw();

GlStateManager.enableTexture2D();

}

 

// Renders the element onto the GUI

public void drawIconOnGui(int drawX, int drawY)

{

int rectX2 = drawX + 9;

int rectY2 = drawY + 9;

Gui.drawRect(drawX, drawY, rectX2, rectY2, this.red >> 16 & 255 | this.green >> 8 & 255 | this.blue & 255);

}

 

 

  • Author

honestly I think that was me testing and not realizing I don't exactly have to do those, but still not 100% sure about the gui

  • Author

I have changed it to Gui.drawRect(drawX, drawY, rectX2, rectY2, (this.red << 16 & 255 | this.green << 8 & 255 | this.blue & 255)); and now it just doesn't appear to draw the rectangle.

Or more accurately, because of math, it's 0 (you start with 0 and start adding things together, and none of the values added end up in the set of bits used by alpha, so its 0).

 

Also, drop the & 255 bit.  That's setting all of your color values to 0.

 

red = 128; //red is 128
red = red << 16; //red is 8388608
red = red & 255; //red is 0
/*
  100000000000000000000000
&                 11111111
==========================
  000000000000000000000000
*/

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.

  • Author

I'm not exactly great with the colors, how would I add the alpha value to the: this.red << 16 | this.green << 8 | this.blue

Complete the next item in the series:  0, 8, 16...

 

 

24.

 

this.alpha << 24

 

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.

Then the color might be oriented in RGBA instead of ARGB

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.

  • Author

tried

int color = (this.red << 16 | this.green << 8 | this.blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, color << 24 | color);

and

int color = (this.red << 16 | this.green << 8 | this.blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, color | color << 24);

but it made no difference.

tried

int color = (this.red << 16 | this.green << 8 | this.blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, color << 24 | color);

and

int color = (this.red << 16 | this.green << 8 | this.blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, color | color << 24);

but it made no difference.

Holy smokes dude!

 

If the bit shifting is causing you that much grief, perhaps try this class instead-

Java.awt.Color

 

Color myColour = new Color(red, green, blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, myColour.getRGB());

 

-TGG

 

 

 

*facepalm*

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.

I'm not exactly great with the colors, how would I add the alpha value to the: this.red << 16 | this.green << 8 | this.blue

You do the same as with red, green and blue, with an alpha value of 255, and bitshifted 24 to the left.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.