Java Code Examples for com.sk89q.worldedit.entity.BaseEntity#getNbtData()

The following examples show how to use com.sk89q.worldedit.entity.BaseEntity#getNbtData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastWorldEditExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Entity createEntity(final Location loc, final BaseEntity entity) {
    if (entity != null) {
        CompoundTag tag = entity.getNbtData();
        Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
        map.put("Id", new StringTag(entity.getTypeId()));
        ListTag pos = (ListTag) map.get("Pos");
        if (pos != null) {
            List<Tag> posList = ReflectionUtils.getList(pos.getValue());
            posList.set(0, new DoubleTag(loc.getX()));
            posList.set(1, new DoubleTag(loc.getY()));
            posList.set(2, new DoubleTag(loc.getZ()));
        }
        queue.setEntity(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), tag);
    }
    return null;
}
 
Example 2
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    net.minecraft.server.v1_10_R1.Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example 3
Source File: FaweAdapter_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example 4
Source File: FaweAdapter_1_9.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    net.minecraft.server.v1_9_R2.Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example 5
Source File: FaweAdapter_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example 6
Source File: FaweAdapter_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity state) {
    try {
        if (classEntity == null) return null;
        World world = location.getWorld();
        Object nmsWorld = getHandleWorld.invoke(world);

        Object createdEntity = createEntityFromId(state.getTypeId(), nmsWorld);

        if (createdEntity != null) {
            CompoundTag nativeTag = state.getNbtData();
            Map<String, Tag> rawMap = ReflectionUtils.getMap(nativeTag.getValue());
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                rawMap.remove(name);
            }
            if (nativeTag != null) {
                Object tag = fromNative(nativeTag);
                readTagIntoEntity.invoke(createdEntity, tag);
            }

            setLocation.invoke(createdEntity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

            addEntity.invoke(nmsWorld, createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
            return (Entity) getBukkitEntity.invoke(createdEntity);
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return null;
}
 
Example 7
Source File: Spigot_v1_16_R1.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example 8
Source File: Spigot_v1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example 9
Source File: Spigot_v1_14_R4.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example 10
Source File: Spigot_v1_13_R2_2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}