Hi guys, I'm making a GUI menu but I dont know how to do something. Code (Text): int money = instance.playerConfig.getInt(UUID + ".money"); int diamond_blocks = money / 5000; int diamond_left = diamond_block * 5000; int redstone_block = (money - diamond_left) / 1000 With this code I can show how much diamond blocks & redstone blocks a player has with his money but how do I show it in a GUI menu? If it's > 64 it will create a new stack and if it's 0 it wont show
While the amount of the item is greater than 64, add a stack of the item, and decrement 64 from the amount. Add the remainder at the end?
If you have for example more then 64 diamond blocks it will create a new stack and if you got everythink from diamond blocks you'll create the blocks for redstone if that's more then 64 it will also get 2 stacks.
That's how you have to think to do that. I remind you he's asking for a COMPLETE GUI, not a GUI to click and get info. I tried but I don't feel like finishing, I am getting tired too... xD So what I will post is only the basics... Code (Text): private void openMoneyGui(Player player) { Inventory inv = Bukkit.createInventory(null, 9, "Your GUI Name, ChatColor supported!"); // This is what you're going to be looking at! if(diamond_blocks != 0){ double rawNumberOfStacks = diamond_blocks / 64; int numberOfStacks = (int) Math.ceil(rawNumberOfStacks); ItemStack diamondBlock[] = new ItemStack[numberOfStacks]; for(int i = 0; i <= numberOfStacks - 1; i++){ diamondBlock[i] = new ItemStack(Material.); } // Here you'll make a stack for leftovers; } // Here's the end of the diamond blocks! ItemStack redstoneBlock = new ItemStack (Material.REDSTONE_BLOCK, redstone_block); ItemStack redstoneBlockMeta = new redstoneBlock.getItemMeta(); redstoneBlockMeta.setDisplayName(ChatColor.DARK_RED + "Exit"); redstoneBlock.setItemMeta(redstoneBlockMeta); inv.setItem(9, redstoneBlock); player.openInventory(inv); }
Leftovers : The last diamond block stack which is not exactly 64 of size, so there are, x number of stacks plus the rest, so for example, 64 (Complete stack) + 64 + 64 + 42 (Leftovers)
Its not finished, I told you I had some problems trying to find out the solution, can I see the code you made from mine please?
Code (Text): int money = Main.getInstance().playerConfig.getInt(UUID + ".bank"); int diamond_blocks = money / 2500; int diamond_left = diamond_blocks * 2500; int redstone_block = (money - diamond_left) / 1000; if(diamond_blocks != 0){ double rawNumberOfStacks = diamond_blocks / 64; int numberOfStacks = (int) Math.ceil(rawNumberOfStacks); ItemStack diamondBlock[] = new ItemStack[numberOfStacks]; for(int i = 0; i <= numberOfStacks - 1; i++){ diamondBlock[i] = new ItemStack(Material.DIAMOND_BLOCK); } int leftover = diamond_blocks - (2500 * numberOfStacks); } I didn't made leftover and I dont know how I've to add the stacks etc to a specific inv slot
What I made was meant to be the gui, you didnt take anything of it :/ Its a method you have to put apart, EVERYTHING in the method has to stay there. Once you have it, it your above code add this: openMoneyGui(player); Code (Text): private void openMoneyGui(Player player) { Inventory inv = Bukkit.createInventory(null, 9, "Your GUI Name, ChatColor supported!"); ItemStack redstoneBlock = new ItemStack (Material.REDSTONE_BLOCK, redstone_block); ItemStack redstoneBlockMeta = new redstoneBlock.getItemMeta(); redstoneBlockMeta.setDisplayName(ChatColor.DARK_RED + "Exit"); redstoneBlock.setItemMeta(redstoneBlockMeta); inv.setItem(9, redstoneBlock); player.openInventory(inv); } Start by telling me if this generates a GUI and shows redstone blocks. But take the complete method and let it be independant in the class, you're not meant to implement some things in your old method.
With @JustCedric we've got the problem and the thread has served its purpose! @JustCedric please tag your post as solved.