package net.glowstone.entity.monster;

import net.glowstone.entity.meta.MetadataIndex;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.EntityType;
import org.bukkit.material.MaterialData;

public class GlowEnderman extends GlowMonster implements Enderman {

    private MaterialData carriedMaterial = new MaterialData(Material.AIR);

    public GlowEnderman(Location loc) {
        super(loc, EntityType.ENDERMAN, 40);
        setBoundingBox(0.6, 2.9);
    }

    @Override
    public MaterialData getCarriedMaterial() {
        return carriedMaterial;
    }

    @Override
    public void setCarriedMaterial(MaterialData type) {
        carriedMaterial = type;
        metadata.set(MetadataIndex.ENDERMAN_BLOCK, new Integer(type.getItemTypeId()).shortValue());
    }

    public boolean isScreaming() {
        return metadata.getBoolean(MetadataIndex.ENDERMAN_SCREAMING);
    }

    public void setScreaming(boolean screaming) {
        metadata.set(MetadataIndex.ENDERMAN_SCREAMING, screaming);
    }

    @Override
    protected Sound getHurtSound() {
        return Sound.ENTITY_ENDERMEN_HURT;
    }

    @Override
    protected Sound getDeathSound() {
        return Sound.ENTITY_ENDERMEN_DEATH;
    }

    @Override
    protected Sound getAmbientSound() {
        return Sound.ENTITY_ENDERMEN_AMBIENT;
    }
}

@@ -748,16 +748,48 @@
 = type;%0A
+        if (type == null) %7B%0A    
         
@@ -835,56 +835,298 @@
 CK, 
-new Integer(type.getItemTypeId()).shortValue());
+0);%0A        %7D else %7B%0A            // TODO: store block data. This code appears to be broken (although documented in the protocol):%0A            // int blockId = type.getItemTypeId() %3C%3C 4 %7C type.getData();%0A            metadata.set(MetadataIndex.ENDERMAN_BLOCK, type.getItemTypeId());%0A        %7D
 %0A   

Fix Enderman carried item metadata not being set properly (#562)