Item and Data Value

Discussion in 'Plugin Development' started by fatmarley, Mar 9, 2012.

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

    fatmarley

    So I am tweaking a pluing to allow for items and DataValues..like 35:5

    This is the code
    Code:
                            if (damage >= Health) {
                            event.getEntity().remove();
                            Location location = event.getEntity().getLocation();
                            String ItemInfo = plugin.getConfig().getString("Drops");
                            String[] itemData = ItemInfo.split(":");
                            if (itemData.length == 3) {
                                int itemID = Integer.parseInt(itemData[0]);
                                byte dataID = Byte.parseByte(itemData[1]);
                                int quantity = Integer.parseInt(itemData[2]);
                                int dcount = 0;
                                ItemStack Alldrops = new ItemStack(itemID, dataID);
                                while (dcount < quantity) {
                                    event.getEntity().getWorld()
                                            .dropItemNaturally(location, Alldrops);
                                    dcount++;}
                            }
                                else if (itemData.length == 2) {
                                int itemID = Integer.parseInt(itemData[0]);
                                int quantity = Integer.parseInt(itemData[1]);
                                int dcount = 0;
                                ItemStack Alldrops = new ItemStack(itemID, dataID);
                                while (dcount < quantity) {
                                    event.getEntity().getWorld()
                                            .dropItemNaturally(location, Alldrops);
                                    dcount++;
                            }
    This is the config


    SpawnRate: 5
    Health: 200
    Drops: '35:7:8'
    FireAttack: false​

    But instead of getting 8 Colored wool, I am getting 8 stacks of 7 white wool. Anyone can offer me some advice/help/shameful remarks?
     
  2. Offline

    nisovin

    The second parameter of dropItemNaturally is quantity. The durability is the third parameter.

    Whoops, totally lied there. I meant that for the ItemStack constructor. So, change the constructor to new ItemStack(itemID, 1, dataID).
     
  3. Offline

    fatmarley

    nisovin but it still wouldnt work, i would just change it to 7 stacks of 8 whitewool.

    The outcome in the config option i posted should be 8 darkgray wool (35:7 * 8)

    But its not working for me...
     
  4. Offline

    nisovin

    You're passing the variable "dataID" as a quantity, but it needs to be passed as a durability. I assure you, this is your problem.

    Edit: Change this line:
    Code:
    ItemStack Alldrops = new ItemStack(itemID, dataID);
    to this:
    Code:
    ItemStack Alldrops = new ItemStack(itemID, 1, dataID);
     
    Benedikt Wüller likes this.
  5. Offline

    fatmarley

    nisovin apologies...i missed your edits.

    nisovin I am trying that now...could you skim one more bit of code?

    I want to be able to set the health of the mob, but currently it isnt working...as far as I can tell I have it set properly..If would use the same config as posted in the topic thread.

    Code:
        @EventHandler
        public void onEntityDamage(EntityDamageEvent event) {
            Entity entity = event.getEntity();
            if ((entity instanceof LivingEntity)) {
                LivingEntity livingentity = (LivingEntity) entity;
                if ((this.plugin.isGiant(livingentity))
                        && ((event instanceof EntityDamageByEntityEvent))) {
                    EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
                    Entity entity2 = sub.getDamager();
                    if ((entity2 instanceof Player)) {
                        int Health = livingentity.getHealth();
                        int damage = event.getDamage();
     
                        int hd = Health - damage;
                        if (hd == 200) {
                            damage++;
                        }
                        if (Health == 200) {
     
                            int sethealth = plugin.getConfig().getInt("Health");
                            livingentity.setHealth(sethealth);
                            Health = sethealth;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
Thread Status:
Not open for further replies.

Share This Page