Head NBT code [UNSOLVED]

Discussion in 'Plugin Development' started by MYCRAFTisbest, Oct 28, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    MYCRAFTisbest

    I am trying to make it so players can craft a pre-defined player's head in a crafting box.
    How would i attach a skullowner to this code?

    Code:
            if (this.getConfig().getBoolean("HEAD_Creator", true)){
                ItemStack headMycraftItem = new ItemStack(Material.SKULL_ITEM, 1, (short)0, (byte)3);
     
                ShapedRecipe headMycraft = new ShapedRecipe(headMycraftItem);
     
     
                headMycraft.shape(
                        "DDD",
                        "DDD",
                        "DDD");
                headMycraft.setIngredient('D', Material.DIAMOND);
                Bukkit.addRecipe(headMycraft);
     
                }
    NOTE: I don't need any variables, just ore-defined names of players.

    If you solve this, I will add your player's head to the plugin.
     
  2. you need to hook into the NBT tags of the ItemStack, to define the tag that is used for the skull owner, sorry, I dont know how to hook exactly, as this mostly chances from update to update
     
  3. Offline

    Tzeentchful

    Someone has already witten a plugin to do this. you can check out his source code here.
     
  4. Offline

    MYCRAFTisbest

    Not rly. I can use the code to help me but this isn't exactly what i am doing. I am making heads craftable in a crafting box.

    Thanks for the help, but I already knew that much

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  5. Offline

    Tzeentchful

    ok i think i've got it. i can't test it atm but this should work.
    You will need to compile against craftbukkit.
    Code:
    public ItemStack addOwner(ItemStack is, String owner){
    CraftItemStack cis = (CraftItemStack) is;
            NBTTagCompound tags = cis.getHandle().tag;
            tags.setString("SkullOwner", owner);
            return cis;
              }
    
     
  6. Offline

    MYCRAFTisbest

    I have been trying to get that code to work for a while, but it isn't completely correct.
    Something is missing.

    Tried a few more things and still can't figure this out

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  7. Offline

    Tzeentchful

    Sorry i was on my phone before and could't test it . Here is one that i can confirm works.
    PHP:
    public ItemStack setOwner(ItemStack iitemString owner){
            
    net.minecraft.server.ItemStack item null;
            
    CraftItemStack stack null;
     
                
    stack = new CraftItemStack(iitem);
                
    item stack.getHandle();
         
            
    NBTTagCompound tags item.tag;
            
    tags item.tag = new NBTTagCompound();
         
            if(
    owner != null && !owner.equals("")) {
                
    tags.setString("SkullOwner"owner);
            }
         
            return 
    stack;
           
            }
    I will just note that bukkit doesn't keep the NBT data when you do world.dropItemNaturally(...) or when you break a had block with SkullOwner set.
     
    xGhOsTkiLLeRx likes this.
  8. Offline

    Codex Arcanum

    Have a link to someone else who appears to be doing this.
     
  9. Offline

    MYCRAFTisbest

    I am editing what you gave me to help me make this
    Thanks for the help, but you don't seem to understand. I am making it so heads can be crafted in a crafting box.

    Ok, so i tried this code
    Code:
            if (this.getConfig().getBoolean("HEAD_Creator", true)){
                ItemStack headMycraftItem = new ItemStack(Material.SKULL_ITEM, 1, (short)0, (byte)3);
         
                net.minecraft.server.ItemStack item = null;
                CraftItemStack stack = null;
     
                    stack = new CraftItemStack(headMycraftItem);
                    item = stack.getHandle();
           
                NBTTagCompound tags = item.tag;
                tags = item.tag = new NBTTagCompound();
           
                    tags.setString("SkullOwner", "MYCRAFTisbest");
             
                ShapedRecipe headMycraft = new ShapedRecipe(stack);
         
     
                headMycraft.shape(
                        "EEE",
                        "IGI",
                        "GEG");
                headMycraft.setIngredient('E', Material.EMERALD_BLOCK);
                headMycraft.setIngredient('I', Material.INK_SACK);
                headMycraft.setIngredient('G', Material.SULPHUR);
     
                    Bukkit.addRecipe(headMycraft);
     
                }
    The good news is there were no errors or anything, but the bad news is that i just got a steve head

    *NOTE: MYCRAFTisbest is my ign. I want my head to be crafted.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  10. Offline

    Tzeentchful

    Ok i tried making it a recipe. What happened is in the result slot it says "Head" but when i drag it out and place the result in my inventory it changes to "Tzeentchful's Head"
    Here is my code:

    Code:
    public void addRecipe() {
            ItemStack is = new ItemStack(397, 1);
            is.setDurability((short) 3);
            ShapedRecipe recipe = new ShapedRecipe(setOwner(is, "Tzeentchful"));
            recipe.shape("AAA", "ABA", "AAA");
            recipe.setIngredient('A', Material.GOLD_NUGGET);
            recipe.setIngredient('B', Material.DIAMOND);
            this.getServer().addRecipe(recipe);
        }
       
        public ItemStack setOwner(ItemStack iitem, String owner){
            net.minecraft.server.ItemStack item = null;
            CraftItemStack stack = null;
     
                stack = new CraftItemStack(iitem);
                item = stack.getHandle();
       
            NBTTagCompound tags = item.tag;
            tags = item.tag = new NBTTagCompound();
       
            if(owner != null && !owner.equals("")) {
                tags.setString("SkullOwner", owner);
            }
       
            return stack;
         
            }
     
  11. Offline

    MYCRAFTisbest

    I added your code word for word and I am just getting Head still, even after removing it from the crafting box.
     
  12. Offline

    Codex Arcanum

    Ah, my bad. Didn't read the whole thread.
     
  13. Offline

    MYCRAFTisbest

    Still haven't figured this out.

    Starting to get a HEADake
     
  14. Offline

    Log-out

    Try this code:
    Code:
    private CraftItemStack getPlayerHead (String playerName) {
     
            CraftItemStack head = new CraftItemStack(Material.SKULL_ITEM, 1);
            head.setDurability((short)3);
     
            NBTTagCompound tag = new NBTTagCompound();
            tag.set("SkullOwner", new NBTTagString("SkullOwner", playerName));
               
            head.getHandle().setTag(tag);
     
            return head;
        }
     
  15. Offline

    stirante

    Try this:
    Code:java
    1.  
    2. public static ItemStack setSkin(ItemStack item, String nick){
    3. CraftItemStack craftStack = null;
    4. net.minecraft.server.ItemStack itemStack = null;
    5. if (item instanceof CraftItemStack) {
    6. craftStack = (CraftItemStack) item;
    7. itemStack = craftStack.getHandle();
    8. }
    9. else if (item instanceof ItemStack) {
    10. craftStack = new CraftItemStack(item);
    11. itemStack = craftStack.getHandle();
    12. }
    13. NBTTagCompound tag = itemStack.tag;
    14. if (tag == null) {
    15. tag = new NBTTagCompound();
    16. }
    17. tag.setString("SkullOwner", nick);
    18. itemStack.tag = tag;
    19. return craftStack;
    20. }
    21.  

    For example, if player have skull in his hand you will do something like that:
    player.setItemInHand(setSkin(player.getItemInHand(), "skinName"));
     
  16. Offline

    MYCRAFTisbest

    Ok i will try that, still need it in recipe form
    Very helpful, but can't get a complete code, especially with limited power/internet
     
  17. Offline

    xGhOsTkiLLeRx

    This code DOES work. Just tested it.
    Thanks for sharing ;)
     
  18. Offline

    MYCRAFTisbest

    Sadly, it isn't the code i need though.
    It needs to be Pre-defined to one players name and work in a crafting box.

    For instance, adding 9 diamonds in a crafting box = one Notch head.

    Please help. I am so close and lost power in hurricane. Would love to see a working solution next time i get a connection.

    Sadly this isn't what i need.

    I need to be able to craft a head (like Notch) in a crafting box with a recipe.
    How do I attach it to the recipe?

    P.S. Storm = little power + faint internet if lucky.
    Please let me come back to this to see it resolved.

    READ POST^^^:D
    Please return to help (hopefully you have power.) I can't post often and am unsure my posts are even sent.

    Hopefully one of the two I just sent is there for you guys to read. THANKS !

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  19. Offline

    devilquak

    I'm just wondering, how do you implement the item that a crafting recipe creates? If it's possible to make the recipe give an ItemStack, just give an edited skull stack.
     
  20. Offline

    jbman223

    I am wondering the exact same thing! any help is greatly appreciated!
     
  21. Offline

    MYCRAFTisbest

    If the item exists, you can make a recipe for it. The code in the original post will make it so 9 diamonds in a crafting box will give you one Steve head.

    I just want someone other than Steve.

    P.S. Retreated to location with power [torch][fire][torch]
     
  22. Offline

    jbman223

    I am doing the same, but with an item. 7 diamond blocks and a fire-charge and gunpowder give you a stick, I just want the stick it gives you to be called "Super Stick" or something. Whenever I try though, the stick is the a regular stick.
    Recipe as seen in the code:

    DFD
    DGD
    DDD

    D=diamond, F=Firecharge,G=Gunpowder


    When i add the item via command /gfs it works, but when I craft it, it is just a regular stick.

    Code:
    Code:java
    1.  
    2. import java.util.logging.Logger;
    3.  
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.inventory.ItemStack;
    9. import org.bukkit.inventory.ShapedRecipe;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class test extends JavaPlugin {
    13.  
    14. private Logger log = Logger.getLogger("Minecraft");
    15. private final ChatListener listener = new ChatListener(this);
    16.  
    17. @Override
    18. public void onEnable () {
    19. fbShooter();
    20. log.info("Started up brah, ready to pound.");
    21. }
    22. @Override
    23. public void onDisable () {
    24. }
    25.  
    26. private void registerEvents() {
    27. this.getServer().getPluginManager().registerEvents(listener, this);
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    31.  
    32. if (cmd.getLabel().equalsIgnoreCase("gfs")) {
    33. Player p = (Player) sender;
    34. p.getInventory().addItem(ItemNamer.getItemStack());
    35. return true;
    36. }
    37. else {
    38. return false;
    39. }
    40. }
    41.  
    42. public void fbShooter() {
    43. ItemStack i = new ItemStack(Material.STICK, 1);
    44. i.setDurability((short)100);
    45. ItemNamer.load(i);
    46. ItemNamer.setName("Super Stick");
    47.  
    48. ShapedRecipe recipe = new ShapedRecipe(ItemNamer.getItemStack());
    49.  
    50. recipe.shape("DFD", "DGD", "DDD");
    51. recipe.setIngredient('F', Material.FIREBALL);
    52. recipe.setIngredient('G', Material.SULPHUR);
    53. recipe.setIngredient('D', Material.DIAMOND_BLOCK);
    54.  
    55. this.getServer().addRecipe(recipe);
    56. }
    57. }
    58.  


    ItemNamer class: http://forums.bukkit.org/threads/item-name-changing-class.104249/
     
  23. Offline

    MYCRAFTisbest

    It only creates a new recipe. You must use an item used less often that looks similar and code it. Maybe redstone torch off.

    Wait, what am i doing? I still need help myself. Can someone help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  24. Offline

    devilquak

    No, I know what you're trying to do. I'm asking about how you return the item that is given from a recipe, in the code, and if an ItemStack can be given as the recipe return, because if it can, you simply return an edited skull item with your custom NBT tag data.
     
  25. Offline

    MYCRAFTisbest

    Hmm. Maybe. I will try that tomorrow.
     
  26. Offline

    jbman223


    That is what I am trying to do. I cant wait until we are able to solve this.
     
  27. Offline

    travja

    Try using inventory click event to edit the NBT data
     
  28. Offline

    MYCRAFTisbest

    I think that could work, but I want it to work with multiple recipes, not just for one head.

    If I did that I feel like it wouldn't work correctly with more then one since there is only one item with a different code attached.
     
  29. Offline

    jbman223

    With the inventory click, would I just change the item-they-click-on's NBT data?
     
  30. Offline

    MYCRAFTisbest

    Yes but that wouldn't work so well. Maybe if the crafting box had temp item's before receiving like 35:17 (wool with meta data not commonly used)

    Otherwise i wouldn't know how to get that method working.
    I am sure we will figure out the code.

    Again this code didn't work for me. I even tried copying it word for word.
    Is there anything not added to the code that i need to know and do you have an ip for your test server i could join to see this?

    Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page