Posted September 11, 201510 yr I have an item that teleports the player when they right click, and saves the location when they shift right click. I want to have the itemstack have a custom name, so the player can get the name when they scroll to the item, which I can set with setStackDisplayName... But how do I get the name string from the GUI? Item Class public class WarpHome extends Item { public WarpHome(String name) { this.setMaxStackSize(1); this.setMaxDamage(64); this.setUnlocalizedName(name); this.setTextureName(Main.MODID + ":" + this.getUnlocalizedName().substring(5)); this.setCreativeTab(ProxyCommon.serialModTab); Main.RegisterItem(this); } @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { NBTTagCompound nbtTagCompound = stack.getTagCompound(); if (nbtTagCompound == null) { nbtTagCompound = new NBTTagCompound(); stack.setTagCompound(nbtTagCompound); } if (player.isSneaking()) { if (!world.isRemote) { GetNameGUI nameGui = new GetNameGUI(stack); Minecraft.getMinecraft().displayGuiScreen(nameGui); //if ((nameGui.name != null) && (!nameGui.name.equals(""))) stack.setStackDisplayName(nameGui.name); } nbtTagCompound.setBoolean("bound", true); nbtTagCompound.setInteger("dimension", player.dimension); nbtTagCompound.setDouble("x", player.posX); nbtTagCompound.setDouble("y", player.posY); nbtTagCompound.setDouble("z", player.posZ); } else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound")) && (player instanceof EntityPlayerMP)) { EntityPlayerMP playerMP = (EntityPlayerMP)player; double x = nbtTagCompound.getDouble("x"); double y = nbtTagCompound.getDouble("y"); double z = nbtTagCompound.getDouble("z"); int dimension = nbtTagCompound.getInteger("dimension"); if (player.dimension != dimension)player.travelToDimension(dimension); playerMP.playerNetServerHandler.setPlayerLocation(x, y, z, playerMP.rotationYaw, playerMP.rotationPitch); world.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F); if (player.isBurning()) player.extinguish(); player.heal(1.0f); stack.damageItem(1, player); } return stack; } @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, EntityPlayer player, List description, boolean advanced) { NBTTagCompound nbtTagCompound = stack.getTagCompound(); if ((nbtTagCompound != null) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound"))) description.add("Warp to x" + nbtTagCompound.getInteger("x") +" y" + nbtTagCompound.getInteger("y") + " z" + nbtTagCompound.getInteger("z") + " d" + nbtTagCompound.getInteger("dimension")); else description.add("Shift + Right Click to store a location"); } } GUI Class public class GetNameGUI extends GuiScreen { public static final int GUI_ID = 20; private int guiWidth = 210; private int guiHeight = 97; private GuiTextField txtName; public String name = ""; private ItemStack caller; public GetNameGUI(ItemStack item) { caller = item; } @Override public void initGui() { txtName = new GuiTextField(fontRendererObj, width / 2 -75, height / 2 -5, 150, 20); txtName.setFocused(true); txtName.setMaxStringLength(32); buttonList.add(new GuiButton(1, width / 2 -50, height / 2 +20, 100, 20, "Done")); } @Override public void keyTyped(char c, int keyCode) { super.keyTyped(c, keyCode); if ((keyCode == Keyboard.KEY_RETURN) || ((keyCode == Keyboard.KEY_E) && (!txtName.isFocused()))) { caller.setStackDisplayName(name); this.mc.displayGuiScreen(null); } txtName.textboxKeyTyped(c, keyCode); } @Override public void mouseClicked(int i, int j, int k) { super.mouseClicked(i, j, k); txtName.mouseClicked(i, j, k); } @Override public void updateScreen() { name = txtName.getText(); } @Override public void drawScreen(int i, int j, float f) { drawDefaultBackground(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(new ResourceLocation(Main.MODID, "textures/gui/name.png")); drawTexturedModalRect((width / 2) - (guiWidth / 2), (height / 2) - (guiHeight / 2), 0, 0, guiWidth, guiHeight); drawCenteredString(fontRendererObj, "Name this location.", width / 2, height / 2 -35, 0xffffff); txtName.drawTextBox(); super.drawScreen(i, j, f); } @Override public void actionPerformed(GuiButton button) { caller.setStackDisplayName(name); this.mc.displayGuiScreen(null); super.actionPerformed(button); } }
September 11, 201510 yr You need to use packets. Send information back from the client to the server, so the server can update the item.
September 12, 201510 yr Author I had never heard of packets in Minecraft before, so I did a search and found this http://www.minecraftforge.net/forum/index.php/topic,20135.0.html It was really easy to implement after I got in the right mindset. TLDR: I named my item stack using a gui plus packets
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.