Jump to content

Recommended Posts

Posted

Hello,

I am trying to create a new GUI using Minecraft Forge and GUI****, however when I try to use this math to display a charge meter, for some obscure reason chargePx always returns 0 and the image is not displayed at all. Can anyone help me, or does anyone know why this would be happening?

 

int barHeight = 32;
int chargeMeter = 50; //Charge %
int chargePx = Math.round(barHeight * (chargeMeter / 100));
this.drawTexturedModalRect(x + 20, y + 16, 176, 16, 16, chargePx);

 

P.s. I tested out the sum on a scientific calculator, and it equalled 16, as it should. This is why I don't understand why Java cannot do simple calculations such as this.

 

I would also like to know how to find the contents of a particular slot in a GUI, in order to use up an item in a specific slot if said item is redstone, for example.

Posted

Your math is a bit incorrect, Try using this:

 

int chargePx = Math.round((float)barHeight * ((float)chargeMeter / 100F));

 

 

The issue is caused because you try to divide integers, which rounds down the values automatically.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Okay, thank you very much. I'll change the math now :)

Any ideas for checking contents of a slot?

 

In which way? Nvm

 

Just get the slot ItemStack, check if it's equal to the redstone item and reduce the stackSize. Like this:

ItemStack stack = tileentity.getStackInSlot(SLOT_ID);
if(stack.isItemEqual(new ItemStack(Item.redstone))) {
    tileentity.decrStackSize(SLOT_ID, 1);
}

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Check out my edit above.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

You should put that in your TileEntity in your updateEntity method, because when placed in the GUI, it won't edit anything on the server and will be reset again.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

whoops, forgot to check if it's null:

ItemStack stack = tileentity.getStackInSlot(SLOT_ID);
if(stack != null && stack.isItemEqual(new ItemStack(Item.redstone))) {
    tileentity.decrStackSize(SLOT_ID, 1);
}

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Okay, all is good, now i need to know how to change how filled up the meter is. Now the meter integer (chargeMeter) is in the draw background method, and I need to update it every time the redstone is filled up. It all works! :)

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



×
×
  • Create New...

Important Information

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