Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] Need help with gui


tigres810
 Share

Recommended Posts

So in 1.12 I made a book with buttons that you can go through pages and im trying to convert that code to 1.16 but is alot different than I though.

My question is: How I can make a gui that when you right click and item it opens it and how I can register that gui?

Also how I can make a gui similar to tetras gui Tetra gui image

So far I have this error on the registry error image idk what it means

Edited by tigres810
Link to comment
Share on other sites

Howdy

 

There are a few working examples of GUIs here

https://github.com/TheGreyGhost/MinecraftByExample

 

Both of them have containers(i.e. you can store items inside them) but that is optional and the basic concepts are the same.  Mbe32 is an item that when you right click it, it opens a GUI.

 

-TGG

 

mbe30 (chest)

mbe30.png

 

mbe32 (an item which can contain other items)

mbe32-1.png

mbe32-2.png

 

 

 

Link to comment
Share on other sites

7 hours ago, TheGreyGhost said:

Howdy

 

There are a few working examples of GUIs here

https://github.com/TheGreyGhost/MinecraftByExample

 

Both of them have containers(i.e. you can store items inside them) but that is optional and the basic concepts are the same.  Mbe32 is an item that when you right click it, it opens a GUI.

 

-TGG

 

mbe30 (chest)

mbe30.png

 

mbe32 (an item which can contain other items)

mbe32-1.png

mbe32-2.png

 

 

 

I tried making the flower bag but I get this error, can you explain me why? 

java.lang.UnsupportedOperationException: Unable to construct this menu by type
    at net.minecraft.inventory.container.Container.getType(Container.java:56) ~[forge:?] {re:classloading}
    at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:223) ~[forge:?] {re:classloading}
    at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:169) ~[forge:?] {re:classloading}
    at com.tigres810.testmod.items.InformationTabletItem.onItemRightClick(InformationTabletItem.java:27) ~[?:?] {re:classloading}
    at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:224) ~[forge:?] {re:classloading}
    at net.minecraft.server.management.PlayerInteractionManager.processRightClick(PlayerInteractionManager.java:296) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.ServerPlayNetHandler.processTryUseItem(ServerPlayNetHandler.java:1013) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.client.CPlayerTryUseItemPacket.processPacket(CPlayerTryUseItemPacket.java:37) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.client.CPlayerTryUseItemPacket.processPacket(CPlayerTryUseItemPacket.java:9) ~[forge:?] {re:classloading}
    at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge:?] {re:classloading}
    at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[forge:?] {re:classloading}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge:?] {re:classloading}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:758) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:159) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.driveOneInternal(MinecraftServer.java:741) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:735) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.driveUntil(ThreadTaskExecutor.java:122) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:721) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:667) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at java.lang.Thread.run(Thread.java:832) [?:?] {}

 

Link to comment
Share on other sites

5 hours ago, tigres810 said:

I tried making the flower bag but I get this error, can you explain me why? 


java.lang.UnsupportedOperationException: Unable to construct this menu by type
    at net.minecraft.inventory.container.Container.getType(Container.java:56) ~[forge:?] {re:classloading}
    at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:223) ~[forge:?] {re:classloading}
    at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:169) ~[forge:?] {re:classloading}
    at com.tigres810.testmod.items.InformationTabletItem.onItemRightClick(InformationTabletItem.java:27) ~[?:?] {re:classloading}
    at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:224) ~[forge:?] {re:classloading}
    at net.minecraft.server.management.PlayerInteractionManager.processRightClick(PlayerInteractionManager.java:296) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.ServerPlayNetHandler.processTryUseItem(ServerPlayNetHandler.java:1013) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.client.CPlayerTryUseItemPacket.processPacket(CPlayerTryUseItemPacket.java:37) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.client.CPlayerTryUseItemPacket.processPacket(CPlayerTryUseItemPacket.java:9) ~[forge:?] {re:classloading}
    at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge:?] {re:classloading}
    at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[forge:?] {re:classloading}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge:?] {re:classloading}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:758) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:159) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.driveOneInternal(MinecraftServer.java:741) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:735) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.driveUntil(ThreadTaskExecutor.java:122) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:721) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:667) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at java.lang.Thread.run(Thread.java:832) [?:?] {}

 

Okay so I fixed the registration problem but now I have this another error 

The method displayGuiScreen(Screen) in the type Minecraft is not applicable for the arguments (TestScreen::new)

How I can display the screen because its only a gui

Link to comment
Share on other sites

I fixed the error but now the text wont fit the gui :/ heres code 

package com.tigres810.testmod.guis;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.tigres810.testmod.Test;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.button.ChangePageButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;

public class TestScreen extends Screen {
	
	private static final int WIDTH = 179;
    private static final int HEIGHT = 151;

    private ResourceLocation GUI = new ResourceLocation(Test.MOD_ID, "textures/gui/book1big_gui.png");

    private int currentpage = 0;
    private static final int maxpages = 2;
    
    private Button closeButton;
    private Button arrowleftButton;
    private Button arrowrightButton;
    private String currentpagetext;
    public TestScreen() {
        super(new TranslationTextComponent("test"));
    }

    @Override
    protected void init() {
    	this.buttons.clear();
		this.children.clear();
    	int centerY = (this.height - HEIGHT) / 2;
    	closeButton = new Button((this.width / 2+90) - this.font.getStringWidth("Prueba") / 2, centerY + 12, 15, 20, new StringTextComponent("X"), button -> close());
    	arrowleftButton = new ChangePageButton((this.width / 2-60) - this.font.getStringWidth("Prueba") / 2, centerY + HEIGHT - 30, false, button -> changepage(1), true);
    	arrowrightButton = new ChangePageButton((this.width / 2+75) - this.font.getStringWidth("Prueba") / 2, centerY + HEIGHT - 30, true, button -> changepage(2), true);
    	this.insertText(currentpagetext, false);
    	this.addButton(closeButton);
    	this.addButton(arrowleftButton);
    	this.addButton(arrowrightButton);
    	arrowleftButton.visible = false;
    }

    @Override
    public boolean isPauseScreen() {
        return false;
    }
    
    private void changepage(int buttonid) {
    	if(currentpage > 0) {
    		if(currentpage < maxpages) {
    			if(currentpage == 1) {
    				if(buttonid == 1) {
    					arrowrightButton.visible = true;
    					arrowleftButton.visible = false;
    					currentpage--;
    				} else {
    					if(currentpage + 1 == maxpages) {
    						arrowleftButton.visible = true;
    						arrowrightButton.visible = false;
    						currentpage++;
    					} else {
    						arrowleftButton.visible = true;
    						arrowrightButton.visible = true;
    						currentpage++;
    					}
    				}
    			}
    		} else {
    			if(buttonid == 1) {
    				if(currentpage - 1 == 0) {
	    				arrowleftButton.visible = false;
	    				arrowrightButton.visible = true;
	    				currentpage--;
    				} else {
    					arrowleftButton.visible = true;
	    				arrowrightButton.visible = true;
	    				currentpage--;
    				}
    			}
    		}
    	} else {
			if(buttonid == 2) {
				arrowleftButton.visible = true;
				arrowrightButton.visible = true;
				currentpage++;
			}
    	}
    	
    	currentpagetext = "" + currentpage;
    }

    private void close() {
        minecraft.displayGuiScreen(null);
    }
    
    @SuppressWarnings("deprecation")
	@Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
    	RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.minecraft.getTextureManager().bindTexture(GUI);
        int relX = (this.width - WIDTH) / 2;
        int relY = (this.height - HEIGHT) / 2;
        this.blit(matrixStack, relX, relY, 0, 0, WIDTH, HEIGHT);
        this.font.drawString(matrixStack, I18n.format("gui.title"), ((width / 2) - this.font.getStringWidth("test") / 2), relY + 10, 0x000000);
        this.font.drawString(matrixStack, currentpage + "/" + maxpages, ((width / 2+10) - this.font.getStringWidth("Prueba") / 2), relY + HEIGHT - 16, 0x000000);
        if(currentpage == 0) {
        	this.font.drawString(matrixStack, I18n.format("gui.leftpage0"), ((width / 2) - this.font.getStringWidth("Prueba") / 2) - 60, relY + 12, 0x000000);
        }
        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }


    public static void open() {
        Minecraft.getInstance().displayGuiScreen(new TestScreen());
    }

}

and this is the issue image, I need to fit that text into the left page, how I can do that? 2020-12-16_12.10.55.png

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.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.