some minor refactoring

This commit is contained in:
Jesse Boyd
2019-08-18 02:09:09 +01:00
parent d1af07b6ae
commit d434dfcfdd
64 changed files with 1892 additions and 812 deletions

View File

@ -22,8 +22,12 @@ package com.sk89q.worldedit.entity;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NbtValued;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import javax.annotation.Nullable;
@ -56,6 +60,10 @@ public class BaseEntity implements NbtValued {
setNbtData(nbtData);
}
public BaseEntity(CompoundTag tag) {
this(EntityTypes.parse(tag.getString("Id")), tag);
}
/**
* Create a new base entity with no NBT data.
*
@ -76,6 +84,17 @@ public class BaseEntity implements NbtValued {
setNbtData(other.getNbtData());
}
public Location getLocation(Extent extent) {
ListTag posTag = nbtData.getListTag("Pos");
ListTag rotTag = nbtData.getListTag("Rotation");
double x = posTag.getDouble(0);
double y = posTag.getDouble(1);
double z = posTag.getDouble(2);
float yaw = rotTag.getFloat(0);
float pitch = rotTag.getFloat(1);
return new Location(extent, x, y, z, yaw, pitch);
}
@Override
public boolean hasNbtData() {
return true;