Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

robertcars

Members
  • Joined

  • Last visited

Everything posted by robertcars

  1. it still didnt work after changing that
  2. Yes right here I did notice i don't know if this helps but when I put System.out.println("test"); in my Guihandler in the getClientGuiElement and try to open the GUI it doesn't print. But im not sure if even if it was working if it would print either.
  3. Im sorry I must have messed up putting my code in. here is my guihandler package com.robertcars.generaltech.gui; import com.robertcars.generaltech.container.ContainerTeleporter; import com.robertcars.generaltech.lib.GuiIDS; import com.robertcars.generaltech.tileentity.TileEntityTeleporter; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler { public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch (ID) { case GuiIDS.guiIDTeleporter: if(entity instanceof TileEntityTeleporter) { return new ContainerTeleporter(player.inventory, (TileEntityTeleporter) entity); } } } return null; } public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch (ID) { case GuiIDS.guiIDTeleporter: if(entity instanceof TileEntityTeleporter) { return new GuiTeleporter(player.inventory, (TileEntityTeleporter) entity); } } } return null; } }
  4. So I am trying to get my GUI to open and its not and I'm not sure why can someone please help me other thanks. My main mod class GuiHandler Gui class Container TileEntity Block
  5. It works now! Thank you so much for your help you've been really nice and helpful.
  6. GuiKeyPad.java package com.techmod.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.world.IBlockAccess; import org.lwjgl.opengl.GL11; import com.techmod.client.container.ContainerKeyPad; import com.techmod.client.tileentity.TileEntityKeyPad; public class GuiKeyPad extends GuiContainer { public IBlockAccess world; @SuppressWarnings("unused") private TileEntityKeyPad tileEntityKeyPad; private GuiTextField textfield; public static TileEntityKeyPad tileentitykeypad = new TileEntityKeyPad(); public static String text = "Keypad"; private static String pass = null; public GuiKeyPad(InventoryPlayer inventoryPlayer, TileEntityKeyPad keypad) { super(new ContainerKeyPad(inventoryPlayer, keypad)); tileEntityKeyPad = keypad; xSize = 176; ySize = 175; } @SuppressWarnings("unchecked") public void initGui() { this.buttonList.clear(); //int posX = (this.width - xSize) / 2; int posY = (this.height - ySize) / 2; //if(this.KeyPad.pass == null) { TileEntityKeyPad tile = (TileEntityKeyPad) tileentitykeypad.getWorldObj().getTileEntity(tileentitykeypad.xCoord, tileentitykeypad.yCoord, tileentitykeypad.zCoord); if (tile != null) { if(tileentitykeypad.pass == null || tileentitykeypad.pass.isEmpty()) { this.buttonList.add(new GuiButton(0, this.width / 2 - 100 / 2, posY + 150, 100, 20, "Set Password")); }else{ this.buttonList.add(new GuiButton(12, this.width / 2 - 100 / 2, posY + 150, 100, 20, "Enter")); } this.buttonList.add(new GuiButton(1, this.width / 2 - 20 - 30 / 2, posY + 50, 20, 20, "1")); this.buttonList.add(new GuiButton(2, this.width / 2 - 20 / 2, posY + 50, 20, 20, "2")); this.buttonList.add(new GuiButton(3, this.width / 2 - 20 + 70 / 2, posY + 50, 20, 20, "3")); this.buttonList.add(new GuiButton(4, this.width / 2 - 20 - 30 / 2, posY + 75, 20, 20, "4")); this.buttonList.add(new GuiButton(5, this.width / 2 - 20 / 2, posY + 75, 20, 20, "5")); this.buttonList.add(new GuiButton(6, this.width / 2 - 20 + 70 / 2, posY + 75, 20, 20, "6")); this.buttonList.add(new GuiButton(7, this.width / 2 - 20 - 30 / 2, posY + 100, 20, 20, "7")); this.buttonList.add(new GuiButton(8, this.width / 2 - 20 / 2, posY + 100, 20, 20, "8")); this.buttonList.add(new GuiButton(9, this.width / 2 - 20 + 70 / 2, posY + 100, 20, 20, "9")); this.buttonList.add(new GuiButton(10, this.width / 2 - 20 / 2, posY + 125, 20, 20, "0")); this.buttonList.add(new GuiButton(11, this.width / 2 - 20 + 70 / 2, posY + 125, 20, 20, "<-")); textfield = new GuiTextField(fontRendererObj, this.width / 2 - 70 / 2, this.height / 2 - 65, 70, 20); textfield.setFocused(false); textfield.setMaxStringLength(10); } } public void updateScreen() { pass = textfield.getText(); } @Override protected void drawGuiContainerForegroundLayer(int x, int y) { fontRendererObj.drawString(text, this.width / 2 - 15, this.height / 2 - 80, 4210752); } public void drawScreen(int i, int j, float f) { super.drawScreen(i, j, f); textfield.drawTextBox(); } protected void actionPerformed(GuiButton guibutton) { TileEntityKeyPad tile = (TileEntityKeyPad) tileentitykeypad.getWorldObj().getTileEntity(tileentitykeypad.xCoord, tileentitykeypad.yCoord, tileentitykeypad.zCoord); if(guibutton.id == 0) { if (tile != null) { if(tileentitykeypad.pass == null) { tileentitykeypad.pass = pass; }else{ } } } if(guibutton.id == 12) { if (tile != null) { if(tileentitykeypad.pass == null) { }else{ String np = textfield.getText(); if(np.equals(tileentitykeypad.pass)) { System.out.println("dddasd"); } } } } if(guibutton.id == 1) { pass = pass + "1"; textfield.setText(pass); } if(guibutton.id == 2) { pass = pass + "2"; textfield.setText(pass); } if(guibutton.id == 3) { pass = pass + "3"; textfield.setText(pass); } if(guibutton.id == 4) { pass = pass + "4"; textfield.setText(pass); } if(guibutton.id == 5) { pass = pass + "5"; textfield.setText(pass); } if(guibutton.id == 6) { pass = pass + "6"; textfield.setText(pass); } if(guibutton.id == 7) { pass = pass + "7"; textfield.setText(pass); } if(guibutton.id == { pass = pass + "8"; textfield.setText(pass); } if(guibutton.id == 9) { pass = pass + "9"; textfield.setText(pass); } if(guibutton.id == 10) { pass = pass + "0"; textfield.setText(pass); } if(guibutton.id == 11) { if(pass != null && pass != "") { pass = pass.substring(0, pass.length() - 1); textfield.setText(pass); } } } @Override protected void drawGuiContainerBackgroundLayer(float opacity, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(Textures.KEY_PAD); int xStart = (width - xSize) / 2; int yStart = (height - ySize) / 2; this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize); } } TileEntityKeyPad.java package com.techmod.client.tileentity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileEntityKeyPad extends TileEntity { public String pass; public int pa; public void readFromNBT(NBTTagCompound p_145839_1_) { super.readFromNBT(p_145839_1_); pass = p_145839_1_.getString("Pass"); } public void writeToNBT(NBTTagCompound p_145841_1_) { super.writeToNBT(p_145841_1_); p_145841_1_.setString("Pass", pass); } }
  7. Well I got that working but now but all the tileentitys of the same type have the same string. Say tile entity a has the password 123 the all the others of that same type have it do you know what is causing that? Btw thank you so much for your help.
  8. Are you saying to make a instance like public TileEntityKeyPad tileentitykeypad;? if so when I do that I crash when using the set password button. And the reason I use new TileEntityKeyPad() is because I was told to make the variables in the tileentity class non static to fix another problem and that was the only way I could figure out how to fix it and not crash
  9. So I am trying to set the string pass which is in my tile entity class from my gui class but its not doing so. GuiKeyPad package com.techmod.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.world.IBlockAccess; import org.lwjgl.opengl.GL11; import com.techmod.client.container.ContainerKeyPad; import com.techmod.client.tileentity.TileEntityKeyPad; public class GuiKeyPad extends GuiContainer { @SuppressWarnings("unused") private TileEntityKeyPad tileEntityKeyPad; private GuiTextField textfield; public static String text = "Keypad"; private static String pass = null; public GuiKeyPad(InventoryPlayer inventoryPlayer, TileEntityKeyPad keypad) { super(new ContainerKeyPad(inventoryPlayer, keypad)); tileEntityKeyPad = keypad; xSize = 176; ySize = 175; } @SuppressWarnings("unchecked") public void initGui() { this.buttonList.clear(); //int posX = (this.width - xSize) / 2; int posY = (this.height - ySize) / 2; //if(this.KeyPad.pass == null) { if(new TileEntityKeyPad().pass == null || new TileEntityKeyPad().pass.isEmpty()) { this.buttonList.add(new GuiButton(0, this.width / 2 - 100 / 2, posY + 150, 100, 20, "Set Password")); }else{ this.buttonList.add(new GuiButton(12, this.width / 2 - 100 / 2, posY + 150, 100, 20, "Enter")); } this.buttonList.add(new GuiButton(1, this.width / 2 - 20 - 30 / 2, posY + 50, 20, 20, "1")); this.buttonList.add(new GuiButton(2, this.width / 2 - 20 / 2, posY + 50, 20, 20, "2")); this.buttonList.add(new GuiButton(3, this.width / 2 - 20 + 70 / 2, posY + 50, 20, 20, "3")); this.buttonList.add(new GuiButton(4, this.width / 2 - 20 - 30 / 2, posY + 75, 20, 20, "4")); this.buttonList.add(new GuiButton(5, this.width / 2 - 20 / 2, posY + 75, 20, 20, "5")); this.buttonList.add(new GuiButton(6, this.width / 2 - 20 + 70 / 2, posY + 75, 20, 20, "6")); this.buttonList.add(new GuiButton(7, this.width / 2 - 20 - 30 / 2, posY + 100, 20, 20, "7")); this.buttonList.add(new GuiButton(8, this.width / 2 - 20 / 2, posY + 100, 20, 20, "8")); this.buttonList.add(new GuiButton(9, this.width / 2 - 20 + 70 / 2, posY + 100, 20, 20, "9")); this.buttonList.add(new GuiButton(10, this.width / 2 - 20 / 2, posY + 125, 20, 20, "0")); this.buttonList.add(new GuiButton(11, this.width / 2 - 20 + 70 / 2, posY + 125, 20, 20, "<-")); textfield = new GuiTextField(fontRendererObj, this.width / 2 - 70 / 2, this.height / 2 - 65, 70, 20); textfield.setFocused(false); textfield.setMaxStringLength(10); } public void updateScreen() { pass = textfield.getText(); } @Override protected void drawGuiContainerForegroundLayer(int x, int y) { fontRendererObj.drawString(text, this.width / 2 - 15, this.height / 2 - 80, 4210752); } public void drawScreen(int i, int j, float f) { super.drawScreen(i, j, f); textfield.drawTextBox(); } protected void actionPerformed(GuiButton guibutton) { IBlockAccess world; if(guibutton.id == 0) { if(new TileEntityKeyPad().pass == null) { new TileEntityKeyPad().pass = pass; System.out.println(new TileEntityKeyPad().pass); }else{ } } if(guibutton.id == 12) { if(new TileEntityKeyPad().pass == null) { }else{ String np = textfield.getText(); if(np.equals(new TileEntityKeyPad().pass)) { System.out.println("dddasd"); } } } if(guibutton.id == 1) { pass = pass + "1"; textfield.setText(pass); } if(guibutton.id == 2) { pass = pass + "2"; textfield.setText(pass); } if(guibutton.id == 3) { pass = pass + "3"; textfield.setText(pass); } if(guibutton.id == 4) { pass = pass + "4"; textfield.setText(pass); } if(guibutton.id == 5) { pass = pass + "5"; textfield.setText(pass); } if(guibutton.id == 6) { pass = pass + "6"; textfield.setText(pass); } if(guibutton.id == 7) { pass = pass + "7"; textfield.setText(pass); } if(guibutton.id == { pass = pass + "8"; textfield.setText(pass); } if(guibutton.id == 9) { pass = pass + "9"; textfield.setText(pass); } if(guibutton.id == 10) { pass = pass + "0"; textfield.setText(pass); } if(guibutton.id == 11) { if(pass != null && pass != "") { pass = pass.substring(0, pass.length() - 1); textfield.setText(pass); } } } @Override protected void drawGuiContainerBackgroundLayer(float opacity, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(Textures.KEY_PAD); int xStart = (width - xSize) / 2; int yStart = (height - ySize) / 2; this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize); } } TileEntityKeyPad package com.techmod.client.tileentity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class TileEntityKeyPad extends TileEntity { public String pass; public int pa; public void readFromNBT(NBTTagCompound p_145839_1_) { super.readFromNBT(p_145839_1_); pass = p_145839_1_.getString("Pass"); } public void writeToNBT(NBTTagCompound p_145841_1_) { super.writeToNBT(p_145841_1_); p_145841_1_.setString("Pass", pass); } }
  10. Could you please explain a little more on where and how to use the world.getTileEntity(x,y,z). Would I use it in the TileEntityClass or somewhere else?
  11. Thanks for the respond I'm at school right now so ill try it when I get home.
  12. I am trying to save the password that someone entered every time you save it though all the tile entitys in the world have the same one. So if tile entity A has the password 123 all the other tile entitys of the same type have the same password 123. Can someone please help me thanks alot. package com.techmod.client.tileentity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileEntityKeyPad extends TileEntity { public static String pass; public static int pa; public void readFromNBT(NBTTagCompound p_145839_1_) { super.readFromNBT(p_145839_1_); TileEntityKeyPad.pass = p_145839_1_.getString("Pass"); } public void writeToNBT(NBTTagCompound p_145841_1_) { super.writeToNBT(p_145841_1_); p_145841_1_.setString("Pass", TileEntityKeyPad.pass); } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.