getOwner().add(Health.class).setSpawnHealth(DEFAULT_HEALTH);
}
super.onAttached();
// Add metadata for the Horse
MetadataComponent metadata = getOwner().add(MetadataComponent.class);
//TODO: Implement tame/saddle/bred/chest/etc. for index 16 (see protocol page)
metadata.addMeta(new Metadata<Integer>(Metadata.TYPE_INT, 16) {
@Override
public Integer getValue() {
int value = 0;
if (isTamed()) {
value |= 2;
}
if (getInventory().hasSaddle()) {
value |= 4;
}
/*
TODO: Check if inventory is setup to have a chest or not.
if (hasChest()) {
value |= 8;
}
TODO: Check if horse has already bred.
if (hasBred()) {
value |= 16;
}
*/
if (isEatingBlocking()) {
value |= 32;
}
/*
TODO: rearing
if (isRearing() {
value |= 64;
}
*/
return value;
}
@Override
public void setValue(Integer value) {
// TODO Auto-generated method stub
}
});
// Metadata for the type ID of the Horse
metadata.addMeta(Metadata.TYPE_BYTE, TYPE_INDEX, VanillaData.ENTITY_CATEGORY);
// Metadata for variant and marking
metadata.addMeta(new Metadata<Integer>(Metadata.TYPE_INT, VARIANT_INDEX) {
@Override
public Integer getValue() {
return (getVariant().getVariantId() & 0x00ff) | (getMarking().getMarkingId() & 0xff00);
}
@Override
public void setValue(Integer value) {
int intValue = value.intValue();
setVariantAndMarking(Variant.fromId(intValue & 0x00ff), Marking.fromId(intValue & 0xff00));
}
});
// Metadata for the owner name of the Horse
metadata.addMeta(OWNER_INDEX, Metadata.TYPE_STRING, VanillaData.OWNER);
// Metadata for the currently equipped Armor
metadata.addMeta(new Metadata<Integer>(Metadata.TYPE_INT, ARMOR_TYPE_INDEX) {
@Override
public Integer getValue() {
return getHorseTypeId() > 0 ? 0 : getInventory().getArmorTypeId();
}