use of com.sk89q.worldedit.entity.BaseEntity in project FastAsyncWorldEdit by IntellectualSites.
the class MutableEntityChange method create.
public void create(UndoContext context) {
Map<String, Tag> map = tag.getValue();
Tag posTag = map.get("Pos");
if (posTag == null) {
LOGGER.warn("Missing pos tag: {}", tag);
return;
}
List<DoubleTag> pos = (List<DoubleTag>) posTag.getValue();
double x = pos.get(0).getValue();
double y = pos.get(1).getValue();
double z = pos.get(2).getValue();
Extent extent = context.getExtent();
Location location = new Location(extent, x, y, z, 0, 0);
String id = tag.getString("Id");
EntityType type = EntityTypes.parse(id);
BaseEntity entity = new BaseEntity(type, tag);
context.getExtent().createEntity(location, entity);
}
use of com.sk89q.worldedit.entity.BaseEntity in project FastAsyncWorldEdit by IntellectualSites.
the class FabricEntity method getState.
@Override
public BaseEntity getState() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
Identifier id = Registry.ENTITY_TYPE.getId(entity.getType());
CompoundTag tag = new CompoundTag();
entity.toTag(tag);
return new BaseEntity(EntityTypes.get(id.toString()), NBTConverter.fromNative(tag));
} else {
return null;
}
}
use of com.sk89q.worldedit.entity.BaseEntity in project FastAsyncWorldEdit by IntellectualSites.
the class ForgeEntity method getState.
@Override
public BaseEntity getState() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
ResourceLocation id = entity.getType().getRegistryName();
if (id != null) {
CompoundNBT tag = new CompoundNBT();
entity.writeWithoutTypeId(tag);
return new BaseEntity(EntityTypes.get(id.toString()), NBTConverter.fromNative(tag));
} else {
return null;
}
} else {
return null;
}
}
use of com.sk89q.worldedit.entity.BaseEntity in project FastAsyncWorldEdit by IntellectualSites.
the class PaperweightAdapter method createEntity.
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
checkNotNull(location);
checkNotNull(state);
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
ServerLevel worldServer = craftWorld.getHandle();
Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());
if (createdEntity != null) {
CompoundBinaryTag nativeTag = state.getNbt();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeBinary(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
readTagIntoEntity(tag, createdEntity);
}
createdEntity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.addFreshEntity(createdEntity, SpawnReason.CUSTOM);
return createdEntity.getBukkitEntity();
} else {
return null;
}
}
use of com.sk89q.worldedit.entity.BaseEntity in project FastAsyncWorldEdit by IntellectualSites.
the class ExtentEntityCopy method apply.
@Override
public boolean apply(Entity entity) throws WorldEditException {
BaseEntity state = entity.getState();
// FAWE start - Don't copy players
if (state != null && state.getType() != EntityTypes.PLAYER) {
// FAWE end
Location newLocation;
Location location = entity.getLocation();
// If the entity has stored the location in the NBT data, we use that location
CompoundTag tag = state.getNbtData();
boolean hasTilePosition = tag != null && tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ");
if (hasTilePosition) {
location = location.setPosition(Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")).add(0.5, 0.5, 0.5));
}
Vector3 pivot = from.round().add(0.5, 0.5, 0.5);
Vector3 newPosition = transform.apply(location.toVector().subtract(pivot));
if (hasTilePosition) {
newPosition = newPosition.subtract(0.5, 0.5, 0.5);
}
Vector3 newDirection;
newDirection = transform.isIdentity() ? entity.getLocation().getDirection() : transform.apply(location.getDirection()).subtract(transform.apply(Vector3.ZERO)).normalize();
newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection);
// Some entities store their position data in NBT
state = transformNbtData(state);
boolean success = destination.createEntity(newLocation, state) != null;
// Remove
if (isRemoving() && success) {
// FAWE start
UUID uuid = null;
if (tag.containsKey("UUID")) {
int[] arr = tag.getIntArray("UUID");
uuid = new UUID((long) arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long) arr[2] << 32 | (arr[3] & 0xFFFFFFFFL));
} else if (tag.containsKey("UUIDMost")) {
uuid = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast"));
} else if (tag.containsKey("PersistentIDMSB")) {
uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB"));
}
if (uuid != null) {
if (source != null) {
source.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid);
} else {
// FAWE end
entity.remove();
}
}
}
return success;
} else {
return false;
}
}
Aggregations