Advertisement
ViiRuS

Name Gui Tutorial Code

Dec 1st, 2011
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. Full GuiName
  2. ----------------------
  3. package net.minecraft.src;
  4.  
  5. import java.awt.image.BufferedImage;
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. public class GuiName extends GuiScreen {
  9.     private BufferedImage img;
  10.     private int imgID = 1000;
  11.     public GuiName(EntityFlyingSpiderPig entity)
  12.     {
  13.         mob=entity;
  14.     }
  15.    
  16.     private GuiTextField textfield;
  17.     public EntityFlyingSpiderPig mob;
  18.    
  19.     public void initGui() {
  20.         try {
  21.             img = ModLoader.loadImage(mc.renderEngine, "/mods/name.png");
  22.             mc.renderEngine.setupTexture(img, imgID);
  23.         } catch (Exception e) {
  24.             e.printStackTrace();
  25.         }
  26.         controlList.clear();
  27.         controlList.add(new GuiButton(1, width / 2 - 49, height / 2 + 20, 70, 20, "Enter"));
  28.         textfield = new GuiTextField(this, fontRenderer, width / 2 - 87, height / 2 - 10, 150, 20, "");
  29.         textfield.isFocused = false;
  30.         textfield.setMaxStringLength(16);
  31.    
  32.     }
  33.     protected void actionPerformed(GuiButton guibutton)
  34.     {
  35.         if(guibutton.id == 1)
  36.         {
  37.             mob.Name = textfield.getText();
  38.             mc.displayGuiScreen(null);
  39.         }
  40.     }
  41.     protected void keyTyped(char c, int i)
  42.     {
  43.         super.keyTyped(c, i);
  44.         textfield.textboxKeyTyped(c, i);
  45.     }
  46.     protected void mouseClicked(int i, int j, int k)
  47.     {
  48.         super.mouseClicked(i, j, k);
  49.         textfield.mouseClicked(i, j, k);
  50.     }
  51.     public boolean doesGuiPauseGame()
  52.     {
  53.         return false;
  54.     }
  55.     public void onGuiClosed()
  56.     {
  57.     }
  58.     public void drawScreen(int i, int j, float f)
  59.     {
  60.         drawDefaultBackground();
  61.         int k = width / 2 - 100;
  62.         int l = height  / 2 - 40;
  63.         try {
  64.             int tempvar = mc.renderEngine.getTexture("/mods/name.png");
  65.             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  66.             mc.renderEngine.bindTexture(tempvar);
  67.             drawTexturedModalRect(k, l, 0, 0, 176, 166);
  68.         }
  69.         finally {
  70.         }
  71.         textfield.drawTextBox();
  72.         drawCenteredString(fontRenderer, "Enter the Name of your Mob", width / 2 - 10, height / 2 - 35, 0xffffff);
  73.         super.drawScreen(i, j, f);
  74.     }
  75.  
  76.  
  77. }
  78. --------------
  79. Render File Code Snippet
  80. -------------------
  81.  
  82. if(entity.Name.length() > 0 && entity.Name != "")      
  83.         {                
  84.             renderLivingLabel(entity, entity.Name, d, d1, d2, 64);      
  85.         }
  86. ----------------------
  87. EntityX Code Snippets
  88. --------------------
  89.  
  90. ModLoader.OpenGUI(entityplayer, new GuiName(this));
  91.  
  92. nbttagcompound.setString("Name", Name);
  93.  
  94. Name = nbttagcompound.getString("Name");
  95.  
  96. String Name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement