Problème GuiTextField dans un inventaire custom.
-
Bonjours, voila j’ai un problème lorsque j’interagie avec mon inventaire, ceci ne produit absoluement rien voici mon code:
package fr.ph1823.MyLife.Gui.Amandes; /** * Created by ph1823 - Minecraft on 29/02/2016. */ import com.mojang.authlib.GameProfile; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.server.FMLServerHandler; import fr.ph1823.MyLife.GloryRP; import fr.ph1823.MyLife.Gui.Amandes.inv.InventoryBackPack; import fr.ph1823.MyLife.Item.Search; import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.server.MinecraftServer; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import fr.ph1823.MyLife.Gui.Amandes.inv.container.*; import java.awt.*; import java.net.URI; import java.util.ArrayList; import java.util.List; public class Amendes extends GuiContainer { public GuiTextField g; public static final ResourceLocation texture = new ResourceLocation("guicustom","textures/a.png"); protected InventoryBackPack inv; protected InventoryPlayer playerInv; public int rows; public Amendes(InventoryPlayer playerInv, InventoryBackPack inv) { super(new ContainerBackPack(playerInv, inv)); this.playerInv = playerInv; this.inv = inv; this.allowUserInput = false; // Calculate the number of rows this.rows = inv.getSizeInventory() / 9; // Height of the GUI using the number of rows this.ySize = 114 + this.rows * 18; } protected List buttonList = new ArrayList(); public void onGuiClosed() { Keyboard.enableRepeatEvents(false); } @Override protected void drawGuiContainerForegroundLayer(int x, int y) { Keyboard.enableRepeatEvents(true); // this.fontRendererObj.drawString(I18n.format(this.inv.getInventoryName(), new Object[0]), 8, 6, 4210752); int i = this.height / 4 + 48; FontRenderer f = this.mc.fontRenderer; g = new GuiTextField(f, 55,230, 100,100) ; g.setVisible(true); g.drawTextBox(); g.setText("Pseudo du joueurs"); g.setFocused(true); g.setEnabled(true); // g.drawTextBox(); // this.buttonList.add(g); this.buttonList.add(new GuiButton(32, this.width / 2 - 100, i+ 24, 200, 20, "Valide") { @Override public void mouseReleased(int x, int y) { mc.currentScreen.confirmClicked(true, 1); playerInv.closeInventory(); EntityPlayer p1 = playerInv.player; MinecraftServer mc1 = FMLServerHandler.instance().getServer(); for(GameProfile g1 : mc1.func_152357_F()) { if(g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId()); p.inventory.addItemStackToInventory(new ItemStack(GloryRP.MenotesItem,1)); } else { IChatComponent msg = IChatComponent.Serializer.func_150699_a("§4Erreur : la personne demandé n'existe pas."); p1.addChatMessage(msg); } } } }); int k; for (k = 0; k < this.buttonList.size(); ++k) { ((GuiButton)this.buttonList.get(k)).drawButton(this.mc, x, y); } // this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName(), new Object[0]), 8, this.ySize - 96 + 2, 4210752); } protected void actionPerformed(GuiButton button) { if(button.id == 0) { this.mc.currentScreen.confirmClicked(true, 1); playerInv.closeInventory(); EntityPlayer p1 = playerInv.player; MinecraftServer mc1 = FMLServerHandler.instance().getServer(); for (GameProfile g1 : mc1.func_152357_F()) { if (g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId()); p.inventory.addItemStackToInventory(new ItemStack(GloryRP.MenotesItem, 1)); } else { IChatComponent msg = IChatComponent.Serializer.func_150699_a("§4Erreur : la personne demandé n'existe pas."); p1.addChatMessage(msg); } } } } /** * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). */ protected void keyTyped(char p_73869_1_, int p_73869_2_) { this.g.textboxKeyTyped(p_73869_1_, p_73869_2_); if (p_73869_2_ == 15) { this.g.setFocused(!this.g.isFocused()); // this.field_146308_f.setFocused(!this.field_146308_f.isFocused()); } } @Override protected void drawGuiContainerBackgroundLayer(float prt, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); // Centering GUI int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; // Drawing the first part of the GUI (slots of the backpack) this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.rows * 18 + 17); // And after the slots from the player's inventory this.drawTexturedModalRect(k, l + this.rows * 18 + 17, 0, 126, this.xSize, 96); } }
Merci de votre aide
-
1. Pense aux balises java pour plus de lisibilité
2. Envoi la méthode où tu affiches le Gui -
Qu’est-ce qui ne marche pas dans ton gui, précisément ? Est-ce que ton background est déjà bien affiché ? Sois aussi sûr de ne display ton gui SEULEMENT côté client, sinon c’est le crash ASSURÉ côté serveur !
Je regarderai + en détail ce week end si personne n’a résolu le problème d’ici là… -
Bonjours, voici la classe au j’affiche mon GUI :
[font=Courier Newpackage ]fr.ph1823.MyLife.Proxy%(#cc7832)[; ] import fr.ph1823.MyLife.Gui.Amandes.inv.*%(#cc7832)[; ]import fr.ph1823.MyLife.Gui.Amandes.inv.container.*%(#cc7832)[; ]import fr.ph1823.MyLife.Gui.Amandes.*%(#cc7832)[; ]import fr.ph1823.MyLife.Item.Menotes%(#cc7832)[; ]import net.minecraft.entity.player.EntityPlayer%(#cc7832)[; ]import net.minecraft.world.World%(#cc7832)[; ]import cpw.mods.fml.common.network.IGuiHandler%(#cc7832)[; ] %(#629755)[*/** *]%(#629755)* ***@author ***%(#629755)[*SCAREX modif ph1823 *]%(#629755)[* * *]%(#629755)[* */ *]public class CommonProxy implements IGuiHandler { %(#bbb529)[@Override ] public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: %(#808080)[// The last parameter must be a multiple of 9 (e.g: 9, 18, 27, 54) ]%(#808080)[ // Condition to check if the player has the right item in hand ] if (player.getHeldItem() == null || !(player.getHeldItem().getItem() instanceof Menotes)) %(#cc7832)[return null; ] return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54))%(#cc7832)[; ] } %(#cc7832)[return null; ] } %(#bbb529)[@Override ] public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: %(#808080)[// The last parameter must be a multiple of 9 (e.g: 9, 18, 27, 54) ]%(#808080)[ // Condition to check if the player has the right item in hand ] if (player.getHeldItem() == null || !(player.getHeldItem().getItem() instanceof Menotes)) %(#cc7832)[return null; ] return new Amendes(player.inventory, new InventoryBackPack(player.getHeldItem(), 54))%(#cc7832)[; ] } %(#cc7832)[return null; ] } } ``` Je n'es pas dit que cela ne marchais pas, mais que ca ne produit rien, enfin je pensée que ca voulait dire que quand l'inventaire s'ouvrez, et qu'on appuyer sur un boutton cela ne produisez rien.
-
Salut,
Il te manque ça :@Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); this.g.mouseClicked(mouseX, mouseY, mouseButton); }
-
Envoies ton GuiHandler, ton problème doit étre touvres pas le container côté serveur
-
Bonsoir, je les ajouté mais cela ne marche toujours, pourriez vous m’indiquez ou l’ajouté ? (Je les ajouté dans la Class Amendes)
-
C’est bien dans la classe amendes.
Il se fait tard donc je vais regarder ton pb de plus près demain -
C’est une fonction à ajouter à la suite des autres.
PS : http://www.minecraftforgefrance.fr/showthread.php?tid=2766
-
Justement, c’est ce que j’ai fait, voici ma class :
[font=Courier Newpackage ]fr.ph1823.MyLife.Gui.Amandes%(#cc7832)[; ] %(#629755)[*/** *]%(#629755)[* * Created by ph1823 - Minecraft on 29/02/2016. *]%(#629755)[* */ *] import com.mojang.authlib.GameProfile%(#cc7832)[; ]import cpw.mods.fml.client.FMLClientHandler%(#cc7832)[; ]import cpw.mods.fml.server.FMLServerHandler%(#cc7832)[; ]import fr.ph1823.MyLife.GloryRP%(#cc7832)[; ]import fr.ph1823.MyLife.Gui.Amandes.inv.InventoryBackPack%(#cc7832)[; ]import fr.ph1823.MyLife.Item.Search%(#cc7832)[; ]import net.minecraft.client.gui.*%(#cc7832)[; ]import net.minecraft.client.gui.inventory.GuiContainer%(#cc7832)[; ]import net.minecraft.client.resources.I18n%(#cc7832)[; ]import net.minecraft.entity.player.EntityPlayer%(#cc7832)[; ]import net.minecraft.entity.player.InventoryPlayer%(#cc7832)[; ]import net.minecraft.item.ItemStack%(#cc7832)[; ]import net.minecraft.nbt.NBTBase%(#cc7832)[; ]import net.minecraft.server.MinecraftServer%(#cc7832)[; ]import net.minecraft.util.IChatComponent%(#cc7832)[; ]import net.minecraft.util.ResourceLocation%(#cc7832)[; ] import org.lwjgl.input.Keyboard%(#cc7832)[; ]import org.lwjgl.opengl.GL11%(#cc7832)[; ]import fr.ph1823.MyLife.Gui.Amandes.inv.container.*%(#cc7832)[; ] import java.awt.*%(#cc7832)[; ]import java.io.IOException%(#cc7832)[; ]import java.net.URI%(#cc7832)[; ]import java.util.ArrayList%(#cc7832)[; ]import java.util.List%(#cc7832)[; ] public class Amendes extends GuiContainer { public GuiTextField g%(#cc7832)[; ] public static final ResourceLocation *texture *= new ResourceLocation("guicustom","textures/a.png")%(#cc7832)[; ] protected InventoryBackPack inv%(#cc7832)[; ] protected InventoryPlayer playerInv%(#cc7832)[; ] public int rows%(#cc7832)[; ] public Amendes(InventoryPlayer playerInv, InventoryBackPack inv) { super(new ContainerBackPack(playerInv, inv))%(#cc7832)[; ] this.playerInv = playerInv%(#cc7832)[; ] this.inv = inv%(#cc7832)[; ] this.allowUserInput = %(#cc7832)[false; ] %(#808080)[// Calculate the number of rows ] this.rows = inv.getSizeInventory() / 9%(#cc7832)[; ] %(#808080)[// Height of the GUI using the number of rows ] this.ySize = 114 + this.rows * 18%(#cc7832)[; ] } protected List buttonList = new ArrayList()%(#cc7832)[; ] public void onGuiClosed() { Keyboard.*enableRepeatEvents*(false)%(#cc7832)[; ] } %(#bbb529)[@Override ] protected void drawGuiContainerForegroundLayer(int x, int y) { Keyboard.*enableRepeatEvents*(true)%(#cc7832)[; ] // this.fontRendererObj.drawString(I18n.format(this.inv.getInventoryName(), new Object[0), 8, 6, 4210752); ] int i = this.height / 4 + 48%(#cc7832)[; ] FontRenderer f = this.mc.fontRenderer%(#cc7832)[; ] g = new GuiTextField(f, 55,230, 100,100) %(#cc7832)[; ] g.setVisible(true)%(#cc7832)[; ] g.drawTextBox()%(#cc7832)[; ] g.setText("Pseudo du joueurs")%(#cc7832)[; ] g.setFocused(true)%(#cc7832)[; ] g.setEnabled(true)%(#cc7832)[; ] %(#808080)[// g.drawTextBox(); ]%(#808080)[ // this.buttonList.add(g); ] this.buttonList.add(new GuiButton(32, this.width / 2 - 100, i+ 24, 200, 20, "Valide") { %(#bbb529)[@Override ] public void mouseReleased(int x, int y) { mc.currentScreen.confirmClicked(true, 1)%(#cc7832)[; ] playerInv.closeInventory()%(#cc7832)[; ] EntityPlayer p1 = playerInv.player%(#cc7832)[; ] MinecraftServer mc1 = FMLServerHandler.*instance*().getServer()%(#cc7832)[; ] for(GameProfile g1 : mc1.func_152357_F()) { if(g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId())%(#cc7832)[; ] p.inventory.addItemStackToInventory(new ItemStack(GloryRP.*MenotesItem*,1))%(#cc7832)[; ] } else { IChatComponent msg = IChatComponent.Serializer.*func_150699_a*("§4Erreur : la personne demandé n'existe pas.")%(#cc7832)[; ] p1.addChatMessage(msg)%(#cc7832)[; ] } } } })%(#cc7832)[; ] int k%(#cc7832)[; ] for (k = 0; k < this.buttonList.size(); ++k) { ((GuiButton)this.buttonList.get(k)).drawButton(this.mc, x, y)%(#cc7832)[; ] } // this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName(), new Object[0), 8, this.ySize - 96 + 2, 4210752); ] } protected void actionPerformed(GuiButton button) { if(button.id == 0) { this.mc.currentScreen.confirmClicked(true, 1)%(#cc7832)[; ] playerInv.closeInventory()%(#cc7832)[; ] EntityPlayer p1 = playerInv.player%(#cc7832)[; ] MinecraftServer mc1 = FMLServerHandler.*instance*().getServer()%(#cc7832)[; ] for (GameProfile g1 : mc1.func_152357_F()) { if (g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId())%(#cc7832)[; ] p.inventory.addItemStackToInventory(new ItemStack(GloryRP.*MenotesItem*, 1))%(#cc7832)[; ] } else { IChatComponent msg = IChatComponent.Serializer.*func_150699_a*("§4Erreur : la personne demandé n'existe pas.")%(#cc7832)[; ] p1.addChatMessage(msg)%(#cc7832)[; ] } } } } %(#629755)[*/** *]%(#629755)[* * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). *]%(#629755)[* */ *] protected void keyTyped(char p_73869_1_, int p_73869_2_) { this.g.textboxKeyTyped(p_73869_1_, p_73869_2_)%(#cc7832)[; ] if (p_73869_2_ == 15) { this.g.setFocused(!this.g.isFocused())%(#cc7832)[; ] %(#808080)[// this.field_146308_f.setFocused(!this.field_146308_f.isFocused()); ] } } %(#bbb529)[@Override ] protected void drawGuiContainerBackgroundLayer(float prt, int x, int y) { GL11.*glColor4f*(1.0F, 1.0F, 1.0F, 1.0F)%(#cc7832)[; ] this.mc.getTextureManager().bindTexture(*texture*)%(#cc7832)[; ] %(#808080)[// Centering GUI ] int k = (this.width - this.xSize) / 2%(#cc7832)[; ] int l = (this.height - this.ySize) / 2%(#cc7832)[; ] %(#808080)[// Drawing the first part of the GUI (slots of the backpack) ] this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.rows * 18 + 17)%(#cc7832)[; ] %(#808080)[// And after the slots from the player's inventory ] this.drawTexturedModalRect(k, l + this.rows * 18 + 17, 0, 126, this.xSize, 96)%(#cc7832)[; ] } %(#bbb529)[@Override ] protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { super.mouseClicked(mouseX, mouseY, mouseButton)%(#cc7832)[; ] this.g.mouseClicked(mouseX, mouseY, mouseButton)%(#cc7832)[; ] } }
-
Voici comment j’ajoute un GuiTextField à mon Gui
D’abord tu crée la variable en dehors de la classe sans l’initialiser.
private GuiTextField name;Et tu peux maintenant l’initialiser dans la méthode initGui:
name= new GuiTextField(fontRenderer, width / 2 - 100, height / 4 + 10, 200, 20);
name.setMaxStringLength(31);
name.func_50033_b(true);Soit la méthode setFocused, soit setEnabled. Au pire rajoute les deux
name.setText(camel.name);Ensuite tu te sers de la méthode updateScreen pour faire la chose suivante:
public void updateScreen()
{
name.updateCursorCounter();
}Pour la méthode keyTyped, ce que tu as mis me semble déjà être correct. Je regarderai quand même si c’est vraiment le cas, quand j’aurai le temps.
Quant à la méthode mouseClicked, idem…Et enfin la dernière chose à ajouter est:
public void drawScreen(int i, int j, float f)
{
namescreen.drawTextBox();
super.drawScreen(i, j, f);
}Voilà après j’ai peut-être pas les mêmes mappings que toi, notamment pour la méthode func_50033_b, au pire dis le moi, je rechercherai l’équivalent
-
Pourquoi c’est dans la méthode “[size=smalldrawGuiContainerForegroundLayer][size=small(][size=smallint] [size=smallx][size=small,] int [size=smally][font=Courier New)” ]?!?!?
Il faut mettre ça dans la méthode init().Le reste me semble correct.
-
Bonjours, voici ma class :
[font=Courier Newpackage ]fr.ph1823.MyLife.Gui.Amandes%(#cc7832)[; ] %(#629755)[*/** *]%(#629755)[* * Created by ph1823 - Minecraft on 29/02/2016. *]%(#629755)[* */ *] import com.mojang.authlib.GameProfile%(#cc7832)[; ]import cpw.mods.fml.client.FMLClientHandler%(#cc7832)[; ]import cpw.mods.fml.server.FMLServerHandler%(#cc7832)[; ]import fr.ph1823.MyLife.GloryRP%(#cc7832)[; ]import fr.ph1823.MyLife.Gui.Amandes.inv.InventoryBackPack%(#cc7832)[; ]import fr.ph1823.MyLife.Item.Search%(#cc7832)[; ]import net.minecraft.client.gui.*%(#cc7832)[; ]import net.minecraft.client.gui.inventory.GuiContainer%(#cc7832)[; ]import net.minecraft.client.resources.I18n%(#cc7832)[; ]import net.minecraft.entity.player.EntityPlayer%(#cc7832)[; ]import net.minecraft.entity.player.InventoryPlayer%(#cc7832)[; ]import net.minecraft.item.ItemStack%(#cc7832)[; ]import net.minecraft.nbt.NBTBase%(#cc7832)[; ]import net.minecraft.server.MinecraftServer%(#cc7832)[; ]import net.minecraft.util.IChatComponent%(#cc7832)[; ]import net.minecraft.util.ResourceLocation%(#cc7832)[; ] import org.lwjgl.input.Keyboard%(#cc7832)[; ]import org.lwjgl.opengl.GL11%(#cc7832)[; ]import fr.ph1823.MyLife.Gui.Amandes.inv.container.*%(#cc7832)[; ] import java.awt.*%(#cc7832)[; ]import java.io.IOException%(#cc7832)[; ]import java.net.URI%(#cc7832)[; ]import java.util.ArrayList%(#cc7832)[; ]import java.util.List%(#cc7832)[; ] public class Amendes extends GuiContainer { public GuiTextField g%(#cc7832)[; ] public static final ResourceLocation *texture *= new ResourceLocation("guicustom","textures/a.png")%(#cc7832)[; ] protected InventoryBackPack inv%(#cc7832)[; ] protected InventoryPlayer playerInv%(#cc7832)[; ] public int rows%(#cc7832)[; ] public Amendes(InventoryPlayer playerInv, InventoryBackPack inv) { super(new ContainerBackPack(playerInv, inv))%(#cc7832)[; ] this.playerInv = playerInv%(#cc7832)[; ] this.inv = inv%(#cc7832)[; ] this.allowUserInput = %(#cc7832)[false; ] %(#808080)[// Calculate the number of rows ] this.rows = inv.getSizeInventory() / 9%(#cc7832)[; ] %(#808080)[// Height of the GUI using the number of rows ] this.ySize = 114 + this.rows * 18%(#cc7832)[; ] } protected List buttonList = new ArrayList()%(#cc7832)[; ] public void init() { int i = this.height / 4 + 48%(#cc7832)[; ] FontRenderer f = this.mc.fontRenderer%(#cc7832)[; ] g = new GuiTextField(f, 55,230, 100,100) %(#cc7832)[; ] g.setVisible(true)%(#cc7832)[; ] g.drawTextBox()%(#cc7832)[; ] g.setText("Pseudo du joueurs")%(#cc7832)[; ] g.setFocused(true)%(#cc7832)[; ] g.setEnabled(true)%(#cc7832)[; ] %(#808080)[// g.drawTextBox(); ]%(#808080)[ // this.buttonList.add(g); ] this.buttonList.add(new GuiButton(32, this.width / 2 - 100, i+ 24, 200, 20, "Valide") { %(#bbb529)[@Override ] public void mouseReleased(int x, int y) { mc.currentScreen.confirmClicked(true, 1)%(#cc7832)[; ] playerInv.closeInventory()%(#cc7832)[; ] EntityPlayer p1 = playerInv.player%(#cc7832)[; ] MinecraftServer mc1 = FMLServerHandler.*instance*().getServer()%(#cc7832)[; ] for(GameProfile g1 : mc1.func_152357_F()) { if(g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId())%(#cc7832)[; ] p.inventory.addItemStackToInventory(new ItemStack(GloryRP.*MenotesItem*,1))%(#cc7832)[; ] } else { IChatComponent msg = IChatComponent.Serializer.*func_150699_a*("§4Erreur : la personne demandé n'existe pas.")%(#cc7832)[; ] p1.addChatMessage(msg)%(#cc7832)[; ] } } } })%(#cc7832)[; ] } public void onGuiClosed() { Keyboard.*enableRepeatEvents*(false)%(#cc7832)[; ] } %(#bbb529)[@Override ] protected void drawGuiContainerForegroundLayer(int x, int y) { Keyboard.*enableRepeatEvents*(true)%(#cc7832)[; ] // this.fontRendererObj.drawString(I18n.format(this.inv.getInventoryName(), new Object[0), 8, 6, 4210752); ] int k%(#cc7832)[; ] for (k = 0; k < this.buttonList.size(); ++k) { ((GuiButton)this.buttonList.get(k)).drawButton(this.mc, x, y)%(#cc7832)[; ] } // this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName(), new Object[0), 8, this.ySize - 96 + 2, 4210752); ] } protected void actionPerformed(GuiButton button) { if(button.id == 0) { this.mc.currentScreen.confirmClicked(true, 1)%(#cc7832)[; ] playerInv.closeInventory()%(#cc7832)[; ] EntityPlayer p1 = playerInv.player%(#cc7832)[; ] MinecraftServer mc1 = FMLServerHandler.*instance*().getServer()%(#cc7832)[; ] for (GameProfile g1 : mc1.func_152357_F()) { if (g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId())%(#cc7832)[; ] p.inventory.addItemStackToInventory(new ItemStack(GloryRP.*MenotesItem*, 1))%(#cc7832)[; ] } else { IChatComponent msg = IChatComponent.Serializer.*func_150699_a*("§4Erreur : la personne demandé n'existe pas.")%(#cc7832)[; ] p1.addChatMessage(msg)%(#cc7832)[; ] } } } } %(#629755)[*/** *]%(#629755)[* * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). *]%(#629755)[* */ *] protected void keyTyped(char p_73869_1_, int p_73869_2_) { this.g.textboxKeyTyped(p_73869_1_, p_73869_2_)%(#cc7832)[; ] if (p_73869_2_ == 15) { this.g.setFocused(!this.g.isFocused())%(#cc7832)[; ] %(#808080)[// this.field_146308_f.setFocused(!this.field_146308_f.isFocused()); ] } } %(#bbb529)[@Override ] protected void drawGuiContainerBackgroundLayer(float prt, int x, int y) { GL11.*glColor4f*(1.0F, 1.0F, 1.0F, 1.0F)%(#cc7832)[; ] this.mc.getTextureManager().bindTexture(*texture*)%(#cc7832)[; ] %(#808080)[// Centering GUI ] int k = (this.width - this.xSize) / 2%(#cc7832)[; ] int l = (this.height - this.ySize) / 2%(#cc7832)[; ] %(#808080)[// Drawing the first part of the GUI (slots of the backpack) ] this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.rows * 18 + 17)%(#cc7832)[; ] %(#808080)[// And after the slots from the player's inventory ] this.drawTexturedModalRect(k, l + this.rows * 18 + 17, 0, 126, this.xSize, 96)%(#cc7832)[; ] } public void updateScreen() { g.updateCursorCounter()%(#cc7832)[; ] } %(#bbb529)[@Override ] protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { super.mouseClicked(mouseX, mouseY, mouseButton)%(#cc7832)[; ] this.g.mouseClicked(mouseX, mouseY, mouseButton)%(#cc7832)[; ] } public void drawScreen(int i, int j, float f) { %(#808080)[// mc.currentScreen.drawTextBox(); ] super.drawScreen(i, j, f)%(#cc7832)[; ] } }
P.S Sans le init ca fait crash, je voulait savoir si avec comme ca ca serais bon?
-
Met un @Override car je sais plus si c’est init() ou initGui()
-
c’est initGui, il faut toujours mettre les @Override
-
Bonjours, c’est bien ce que j’ai fait sauf que maintenant le GuiTextField ne s’affiche pas, et en plus le validé ne fait rien. voici le code :
package fr.ph1823.MyLife.Gui.Amandes; /** * Created by ph1823 - Minecraft on 29/02/2016. */ import com.mojang.authlib.GameProfile; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.server.FMLServerHandler; import fr.ph1823.MyLife.GloryRP; import fr.ph1823.MyLife.Gui.Amandes.inv.InventoryBackPack; import fr.ph1823.MyLife.Item.Search; import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.server.MinecraftServer; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import fr.ph1823.MyLife.Gui.Amandes.inv.container.*; import java.awt.*; import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.List; public class Amendes extends GuiContainer { public GuiTextField g; public static final ResourceLocation texture = new ResourceLocation("guicustom","textures/a.png"); protected InventoryBackPack inv; protected InventoryPlayer playerInv; public int rows; public Amendes(InventoryPlayer playerInv, InventoryBackPack inv) { super(new ContainerBackPack(playerInv, inv)); this.playerInv = playerInv; this.inv = inv; this.allowUserInput = false; // Calculate the number of rows this.rows = inv.getSizeInventory() / 9; // Height of the GUI using the number of rows this.ySize = 114 + this.rows * 18; } protected List buttonList = new ArrayList(); @Override public void initGui() { int i = this.height / 4 + 48; FontRenderer f = this.mc.fontRenderer; g = new GuiTextField(f, 55,230, 100,100) ; g.setVisible(true); g.drawTextBox(); g.setText("Pseudo du joueurs"); g.setFocused(true); g.setEnabled(true); // g.drawTextBox(); // this.buttonList.add(g); this.buttonList.add(new GuiButton(32, this.width / 2 - 100, i+ 24, 200, 20, "Valide") { @Override public void mouseReleased(int x, int y) { mc.currentScreen.confirmClicked(true, 1); playerInv.closeInventory(); EntityPlayer p1 = playerInv.player; MinecraftServer mc1 = FMLServerHandler.instance().getServer(); for(GameProfile g1 : mc1.func_152357_F()) { if(g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId()); p.inventory.addItemStackToInventory(new ItemStack(GloryRP.MenotesItem,1)); } else { IChatComponent msg = IChatComponent.Serializer.func_150699_a("§4Erreur : la personne demandé n'existe pas."); p1.addChatMessage(msg); } } int k; for (k = 0; k < buttonList.size(); ++k) { ((GuiButton) buttonList.get(k)).drawButton(mc, x, y); } } }); } public void onGuiClosed() { Keyboard.enableRepeatEvents(false); } protected void drawGuiContainerForegroundLayer(int x, int y) { int k; for (k = 0; k < this.buttonList.size(); ++k) { ((GuiButton) this.buttonList.get(k)).drawButton(this.mc, x, y); } } /* @Override protected void drawGuiContainerForegroundLayer(int x, int y) { Keyboard.enableRepeatEvents(true); // this.fontRendererObj.drawString(I18n.format(this.inv.getInventoryName(), new Object[0]), 8, 6, 4210752); int k; for (k = 0; k < this.buttonList.size(); ++k) { ((GuiButton)this.buttonList.get(k)).drawButton(this.mc, x, y); } // this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName(), new Object[0]), 8, this.ySize - 96 + 2, 4210752); }*/ protected void actionPerformed(GuiButton button) { if(button.id == 0) { this.mc.currentScreen.confirmClicked(true, 1); playerInv.closeInventory(); EntityPlayer p1 = playerInv.player; MinecraftServer mc1 = FMLServerHandler.instance().getServer(); for (GameProfile g1 : mc1.func_152357_F()) { if (g.getText().equals(g1.getName())) { EntityPlayer p = mc1.getEntityWorld().func_152378_a(g1.getId()); p.inventory.addItemStackToInventory(new ItemStack(GloryRP.MenotesItem, 1)); } else { IChatComponent msg = IChatComponent.Serializer.func_150699_a("§4Erreur : la personne demandé n'existe pas."); p1.addChatMessage(msg); } } } } /** * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). */ protected void keyTyped(char p_73869_1_, int p_73869_2_) { this.g.textboxKeyTyped(p_73869_1_, p_73869_2_); if (p_73869_2_ == 15) { this.g.setFocused(!this.g.isFocused()); // this.field_146308_f.setFocused(!this.field_146308_f.isFocused()); } } @Override protected void drawGuiContainerBackgroundLayer(float prt, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); // Centering GUI int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; // Drawing the first part of the GUI (slots of the backpack) this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.rows * 18 + 17); // And after the slots from the player's inventory this.drawTexturedModalRect(k, l + this.rows * 18 + 17, 0, 126, this.xSize, 96); } public void updateScreen() { g.updateCursorCounter(); } @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { super.mouseClicked(mouseX, mouseY, mouseButton); this.g.mouseClicked(mouseX, mouseY, mouseButton); } public void drawScreen(int i, int j, float f) { // mc.currentScreen.drawTextBox(); super.drawScreen(i, j, f); } }
Merci de vos réponse.
-
Ah oui il faut que tu laisses g.drawTextBox dans la fonction draw où il était avant.
-
Bonjours, cela ne change rien, quand on tente de changé le texte ou autre cela ne marche toujours pas même en appuyant sur validé
-
Punaise c’est pourtant pas compliqué de faire une texte box x)
Il suffit de reprendre le même code que dans GuiRepair -
Surtout que je t’ai donné tous les éléments. Clean entièrement ta classe et repart à 0, en faisant des pauses de temps en temps pour vérifier le résultat. Il n’y a que comme ça que tu y arriveras…