Jump to content

Gui randomly shifts 10px sideways


TripleXGaming

Recommended Posts

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Wait guys, I still don't don't understand... I shall send my code -- Define the function to decrease hunger local function decreaseHunger(player)     local currentHunger = player.getHunger()          -- Check if hunger is not already zero     if currentHunger > 0 then         player.setHunger(currentHunger - 1)     end end -- Register event to decrease hunger over time script.registerEvent(EntityPlayer, function(player)     while true do         -- Decrease hunger every few seconds         decreaseHunger(player)         script.sleep(1000) -- Sleep for 1 second     end end)     Any help appriecated. It's been a while since I learnt Javascript or whatever Minecraft is made with... ... ... ... Nicknotname Hungerinpeaceful xx
    • good days  i get this error: java.lang.ClassCastException: class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraftforge.common.extensions.IForgeServerPlayer (net.minecraft.client.player.LocalPlayer is in module minecraft@1.20.4 of loader 'TRANSFORMER' @3e8b3b79; net.minecraftforge.common.extensions.IForgeServerPlayer is in module forge@49.0.26 of loader 'TRANSFORMER' @3e8b3b79)     at mercmod.blocks.classes.panel_whit_entity_inside.use(panel_whit_entity_inside.java:576) ~[main/:?] {re:classloading}     at net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase.use(BlockBehaviour.java:826) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.performUseItemOn(MultiPlayerGameMode.java:324) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.lambda$useItemOn$4(MultiPlayerGameMode.java:292) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.startPrediction(MultiPlayerGameMode.java:251) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.useItemOn(MultiPlayerGameMode.java:291) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.startUseItem(Minecraft.java:1799) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.handleKeybinds(Minecraft.java:2083) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.tick(Minecraft.java:1902) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.runTick(Minecraft.java:1216) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.run(Minecraft.java:801) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:234) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} ------------------------------------------------------------------------------------------------------------------   context:  im updating the briefcase from mi mod an i need to make a gui whit this image that gonna be launched from a block and from a item soo im using kapenjoe tutorials  ---------------------------------------------------------------------------------------- The problem is that tutorial is for 1.20.1 and im using 1.20.4 and i really dont get how to call and open the gui from the block nor from the item i made this based on post i made short ago everything seems find but when right click the block to open the gui it crash the game  @Override public InteractionResult use(BlockState blkstate, Level warudo, BlockPos pos, Player pe, InteractionHand hand, BlockHitResult hitresult) {     if(warudo.isClientSide()){         BlockEntity blkentity = warudo.getBlockEntity(pos);         if(blkentity instanceof Panel_BlockEntity){             //   ↓↓↓  open the menu from the block              IForgeServerPlayer ifpe = (IForgeServerPlayer)pe; //<--- this is wrong  "class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraftforge.common.extensions.IForgeServerPlayer"             ifpe.openMenu( (Panel_BlockEntity) blkentity, pos ); //<-- i need an example of how open a gui in 1.20.4         }     } return InteractionResult.sidedSuccess(warudo.isClientSide()); } Theres nothing highlighted in red in the code like everything where right an possible but dont works  ####################################################################################################### i need to see an example, just the piece of code for the use() method of the block whit the block entity for 1.20.4  and the same  but for the item     @Override     public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level warudo, @NotNull Player pe, @NotNull InteractionHand interactionHand)     {         if (!warudo.isClientSide())         {             ItemStack heldItem = pe.getItemInHand(interactionHand);                          if (heldItem.getCapability(ForgeCapabilities.ITEM_HANDLER).isPresent())             {                 //   ↓↓↓  open the menu from the item                 NetworkHooks.openScreen((ServerPlayer) pe, this);             }         }         return super.use(warudo, pe, interactionHand);     }   thanks for your attention           
    • It depends on the data you want to save, but generally speaking you should use some custom Player Capabilities, attach to the Player and use them to store/retrieve any kind of data you want. You can find how to make them work for 1.20.x in the documentation here: https://docs.minecraftforge.net/en/latest/datastorage/capabilities/
  • Topics

×
×
  • Create New...

Important Information

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