Posted September 14, 20178 yr Hi, I am working on a mod. I've made a Syring, when you rightclicking it , it will fill with the players blood (i save the player's name and uuid as nbttag in the item). When you hover over the filled syring the Name of the "victim" will be shown (i check the nbt data). My problem is: It seems that the nbt data is for all items the same. When i used a syring and look in the Creative menu the syring in it shows me the name of mine. How can i do it that the nbt is bound to the itemstack? If you need my code: NBT Data (Syring-Use): public class ItemSyringEmpty extends BasicItem{ public ItemSyringEmpty() { super("You can fill the Syring by rightclicking.", "§7Status: §c§lEmpty"); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getUnlocalizedName().contains("itemSyringEmpty")) { int slot = getSlot(playerIn, itemStackIn); if(slot != -1) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data; if(itemStack.hasTagCompound()) data = itemStack.getTagCompound(); else data = new NBTTagCompound(); data.setString("bloodFrom", playerIn.getName()); data.setString("bloodFromID", playerIn.getUniqueID().toString()); itemStack.setTagCompound(data); playerIn.inventory.mainInventory[slot] = itemStack; } } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } private int getSlot(EntityPlayer player, ItemStack item) { try { return player.inventory.getSlotFor(item); }catch (Exception e) { return -1; } } } NBT Data (Syring-Hover-Lore): public class ItemSyringFilled extends BasicItem{ public ItemSyringFilled() { super("Its filled with Blood. It can be \nused to inject medicine or \nyour own virus by rightclicking.", "§7Status: §a§lFilled"); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(stack.hasTagCompound()) { if(stack.getTagCompound().hasKey("bloodFrom")) { this.addLine("§7Blood from: §4" + stack.getTagCompound().getString("bloodFrom")); } } super.addInformation(stack, playerIn, tooltip, advanced); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getUnlocalizedName().contains("itemSyringFilled")) { //TODO inject } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } }
September 14, 20178 yr 41 minutes ago, Darki said: if(itemStackIn.getUnlocalizedName().contains("itemSyringEmpty")) { Why the fuck are you comparing unlocalized name strings? Jesus christ, itemStackIn.getItem() == MainMod.SyringeEmpty 43 minutes ago, Darki said: playerIn.inventory.mainInventory[slot] = itemStack; You do know what ActionResult<ItemStack> means, yes? It means that the item stack that is a part of the ActionResult return is the item that gets put into the player's active inventory slot... As for your asked question, you're doing something really, seriously wrong. I need to see more code, probably your BasicItem class and both syringes in completion. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
September 14, 20178 yr Author Quote Why the fuck are you comparing unlocalized name strings? Jesus christ, itemStackIn.getItem() == MainMod.SyringeEmpty Hmm. Yeah i see. Thats better... Quote You do know what ActionResult<ItemStack> means, yes? It means that the item stack that is a part of the ActionResult return is the item that gets put into the player's active inventory slot... Nope. I didn't know that. Thanks for the info^^ Here the rest of my Code: BasicItem: public abstract class BasicItem extends Item{ private String[] extraLore; private String[] description; public BasicItem(String description, String...extraLore) { setCreativeTab(Diseases.TAB); this.description = description.split("\n"); this.extraLore = extraLore; } public void addLine(String line) { List<String> list = new ArrayList<String>(); for(String str : extraLore) { list.add(str); } if(!list.contains(line)) list.add(line); extraLore = list.toArray(new String[list.size()]); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(extraLore.length > 0) { for(String line : extraLore) { tooltip.add(line); } tooltip.add(" "); } for(String line : description) { tooltip.add("§7" + line); } } } And you do have the syrings on the top^^
September 14, 20178 yr Author Ok. I'll improve it. But one question: How do i use Sub-compound? Never used it^^
September 14, 20178 yr Author Can the Sub-Compound be null? Because i cant see a hasSubCompund Method....
September 15, 20178 yr Author Ok. Here we go: public class ItemSyringEmpty extends BasicItem{ public ItemSyringEmpty() { super("SyringEmpty", "You can fill the Syring by rightclicking.", "§7Status: §c§lEmpty"); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getItem() == Diseases.instance.items.itemSyringEmpty) { int slot = getSlot(playerIn, itemStackIn); if(slot != -1) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data = itemStack.getSubCompound("itemData", true); data.setString("bloodFrom", playerIn.getName()); data.setString("bloodFromID", playerIn.getUniqueID().toString()); playerIn.inventory.mainInventory[slot] = itemStack; } } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { if(stack.getItem() == Diseases.instance.items.itemSyringEmpty) { int slot = getSlot(player, stack); if(slot != -1) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data = itemStack.getSubCompound("itemData", true); data.setString("bloodFrom", entity.getName()); data.setString("bloodFromID", entity.getUniqueID().toString()); Random random = new Random(); if(random.nextInt(10) == 0) { int amount = random.nextInt(2) + 1; while(amount != 0) { amount--; Diseases.instance.dataManager.addDisease(itemStack, EnumDisease.values()[random.nextInt(EnumDisease.values().length)]); } } player.inventory.mainInventory[slot] = itemStack; } } return super.onLeftClickEntity(stack, player, entity); } private int getSlot(EntityPlayer player, ItemStack item) { try { return player.inventory.getSlotFor(item); }catch (Exception e) { return -1; } } I didnt change the line with removing item from inventory by now but i will....^^ public class ItemSyringFilled extends BasicItem{ public ItemSyringFilled() { super("SyringFilled", "Its filled with Blood. It can be \nused to inject medicine or \nyour own virus by rightclicking.", "§7Status: §a§lFilled"); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(stack.hasTagCompound()) { if(stack.getSubCompound("itemData", true).hasKey("bloodFrom")) { this.addLine("§7Blood from: §4" + stack.getSubCompound("itemData", true).getString("bloodFrom")); } if(stack.getSubCompound("itemData", true).hasKey("diseases")) { } } super.addInformation(stack, playerIn, tooltip, advanced); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getItem() == Diseases.instance.items.itemSyringFilled) { //TODO inject } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } }
September 15, 20178 yr Author Yes. I use subcompund. But the other ones: I dont know how to do it. Ok the Exception Catch I could change easily. But never used TextFormatting and Tooltips in the lang file
September 15, 20178 yr Author Just now, diesieben07 said: This is the most important and the source of your problem. Ok this I did solve, i hope: @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getItem() == Diseases.instance.items.itemSyringEmpty) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data = itemStack.getSubCompound("itemData", true); data.setString("bloodFrom", playerIn.getName()); data.setString("bloodFromID", playerIn.getUniqueID().toString()); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStack); } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } 2 minutes ago, diesieben07 said: What do you not understand about these? I dont know how to use it. And can it be dynamic then? So that the item shows the name of the "victim". Can you just explain how to use it (i dont want code^^) just an explaination.
September 15, 20178 yr Author Thank you very much. Its working^^ Normally i code spigot plugins its in some points alot easier
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.