Mob Item Drop

Discussion in 'Plugin Development' started by Major_Derp, Jan 25, 2013.

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

    Major_Derp

    So i wanted to edit what a mob drops upon death using(event.getDrops().add();). I know how to setup everything, and i am using an integer list, so a user can set values in of items. Everything works, but i noticed you cant enter items with colons like 5:2 5:3...etc. Is there any workaround for this? r any specific way this is done?
     
  2. Offline

    RealDope

    Store a string list instead. Check if the string contains ":". If it does, use String [] newString = string.split(":"); then do something with newString[0] and newString[1]
     
  3. Offline

    Major_Derp

    Here is some code i tried, and it is same as normal. It drops the items on death, but will not spawn the items such as 5:2 and such. I added some messages to show whats happening, but it seems as if the If Statement that checks for the contains doesnt even execute.
    Code:java
    1.  
    2. event.getDrops().clear();
    3. List<String> setdrops = plugin.getConfig().getStringList("General_Zombie_Modifications.Zombie_Drops");
    4. for(String drops : setdrops){
    5. if(drops.contains(":")){
    6. String[] string = drops.split(":");
    7. Bukkit.broadcastMessage("--"+drops);
    8. Bukkit.broadcastMessage("--"+string[0]+" "+string[1]);
    9. }
    10. ItemStack test = new ItemStack(Integer.parseInt(drops));
    11. event.getDrops().add(test);
    12. //Add Specific drops mode
    13. }
    14.  
     
  4. Offline

    raGan.

    Don't store it as string, you would need to calculate it every time. Create new class for it or use ItemStack.
     
  5. Offline

    Major_Derp

    I hav't done much stuff with splitting strings and stuff, so how would i go about doing it?
    Making a class out of it? Or saving it directly to an itemstack? But the first problem is it seems like the If statement checking for the .contains:)) doesnt even execute.
     
  6. Offline

    raGan.

    Code:
    public class ItemAndData {
        public int id = 0;
        public short data = 0;
        
        public ItemAndData(int id, short data) {
            this.id = id;
            this.data = data;
        }
    }
    then
    Code:
    List<ItemAndData> items = new ArrayList<ItemAndData>();
    items.add(new ItemAndData(5, (short) 2));
    items.get(0).id;
    items.get(0).data;
     
  7. Offline

    Major_Derp

    @raGan
    I was messing around with some of that code, but i went back to my default way, and i found a way that works. What was wrong was whenever there was like 5:2 in the config it would come out as 302 in the actual code. For some reason it multiplied the first number by 6 and added 2 at the end, Which i found weird. But i found a way that works, so in the config they would just enter 5,2 and it would give a birch plank. Here is the code:
    Code:
    event.getDrops().clear();
                    List<String> setdrops = plugin.getConfig().getStringList("General_Zombie_Modifications.Zombie_Drops");
                    for(String drops : setdrops){
                        if(drops.contains(",")){
                            String[] string = drops.split(",");
                            ItemStack items = new ItemStack(Integer.parseInt(string[0]), 1, (byte)Integer.parseInt(string[1]));
                            event.getDrops().add(items);
                        }else{
                            ItemStack test = new ItemStack(Integer.parseInt(drops));
                            event.getDrops().add(test);
                        }
                    }
    I used RealDope 's way kind of. But the only thing i cannot get to work is Mob Heads. Whenever i try to drop one on death, it gives this weird looking block, and when i place it it just places a skeleton head. Same with when i want it to drop a zombie head, it gives the same weird looking block that only places a skeleton head. Even when i just put 144 the same thing happens. I even tried dropping the block naturally but nothing. Thanks for all your help too!
     
  8. Offline

    raGan.

    Major_Derp
    Both ways should work, but string solution performs much worse, since it has to be processed every single time a mob dies. It sounds reasonable to store numbers as actual numbers and just use those.

    Heads use NBT tags to determine head type, so you won't be able to do it with just damage value.
     
  9. Offline

    Major_Derp

    Thanks for the help! And i might try the way you suggested once i figure out how to set it up with the config values stuff. Thanks!
     
  10. Offline

    raGan.

    Major_Derp likes this.
Thread Status:
Not open for further replies.

Share This Page