Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12] Properly creating a custom sign GUI (Without block)
The update for 1.13 is being worked on - please be patient. (Updated 02/19/19)
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Stenbergcsgo

[1.12] Properly creating a custom sign GUI (Without block)

Started by Stenbergcsgo, April 6, 2018

7 posts in this topic

Stenbergcsgo    0

Stenbergcsgo

Stenbergcsgo    0

  • Stone Miner
  • Stenbergcsgo
  • Members
  • 0
  • 62 posts
  • Report post
Posted April 6, 2018

Hello Minecraft Forge, I'm trying to create a GUI which does the following:

    - Player rightclicks with custom item

    - GUI similar to the sign GUI appears, where the player can input a string, which is  then stored (Client side only)

    - Clicking done closes the GUI

 

So I've tried creating this, but ran into some issues. The GUI doesn't load at all.

 

signInputGui:

package com.mta.utzonmod.client.gui;

import java.io.IOException;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class signInputGui extends GuiScreen {
	
	private GuiButton doneBtn;
	
	private int updateCounter;
	
	private int editLine;
	
	public String playerInput;
	
	public void initGui() {
		this.buttonList.clear();
		Keyboard.enableRepeatEvents(true);
		this.doneBtn = this.addButton(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120, I18n.format("gui.done")));	
	}
	
	public void onGuiClosed() {
		Keyboard.enableRepeatEvents(false);
	}
	
	public void updateScreen() {
		++this.updateCounter;
	}
	
	protected void actionPerformed(GuiButton button) throws IOException {
		if(button.enabled) {
			if(button.id == 0) {
				this.mc.displayGuiScreen((GuiScreen)null);
			}
		}
	}
	
	public final ITextComponent[] signText = new ITextComponent[] {new TextComponentString(""), new TextComponentString(""), new TextComponentString(""), new TextComponentString("")};
	
	protected void keyTyped(char typedChar, int keyCode) throws IOException {
		if(keyCode == 200) {
			this.editLine = this.editLine - 1 & 3;
		}
		
		if (keyCode == 208 || keyCode == 28 || keyCode == 156) {
			this.editLine = this.editLine + 1 & 3;
		}
		
		for (int i = 0; i < 4; ++i)
        {
            playerInput = ITextComponent.Serializer.componentToJson(this.signText[i]);
        }
		
		if (keyCode == 14 && !playerInput.isEmpty()) {
			playerInput = playerInput.substring(0, playerInput.length() - 1);
		}
		
		if (ChatAllowedCharacters.isAllowedCharacter(typedChar) && this.fontRenderer.getStringWidth(playerInput + typedChar) <= 90) {
			playerInput = playerInput + typedChar;
		}
		
		if (keyCode == 1) {
			this.actionPerformed(this.doneBtn);
		}	
	}
	
	public void drawScreen(int mouseX, int mouseY, float partialTicks) {
		this.drawDefaultBackground();
		this.drawCenteredString(this.fontRenderer, I18n.format("sign.edit"),this.width / 2, 40, 16777215);
		GlStateManager.color(1.0F,  1.0F,  1.0F, 1.0F);
		GlStateManager.pushMatrix();
		GlStateManager.translate((float)(this.width / 2), 0.0F, 50.0F);
		
        GlStateManager.scale(-93.75F, -93.75F, -93.75F);
        GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
		
		GlStateManager.popMatrix();
		super.drawScreen(mouseX, mouseY, partialTicks);
	}
}

 

SchematicSign:

package com.mta.utzonmod.items;

import com.mta.utzonmod.client.gui.signInputGui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

public class SchematicSign extends ItemBase {
	
	public SchematicSign(String name) {
		super(name);
	}
	
	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) {
		ITextComponent message = new TextComponentString("Hello");
		player.sendMessage(message);
		//player.openGui(Main.instance, 0, worldIn, 1, 1, 1);
		signInputGui inputGui = new signInputGui();
		inputGui.initGui();
		return super.onItemRightClick(worldIn, player, handIn);
	}
}

 

ItemBase:

package com.mta.utzonmod.items;

import com.mta.utzonmod.Main;
import com.mta.utzonmod.init.ModItems;
import com.mta.utzonmod.util.IHasModel;

import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;

public class ItemBase extends Item implements IHasModel{

	public ItemBase(String name) {
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.utzontab);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void registerModels() {

		Main.proxy.registerItemRenderer(this, 0, "inventory");
		
	}	
}

 

So instead of messing too much around, I'd hope some of you guys might be able to chip in where I went right and where I went wrong. As mentioned the GUI doesn't even appear at the moment, which I assume is related to the "drawScreen()" not getting called.

Share this post


Link to post
Share on other sites

diesieben07    6115

diesieben07

diesieben07    6115

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6115
  • 40266 posts
  • Report post
Posted April 6, 2018
  • That's not how you open a GuiScreen. Never call initGui yourself. To open a screen, call Minecraft::displayGuiScreen.
  • You cannot access client-only classes (such as your GuiScreen) from common code (your item). You must use your @SidedProxy.
  • You must perform a check for the logical side in onItemRightClick.

Share this post


Link to post
Share on other sites

Stenbergcsgo    0

Stenbergcsgo

Stenbergcsgo    0

  • Stone Miner
  • Stenbergcsgo
  • Members
  • 0
  • 62 posts
  • Report post
Posted April 6, 2018
41 minutes ago, diesieben07 said:
  • That's not how you open a GuiScreen. Never call initGui yourself. To open a screen, call Minecraft::displayGuiScreen.
  • You cannot access client-only classes (such as your GuiScreen) from common code (your item). You must use your @SidedProxy.
  • You must perform a check for the logical side in onItemRightClick.

So would I modify my ClientProxy to?:

package com.mta.utzonmod.proxy;

import com.mta.utzonmod.client.gui.signInputGui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class ClientProxy extends CommonProxy {
	
	public void registerItemRenderer(Item item, int meta, String id) {
		ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), id));
	}
	
	public void init() {
		Minecraft mc = Minecraft.getMinecraft();
		mc.displayGuiScreen(new signInputGui());
	}
}

 

And also added the check to my item:

package com.mta.utzonmod.items;


import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

public class SchematicSign extends ItemBase {
	
	public SchematicSign(String name) {
		super(name);
	}
	
	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) {
		if(!worldIn.isRemote) {
			ITextComponent message = new TextComponentString("Hello");
			player.sendMessage(message);
			//player.openGui(Main.instance, 0, worldIn, 1, 1, 1);
			return super.onItemRightClick(worldIn, player, handIn);
		} else {
			return super.onItemRightClick(worldIn, player, handIn);
		}
		
	}
}

 

Share this post


Link to post
Share on other sites

diesieben07    6115

diesieben07

diesieben07    6115

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6115
  • 40266 posts
  • Report post
Posted April 6, 2018
  • You are now not opening the GUI at all from your item.
  • You probably want to return a different result than EnumActionResult.PASS.

Share this post


Link to post
Share on other sites

Stenbergcsgo    0

Stenbergcsgo

Stenbergcsgo    0

  • Stone Miner
  • Stenbergcsgo
  • Members
  • 0
  • 62 posts
  • Report post
Posted April 6, 2018
53 minutes ago, diesieben07 said:
  • You are now not opening the GUI at all from your item.
  • You probably want to return a different result than EnumActionResult.PASS.

Just a really stupid question, so how should i properly open it from my item?

Move

Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(new signInputGui());

 

to the item class?

Share this post


Link to post
Share on other sites

diesieben07    6115

diesieben07

diesieben07    6115

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6115
  • 40266 posts
  • Report post
Posted April 6, 2018
20 minutes ago, Stenbergcsgo said:

Just a really stupid question, so how should i properly open it from my item?

Move


Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(new signInputGui());

 

to the item class?

Do you even understand how @SidedProxy works? You now made a method in your proxy, but you don't call it from anywhere. What do you think this does? Exactly: nothing.

  • Thanks 1

Share this post


Link to post
Share on other sites

Stenbergcsgo    0

Stenbergcsgo

Stenbergcsgo    0

  • Stone Miner
  • Stenbergcsgo
  • Members
  • 0
  • 62 posts
  • Report post
Posted April 6, 2018
8 minutes ago, diesieben07 said:

Do you even understand how @SidedProxy works? You now made a method in your proxy, but you don't call it from anywhere. What do you think this does? Exactly: nothing.

Yea my bad guess I'm starting to oversee some stuff after messing around with it for so long. Called the init from my item, and it works now. Thanks =)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0
Go To Topic Listing Modder Support

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • LordTSI
      cant make modded server

      By LordTSI · Posted 13 minutes ago

      java version "1.8.0_201"
      Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
      Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode) i got it from the forge website
    • LexManos
      No Values in ForgeRegistries.ENTITIES 1.13.2

      By LexManos · Posted 15 minutes ago

      Yes, it worked in the version of Forge from before you posted. Please be sure you're on the latest version before posting.
    • LexManos
      MinecraftForge JSON API 404 Not Found

      By LexManos · Posted 15 minutes ago

      Many systems exist, the fat json file has long been the wrong way to get this information. You should make your usecase better known. If it's actually good then we can advise you how to do it now.

      But yes, Don't auto-download Forge. Don't use the giant json file.
    • IceMetalPunk
      1.13.2 - No Console Output?

      By IceMetalPunk · Posted 49 minutes ago

      Hm... the latest version won't build at all. I've gotten everything setup for Eclipse, and the project imported into Eclipse, but there are no configurations. When I try to run the Gradle "build" task, it fails, because it's looking in my JRE folder instead of my JDK folder. My JAVA_HOME environment variables are set to point to the JDK directory... is there somewhere else I need to change a path definition?
    • Choonster
      [1.12.2] Remapping IBlockState -> IBlockState

      By Choonster · Posted 59 minutes ago

      I have a DataFixer designed to flatten blocks in preparation for 1.13 here (the flattening definitions are initialised here). You should be able to use it to achieve this remapping.   If you decide to use it, make sure you understand how it works first.
  • Topics

    • LordTSI
      2
      cant make modded server

      By LordTSI
      Started 4 hours ago

    • MrMarnic
      7
      No Values in ForgeRegistries.ENTITIES 1.13.2

      By MrMarnic
      Started Wednesday at 09:21 PM

    • BloomCake
      3
      MinecraftForge JSON API 404 Not Found

      By BloomCake
      Started 2 hours ago

    • IceMetalPunk
      4
      1.13.2 - No Console Output?

      By IceMetalPunk
      Started 1 hour ago

    • SaltyBrownie18
      1
      [1.12.2] Remapping IBlockState -> IBlockState

      By SaltyBrownie18
      Started 10 hours ago

  • Who's Online (See full list)

    • Tyler0421
    • Choonster
    • IceMetalPunk
    • crackedEgg
    • wally123
    • tokuhausu
    • ItHurtsLikeHell
    • fieldbox
    • Littoil
    • DavidM
    • Roadhog360
    • LexManos
    • LordTSI
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12] Properly creating a custom sign GUI (Without block)
  • Theme
  • Contact Us

Copyright © 2017 ForgeDevelopment LLC Powered by Invision Community