Posted November 17, 201212 yr 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.
November 17, 201212 yr 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.
November 17, 201212 yr Author Okay, thank you very much. I'll change the math now Any ideas for checking contents of a slot?
November 17, 201212 yr 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.
November 17, 201212 yr Author I need to be able to check the contents (I assume an ItemStack) of a particular slot in my GUI, so I can use an if to check if the item in the slot matches redstone, to fill up my meter.
November 17, 201212 yr 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.
November 17, 201212 yr Author So in which class should I put this code, and where? GUI***? I'm getting a "cannot make a static reference to thee non-static method".
November 17, 201212 yr 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.
November 17, 201212 yr Author Okay, that works, so now how can I change the charge meter value, which is in drawGuiContainerBackgroundLayer()? Also, why am I getting a NullPointerException with that last code?
November 17, 201212 yr Author Any ideas? The game force closes when I try to place the block and goes to a crash screen saying there's a nullpointerexception.
November 17, 201212 yr 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.
November 17, 201212 yr Author 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.