Search in sources :

Example 1 with BaseEntity

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);
}
Also used : EntityType(com.sk89q.worldedit.world.entity.EntityType) Extent(com.sk89q.worldedit.extent.Extent) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) List(java.util.List) DoubleTag(com.sk89q.jnbt.DoubleTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) LongTag(com.sk89q.jnbt.LongTag) DoubleTag(com.sk89q.jnbt.DoubleTag) Location(com.sk89q.worldedit.util.Location)

Example 2 with BaseEntity

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;
    }
}
Also used : Identifier(net.minecraft.util.Identifier) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 3 with BaseEntity

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;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BaseEntity(com.sk89q.worldedit.entity.BaseEntity)

Example 4 with BaseEntity

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;
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) StructureBlockEntity(net.minecraft.world.level.block.entity.StructureBlockEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) Nullable(javax.annotation.Nullable)

Example 5 with BaseEntity

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;
    }
}
Also used : BaseEntity(com.sk89q.worldedit.entity.BaseEntity) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) UUID(java.util.UUID) CompoundTag(com.sk89q.jnbt.CompoundTag) Location(com.sk89q.worldedit.util.Location)

Aggregations

BaseEntity (com.sk89q.worldedit.entity.BaseEntity)17 Location (com.sk89q.worldedit.util.Location)11 CompoundTag (com.sk89q.jnbt.CompoundTag)9 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)9 Tag (com.sk89q.jnbt.Tag)8 ListTag (com.sk89q.jnbt.ListTag)7 StringTag (com.sk89q.jnbt.StringTag)6 IntTag (com.sk89q.jnbt.IntTag)5 CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)5 NamedTag (com.sk89q.jnbt.NamedTag)4 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)4 BlockState (com.sk89q.worldedit.world.block.BlockState)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)3 IntArrayTag (com.sk89q.jnbt.IntArrayTag)3 ShortTag (com.sk89q.jnbt.ShortTag)3 Entity (com.sk89q.worldedit.entity.Entity)3 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)3