No texture for Custom ItemStack with MaterialData

Discussion in 'Plugin Development' started by OddDuck, Jan 11, 2016.

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

    OddDuck

    Hi, I've create an plugin for my server, which create some new item for the game.

    I use this following code to create (for example) hot water, I KNOW that the data byte 100 do not exist, but I would like to type code for my spigot/bukkit server can load a special texture, for example the texture of original water bukket but with my data, because my items was re-used in other potions and I think I need to use byte.


    Code:
         ItemStack hotwater = new ItemStack(Material.WATER_BUCKET, 1, (short)1, (byte)100);
         ItemMeta meta = hotwater.getItemMeta();
       
         meta.setDisplayName("Eau chaude");
         List<String> lores = new ArrayList<String>();
         lores.add("Eau chaude");
         meta.setLore(lores);
         hotwater.setItemMeta(meta);
         _hotwater = hotwater.clone();
       
         FurnaceRecipe recipe = new FurnaceRecipe(new ItemStack(hotwater), Material.WATER_BUCKET);
         getServer().addRecipe(recipe);
    And after I use for example :

    Code:
            ShapelessRecipe recipe = new ShapelessRecipe(new ItemStack(melange));
            recipe.addIngredient(1, Material.SUGAR);
            recipe.addIngredient(1, new MaterialData(Material.WATER_BUCKET, _hotwater.getData().getData()));
     
  2. Offline

    mcdorli

    Not possible to create custom items with bukkit, learn to mod.
    If you want the custom item, to have a other items texture, then use that item instead (with possibly lores for distinctiom purposes)
     
  3. Offline

    OddDuck

    Ok, so I can't have hot water bukket ans water bukket :(
    If the lores was different, you think my spigot can biew the difference with a simple water bukket ?
    Or may be follow an inventory event to control item ?
     
  4. Offline

    AppleBabies

    @OddDuck Just do this if you want ItemMeta:

    Code:
    ItemStack hotwater = new ItemStack(Material.WATER_BUCKET);
    ItemMeta meta = hotwater.getItemMeta();
    meta.setDisplayName("Eau chaude");
    meta.setLore(Arrays.asList("Eau chaude"));
    hotwater.setItemMeta(meta);
    And then continue your recipe normally. Then, if you want to check if the place item is hot water, do:
    Code:
    @EventHandler
    public void onHotWaterPlace(PlayerInteractEvent e){
    if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equals("Eau chaude")){
                 if (e.getAction() ==  Action.RIGHT_CLICK_BLOCK){
                     //Do what you need
         }
             }
    }
     
  5. Offline

    OddDuck

    Thank you AppleBabies, I understand the process, do you think it's possible to adapt this code for using in a craft_table ?
    I have good try to test on CraftItem and onPlayerCraftPrepare, but each time I just get the final result and not the craft table details. And also, I don't understand the second block about Confuse
     
    Last edited: Jan 11, 2016
  6. Offline

    Zombie_Striker

    Then his signature worked.

    To apply this for for Crafting Recipes, You have to create a ShapedRecipe, add the ingredients and the return item, and then register it (if you do not know how to register your crafting recipe, google it. There are dozens of tutorials there.)
     
  7. Offline

    OddDuck

    Thank you Zombie_Striker... But I have already create my recipes...
    Now my project running, but I would like to search a solution for example to force player to use my "hot water" with sugar and not just a simple "water bukket" with sugar. For the moment, both work, and I try to catch event before the end of Craft, I have try with InvotoryClickEvent, but haven't find when the item was deposit in the workbench event to craft

    Thank you to all, I have finish by find a way to verify the contract between my elements.

    This next code check if I have good elements in my workbench ;)

    Code:
    @EventHandler(priority=EventPriority.HIGH)
        public void onInventoryClick(InventoryClickEvent event) {
            Inventory inv = event.getClickedInventory();
            if (inv.getType() == InventoryType.WORKBENCH) {
                boolean containsSugar = false;
                boolean containsWater = false;
               
                for (int k = 0; k<inv.getSize(); k++) {
                    ItemStack item = inv.getItem(k);
                    if (item != null) {                   
                        if (item.getType() == Material.WATER_BUCKET) {
                            if (item.hasItemMeta()) {
                                if (!item.getItemMeta().getDisplayName().equals("Eau chaude")) {
                                    containsWater = true;
                                }
                            }
                            else {
                                containsWater = true;
                            }
                        }
                        else if (item.getType() == Material.SUGAR) {
                            containsSugar = true;
                        }
                    }
                }
               
                ItemStack currentItem = event.getCurrentItem();
               
                if (containsSugar && containsWater) {
                    if ((currentItem.getType() == Material.MUSHROOM_SOUP) &&
                            currentItem.hasItemMeta()) {
                        if (currentItem.getItemMeta().getDisplayName().equals("Pate sucre")) {
                            Bukkit.broadcastMessage(ChatColor.GREEN + currentItem.getItemMeta().getDisplayName());
                            event.setResult(Result.DENY);
                            return;
                        }
                    }
                }
                event.setResult(Result.DEFAULT);
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 12, 2016
  8. Offline

    Zombie_Striker

    @OddDuck
    Why are you using InventoryClickEvent? Why not: THIS.
     
Thread Status:
Not open for further replies.

Share This Page