Java Code Examples for net.minecraft.entity.Entity#getPassengers()

The following examples show how to use net.minecraft.entity.Entity#getPassengers() . 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: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Check if the Entity <b>rider</b> is among the riders of the other Entity <b>target</b>.
 * This check is done recursively to all the riders of <b>target</b>.
 */
public static boolean isEntityRiddenBy(Entity target, Entity rider)
{
    if (target == null || rider == null)
    {
        return false;
    }

    if (target.isBeingRidden())
    {
        List<Entity> passengers = target.getPassengers();

        for (Entity passenger : passengers)
        {
            if (passenger.equals(rider) || isEntityRiddenBy(passenger, rider))
            {
                return true;
            }
        }
    }

    return false;
}
 
Example 2
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void getAllEntitiesInStack(Entity entity, List<Entity> entities, boolean startFromBottom)
{
    if (startFromBottom)
    {
        entity = getBottomEntity(entity);
    }

    entities.add(entity);

    if (entity.isBeingRidden())
    {
        for (Entity passenger : entity.getPassengers())
        {
            getAllEntitiesInStack(passenger, entities, false);
        }
    }
}
 
Example 3
Source File: EntityUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void spawnEntityAndPassengersInWorld(Entity entity, World world)
{
    if (world.spawnEntity(entity) && entity.isBeingRidden())
    {
        for (Entity passenger : entity.getPassengers())
        {
            passenger.setPosition(entity.posX, entity.posY + entity.getMountedYOffset() + passenger.getYOffset(), entity.posZ);
            spawnEntityAndPassengersInWorld(passenger, world);
        }
    }
}
 
Example 4
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Entity findEntityFromStackByUUID(Entity entityInStack, UUID uuid, boolean startFromBottom)
{
    // TODO useless check?
    if (entityInStack == null)
    {
        return null;
    }

    if (uuid.equals(entityInStack.getUniqueID()))
    {
        return entityInStack;
    }

    if (startFromBottom)
    {
        entityInStack = getBottomEntity(entityInStack);
    }

    if (entityInStack.isBeingRidden())
    {
        List<Entity> passengers = entityInStack.getPassengers();

        for (Entity passenger : passengers)
        {
            if (uuid.equals(passenger.getUniqueID()))
            {
                return passenger;
            }

            entityInStack = findEntityFromStackByUUID(passenger, uuid, false);

            if (entityInStack != null)
            {
                return entityInStack;
            }
        }
    }

    return null;
}
 
Example 5
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean doesEntityStackHavePlayers(Entity entity, boolean startFromBottom)
{
    if (entity instanceof EntityPlayer)
    {
        return true;
    }

    if (startFromBottom)
    {
        entity = getBottomEntity(entity);
    }

    if (entity.isBeingRidden())
    {
        List<Entity> passengers = entity.getPassengers();

        for (Entity passenger : passengers)
        {
            if (passenger instanceof EntityPlayer || doesEntityStackHavePlayers(passenger, false))
            {
                return true;
            }
        }
    }

    return false;
}
 
Example 6
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean doesEntityStackContainEntity(Entity entity, Entity entityInStack, boolean startFromBottom)
{
    if (startFromBottom)
    {
        entityInStack = getBottomEntity(entityInStack);
    }

    if (entity == entityInStack)
    {
        return true;
    }

    if (entityInStack.isBeingRidden())
    {
        List<Entity> passengers = entityInStack.getPassengers();

        for (Entity passenger : passengers)
        {
            if (passenger == entity || doesEntityStackContainEntity(entity, passenger, false))
            {
                return true;
            }
        }
    }

    return false;
}
 
Example 7
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean doesEntityStackHaveBlacklistedEntities(Entity entity, boolean startFromBottom)
{
    if (BlackLists.isEntityBlacklistedForTeleport(entity))
    {
        return true;
    }

    if (startFromBottom)
    {
        entity = getBottomEntity(entity);
    }

    if (entity.isBeingRidden())
    {
        List<Entity> passengers = entity.getPassengers();

        for (Entity passenger : passengers)
        {
            if (BlackLists.isEntityBlacklistedForTeleport(passenger) ||
                doesEntityStackHaveBlacklistedEntities(passenger, false))
            {
                return true;
            }
        }
    }

    return false;
}