Custom item crafting not working [for me]

Discussion in 'Plugin Development' started by AlisiaRose, Mar 13, 2016.

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

    AlisiaRose

    Good morning!

    I was reading up on how to set up custom crafting recipes, so I decided to have a hand at it myself for use in my food plug-in. Similar to Slimefun, the food is represented by player skulls.

    Recipes are initialized like so:
    Code:
    private void initializeRecipes() {
        initializeBentoBoxRecipe();
        logger.info("Initialized Bento Box recipe!"); // debug message
    }
    private void initializeBentoBoxRecipe() {
        ItemStack bentoBox = new ItemStack(SKULL_ITEM);
        initializeBentoMeta(bentoBox);
       
        ShapedRecipe bentoRecipe = new ShapedRecipe(bentoBox);
        bentoRecipe.shape("PCF", "WEW", "WWW");
        bentoRecipe.setIngredient('P', BAKED_POTATO);
        bentoRecipe.setIngredient('C', CARROT);
        bentoRecipe.setIngredient('F', COOKED_FISH);
        bentoRecipe.setIngredient('W', WOOD);
        bentoRecipe.setIngredient('E', EGG);
       
        server.addRecipe(bentoRecipe);
    }
    private void initializeBentoMeta(ItemStack bentoBox) {
        SkullMeta bentoMeta = (SkullMeta) bentoBox.getItemMeta();
        bentoMeta.setOwner(BENTO_BOX);
        bentoMeta.setLore(BENTO_BOX_LORE);
        bentoBox.setItemMeta(bentoMeta);
    }
    where BENTO_BOX and BENTO_BOX_LORE are defined as:
    Code:
    public static final String BENTO_BOX = "a2a2505a-4238-4ed3-bd0d-4313b3dc4b3f";
    public static final List<String> BENTO_BOX_LORE = Arrays.asList("A generic bento box");
    It doesn't seem to want to be crafted :(
    [​IMG]
     
  2. Offline

    Zombie_Striker

    @AlisiaRose
    Are you sure you are using the correct form of "Wood"? Are you sure those methods are being called?
     
  3. Offline

    AlisiaRose

    I was hoping there would be a more specific enum value name, but I only saw WOOD. I assumed WOOD to mean plank, because I couldn't find any enum member called PLANK or OAK_PLANK, and LOG seems to represent unprocessed wood.

    As for the methods being called, initializeRecipes() is indeed called in onEnable().

    Do crafting listeners need to be used to allow players to craft stuff like this, or should simply registering a Recipe allow the crafting of custom items?
     
  4. Offline

    Jetsinsu

    I've been fiddling around with crafting tables. Crafting listeners would be used if you have created a custom item and want to use the "Custom" item to be used to craft something else. If you are crafting an item with ingredients that do not have a custom name, it should work fine. Are you getting any errors on the console.
     
    Last edited: Mar 14, 2016
  5. Offline

    Zombie_Striker

    Please do not bring topics off of the main thread. Any conversation or thread on the bukkit forum should stay on the bukkit forums.

    [Edit] It is actually against the rules to request or post personal information. Rule #4:
    https://bukkit.org/help/terms
     
  6. Offline

    Jetsinsu

    To think that I would still remember that 2 years ago. My brain lied to me :p Thanks for the terms!
     
  7. Offline

    AlisiaRose

    @Jetsinsu

    I do not get any errors. It silently fails. Later, I'll insert a few debug messages and dummy listeners here and there to see what is being called and what isn't.

    I'm wondering if the problem lies at setOwner, for I'm not sure if a skull owner can be set to a UUID instead of a player name.
     
  8. Offline

    Zombie_Striker

    @AlisiaRose
    setOwner requires the name of the player. From there, the server converts the name to the player's UUID and stores the UUID inside the skull meta. (This is why skull names can change if a player changes their username)

    Use SkullMeta.setOwner(Player-name) when you want to set the skull's skin.
     
  9. Offline

    AlisiaRose

    @Zombie_Striker

    This might sound a bit weird, but what if I am given only UUIDs and no name? Would Bukkit#getPlayer(UUID) work here? If not, how can I get a player's name from a UUID string?
     
  10. Offline

    I Al Istannen

    @AlisiaRose
    Bukkit.getOnlinePlayer(UUID) only works if the player is online. You could use Bukkit.getOfflinePlayer(UUID) and then OfflinePlayer.getName(). The getOfflinePlayer method may make a blocking web request, also I am not sure and the javadocs don't say anything. Just try it and if your server freezes, you will know it does :p

    Apart from that, as you seem to know the UUID beforehand, you could use something like namemc.com or the Mojang API to get the name and save that instead of the UUID.
     
  11. Offline

    AlisiaRose

  12. Offline

    I Al Istannen

    @AlisiaRose
    Than the had isn't valid. You will need to find a working one.
     
  13. Offline

    AlisiaRose

    @I Al Istannen
    As I keep looking around https://headmc.net/view/food, none of the heads [so far] seem to have valid UUID's. I came across this whilst looking for an answer, though I am uncertain whether it pertains to my particular issue or not.

    And another thing, I see something like Properties:{textures:[{Value:"..."}]} as part of the command in the Command column at https://headmc.net/view/food. If this is what I think it is (i.e. the head textures encoded as a text string), is it possible to implement custom heads using just this?

    The person for whom I am programming my plug-in reeeeaaaaly likes her bento boxes and other custom food items, so...I want [working] food heads o3o
     
  14. Offline

    Zombie_Striker

    That value represents the skin for the head. This is a datatag that sends the skin based off of the value given and does not send the UUID or name. This is why you were not able to get the head via the UUID.

    You would have to somehow insert this tag onto the head. Give yourself the head by using this command in-game
    command (open)
    /give @p skull 1 3 {display:{Name:"Bento Box"},SkullOwner:{Id:"a2a2505a-4238-4ed3-bd0d-4313b3dc4b3f",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmUzMDUyYzUzNWUxNDU5N2E0MTNlYzMyYjMyYWFmZGQyODY4NmZkYWI2ZWVkNzMwMzBlMWI5NGY3YzM4ZmYifX19"}]}}}
    . After that, get the head into a object that can be saved by using the "Itemstack.serialize()" method. Now you got all the data of the head inside one object that can be saved somewhere (e.g. the config) and whenever you need to get that head, use "ItemStack is = Itemstack.deserialize(serialized object);"
     
    I Al Istannen likes this.
  15. Offline

    mcdorli

    That's actually the texture's URL in base64, decode it and you get http://textures.minecraft.net/texture/fe3052c535e14597a413ec32b32aafdd28686fdab6eed73030e1b94f7c38ff
     
  16. Offline

    AlisiaRose

    @Zombie_Striker

    Thankies! I can see some progress now that I've got the head in-game. I just need to program in the serialization like you said, make it edible, and I will hopefully be done!

    As a wee side question, what information does ItemStack.serialize() not retain?
     
  17. Offline

    Zombie_Striker

    @AlisiaRose
    It contains all data regarding the itemstack. That is how the server adds the items back to your inventory after reloads/restarts. Since there is no data that gets lost after you stop your server, there is no data lost when you serialize it..
     
Thread Status:
Not open for further replies.

Share This Page