Search in sources :

Example 1 with SimpleNBTDataHolder

use of org.spongepowered.common.data.holder.SimpleNBTDataHolder in project SpongeCommon by SpongePowered.

the class SpongeEntitySnapshotBuilder method build.

@Override
public EntitySnapshot build() {
    Objects.requireNonNull(this.worldKey);
    Objects.requireNonNull(this.position);
    Objects.requireNonNull(this.rotation);
    Objects.requireNonNull(this.scale);
    Objects.requireNonNull(this.entityType);
    final EntitySnapshot snapshot = new SpongeEntitySnapshot(this);
    // Write the the manipulator values to NBT
    if (this.manipulator != null && !this.manipulator.getKeys().isEmpty()) {
        if (this.compound == null) {
            this.compound = new CompoundTag();
        }
        final SimpleNBTDataHolder dataHolder = new SimpleNBTDataHolder(this.compound, NBTDataTypes.ENTITY);
        dataHolder.copyFrom(this.manipulator);
        this.compound = dataHolder.data$getCompound();
        // If there was no data remove the compound again
        if (this.compound.isEmpty()) {
            this.compound = null;
        }
    }
    return snapshot;
}
Also used : EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) SimpleNBTDataHolder(org.spongepowered.common.data.holder.SimpleNBTDataHolder) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

CompoundTag (net.minecraft.nbt.CompoundTag)1 EntitySnapshot (org.spongepowered.api.entity.EntitySnapshot)1 SimpleNBTDataHolder (org.spongepowered.common.data.holder.SimpleNBTDataHolder)1