Java Code Examples for net.minecraft.entity.EntityLivingBase#dismountRidingEntity()

The following examples show how to use net.minecraft.entity.EntityLivingBase#dismountRidingEntity() . 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: ItemLivingManipulator.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult storeEntity(ItemStack containerStack, EntityLivingBase livingBase, EntityPlayer player)
{
    ItemStack moduleStack = this.getSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC);

    if (moduleStack.isEmpty() || this.canStoreEntity(livingBase) == false)
    {
        return EnumActionResult.PASS;
    }

    // Dismount the entity from its rider and the entity it's riding, if any
    livingBase.dismountRidingEntity();
    livingBase.removePassengers();

    NBTTagCompound nbtEntity = new NBTTagCompound();

    if (livingBase.writeToNBTOptional(nbtEntity) == false)
    {
        return EnumActionResult.FAIL;
    }

    String str = EntityList.getEntityString(livingBase);

    if (str != null)
    {
        nbtEntity.setString("EntityString", str);
    }

    // Store the player's yaw rotation, for applying a relative rotation to the entity's rotation upon release
    nbtEntity.setFloat("playerYaw", player.rotationYaw);

    NBTTagList tagList = NBTUtils.getTagList(moduleStack, WRAPPER_TAG_NAME, "Entities", Constants.NBT.TAG_COMPOUND, true);

    tagList = NBTUtils.insertToTagList(tagList, nbtEntity, NBTUtils.getByte(moduleStack, WRAPPER_TAG_NAME, "Current"));
    NBTUtils.setTagList(moduleStack, WRAPPER_TAG_NAME, "Entities", tagList);

    this.setSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC, moduleStack);

    livingBase.isDead = true;

    return EnumActionResult.SUCCESS;
}