Changing the Color of a clay block

Discussion in 'Plugin Development' started by EpicCraft21, Jan 17, 2015.

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

    EpicCraft21

    Is it possible to change the color of an already-placed clay block? With my code:
    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onHit(ProjectileHitEvent e){
            BlockIterator iterator = new BlockIterator(e.getEntity().getWorld(), e.getEntity().getLocation().toVector(), e.getEntity().getVelocity().normalize(), 0.0D, 4);
            Block target = null;
            while (iterator.hasNext()) {
                target = iterator.next();
                if (target.getTypeId() != 0) {
                break;
                }
                }
                
                if (target.getType() == Material.CLAY) {
                    target.getWorld().playEffect(target.getLocation(), Effect.EXTINGUISH, target.getTypeId());
                    target.setType(Material.STAINED_CLAY);
                }
            }   
        }
    which throws a projectile(code not included). When the projectile hits a block, it checks if it is a clay block, and if so, turns it into a blue clay block. The problem is with this part of code:
    Code:
                if (target.getType() == Material.CLAY) {
                    target.getWorld().playEffect(target.getLocation(), Effect.EXTINGUISH, target.getTypeId());
                    target.setType(Material.STAINED_CLAY);
                }
    I can't change the stained clay to BLUE_STAINED_CLAY as it doesn't exist and I can't add DyeColor to the end because .setType() only is applicable for Material.

    So how would I change the clay to a blue stained clay? Thanks :D
     
  2. Offline

    Krizeh

    block.setData((byte) 3);
    Note: I'm not sure why you're coding this as I already made this for the person who requested the paintball gun. :S
     
  3. Offline

    EpicCraft21

    Just for fun, I have a friend who wants this 2.

    And is this the final code, or do I have to add anything to this?
     
  4. Offline

    Skionz

    @EpicCraft21 You simply have to use the setData method on a Block instance.
     
Thread Status:
Not open for further replies.

Share This Page