Search in sources :

Example 1 with UuidUtils

use of net.glowstone.util.UuidUtils in project Glowstone by GlowstoneMC.

the class EntityStore method load.

// For information on the NBT tags loaded here and elsewhere:
// http://minecraft.gamepedia.com/Chunk_format#Entity_Format
// todo: the following tags
// - bool "Invulnerable"
// - int "PortalCooldown"
/**
 * Load data into an existing entity of the appropriate type from the given compound tag.
 *
 * @param entity The target entity.
 * @param tag    The entity's tag.
 */
public void load(T entity, CompoundTag tag) {
    // id, world, and location are handled by EntityStore
    // base stuff for all entities is here:
    tag.readDoubleList("Motion", list -> entity.setVelocity(NbtSerialization.listToVector(list)));
    tag.readFloat("FallDistance", entity::setFallDistance);
    tag.readShort("Fire", entity::setFireTicks);
    tag.readBoolean("OnGround", entity::setOnGround);
    tag.readBooleanNegated("NoGravity", entity::setGravity);
    tag.readBoolean("Silent", entity::setSilent);
    tag.readBoolean("Glowing", entity::setGlowing);
    tag.readBoolean("Invulnerable", entity::setInvulnerable);
    tag.readStringList("Tags", list -> {
        entity.getCustomTags().clear();
        entity.getCustomTags().addAll(list);
    });
    tag.readInt("PortalCooldown", entity::setPortalCooldown);
    // TODO: Refactor using JDK9's Optional.or() once JDK8 support ends
    Optional.ofNullable(tag.tryGetUniqueId("UUIDMost", "UUIDLeast").orElseGet(() -> tag.tryGetString("UUID").map(UuidUtils::fromString).orElse(null))).ifPresent(entity::setUniqueId);
    tag.iterateCompoundList("Passengers", entityTag -> {
        Entity passenger = loadPassenger(entity, entityTag);
        if (passenger != null) {
            entity.addPassenger(passenger);
        }
    });
}
Also used : Entity(org.bukkit.entity.Entity) GlowEntity(net.glowstone.entity.GlowEntity) UuidUtils(net.glowstone.util.UuidUtils)

Aggregations

GlowEntity (net.glowstone.entity.GlowEntity)1 UuidUtils (net.glowstone.util.UuidUtils)1 Entity (org.bukkit.entity.Entity)1