Thornack Posted May 11, 2016 Posted May 11, 2016 Hi everyone, I am trying to add slots to a gui that the player can open anytime. The purpose of this gui will be so that the player can convert the amount of currency called "Miney" he stored in his ieep to coin items or vice versa (kinda like a deposit/withdrawal system) I have run into a problem however. I cant seem to get my inventory slots to align with the gui "slots". When the game is resized they end up in the incorrect spot. Anyone know how to fix this? My gui is centered and resizes correctly it seems. It is basically the same shape as the default vanilla furnace gui (same size too and has the players inventory as in the vanilla gui). I cant get the slots to stay aligned with the gui on game resize. Anyone know what the issue is and how to solve this? GuiClass @SideOnly(Side.CLIENT) public class GuiPlayerMiney extends InventoryEffectRenderer { private GuiTextField mineyDepositTextField; private static ContainerMiney containerMiney; private ArrayList<GuiTextField> editControls = new ArrayList<GuiTextField>(); private static final ResourceLocation guiTexture = new ResourceLocation("custommod:textures/gui/MineyGui.png"); private boolean wasInitialized; private static final int TEXTURE_SIZE = 256; public GuiPlayerMiney(InventoryPlayer inv){ super(new ContainerMiney(inv)); this.wasInitialized = false; } /** * Adds the buttons (and other controls) to the screen in question. */ @Override public void initGui() { if(this.wasInitialized) return; this.wasInitialized = true; //edit controls this.editControls.clear(); this.mineyDepositTextField = new GuiTextField(fontRendererObj, 100, 70, 50, 12); this.editControls.add(mineyDepositTextField); } @Override public boolean doesGuiPauseGame(){ return false; } @Override public void onGuiClosed(){ } @Override protected void mouseClicked(int x, int y, int event){ super.mouseClicked(x, y, event); for(GuiTextField textBox : this.editControls){ textBox.mouseClicked(x, y, event); } } @Override protected void mouseMovedOrUp(int mouseX, int mouseY, int event){ super.mouseMovedOrUp(mouseX, mouseY, event); } @Override protected void keyTyped(char key, int event){ super.keyTyped(key, event); for(GuiTextField textBox : this.editControls){ textBox.textboxKeyTyped(key, event); } } private void sendUpdateToSpawner(TileEntitySpawner spawner){ int withdrawAmount = this.getTextboxValue(this.mineyDepositTextField.getText()); } //checks the string to see if it is an integer private boolean validateTextboxInt(String s){ int val = 0; try{ val = Integer.valueOf(s); } catch(NumberFormatException e){ return false; } return true; } private int getTextboxValue(String s){ if(validateTextboxInt(s)){ return Integer.valueOf(s); } return 0; } @Override protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_){ int fontColor = 0x404040; //RGB value of the text color } @Override protected void drawGuiContainerBackgroundLayer(float x, int y, int z) { this.mc.getTextureManager().bindTexture(guiTexture); int xPos = (this.width - this.xSize) / 2; int yPos = (this.height - this.ySize) / 2; this.drawTexturedModalRect(xPos, yPos, 0, 0, this.xSize, this.ySize); final String withdraw = "Withdraw"; this.drawString(this.fontRendererObj, withdraw, this.width/2 - 82, this.height/2 - 74, 0xFFFFFF); final String deposit = "Deposit"; this.drawString(this.fontRendererObj, deposit, this.width/2 - 77, this.height/2 - 26, 0xFFFFFF); final String total = "Total Miney"; this.drawString(this.fontRendererObj, total, this.width/2 +10, this.height/2 - 78, 0xFFFFFF); final String miney = "" + (BattlePlayerProperties.get(Minecraft.getMinecraft().thePlayer).getMineyTotal() - this.getTextboxValue(this.mineyDepositTextField.getText())); this.drawString(this.fontRendererObj, miney, (this.width/2 + 12) + 50/2 - this.fontRendererObj.getStringWidth(miney)/2, this.height/2 - 66, 0xFFFFFF); //draw edit controls for(GuiTextField textBox : this.editControls){ textBox.width = 45; textBox.xPosition = this.width/2 -82; //so it stays in the same position when gui is scaled textBox.yPosition = this.height/2 -64; textBox.drawTextBox(); } } } ContainerClass public class ContainerMiney extends Container { private final int slotCols = 9; private int slotRows; public ContainerMiney(IInventory playerInventory){ int i; for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 179)); } } /** * Called when the container is closed. */ public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); } @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 < this.slotRows * 9) { if (!this.mergeItemStack(itemstack1, this.slotRows * 9, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, this.slotRows * 9, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } @Override public boolean canInteractWith(EntityPlayer var1) { return true; } } Quote
Ernio Posted May 11, 2016 Posted May 11, 2016 http://www.minecraftforge.net/forum/index.php/topic,31297.0.html If you need more. Quote 1.7.10 is no longer supported by forge, you are on your own.
Recommended Posts
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.