package net.glowstone.io.entity;

import net.glowstone.entity.monster.GlowEnderman;
import net.glowstone.util.nbt.CompoundTag;
import org.bukkit.entity.EntityType;

class EndermanStore extends MonsterStore<GlowEnderman> {

    public EndermanStore() {
        super(GlowEnderman.class, EntityType.ENDERMAN);
    }

    @Override
    public void load(GlowEnderman entity, CompoundTag compound) {
        super.load(entity, compound);
        //TODO: Block
    }

    @Override
    public void save(GlowEnderman entity, CompoundTag tag) {
        super.save(entity, tag);
        //TODO: Block
    }
}

@@ -27,16 +27,56 @@
 ntity;%0A%0A
+import net.glowstone.constants.ItemIds;%0A
 import n
@@ -160,16 +160,44 @@
 undTag;%0A
+import org.bukkit.Material;%0A
 import o
@@ -224,16 +224,57 @@
 ityType;
+%0Aimport org.bukkit.material.MaterialData;
 %0A%0Aclass 
@@ -547,158 +547,1786 @@
     
-//TODO: Block%0A    %7D%0A%0A    @Override%0A    public void save(GlowEnderman entity, CompoundTag tag) %7B%0A        super.save(entity, tag);%0A        //TODO: Block
+MaterialData carried = null;%0A        // Load carried block. May be saved as a String or short ID.%0A        // If the id is 0 or AIR, it is ignored.%0A        if (compound.isShort(%22carried%22)) %7B%0A            short id = compound.getShort(%22carried%22);%0A            Material type = Material.getMaterial(id);%0A            if (type != null && type != Material.AIR) %7B%0A                carried = new MaterialData(type);%0A            %7D%0A        %7D else if (compound.isString(%22carried%22)) %7B%0A            String id = compound.getString(%22carried%22);%0A            if (!id.isEmpty()) %7B%0A                if (!id.contains(%22:%22)) %7B%0A                    // There is no namespace, so prepend the default minecraft: namespace%0A                    id = %22minecraft:%22 + id;%0A                %7D%0A                Material type = ItemIds.getBlock(id);%0A                if (type == null) %7B%0A                    // Not a block, might be an item%0A                    type = ItemIds.getItem(id);%0A                %7D%0A                if (type != null && type != Material.AIR) %7B%0A                    carried = new MaterialData(type);%0A                %7D%0A            %7D%0A        %7D%0A        if (carried != null) %7B%0A            if (compound.isShort(%22carriedData%22)) %7B%0A                carried.setData((byte) compound.getShort(%22carriedData%22));%0A            %7D%0A            entity.setCarriedMaterial(carried);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void save(GlowEnderman entity, CompoundTag tag) %7B%0A        super.save(entity, tag);%0A        MaterialData carried = entity.getCarriedMaterial();%0A        // Save the carried block, if there is one.%0A        if (carried != null && carried.getItemType() != Material.AIR) %7B%0A            tag.putShort(%22carried%22, carried.getItemType().getId());%0A            tag.putShort(%22carriedData%22, carried.getData());%0A        %7D
 %0A   

Store and load Enderman's carried block (#561)