Posted December 25, 201311 yr i've been working on a gui for a particle accelerator and i've gotten a lot done but the problem is the gui will randomly shift right 10 px so i will go in and change the slots to line up again and it works but then randomly it will shift back 10px. ive tried to re code the gui and it still happens so yes i know the code doesnt look good but it was a quick test to see if it would happen again. this is the container for it package TripleXGaming.Quantumcraft.TileEntities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class containerControlUnit extends Container{ protected TileEntityControlUnit tileEntity; // public static final int INPUT_1 = 1, INPUT_2 = 2, INPUT_3 = 3, QCore = 4, OUTPUT_1 = 5, OUTPUT_2 = 6, OUTPUT_3 = 7; public containerControlUnit (InventoryPlayer inventoryPlayer, TileEntityControlUnit te){ tileEntity = te; for(int i = 0; i < 9; i++){ this.addSlotToContainer(new MachineOutput(tileEntity, i, 8 + i * 18, -40)); } for(int i = 14; i < 20; i++){ this.addSlotToContainer(new ParticalAcceleratorQCSlot(tileEntity, i, 263, -27 + i * 18 - 14 * 18)); } this.addSlotToContainer(new Slot(tileEntity, 10, 44, 14)); this.addSlotToContainer(new Slot(tileEntity, 11, 44, 32)); this.addSlotToContainer(new Slot(tileEntity, 12, 116, 14)); this.addSlotToContainer(new Slot(tileEntity, 13, 116, 32)); bindPlayerInventory(inventoryPlayer) } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for(int i = 0; i < 9; i++){ this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 148)); } for(int j = 9; j < 18; j++){ this.addSlotToContainer(new Slot(inventoryPlayer, j, 8 + j * 18 - 9 * 18, 90)); } for(int j = 18; j < 27; j++){ this.addSlotToContainer(new Slot(inventoryPlayer, j, 8 + j * 18 - 18 * 18, 108)); } for(int j = 27; j < 36; j++){ this.addSlotToContainer(new Slot(inventoryPlayer, j, 8 + j * 18 - 27 * 18, 126)); } } //Todo once gui is done @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { return null; } } this is the gui for the machine package TripleXGaming.Quantumcraft.gui; import org.lwjgl.opengl.GL11; import TripleXGaming.Quantumcraft.QCModInfo; import TripleXGaming.Quantumcraft.Quantumcraft; import TripleXGaming.Quantumcraft.TileEntities.TileEntityControlUnit; import TripleXGaming.Quantumcraft.TileEntities.containerControlUnit; import cpw.mods.fml.common.network.PacketDispatcher; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; public class GuiControlUnit extends GuiContainer { containerControlUnit CU = new containerControlUnit(null, null); public GuiControlUnit (InventoryPlayer inventoryPlayer, TileEntityControlUnit tileEntity) { super(new containerControlUnit(inventoryPlayer, tileEntity)); } public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel){ Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0,1); tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1); tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1,0); tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0); tessellator.draw(); } @Override protected void drawGuiContainerForegroundLayer(int param1, int param2) { //draw text and stuff here //the parameters for drawString are: string, x, y, color fontRenderer.drawString(" Particle Accelerator", 8, -20, 4210752); //draws "Inventory" or your regional equivalent // fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { //draw your Gui here, only thing you need to change is the path ResourceLocation textures = (new ResourceLocation("quantumcraft:textures/gui/guibase.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(textures); int xSize = 512; int ySize = 256; int x = (width - xSize) / 2; int y = (height - ySize) / 2; drawTexturedQuadFit(x+62, y, xSize, ySize, zLevel); } @Override public void initGui() { super.initGui(); } protected void actionPerformed(GuiButton guibutton) { //id is the id you give your button switch(guibutton.id) { case 1: break; case 2: break; default: } } } this is my first time posting on here so im not sure if i included all needed information. Developer of Quantumcraft - a quantum mechanics based mod
December 26, 201311 yr Author these are the two screenshots of the good one and bad one. http://i.imgur.com/TywGMZ1.png - good http://i.imgur.com/AYMgj8D.png - bad hope someone can help. still haven't found the issue on my own all slots are being shifted not just the inventory Developer of Quantumcraft - a quantum mechanics based mod
December 26, 201311 yr Hi It looks to me like you might have added some custom rendering code (to one of the buttons or the background layer) that does a GL11.glTranslatef but forgets to undo it afterwards. Perhaps the fancy "level" gauges on the left? The reason I think that, is because your background layer plus the slots (all the graphics and slot positions) are totally fine, just the items themselves are shifted. I think the code responsible for drawing your screen is in GUIcontainer::drawScreen this.drawGuiContainerBackgroundLayer(par3, par1, par2); // ... some stuff super.drawScreen(par1, par2, par3); // some more stuff for (int j1 = 0; j1 < this.inventorySlots.inventorySlots.size(); ++j1) { Slot slot = (Slot)this.inventorySlots.inventorySlots.get(j1); this.drawSlotInventory(slot); The fastest way to test might be to remove some of the slots, or alternatively wrap the rendering of each one in a glPushMatrix and glPopMatrix. -TGG
December 26, 201311 yr Author sorry if i dont see what your trying to say ive only been coding for a month and a half but i am not useing any GL11.glTranslatef , and all the gui things you see don't actually work atm they are just on the texture to show me what goes where. so the only thing this is doing is rendering the gui and slots ... the reason i have the tessellator is because the normal way to render the gui was making the gui too small/large and not scaled correctly i will try what you sugested.. anyways edit so i added a GL11.glTranslatef(0.0f, 0.0f, 0.0f); and so far i think it fixed it .. cant be sure tho it has taken over an hour to shift the positions so time will tell ... Developer of Quantumcraft - a quantum mechanics based mod
December 26, 201311 yr Hi gui will randomly shift right 10 px so i will go in and change the slots to line up again a What do you mean "change the slots to line up again"? how are you doing that? so i added a GL11.glTranslatef(0.0f, 0.0f, 0.0f); and so far i think it fixed it .. cant be sure tho it has taken over an hour to shift the positions so time will tell ... Hmmm I would be doubtful that this would help, to be honest. the normal way to render the gui was making the gui too small/large and not scaled correctly what did you use before? Do you notice a pattern of when the items move, compared with when they don't? Does it flick back and forth randomly, or at regular intervals, while you've got the GUI open? Or does it only change when you close and reopen? If you try to drag items out of the slot, does the item get selected when you click on the item, or on the slot (if you click the part of the slot which isn't covered by the item)? As you might have guessed I'm fishing for clues because I don't actually know what's happening. If you can narrow it down to the difference between a rendering problem vs an actual coordinates problem (hence the test with the item clicking / dragging), it might help a lot. -TGG
December 26, 201311 yr Author so for adding slots and moving them back to the correct locations so im shifting the 8 to 18 and that is moving the slots over then when it does it again i change it back this for(int i = 0; i < 9; i++){ this.addSlotToContainer(new MachineOutput(tileEntity, i, 8 + i * 18, -40)); to for(int i = 0; i < 9; i++){ this.addSlotToContainer(new MachineOutput(tileEntity, i, 18 + i * 18, -40)); for the gui texture i was useing something like this but of couse changed @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { ResourceLocation textures = (new ResourceLocation("quantumcraft:textures/gui/guibase.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(textures); int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); } and that only worked for guis a little bit bigger than the normal gui size before it wouldnt display correctly now im useing @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { //draw your Gui here, only thing you need to change is the path GL11.glPushMatrix(); GL11.glTranslatef(0.0f, 0.0f,0.0f); ResourceLocation textures = (new ResourceLocation("quantumcraft:textures/gui/guibase.png")); // GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(textures); int xSize = 512; int ySize = 256; int x = (width - xSize) / 2; int y = (height - ySize) / 2; drawTexturedQuadFit(x+62, y, xSize, ySize, zLevel); GL11.glPopMatrix(); } when the slots shift sideways all of them shift exactly 10px to the right then when i go and changed the location in the code when they shift again they shift left.. i hope you understand all this .. im not sure if im makeing it as clear as it could be Developer of Quantumcraft - a quantum mechanics based mod
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.