Util Hex Utils - ItemStack chain builder, custom-textured skulls and more!

Discussion in 'Resources' started by TigerHix, Dec 28, 2014.

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

    TigerHix

    2015 is coming, so I decided to share some util classes as a tiny new year gift :D Some of the techniques and/or methods used are from public libraries and resources.

    https://github.com/TigerHix/Hex-Utils

    First the ItemStack chain builder. The traditional way is like this:

    Code:
    ItemStack item = new ItemStack(Material.DIAMOND_SWORD, 1);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(ChatColor.translateFormattingCodes('&', "&b&lOMFG SWORD");
    List<String> lore = Arrays.asList("\"This sword is awesome.\"", "said Chuck Norris.");
    meta.setLore(lore);
    item.setItemMeta(meta);
    item.addEnchantment(Enchantment.DAMAGE_ALL, 2);
    player.getInventory().addItem(item);
    With Items.java, it is like this:

    Code:
    ItemStack item = Items.builder()
            .setMaterial(Material.DIAMOND_SWORD)
            .setName("&b&lOMFG SWORD"
            .addLore("\"This sword is awesome.\"", "said Chuck Norris.")
            .addEnchantment(Enchantment.DAMAGE_ALL, 2)
            .build();
    player.getInventory().addItem(item);
    Want to edit something about an item? Just use Items.editor(ItemStack item), which will set the item ItemStack as the base to operate.

    There's also a BookBuilder which has a similar chain-builder design. Try it yourself ;)

    Second the Skulls. Well, I just saw a post about skullMeta.setOwner awhile ago.. anyway, why not use the Skulls.java to create skulls?

    Code:
    ItemStack skull = Skulls.CHEST; // Built-in skulls
    ItemStack skull2 = Skulls.getPlayerSkull("TigerHix"); // Get player skull
    ItemStack skull3 = Skulls.getCustomSkull("http://i.imgur.com/w9HuNGl.png"); // Get custom-textured skull
    Here's a look of how custom skulls look like:

    [​IMG]

    Lastly Reflections.java made by @Comprenix. I'm not sure is it alright to include the class inside the utils, but this class is really handy. Seen many code like this:

    Code:
    try {
            String name = "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + "." + "NMSClassHere";
            Class<?> cl = Class.forName(name):
            Field f = cl.getDeclaredField("FieldHere");
            f.setAccessible(true);
            f.set(Object, Value);
    } catch (Throwable t) {
            t.printStackTrace();
    }
    
    With Reflections.java:

    Code:
    try {
            Reflections
                    .getMinecraftClass("NMSClassHere")
                    .getDeclaredField("FieldHere")
                    .set(Object, Value);
    } catch (Throwable t) {
            t.printStackTrace();
    }
    Anyway, there are more methods out there that you might find useful, just browse them yourself :p

    Wish you all a happy new year!
     
    Last edited: Dec 28, 2014
  2. Offline

    ChipDev

    Love it! This is the one stop skull place!!
    :D
    Oh and yes, there is already a item builder.
    ONE LAST THING:
    really, what are the names to those skulls ;P I need them!
     
    Last edited: Dec 28, 2014
  3. Offline

    TigerHix

    @ChipDev Uhm.. read the source code (Skulls.java) yourself?
     
    Shortninja66 likes this.
  4. Offline

    ChipDev

    ARROW_LEFT("MHF_ArrowLeft"),
    ARROW_RIGHT("MHF_ArrowRight"),
    ARROW_UP("MHF_ArrowUp"),
    ARROW_DOWN("MHF_ArrowDown"),
    QUESTION("MHF_Question"),
    EXCLAMATION("MHF_Exclamation"),
    CAMERA("FHG_Cam"),
    ZOMBIE_PIGMAN("MHF_PigZombie"),
    PIG("MHF_Pig"),
    SHEEP("MHF_Sheep"),
    BLAZE("MHF_Blaze"),
    CHICKEN("MHF_Chicken"),
    COW("MHF_Cow"),
    SLIME("MHF_Slime"),
    SPIDER("MHF_Spider"),
    SQUID("MHF_Squid"),
    VILLAGER("MHF_Villager"),
    OCELOT("MHF_Ocelot"),
    HEROBRINE("MHF_Herobrine"),
    LAVA_SLIME("MHF_LavaSlime"),
    MOOSHROOM("MHF_MushroomCow"),
    GOLEM("MHF_Golem"),
    GHAST("MHF_Ghast"),
    ENDERMAN("MHF_Enderman"),
    CAVE_SPIDER("MHF_CaveSpider"),
    CACTUS("MHF_Cactus"),
    CAKE("MHF_Cake"),
    CHEST("MHF_Chest"),
    MELON("MHF_Melon"),
    LOG("MHF_OakLog"),
    PUMPKIN("MHF_Pumpkin"),
    TNT("MHF_TNT"),
    DYNAMITE("MHF_TNT2");
    I mean the ones in the picture.
     
  5. Offline

    TigerHix

    @ChipDev Those are custom skulls using Skulls.getCustomSkull(String url). Javadocs are provided in the source so check it out ;)
     
  6. Offline

    ChipDev

    What are the names/images of the heads? I know all that!
     
  7. Offline

    Phasesaber

    @ChipDev They're TF2 classes. Pretty cool idea to use them in a class selection!

    Why not put an Enum within the skull class, instead of making the whole class an Enum?

    And does the
    Code:
    com.mojang.xyz
    need CraftBukkit? (Haven't done this in a while :p)
     
    Last edited: Jan 17, 2015
  8. Offline

    gimic9912

    I got a pretty stupid question, so here is goes...

    So i don't know what i am doing wrong?

    Code:
                    ItemStack skull2 = APIs.Skull.getPlayerSkull("TigerHix");
                    ItemStack skull3 = APIs.Skull.getCustomSkull("http://i.imgur.com/w9HuNGl.png");
                   
                    ItemStack Hero = skull2;
                    ItemMeta HeroMeta = Hero.getItemMeta();
     
  9. Offline

    MCMatters

    Code:
    ItemStack Hero = APIs.Skull.getPlayerSkull("TigerHix");
    ItemMeta HeroMeta = Hero.getItemMeta();
     
  10. Offline

    gimic9912

    That has the same effects btw,

    i figured it out, but it only works in some versions

    Is there something i am missing?
     
  11. Offline

    mrCookieSlime Retired Staff

    No, it is just because HexUtils' Skull API seems to be built upon an Security Exploit that has been fixed already a while ago. It may still work in old Versions but Fixed Security Exploits are a good reason to update!
     
Thread Status:
Not open for further replies.

Share This Page