How to use the new things added in 1.4.6 (no NBT)

Discussion in 'Resources' started by KeybordPiano459, Dec 29, 2012.

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

    KeybordPiano459

    So, I think that this has been going around in the plugin development forum long enough that someone needed to make a thread in the resources section about it. I'll try to add most of the new things that are in high demand for coding that were removed with the NBT stuff that CraftBukkit made in the 1.4.6 update. Feel free to contribute any code snippets in the comments below!


    1. Adding armor to mobs
    Edit these as much as you want, and also, keep in mind that it doesn't have to be a zombie that you're modifying, it can be other mobs, such as a skeleton or a baby zombie (#2)
    Code:java
    1. EntityEquipment equipment = entity.getEquipment();
    2. Zombie zombie = (Zombie) event.getEntity;
    3.  
    4. equipment.setItemInHand(new ItemStack(Material.IRON_SWORD, 1));
    5. equipment.setHelmet(new ItemStack(Material.DIAMOND_HELMET, 1));
    6. equipment.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
    7. equipment.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
    8. equipment.setBoots(new ItemStack(Material.DIAMOND_BOOTS, 1));


    2. Spawning baby zombies/zombie villagers
    With these methods, you can make baby zombies or zombie testificates :)
    Code:java
    1. Zombie zombie = (Zombie) event.getEntity();
    2. zombie.setBaby(true);
    3. zombie.setVillager(true);


    3. Renaming items/Giving items descriptions (1.4.6/no NBT)
    In this case, you would replace "whatever" with what you wanted to name your item, and "I'm a description..." with what you want the description to be. You can also add multiple lines to the description with more lines of 'description.add(string)'.
    Code:java
    1. ItemStack item = new ItemStack(Material.DIAMOND);
    2. ItemMeta meta = item.getItemMeta();
    3. meta.setDisplayName("whatever");
    4. ArrayList<String> description = new ArrayList<String>();
    5. description.add("I'm a description...");
    6. meta.setLore(description);
    7. item.setItemMeta(meta);
    8. player.getInventory().addItem(item);


    4. Coloring leather armor
    This one is pretty similar to #3, it has to do with getting the ItemMeta of the leather armor.
    Code:java
    1. ItemStack helm = new ItemStack(Material.LEATHER_HELMET);
    2. LeatherArmorMeta meta = (LeatherArmorMeta) helm.getItemMeta();
    3. meta.setColor(Color.AQUA);
    4. helm.setItemMeta(meta);
    5. player.getInventory().setHelmet(helm);


    5. Setting skull skins
    This is also similar to #3, just get the skull's itemmeta and edit it.
    Code:java
    1. ItemStack skull = new ItemStack(397, 1, (short) 3);
    2. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    3. meta.setOwner(player.getName());
    4. skull.setItemMeta(meta);
    5. player.getInventory().addItem(skull);


    6. Setting the color of a wolf collar
    For this one, you can't use ChatColor for the color of the wolf collar, you have to use DyeColor, which is basically the same thing.
    Code:java
    1. Wolf wolf = (Wolf) event.getEntity();
    2. wolf.setCollarColor(DyeColor.LIME);


    7. Setting the contents of books
    This one you also have to just set things by using the methods. For setting the pages of the book, I showed two ways, by using a list, or by setting every page individually.
    Code:java
    1. ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
    2. BookMeta meta = (BookMeta) book.getItemMeta();
    3. meta.setTitle("My really cool book");
    4. meta.setAuthor("KeybordPiano459");
    5. meta.setPage(1, "This will be page one.");
    6. meta.setPage(2, "This will be page two.");
    7. List<String> pages;
    8. pages.add("This will be page one.");
    9. pages.add("This will be page two.");
    10. meta.setPages(pages);
    11. book.setItemMeta(meta);


    8. Setting the enchantment on an enchanted book
    The format for adding an enchantment is-
    meta.addStoredEnchantment(Enchantment cnchantment, int level, boolean ignoreLevelRestriction);
    Code:java
    1. ItemStack ebook = new ItemStack(Material.ENCHANTED_BOOK);
    2. EnchantmentStorageMeta meta = (EnchantmentStorageMeta) ebook.getItemMeta();
    3. meta.addStoredEnchantment(Enchantment.ARROW_FIRE, 5, true);
    4. ebook.setItemMeta(meta);


    9. Setting firework properties
    The list of possible firework events is listed here. Also, there are more things that you can do with the FireworkEffect.builder() thingy. Just remember to have .build() at the end.
    Code:java
    1. ItemStack fwork = new ItemStack(Material.FIREWORK);
    2. FireworkMeta meta = (FireworkMeta) fwork.getItemMeta();
    3. meta.addEffect(FireworkEffect.builder().trail(false).flicker(false).build());
    4. fwork.setItemMeta(meta);



    So... yeah I hope you like this thread, and I also hope that there are less threads about how to do this kind of stuff in the plugin development forum. Again, if you have any suggestions on more 1.4.6 snippets, put them in the comments, and I'll try to add them up here.

    Also, does anyone have an idea for a better title? I don't think the current one is great =/

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

    Infamous Jeezy

    Thanks this is cool.
    Do you know if the leather color changing and skull skins are still accessible?
     
  3. Offline

    KeybordPiano459

    Yes, very. I'll add those later today.

    Infamous Jeezy
    Added :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
    Infamous Jeezy likes this.
  4. Offline

    KeybordPiano459

    I also just added setting the color of a wolf collar :)
     
  5. Offline

    slater96

  6. Offline

    KylexDavis

    Thanks a bunch for this, using the colouring armour thing now! :)
     
  7. Offline

    bossomeness

    So how would I go about putting #1 into the plugin, public static, public void, or what. I also want the armor to be dyed leather armor. How would I do that?
     
  8. Offline

    KeybordPiano459

    What?
     
  9. Offline

    bossomeness

    how would i put it into the plugin? When I copy and paste it into Eclipse, it gives me a bunch of errors, and its not importing anything. Please help, noob with java.
     
  10. Offline

    CeramicTitan

    Then learn java.....
     
    chasechocolate likes this.
  11. Offline

    KeybordPiano459

    bossomeness
    I have been told this when I first started hanging out on these forums, you need to learn java and do projects other than bukkit before you start copying and pasting code while knowing what you're doing :p
     
  12. Offline

    DarkBladee12

    KeybordPiano459 awesome work! I didn't know that there is even an EntityEquipment class^^
     
  13. Offline

    bossomeness

    learning it...
    ok...will do
     
  14. Offline

    NinjaW0lf

    A good method i learned to do this is to use pictures with the code in it, instead of copy-pasta code. :p
    Forces people to type the code.
     
  15. Offline

    KeybordPiano459

    I've never thought of that, but I like my syntax tags :p
     
  16. Offline

    theguynextdoor

    Take a picture of the code in the syntax tags. Could work, wont know until you try it
     
  17. Offline

    KeybordPiano459

    Meh. Too lazy :p
     
  18. Offline

    lucasdidur

    You forgot to add a BookMeta
     
  19. Offline

    KeybordPiano459

    It isn't that I forgot, I asked for suggestions on the bottom of the original post =3
    I'll add it, gimme a minute or two...
     
  20. Offline

    makertim

    1.4.6 has alose Added fireworks

    Is there also support for here?
     
  21. Offline

    KeybordPiano459

    I'll add that too, in a minute or so it should be on the thread :)
     
  22. Offline

    makertim

    Spawners are now also edit able whith plugins, (custom entety editing)
    but that is still nbt i though,,,
     
  23. Offline

    KeybordPiano459

    They were always able to be edited, and that hasn't changed (I'm pretty sure) since the release of 1.4.6, so that won't go on here.
     
    joehot2000 likes this.
  24. Offline

    joehot2000

    Man, i love you, this awnseres almost all the questions i was about to ask on the bukkit forums xD

    edit: "almost all"? i just found the question i thought u had not put.

    So, yeah, man, thanks for awnsering every single one of my questions :D
     
    KeybordPiano459 likes this.
  25. Offline

    bossomeness

    For setting skull skins, how do I make it something other than the player. I tried to use EntityType, but that wasn't compatible with setOwner(). Still learning java, so bear with me.
     
  26. Offline

    KeybordPiano459

    You can't use the SkullMeta for this (up to my knowledge). In the minecraft code, there is still zombie/skeleton/etc skulls, which are accessible with different metadatas. So just do something like this:
    Code:java
    1. @EventHandler
    2. public void onEntityInteract(EntityInteractEvent event) {
    3. Entity entity = event.getEntity();
    4. Block block = entity.getWorld().getBlockAt(entity.getLocation());
    5. block.setType(Material.SKULL);
    6. block.setData(1);
    7. }

    Set the block to whatever block you're using, and set the data corresponding with the mob that you need. You can find the skull metadatas here: http://www.minecraftwiki.net/wiki/Data_values#Heads
     
  27. Offline

    bossomeness

    This looks like just for placing it. I'm using it as a hat. Is there a way to do that? I'm thinking its just something like player.getInventory().setHelmet(block), not really sure though. Thanks for the help!
     
  28. Offline

    C0nsole

    KeybordPiano459
    How do I set the players helmet as a certain player's head? I tried using number 5 like this
    Code:
                        ItemStack skull = new ItemStack(Material.SKULL_ITEM);
                        SkullMeta meta3 = (SkullMeta) skull.getItemMeta();
                        meta3.setOwner("garrett2smart87");
                        skull.setItemMeta(meta3);
                        player.getInventory().setHelmet(skull);
    But that gave me a skeleton skull... Help?
     
  29. Offline

    KeybordPiano459

    I'm pretty sure you need to use Material.SKULL, as that's the actual skull block. I may be wrong, though.
     
  30. Offline

    C0nsole

    Just changing that gives me an error, what else do I need to change in the bit of code? Any idea?
     
Thread Status:
Not open for further replies.

Share This Page